diff --git a/silkaj/money.py b/silkaj/money.py index 4eef77e39470e5a6e70efe5732aca3a8c4524076..a5646ef6e2a32bab2f9aeef3a60944e37ef6c371 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -20,15 +20,14 @@ from typing import List, Tuple, Union from click import Context, argument, command, echo, pass_context from duniterpy.api.bma import blockchain, tx from duniterpy.documents.transaction import InputSource, OutputSource -from tabulate import tabulate +from silkaj import tui from silkaj import wot_tools as wt from silkaj.auth import auth_method, has_auth_method from silkaj.blockchain_tools import get_head_block from silkaj.crypto_tools import is_pubkey_and_check from silkaj.network_tools import client_instance from silkaj.tools import get_currency_symbol -from silkaj.tui import display_amount, gen_pubkey_checksum @command("balance", help="Get wallet balance") @@ -52,7 +51,7 @@ def cmd_amount(ctx: Context, pubkeys: str) -> None: print(f"ERROR: pubkey {pubkey} has a wrong format") if pubkey in pubkeys_list: sys.exit( - f"ERROR: pubkey {gen_pubkey_checksum(pubkey)} was specified many times" + f"ERROR: pubkey {tui.gen_pubkey_checksum(pubkey)} was specified many times" ) pubkeys_list.append(pubkey) if wrong_pubkeys: @@ -87,7 +86,7 @@ def show_amount_from_pubkey(label: str, inputs_balance: List[int]) -> None: # if `pubkey` is a pubkey, get pubkey:checksum and uid if label != "Total": member = wt.is_member(label) - label = gen_pubkey_checksum(label) + label = tui.gen_pubkey_checksum(label) # display balance table display = [] display.append(["Balance of pubkey", label]) @@ -96,22 +95,29 @@ def show_amount_from_pubkey(label: str, inputs_balance: List[int]) -> None: display.append(["User identifier", member["uid"]]) if totalAmountInput - balance != 0: - display_amount(display, "Blockchain", balance, ud_value, currency_symbol) - display_amount( + tui.display_amount(display, "Blockchain", balance, ud_value, currency_symbol) + tui.display_amount( display, "Pending transaction", (totalAmountInput - balance), ud_value, currency_symbol, ) - display_amount(display, "Total amount", totalAmountInput, ud_value, currency_symbol) + tui.display_amount( + display, "Total amount", totalAmountInput, ud_value, currency_symbol + ) display.append( [ "Total relative to M/N", f"{round(totalAmountInput / average, 2)} x M/N", ] ) - echo(tabulate(display, tablefmt="fancy_grid")) + + # table = tui.create_table() + # echo(tui.vert_table(table, display)) + table = tui.Table() + table.fill_rows(display) + echo(table.draw()) def get_average() -> int: diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index 5dd7e168252a26c38be718fc5ef200fc844033d1..2df18f643728bb772ff1a9feee5deb2d439db410 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -50,9 +50,10 @@ def test_balance(): silkaj + ["--gtest", "balance", "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj"] ).decode() assert ( - "│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj:EyF │" + "│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj: │" in output ) + assert "EyF" in output assert "│ Total amount (unit|relative) │" in output assert "UD ĞTest" in output assert "Total relative to M/N" in output