show clean balance

This commit is contained in:
callebtc
2022-10-30 00:18:00 +02:00
parent 28510d5518
commit e5b18b4f3b
2 changed files with 19 additions and 7 deletions

View File

@@ -160,9 +160,17 @@ async def pay(ctx, invoice: str, yes: bool):
@cli.command("balance", help="Balance.") @cli.command("balance", help="Balance.")
@click.option(
"--verbose",
"-v",
default=False,
is_flag=True,
help="Show pending tokens as well.",
type=bool,
)
@click.pass_context @click.pass_context
@coro @coro
async def balance(ctx): async def balance(ctx, verbose):
wallet: Wallet = ctx.obj["WALLET"] wallet: Wallet = ctx.obj["WALLET"]
keyset_balances = wallet.balance_per_keyset() keyset_balances = wallet.balance_per_keyset()
if len(keyset_balances) > 1: if len(keyset_balances) > 1:
@@ -173,9 +181,12 @@ async def balance(ctx):
f"Keyset: {k or 'undefined'} Balance: {v['balance']} sat (available: {v['available']} sat)" f"Keyset: {k or 'undefined'} Balance: {v['balance']} sat (available: {v['available']} sat)"
) )
print("") print("")
if verbose:
print( print(
f"Balance: {wallet.balance} sat (available: {wallet.available_balance} sat in {len([p for p in wallet.proofs if not p.reserved])} tokens)" f"Balance: {wallet.balance} sat (available: {wallet.available_balance} sat in {len([p for p in wallet.proofs if not p.reserved])} tokens)"
) )
else:
print(f"Balance: {wallet.available_balance} sat")
@cli.command("send", help="Send coins.") @cli.command("send", help="Send coins.")

View File

@@ -552,9 +552,10 @@ class Wallet(LedgerAPI):
return sum_proofs([p for p in self.proofs if not p.reserved]) return sum_proofs([p for p in self.proofs if not p.reserved])
def status(self): def status(self):
print( # print(
f"Balance: {self.balance} sat (available: {self.available_balance} sat in {len([p for p in self.proofs if not p.reserved])} tokens)" # f"Balance: {self.balance} sat (available: {self.available_balance} sat in {len([p for p in self.proofs if not p.reserved])} tokens)"
) # )
print(f"Balance: {self.available_balance} sat")
def balance_per_keyset(self): def balance_per_keyset(self):
return { return {