mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-02-03 15:54:20 +01:00
Fix: Mints are sorted by balance which can suddenly change (#145)
* Sort mints by URL when displaying balances * Use mint with largest balance as default when spending * Make format * Display mint with largest balance in prompt
This commit is contained in:
@@ -134,17 +134,23 @@ async def get_mint_wallet(ctx: Context):
|
||||
if len(mint_balances) > 1:
|
||||
await print_mint_balances(ctx, wallet, show_mints=True)
|
||||
|
||||
mint_nr_str = (
|
||||
input(f"Select mint [1-{len(mint_balances)}, press enter for default 1]: ")
|
||||
or "1"
|
||||
)
|
||||
if not mint_nr_str.isdigit():
|
||||
raise Exception("invalid input.")
|
||||
mint_nr = int(mint_nr_str)
|
||||
else:
|
||||
mint_nr = 1
|
||||
url_max = max(mint_balances, key=lambda v: mint_balances[v]["available"])
|
||||
nr_max = list(mint_balances).index(url_max) + 1
|
||||
|
||||
mint_url = list(mint_balances.keys())[mint_nr - 1]
|
||||
mint_nr_str = input(
|
||||
f"Select mint [1-{len(mint_balances)}] or "
|
||||
f"press enter for mint with largest balance (Mint {nr_max}): "
|
||||
)
|
||||
if not mint_nr_str: # largest balance
|
||||
mint_url = url_max
|
||||
elif mint_nr_str.isdigit() and int(mint_nr_str) <= len(
|
||||
mint_balances
|
||||
): # specific mint
|
||||
mint_url = list(mint_balances.keys())[int(mint_nr_str) - 1]
|
||||
else:
|
||||
raise Exception("invalid input.")
|
||||
else:
|
||||
mint_url = list(mint_balances.keys())[0]
|
||||
|
||||
# load this mint_url into a wallet
|
||||
mint_wallet = Wallet(
|
||||
|
||||
@@ -843,4 +843,4 @@ class Wallet(LedgerAPI):
|
||||
}
|
||||
for key, proofs in balances.items()
|
||||
}
|
||||
return dict(sorted(balances_return.items(), key=lambda item: item[1]["available"], reverse=True)) # type: ignore
|
||||
return dict(sorted(balances_return.items(), key=lambda item: item[0])) # type: ignore
|
||||
|
||||
Reference in New Issue
Block a user