Deduplicate getCoinIdFromTicker.

This commit is contained in:
tecnovert
2025-02-23 22:19:24 +02:00
parent 0e9bb47902
commit 3cdab962d3
4 changed files with 16 additions and 37 deletions

View File

@@ -15,7 +15,6 @@ from .util import (
get_data_entry_or,
have_data_entry,
inputAmount,
known_chart_coins,
listAvailableCoins,
PAGE_LIMIT,
setCoinFilter,
@@ -40,6 +39,7 @@ from basicswap.basicswap_util import (
)
from basicswap.chainparams import (
Coins,
ticker_map,
)
default_chart_api_key = (
@@ -996,7 +996,8 @@ def page_offers(self, url_split, post_string, sent=False):
enabled_chart_coins = []
enabled_chart_coins_setting = swap_client.settings.get("enabled_chart_coins", "")
if enabled_chart_coins_setting.lower() == "all":
enabled_chart_coins = known_chart_coins
for coin_ticker in ticker_map:
enabled_chart_coins.append(coin_ticker.upper())
elif enabled_chart_coins_setting.strip() == "":
for coin_id in swap_client.coin_clients:
if not swap_client.isCoinActive(coin_id):
@@ -1007,7 +1008,7 @@ def page_offers(self, url_split, post_string, sent=False):
continue
if (
enabled_ticker not in enabled_chart_coins
and enabled_ticker in known_chart_coins
and enabled_ticker.lower() in ticker_map
):
enabled_chart_coins.append(enabled_ticker)
else:
@@ -1016,7 +1017,7 @@ def page_offers(self, url_split, post_string, sent=False):
if (
upcased_ticker not in enabled_chart_coins
and upcased_ticker in known_chart_coins
and upcased_ticker.lower() in ticker_map
):
enabled_chart_coins.append(upcased_ticker)

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2024 tecnovert
# Copyright (c) 2024 The Basicswap developers
# Copyright (c) 2024-2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@@ -15,6 +15,7 @@ from basicswap.util import (
from basicswap.chainparams import (
Coins,
chainparams,
getCoinIdFromTicker,
)
from basicswap.basicswap_util import (
ActionTypes,
@@ -34,30 +35,6 @@ from basicswap.basicswap_util import (
from basicswap.protocols.xmr_swap_1 import getChainBSplitKey, getChainBRemoteSplitKey
PAGE_LIMIT = 1000
invalid_coins_from = []
known_chart_coins = [
"BTC",
"PART",
"XMR",
"LTC",
"FIRO",
"DASH",
"PIVX",
"DOGE",
"ETH",
"DCR",
"ZANO",
"WOW",
"BCH",
]
def tickerToCoinId(ticker):
search_str = ticker.upper()
for c in Coins:
if c.name == search_str:
return c.value
raise ValueError("Unknown coin")
def getCoinType(coin_type_ind):
@@ -65,7 +42,7 @@ def getCoinType(coin_type_ind):
try:
return int(coin_type_ind)
except Exception:
return tickerToCoinId(coin_type_ind)
return getCoinIdFromTicker(coin_type_ind)
def validateAmountString(amount, ci):
@@ -667,12 +644,12 @@ def listAvailableCoins(swap_client, with_variants=True, split_from=False):
continue
if v["connection_type"] == "rpc":
coins.append((int(k), getCoinName(k)))
if split_from and k not in invalid_coins_from:
if split_from:
coins_from.append(coins[-1])
if with_variants and k == Coins.PART:
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:
if split_from:
coins_from.append(coins[-1])
if with_variants and k == Coins.LTC:
for v in (Coins.LTC_MWEB,):