From 81e99246549e21d9f6be640fd6fc417eb96321aa Mon Sep 17 00:00:00 2001 From: tecnovert Date: Sat, 11 Dec 2021 22:11:42 +0200 Subject: [PATCH] ui: New offer, when 'Lock Rate' is set rate must update if it's empty. Remove invalid coins from coin from list. --- basicswap/http_server.py | 19 +++++++++++++++---- basicswap/templates/offer_confirm.html | 2 +- basicswap/templates/offer_new_1.html | 4 ++-- basicswap/templates/offer_new_2.html | 2 +- basicswap/templates/offers.html | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/basicswap/http_server.py b/basicswap/http_server.py index d101da9..8d43df2 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -63,6 +63,8 @@ from .ui import ( env = Environment(loader=PackageLoader('basicswap', 'templates')) env.filters['formatts'] = format_timestamp +invalid_coins_from = (Coins.XMR, Coins.PART_ANON) + def value_or_none(v): if v == -1 or v == '-1': @@ -78,16 +80,23 @@ def getCoinName(c): return chainparams[c]['name'].capitalize() -def listAvailableCoins(swap_client, with_variants=True): +def listAvailableCoins(swap_client, with_variants=True, split_from=False): + coins_from = [] coins = [] for k, v in swap_client.coin_clients.items(): if k not in chainparams: continue if v['connection_type'] == 'rpc': coins.append((int(k), getCoinName(k))) + if split_from and k not in invalid_coins_from: + coins_from.append(coins[-1]) if with_variants and k == Coins.PART: - coins.append((int(Coins.PART_ANON), getCoinName(Coins.PART_ANON))) - coins.append((int(Coins.PART_BLIND), getCoinName(Coins.PART_BLIND))) + for v in (Coins.PART_ANON, Coins.PART_BLIND): + coins.append((int(v), getCoinName(v))) + if split_from and v not in invalid_coins_from: + coins_from.append(coins[-1]) + if split_from: + return coins_from, coins return coins @@ -731,11 +740,13 @@ class HttpHandler(BaseHTTPRequestHandler): else: template = env.get_template('offer_new_1.html') + coins_from, coins_to = listAvailableCoins(swap_client, split_from=True) return bytes(template.render( title=self.server.title, h2=self.server.title, messages=messages, - coins=listAvailableCoins(swap_client), + coins_from=coins_from, + coins=coins_to, addrs=swap_client.listSmsgAddresses('offer_send_from'), addrs_to=swap_client.listSmsgAddresses('offer_send_to'), data=page_data, diff --git a/basicswap/templates/offer_confirm.html b/basicswap/templates/offer_confirm.html index 4612d71..2e15401 100644 --- a/basicswap/templates/offer_confirm.html +++ b/basicswap/templates/offer_confirm.html @@ -23,7 +23,7 @@ Coin From diff --git a/basicswap/templates/offer_new_1.html b/basicswap/templates/offer_new_1.html index 40e8377..ef441de 100644 --- a/basicswap/templates/offer_new_1.html +++ b/basicswap/templates/offer_new_1.html @@ -23,7 +23,7 @@ Coin From @@ -102,7 +102,7 @@ function set_rate(value_changed) { const amt_from = document.getElementById('amt_from').value; const amt_to = document.getElementById('amt_to').value; const rate = document.getElementById('rate').value; - const lock_rate = document.getElementById('rate_lock').checked; + const lock_rate = rate == '' ? false : document.getElementById('rate_lock').checked; if (coin_from == '-1' || coin_to == '-1') { return; diff --git a/basicswap/templates/offer_new_2.html b/basicswap/templates/offer_new_2.html index 54a7d21..3509437 100644 --- a/basicswap/templates/offer_new_2.html +++ b/basicswap/templates/offer_new_2.html @@ -23,7 +23,7 @@ Coin From diff --git a/basicswap/templates/offers.html b/basicswap/templates/offers.html index fd348b2..51ce728 100644 --- a/basicswap/templates/offers.html +++ b/basicswap/templates/offers.html @@ -12,7 +12,7 @@
Coin From