Skip to content
Snippets Groups Projects
Commit 5ea02661 authored by matograine's avatar matograine
Browse files

[enh] #255 modify Balance display

* change the balance display to a table
* use display_amount() and tabulate in the balance display
* mod tests_end_to_end.py to match new display
parent 87132337
No related merge requests found
Pipeline #7610 failed
......@@ -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():
......
......@@ -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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment