From fcf234ef3423d85df7b42137679c4fb6d755c0a4 Mon Sep 17 00:00:00 2001 From: tecnovert <tecnovert@tecnovert.net> Date: Tue, 21 May 2024 14:29:02 +0200 Subject: [PATCH] ui: Improve rpc page usability for Decred. --- basicswap/http_server.py | 24 +++++++++++++--- basicswap/interface/dcr/dcr.py | 2 +- basicswap/interface/firo.py | 3 ++ basicswap/interface/nav.py | 3 ++ basicswap/interface/pivx.py | 3 ++ basicswap/templates/offer_confirm.html | 24 ++++++++-------- basicswap/templates/offer_new_2.html | 22 +++++++------- basicswap/templates/rpc.html | 40 ++++++++++++++++++++------ 8 files changed, 85 insertions(+), 36 deletions(-) diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 22e36a9..19cecfa 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -98,6 +98,8 @@ def parse_cmd(cmd: str, type_map: str): type_ind = type_map[i] if type_ind == 'i': typed_params.append(int(param)) + elif type_ind == 'f': + typed_params.append(float(param)) elif type_ind == 'b': typed_params.append(toBool(param)) elif type_ind == 'j': @@ -265,6 +267,7 @@ class HttpHandler(BaseHTTPRequestHandler): summary = swap_client.getSummary() result = None + cmd = '' coin_type = -1 coin_id = -1 call_type = 'cli' @@ -282,11 +285,16 @@ class HttpHandler(BaseHTTPRequestHandler): 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) except Exception: raise ValueError('Unknown Coin Type') + if coin_type in (Coins.DCR,): + call_type = 'http' + try: cmd = get_data_entry(form_data, 'cmd') except Exception: @@ -309,18 +317,24 @@ class HttpHandler(BaseHTTPRequestHandler): 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 == -5: - rv = swap_client.ci(coin_type).rpc_wallet_mweb(method, params) + if coin_id == -6: + rv = ci.rpc_wallet(method, params) + elif coin_id == -5: + rv = ci.rpc_wallet_mweb(method, params) else: - rv = swap_client.ci(coin_type).rpc_wallet(method, params) + if coin_type in (Coins.DCR, ): + rv = ci.rpc(method, params) + else: + rv = ci.rpc_wallet(method, params) if not isinstance(rv, str): rv = json.dumps(rv, indent=4) result = cmd + '\n' + rv else: result = cmd + '\n' + swap_client.callcoincli(coin_type, cmd) except Exception as ex: - result = str(ex) + result = cmd + '\n' + str(ex) if self.server.swap_client.debug is True: self.server.swap_client.log.error(traceback.format_exc()) @@ -330,6 +344,8 @@ class HttpHandler(BaseHTTPRequestHandler): with_xmr: bool = any(c[0] == Coins.XMR for c in coins) coins = [c for c in coins if c[0] != 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 with_xmr: diff --git a/basicswap/interface/dcr/dcr.py b/basicswap/interface/dcr/dcr.py index bf00637..15d2676 100644 --- a/basicswap/interface/dcr/dcr.py +++ b/basicswap/interface/dcr/dcr.py @@ -564,7 +564,7 @@ class DCRInterface(Secp256k1Interface): def withdrawCoin(self, value: float, addr_to: str, subfee: bool = False) -> str: if subfee: raise ValueError('TODO') - params = [addr_to, value] + params = [addr_to, float(value)] return self.rpc_wallet('sendtoaddress', params) def isAddressMine(self, address: str, or_watch_only: bool = False) -> bool: diff --git a/basicswap/interface/firo.py b/basicswap/interface/firo.py index 8943cef..c4d56af 100644 --- a/basicswap/interface/firo.py +++ b/basicswap/interface/firo.py @@ -49,6 +49,9 @@ class FIROInterface(BTCInterface): # load with -hdseed= parameter pass + def checkWallets(self) -> int: + return 1 + def getNewAddress(self, use_segwit, label='swap_receive'): return self.rpc('getnewaddress', [label]) # addr_plain = self.rpc('getnewaddress', [label]) diff --git a/basicswap/interface/nav.py b/basicswap/interface/nav.py index 82c7019..ce97fee 100644 --- a/basicswap/interface/nav.py +++ b/basicswap/interface/nav.py @@ -84,6 +84,9 @@ class NAVInterface(BTCInterface): # Load with -importmnemonic= parameter pass + def checkWallets(self) -> int: + return 1 + def getWalletSeedID(self): return self.rpc('getwalletinfo')['hdmasterkeyid'] diff --git a/basicswap/interface/pivx.py b/basicswap/interface/pivx.py index a88a6a1..038744c 100644 --- a/basicswap/interface/pivx.py +++ b/basicswap/interface/pivx.py @@ -35,6 +35,9 @@ class PIVXInterface(BTCInterface): # No multiwallet support self.rpc_wallet = make_rpc_func(self._rpcport, self._rpcauth, host=self._rpc_host) + def checkWallets(self) -> int: + return 1 + def signTxWithWallet(self, tx): rv = self.rpc('signrawtransaction', [tx.hex()]) return bytes.fromhex(rv['hex']) diff --git a/basicswap/templates/offer_confirm.html b/basicswap/templates/offer_confirm.html index 09f548b..b5d2cbf 100644 --- a/basicswap/templates/offer_confirm.html +++ b/basicswap/templates/offer_confirm.html @@ -113,7 +113,7 @@ </div> </div> </div> - </div> + </div> <div class="py-0 border-b items-center justify-between -mx-4 mb-6 pb-3 border-gray-400 border-opacity-20"> <div class="w-full md:w-10/12"> <div class="flex flex-wrap -m-3 w-full sm:w-auto px-4 mb-6 sm:mb-0"> @@ -129,7 +129,7 @@ <select class="cursor-not-allowed disabled-select pl-10 hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="swap_type" id="swap_type" disabled> {% for a in swap_types %} <option{% if data.swap_type==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[1] }}</option> - {% endfor %} + {% endfor %} </select> </div> </div> @@ -145,11 +145,11 @@ <div class="w-full md:flex-1 p-3"> <div class="flex flex-wrap -m-3"> <div class="w-full md:w-1/2 p-3"> - <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Coin You Send:</p> + <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Coin You Send:</p> <div class="custom-select"> <div class="relative"> {{ input_down_arrow_offer_svg | safe }} - <select class="select cursor-not-allowed disabled-select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" id="coin_from" name="coin_from" onchange="set_rate('coin_from');" disabled> + <select class="select cursor-not-allowed disabled-select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" id="coin_from" name="coin_from" disabled> <option value="-1">Select coin you send</option> {% for c in coins_from %} <option{% if data.coin_from==c[0] %} selected{% endif %} value="{{ c[0] }}" data-image="/static/images/coins/{{ c[1]|replace(" ", "-") }}-20.png">{{ c[1] }} @@ -162,9 +162,9 @@ </div> </div> <div class="w-full md:w-1/2 p-3"> - <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Amount You Send</p> + <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Amount You Send</p> <div class="relative"> - <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> </div> <input class="cursor-not-allowed disabled-input hover:border-blue-500 pr-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" type="text" id="amt_from" name="amt_from" value="{{ data.amt_from }}" onchange="set_rate('amt_from');" readonly> + <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> </div> <input class="cursor-not-allowed disabled-input hover:border-blue-500 pr-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" type="text" id="amt_from" name="amt_from" value="{{ data.amt_from }}" readonly> </div> </div> {% if data.swap_style == 'xmr' %} @@ -216,11 +216,11 @@ <div class="w-full md:flex-1 p-3"> <div class="flex flex-wrap -m-3"> <div class="w-full md:w-1/2 p-3"> - <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Coin You Get</p> + <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Coin You Get</p> <div class="custom-select"> <div class="relative"> {{ input_down_arrow_offer_svg | safe }} - <select class="cursor-not-allowed disabled-select select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" id="coin_to" name="coin_to" onchange="set_rate('coin_to');" disabled> + <select class="cursor-not-allowed disabled-select select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" id="coin_to" name="coin_to" disabled> <option value="-1"></option> {% for c in coins %} <option{% if data.coin_to==c[0] %} selected{% endif %} value="{{ c[0] }}" data-image="/static/images/coins/{{ c[1]|replace(" ", "-") }}-20.png">{{ c[1] }}</option> @@ -233,9 +233,9 @@ </div> </div> <div class="w-full md:w-1/2 p-3"> - <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Amount You Get</p> + <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Amount You Get</p> <div class="relative"> - <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> </div> <input class="cursor-not-allowed disabled-input hover:border-blue-500 pr-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" type="text" id="amt_to" name="amt_to" value="{{ data.amt_to }}" onchange="set_rate('amt_to');" readonly> + <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> </div> <input class="cursor-not-allowed disabled-input hover:border-blue-500 pr-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" type="text" id="amt_to" name="amt_to" value="{{ data.amt_to }}" readonly> </div> </div> {% if data.swap_style == 'xmr' and coin_to != '6' %} @@ -301,7 +301,7 @@ <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> {{ select_rate_svg | safe }} </div> - <input class="cursor-not-allowed disabled-input pl-10 hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" id="rate" name="rate" value="{{ data.rate }}" onchange="set_rate('rate');" readonly> + <input class="cursor-not-allowed disabled-input pl-10 hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" id="rate" name="rate" value="{{ data.rate }}" readonly> </div> </div> </div> @@ -426,7 +426,7 @@ <div class="w-full md:w-auto p-1.5"> <button name="step2" type="submit" value="Back" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md focus:ring-0 focus:outline-none dark:text-white dark:hover:text-white dark:bg-gray-600 dark:hover:bg-gray-700 dark:border-gray-600 dark:hover:border-gray-600"> <span>Back</span> - </button> + </button> </div> <div class="w-full md:w-auto p-1.5"> <button name="submit_offer" value="Continue" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 bg-blue-500 hover:bg-green-600 hover:border-green-600 font-medium text-sm text-white border border-blue-500 rounded-md shadow-button focus:ring-0 focus:outline-none"> diff --git a/basicswap/templates/offer_new_2.html b/basicswap/templates/offer_new_2.html index e24feb1..8374a57 100644 --- a/basicswap/templates/offer_new_2.html +++ b/basicswap/templates/offer_new_2.html @@ -153,11 +153,11 @@ <div class="w-full md:flex-1 p-3"> <div class="flex flex-wrap -m-3"> <div class="w-full md:w-1/2 p-3"> - <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Coin You Send</p> + <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Coin You Send</p> <div class="custom-select"> <div class="relative"> {{ input_down_arrow_offer_svg | safe }} - <select class="select cursor-not-allowed disabled-select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" id="coin_from" name="coin_from" onchange="set_rate('coin_from');" disabled> + <select class="select cursor-not-allowed disabled-select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" id="coin_from" name="coin_from" disabled> <option value="-1">Select coin you send</option> {% for c in coins_from %} <option{% if data.coin_from==c[0] %} selected{% endif %} value="{{ c[0] }}" data-image="/static/images/coins/{{ c[1]|replace(" ", "-") }}-20.png">{{ c[1] }}</option> @@ -169,9 +169,9 @@ </div> </div> <div class="w-full md:w-1/2 p-3"> - <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Amount You Send</p> + <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Amount You Send</p> <div class="relative"> - <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> </div> <input class="cursor-not-allowed disabled-input appearance-none pr-10 bg-gray-50 text-gray-900 appearance-none dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" type="text" id="amt_from" name="amt_from" value="{{ data.amt_from }}" onchange="set_rate('amt_from');" readonly> + <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> </div> <input class="cursor-not-allowed disabled-input appearance-none pr-10 bg-gray-50 text-gray-900 appearance-none dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" type="text" id="amt_from" name="amt_from" value="{{ data.amt_from }}" readonly> </div> </div> {% if data.swap_style == 'xmr' %} @@ -213,11 +213,11 @@ <div class="w-full md:flex-1 p-3"> <div class="flex flex-wrap -m-3"> <div class="w-full md:w-1/2 p-3"> - <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Coin You Get</p> + <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Coin You Get</p> <div class="custom-select"> <div class="relative"> {{ input_down_arrow_offer_svg | safe }} - <select class="select cursor-not-allowed disabled-select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" id="coin_to" name="coin_to" onchange="set_rate('coin_to');" disabled> + <select class="select cursor-not-allowed disabled-select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" id="coin_to" name="coin_to" disabled> <option value="-1"></option> {% for c in coins %} <option{% if data.coin_to==c[0] %} selected{% endif %} value="{{ c[0] }}" data-image="/static/images/coins/{{ c[1]|replace(" ", "-") }}-20.png">{{ c[1] }}</option> @@ -228,9 +228,9 @@ </div> </div> <div class="w-full md:w-1/2 p-3"> - <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Amount You Get</p> + <p class="mb-1.5 font-medium text-base text-coolGray-800 dark:text-white">Amount You Get</p> <div class="relative"> - <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> </div> <input class="cursor-not-allowed disabled-input hover:border-blue-500 pr-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" type="text" id="amt_to" name="amt_to" value="{{ data.amt_to }}" onchange="set_rate('amt_to');" readonly> + <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> </div> <input class="cursor-not-allowed disabled-input hover:border-blue-500 pr-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-5 focus:ring-0" type="text" id="amt_to" name="amt_to" value="{{ data.amt_to }}" readonly> </div> </div> {% if data.swap_style == 'xmr' and coin_to != '6' %} @@ -286,7 +286,7 @@ <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"> {{ select_rate_svg | safe }} </div> - <input class="cursor-not-allowed disabled-input pl-10 hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" id="rate" name="rate" value="{{ data.rate }}" onchange="set_rate('rate');" readonly> + <input class="cursor-not-allowed disabled-input pl-10 hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" id="rate" name="rate" value="{{ data.rate }}" readonly> </div> </div> </div> @@ -321,7 +321,7 @@ <input class="pl-10 hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="number" name="lockmins" min="10" max="5000" value="{{ data.lockmins }}"> </div> {% if data.swap_style != 'xmr' %} - <div class="text-sm text-gray-500 mt-1.5">(Participate txn will be locked for half the time.)</div> + <div class="text-sm text-gray-500 mt-1.5">(Participate txn will be locked for half the time.)</div> {% endif %} </div> {% else %} @@ -442,7 +442,7 @@ <input type="hidden" name="rate_var" value="true"> {% endif %} </form> - <script src="static/js/new_offer.js"></script> + <script src="static/js/new_offer.js"></script> </div> </div> </div> diff --git a/basicswap/templates/rpc.html b/basicswap/templates/rpc.html index 918a562..fc0c74f 100644 --- a/basicswap/templates/rpc.html +++ b/basicswap/templates/rpc.html @@ -1,5 +1,5 @@ {% include 'header.html' %} -{% from 'style.html' import breadcrumb_line_svg, input_arrow_down_svg %} +{% from 'style.html' import breadcrumb_line_svg, input_arrow_down_svg %} <div class="container mx-auto"> <section class="p-5 mt-5"> <div class="flex flex-wrap items-center -m-2"> @@ -62,8 +62,8 @@ <tr class="opacity-100 text-gray-500 dark:text-gray-100"> <td class="py-3 px-6"> <div class="relative"> - {{ input_arrow_down_svg| safe }} - <select class="hover:border-blue-500 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="coin_type"> + {{ input_arrow_down_svg| safe }} + <select class="hover:border-blue-500 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="coin_type" id="coin_type" onchange="set_coin();"> <option value="-1" {% if coin_type==-1 %} selected{% endif %}>Select Coin</option> {% for c in coins %} <option value="{{ c[0] }}" {% if coin_type==c[0] %} selected{% endif %}>{{ c[1] }}</option> @@ -72,21 +72,21 @@ </div> </td> <td class="py-3 px-6"> - <input class="hover:border-blue-500 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" name="cmd"> + <input class="hover:border-blue-500 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" name="cmd" id="cmd" oninput="set_method();"> </td> </tr> <tr class="opacity-100 text-gray-500 dark:text-gray-100"> <td class="py-3 px-6"> <div class="relative"> - {{ input_arrow_down_svg| safe }} - <select class="hover:border-blue-500 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="call_type"> + {{ input_arrow_down_svg| safe }} + <select class="hover:border-blue-500 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="call_type" id="call_type" > <option value="cli" {% if call_type=="cli" %} selected{% endif %}>CLI</option> <option value="http" {% if call_type=="http" %} selected{% endif %}>HTTP</option> </select> </div> </td> <td class="py-3 px-6"> - <input class="hover:border-blue-500 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" name="type_map" title="Convert inputs when using http. Example: 'sibj' 1st parameter is a string, 2nd is converted to an int then boolean and json object or array"> + <input class="hover:border-blue-500 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" name="type_map" id="type_map" title="Convert inputs when using http. Example: 'sifbj' 1st parameter is a string, 2nd is converted to an int, 3rd to float then boolean and json object or array"> </td> </table> </div> @@ -148,7 +148,7 @@ </tr> </table> </div> - </div> + </div> </form> </div> </div> @@ -176,4 +176,28 @@ </div> {% include 'footer.html' %} </body> +<script> + function set_method() { + const coin_type = document.getElementById('coin_type').value; + if (coin_type == 4 || coin_type == -6) { + const cmd = document.getElementById('cmd'); + const type_map = document.getElementById('type_map'); + let method = cmd.value.split(' ')[0]; + if (method == 'sendtoaddress') { + type_map.value = 'sf'; + } + } + } + function set_coin() { + const coin_type = document.getElementById('coin_type').value; + let call_type = document.getElementById('call_type'); + if (coin_type == 4 || coin_type == -6) { + call_type.disabled = true; + call_type.value = 'http'; + } else { + call_type.disabled = false; + } + set_method(); + } + </script> </html>