diff --git a/handler/ux/commands.py b/handler/ux/commands.py index 9521bb4..7cbe41e 100644 --- a/handler/ux/commands.py +++ b/handler/ux/commands.py @@ -238,21 +238,26 @@ class GenericCommands(object): msg(dumps(rtrn)) class wallet(object): + @staticmethod + def got_wallet(wallet_output, msg, asset): + if not wallet_output["success"]: + msg(f"Error getting {asset} wallet details.") + return + if not wallet_output["response"]: + msg(f"Error getting {asset} wallet details.") + return + balance = wallet_output["response"]["data"]["total"]["balance"] + msg(f"{asset} wallet balance: {balance}") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux, xmr, caller): if xmr: rtrn_xmr = caller.wallet_balance_xmr() - if not rtrn_xmr["success"]: - msg("Error getting XMR wallet details.") - return - balance_xmr = rtrn_xmr["response"]["data"]["total"]["balance"] - msg(f"XMR wallet balance: {balance_xmr}") - rtrn_btc = caller.wallet_balance() - if not rtrn_btc["success"]: - msg("Error getting BTC wallet details.") - return - balance_btc = rtrn_btc["response"]["data"]["total"]["balance"] - msg(f"BTC wallet balance: {balance_btc}") + rtrn_xmr.addCallback(GenericCommands.wallet.got_wallet, msg, "XMR") + + else: + rtrn_btc = caller.wallet_balance() + rtrn_btc.addCallback(GenericCommands.wallet.got_wallet, msg, "BTC") class IRCCommands(object): @@ -396,13 +401,20 @@ class IRCCommands(object): helptext = "Get total account balance from Sinks and Agora." @staticmethod - def run(cmd, spl, length, authed, msg, agora, tx, ux): - totals_all = tx.money.get_total() - totals = totals_all[0] - wallets = totals_all[1] + def got_total(total_output, msg): + if not total_output: + msg("Error getting total output") + return + totals = total_output[0] + wallets = total_output[1] msg(f"Totals: SEK: {totals[0]} | USD: {totals[1]} | GBP: {totals[2]}") msg(f"Wallets: XMR USD: {wallets[0]} | BTC USD: {wallets[1]}") + @staticmethod + def run(cmd, spl, length, authed, msg, agora, tx, ux): + totals_all = tx.money.get_total() + totals_all.addCallback(IRCCommands.total.got_total, msg) + class ping(object): name = "ping" authed = False @@ -541,7 +553,7 @@ class IRCCommands(object): @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): - GenericCommands.wallet.run(cmd, spl, length, authed, msg, agora, tx, ux, True, agora.agora) + GenericCommands.wallet.run(cmd, spl, length, authed, msg, agora, tx, ux, True, agora.api) class lwallet(object): authed = True @@ -550,7 +562,7 @@ class IRCCommands(object): @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): - GenericCommands.wallet.run(cmd, spl, length, authed, msg, agora, tx, ux, False, tx.lbtc.lbtc) + GenericCommands.wallet.run(cmd, spl, length, authed, msg, agora, tx, ux, False, tx.lbtc.api) class apubads(object): authed = True