From 57bc1d5ccf471f2f13a4b470bedd7ae6a8d9fb89 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Sun, 26 May 2024 11:32:43 +0200 Subject: [PATCH] ui: Improve rpc page. --- basicswap/http_server.py | 50 +++++++++++++--------------- basicswap/templates/rpc.html | 9 +++-- basicswap/templates/wallet.html | 5 ++- tests/basicswap/extended/test_dcr.py | 5 ++- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 19cecfa..ba9c6d3 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -268,6 +268,7 @@ class HttpHandler(BaseHTTPRequestHandler): result = None cmd = '' + coin_type_selected = -1 coin_type = -1 coin_id = -1 call_type = 'cli' @@ -280,15 +281,10 @@ class HttpHandler(BaseHTTPRequestHandler): call_type = get_data_entry_or(form_data, 'call_type', 'cli') type_map = get_data_entry_or(form_data, 'type_map', '') try: - coin_id = int(get_data_entry(form_data, 'coin_type')) - if coin_id in (-2, -3, -4): - coin_type = Coins(Coins.XMR) - elif coin_id in (-5,): - coin_type = Coins(Coins.LTC) - elif coin_id in (-6,): - coin_type = Coins(Coins.DCR) - else: - coin_type = Coins(coin_id) + coin_type_selected = get_data_entry(form_data, 'coin_type') + coin_type_split = coin_type_selected.split(',') + coin_type = Coins(int(coin_type_split[0])) + coin_variant = int(coin_type_split[1]) except Exception: raise ValueError('Unknown Coin Type') @@ -299,29 +295,29 @@ class HttpHandler(BaseHTTPRequestHandler): cmd = get_data_entry(form_data, 'cmd') except Exception: raise ValueError('Invalid command') - if coin_type == Coins.XMR: + if coin_type in (Coins.XMR, ): ci = swap_client.ci(coin_type) arr = cmd.split(None, 1) method = arr[0] params = json.loads(arr[1]) if len(arr) > 1 else [] - if coin_id == -4: + if coin_variant == 2: rv = ci.rpc_wallet(method, params) - elif coin_id == -3: + elif coin_variant == 0: rv = ci.rpc(method, params) - elif coin_id == -2: + elif coin_variant == 1: if params == []: params = None rv = ci.rpc2(method, params) else: - raise ValueError('Unknown XMR RPC variant') + raise ValueError('Unknown RPC variant') result = json.dumps(rv, indent=4) else: if call_type == 'http': ci = swap_client.ci(coin_type) method, params = parse_cmd(cmd, type_map) - if coin_id == -6: + if coin_variant == 1: rv = ci.rpc_wallet(method, params) - elif coin_id == -5: + elif coin_variant == 2: rv = ci.rpc_wallet_mweb(method, params) else: if coin_type in (Coins.DCR, ): @@ -340,24 +336,24 @@ class HttpHandler(BaseHTTPRequestHandler): template = env.get_template('rpc.html') - coins = listAvailableCoins(swap_client, with_variants=False) - with_xmr: bool = any(c[0] == Coins.XMR for c in coins) - coins = [c for c in coins if c[0] != Coins.XMR] + coin_available = listAvailableCoins(swap_client, with_variants=False) + with_xmr: bool = any(c[0] == Coins.XMR for c in coin_available) + coins = [(str(c[0]) + ',0', c[1]) for c in coin_available if c[0] not in (Coins.XMR, )] - if any(c[0] == Coins.DCR for c in coins): - coins.append((-6, 'Decred Wallet')) - if any(c[0] == Coins.LTC for c in coins): - coins.append((-5, 'Litecoin MWEB Wallet')) + if any(c[0] == Coins.DCR for c in coin_available): + coins.append((str(int(Coins.DCR)) + ',1', 'Decred Wallet')) + if any(c[0] == Coins.LTC for c in coin_available): + coins.append((str(int(Coins.LTC)) + ',2', 'Litecoin MWEB Wallet')) if with_xmr: - coins.append((-2, 'Monero')) - coins.append((-3, 'Monero JSON')) - coins.append((-4, 'Monero Wallet')) + coins.append((str(int(Coins.XMR)) + ',0', 'Monero')) + coins.append((str(int(Coins.XMR)) + ',1', 'Monero JSON')) + coins.append((str(int(Coins.XMR)) + ',2', 'Monero Wallet')) return self.render_template(template, { 'messages': messages, 'err_messages': err_messages, 'coins': coins, - 'coin_type': coin_id, + 'coin_type': coin_type_selected, 'call_type': call_type, 'result': result, 'messages': messages, diff --git a/basicswap/templates/rpc.html b/basicswap/templates/rpc.html index fc0c74f..8937b6d 100644 --- a/basicswap/templates/rpc.html +++ b/basicswap/templates/rpc.html @@ -178,7 +178,7 @@ diff --git a/basicswap/templates/wallet.html b/basicswap/templates/wallet.html index caa23dd..3ed9b96 100644 --- a/basicswap/templates/wallet.html +++ b/basicswap/templates/wallet.html @@ -964,9 +964,7 @@ } }); - -{% include 'footer.html' %} - +{% include 'footer.html' %} \ No newline at end of file diff --git a/tests/basicswap/extended/test_dcr.py b/tests/basicswap/extended/test_dcr.py index b68c2d7..c0c668f 100644 --- a/tests/basicswap/extended/test_dcr.py +++ b/tests/basicswap/extended/test_dcr.py @@ -63,7 +63,6 @@ logger = logging.getLogger() DCR_BINDIR = os.path.expanduser(os.getenv('DCR_BINDIR', os.path.join(cfg.DEFAULT_TEST_BINDIR, 'decred'))) DCRD = os.getenv('DCRD', 'dcrd' + cfg.bin_suffix) DCR_WALLET = os.getenv('DCR_WALLET', 'dcrwallet' + cfg.bin_suffix) -DCR_CLI = os.getenv('DCR_CLI', 'dcrctl' + cfg.bin_suffix) DCR_BASE_PORT = 44932 DCR_BASE_RPC_PORT = 45932 @@ -583,6 +582,10 @@ class Test(BaseTest): waitForRPC(make_rpc_func(i, base_rpc_port=DCR_BASE_WALLET_RPC_PORT), test_delay_event, rpc_command='getinfo', max_tries=12) + @classmethod + def addPIDInfo(cls, sc, i): + sc.setDaemonPID(Coins.DCR, cls.dcr_daemons[i].handle.pid) + @classmethod def addCoinSettings(cls, settings, datadir, node_id): settings['chainclients']['decred'] = {