ui: Improve rpc page.

master^2
tecnovert 7 months ago
parent 62aa1fa5d7
commit 57bc1d5ccf
  1. 50
      basicswap/http_server.py
  2. 9
      basicswap/templates/rpc.html
  3. 5
      basicswap/templates/wallet.html
  4. 5
      tests/basicswap/extended/test_dcr.py

@ -268,6 +268,7 @@ class HttpHandler(BaseHTTPRequestHandler):
result = None result = None
cmd = '' cmd = ''
coin_type_selected = -1
coin_type = -1 coin_type = -1
coin_id = -1 coin_id = -1
call_type = 'cli' call_type = 'cli'
@ -280,15 +281,10 @@ class HttpHandler(BaseHTTPRequestHandler):
call_type = get_data_entry_or(form_data, 'call_type', 'cli') call_type = get_data_entry_or(form_data, 'call_type', 'cli')
type_map = get_data_entry_or(form_data, 'type_map', '') type_map = get_data_entry_or(form_data, 'type_map', '')
try: try:
coin_id = int(get_data_entry(form_data, 'coin_type')) coin_type_selected = get_data_entry(form_data, 'coin_type')
if coin_id in (-2, -3, -4): coin_type_split = coin_type_selected.split(',')
coin_type = Coins(Coins.XMR) coin_type = Coins(int(coin_type_split[0]))
elif coin_id in (-5,): coin_variant = int(coin_type_split[1])
coin_type = Coins(Coins.LTC)
elif coin_id in (-6,):
coin_type = Coins(Coins.DCR)
else:
coin_type = Coins(coin_id)
except Exception: except Exception:
raise ValueError('Unknown Coin Type') raise ValueError('Unknown Coin Type')
@ -299,29 +295,29 @@ class HttpHandler(BaseHTTPRequestHandler):
cmd = get_data_entry(form_data, 'cmd') cmd = get_data_entry(form_data, 'cmd')
except Exception: except Exception:
raise ValueError('Invalid command') raise ValueError('Invalid command')
if coin_type == Coins.XMR: if coin_type in (Coins.XMR, ):
ci = swap_client.ci(coin_type) ci = swap_client.ci(coin_type)
arr = cmd.split(None, 1) arr = cmd.split(None, 1)
method = arr[0] method = arr[0]
params = json.loads(arr[1]) if len(arr) > 1 else [] params = json.loads(arr[1]) if len(arr) > 1 else []
if coin_id == -4: if coin_variant == 2:
rv = ci.rpc_wallet(method, params) rv = ci.rpc_wallet(method, params)
elif coin_id == -3: elif coin_variant == 0:
rv = ci.rpc(method, params) rv = ci.rpc(method, params)
elif coin_id == -2: elif coin_variant == 1:
if params == []: if params == []:
params = None params = None
rv = ci.rpc2(method, params) rv = ci.rpc2(method, params)
else: else:
raise ValueError('Unknown XMR RPC variant') raise ValueError('Unknown RPC variant')
result = json.dumps(rv, indent=4) result = json.dumps(rv, indent=4)
else: else:
if call_type == 'http': if call_type == 'http':
ci = swap_client.ci(coin_type) ci = swap_client.ci(coin_type)
method, params = parse_cmd(cmd, type_map) method, params = parse_cmd(cmd, type_map)
if coin_id == -6: if coin_variant == 1:
rv = ci.rpc_wallet(method, params) rv = ci.rpc_wallet(method, params)
elif coin_id == -5: elif coin_variant == 2:
rv = ci.rpc_wallet_mweb(method, params) rv = ci.rpc_wallet_mweb(method, params)
else: else:
if coin_type in (Coins.DCR, ): if coin_type in (Coins.DCR, ):
@ -340,24 +336,24 @@ class HttpHandler(BaseHTTPRequestHandler):
template = env.get_template('rpc.html') template = env.get_template('rpc.html')
coins = listAvailableCoins(swap_client, with_variants=False) coin_available = listAvailableCoins(swap_client, with_variants=False)
with_xmr: bool = any(c[0] == Coins.XMR for c in coins) with_xmr: bool = any(c[0] == Coins.XMR for c in coin_available)
coins = [c for c in coins if c[0] != Coins.XMR] 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): if any(c[0] == Coins.DCR for c in coin_available):
coins.append((-6, 'Decred Wallet')) coins.append((str(int(Coins.DCR)) + ',1', 'Decred Wallet'))
if any(c[0] == Coins.LTC for c in coins): if any(c[0] == Coins.LTC for c in coin_available):
coins.append((-5, 'Litecoin MWEB Wallet')) coins.append((str(int(Coins.LTC)) + ',2', 'Litecoin MWEB Wallet'))
if with_xmr: if with_xmr:
coins.append((-2, 'Monero')) coins.append((str(int(Coins.XMR)) + ',0', 'Monero'))
coins.append((-3, 'Monero JSON')) coins.append((str(int(Coins.XMR)) + ',1', 'Monero JSON'))
coins.append((-4, 'Monero Wallet')) coins.append((str(int(Coins.XMR)) + ',2', 'Monero Wallet'))
return self.render_template(template, { return self.render_template(template, {
'messages': messages, 'messages': messages,
'err_messages': err_messages, 'err_messages': err_messages,
'coins': coins, 'coins': coins,
'coin_type': coin_id, 'coin_type': coin_type_selected,
'call_type': call_type, 'call_type': call_type,
'result': result, 'result': result,
'messages': messages, 'messages': messages,

@ -178,7 +178,7 @@
</body> </body>
<script> <script>
function set_method() { function set_method() {
const coin_type = document.getElementById('coin_type').value; const coin_type = document.getElementById('coin_type').value.split(',')[0];
if (coin_type == 4 || coin_type == -6) { if (coin_type == 4 || coin_type == -6) {
const cmd = document.getElementById('cmd'); const cmd = document.getElementById('cmd');
const type_map = document.getElementById('type_map'); const type_map = document.getElementById('type_map');
@ -189,9 +189,9 @@
} }
} }
function set_coin() { function set_coin() {
const coin_type = document.getElementById('coin_type').value; const coin_type = document.getElementById('coin_type').value.split(',')[0];
let call_type = document.getElementById('call_type'); let call_type = document.getElementById('call_type');
if (coin_type == 4 || coin_type == -6) { if (coin_type == '4' || coin_type == '6') {
call_type.disabled = true; call_type.disabled = true;
call_type.value = 'http'; call_type.value = 'http';
} else { } else {
@ -199,5 +199,8 @@
} }
set_method(); set_method();
} }
document.addEventListener('DOMContentLoaded', () => {
set_coin();
});
</script> </script>
</html> </html>

@ -964,9 +964,7 @@
} }
}); });
</script>
{% include 'footer.html' %}
<script>
function confirmReseed() { function confirmReseed() {
return confirm("Are you sure?\nBackup your wallet before and after.\nWon't detect used keys.\nShould only be used for new wallets."); return confirm("Are you sure?\nBackup your wallet before and after.\nWon't detect used keys.\nShould only be used for new wallets.");
} }
@ -979,5 +977,6 @@
return confirm("Are you sure?"); return confirm("Are you sure?");
} }
</script> </script>
{% include 'footer.html' %}
</body> </body>
</html> </html>

@ -63,7 +63,6 @@ logger = logging.getLogger()
DCR_BINDIR = os.path.expanduser(os.getenv('DCR_BINDIR', os.path.join(cfg.DEFAULT_TEST_BINDIR, 'decred'))) 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) DCRD = os.getenv('DCRD', 'dcrd' + cfg.bin_suffix)
DCR_WALLET = os.getenv('DCR_WALLET', 'dcrwallet' + 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_PORT = 44932
DCR_BASE_RPC_PORT = 45932 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) 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 @classmethod
def addCoinSettings(cls, settings, datadir, node_id): def addCoinSettings(cls, settings, datadir, node_id):
settings['chainclients']['decred'] = { settings['chainclients']['decred'] = {

Loading…
Cancel
Save