diff --git a/silkaj/money.py b/silkaj/money.py index 58ae9d2614fd059132d4f1f2cb00fdc6620de25e..1c178800a896279d702e49ddfa795f1a2725ea71 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -15,12 +15,15 @@ You should have received a copy of the GNU Affero General Public License along with Silkaj. If not, see <https://www.gnu.org/licenses/>. """ -from click import command, argument, pass_context +from click import command, argument, pass_context, echo +from tabulate import tabulate from silkaj.network_tools import ClientInstance, HeadBlock from silkaj.tools import CurrencySymbol, message_exit, coroutine from silkaj.auth import auth_method from silkaj.wot import check_public_key +from silkaj.tui import display_amount + from duniterpy.api.bma import tx, blockchain from duniterpy.documents.transaction import InputSource @@ -64,45 +67,32 @@ async def show_amount_from_pubkey(pubkey, value): currency_symbol = await CurrencySymbol().symbol ud_value = await UDValue().ud_value average, monetary_mass = await get_average() + # display balance table + display = list() + display.append(["Balance of pubkey", pubkey]) if totalAmountInput - amount != 0: - print("Blockchain:") - print("-----------") - print("Relative =", round(amount / ud_value, 2), "UD", currency_symbol) - print("Quantitative =", round(amount / 100, 2), currency_symbol + "\n") - - print("Pending Transaction:") - print("--------------------") - print( - "Relative =", - round((totalAmountInput - amount) / ud_value, 2), - "UD", + display_amount(display, "Blockchain", amount, ud_value, currency_symbol) + display_amount( + display, + "Pending transaction", + (totalAmountInput - amount), + ud_value, currency_symbol, ) - print( - "Quantitative =", - round((totalAmountInput - amount) / 100, 2), - currency_symbol + "\n", - ) - - print("Total amount of: " + pubkey) - print("----------------------------------------------------------------") - print( - "Total Relative =", - round(totalAmountInput / ud_value, 2), - "UD", - currency_symbol, - ) - print("Total Quantitative =", round(totalAmountInput / 100, 2), currency_symbol) - print( - "Total Relative to average money share =", - round(totalAmountInput / average, 2), - "× M/N", + display_amount(display, "Total amount", totalAmountInput, ud_value, currency_symbol) + display.append( + [ + "Total relative to M/N", + "{0} x M/N".format(round(totalAmountInput / average, 2)), + ] ) - print( - "Total Relative to monetary mass =", - round((totalAmountInput / monetary_mass) * 100, 3), - "% M" + "\n", + display.append( + [ + "Total relative to M", + "{0} % M".format(round(totalAmountInput / monetary_mass, 2)), + ] ) + echo(tabulate(display, tablefmt="fancy_grid")) async def get_average(): diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index 1ea84e37195cacfe7d855b6ef81983fa39152c24..d673a35872678d6dfe6c661111791ee2644f8209 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -28,13 +28,16 @@ def test_id(): assert "D7CYHJXjaH4j7zRdWngUbsURPnSnjsCYtvo6f8dvW3C" in output -def test_amount(): +def test_balance(): """tests 'silkaj amount' command on gtest""" output = check_output( silkaj + ["--gtest", "balance", "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj"] ).decode() - assert "Total amount of: 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj" in output - assert "Total Relative =" in output + assert ( + "│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj │" + in output + ) + assert "│ Total amount (unit|relative) │" in output assert "UD ĞTest" in output - assert "Total Quantitative =" in output + assert "Total relative to M/N" in output