From ec092eaa6e6f6bdd2b6f7944a488cd514791ee73 Mon Sep 17 00:00:00 2001 From: nahuhh <50635951+nahuhh@users.noreply.github.com> Date: Thu, 17 Apr 2025 02:44:42 +0000 Subject: [PATCH] cleanup --- basicswap/static/js/modules/coin-manager.js | 2 +- basicswap/static/js/modules/price-manager.js | 40 +++++++++---------- basicswap/static/js/modules/wallet-manager.js | 14 +++---- basicswap/static/js/pricechart.js | 4 +- basicswap/templates/header.html | 2 +- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/basicswap/static/js/modules/coin-manager.js b/basicswap/static/js/modules/coin-manager.js index b4ee830..7d0a1e0 100644 --- a/basicswap/static/js/modules/coin-manager.js +++ b/basicswap/static/js/modules/coin-manager.js @@ -180,7 +180,7 @@ const CoinManager = (function() { const normalizedId = identifier.toString().toLowerCase().trim(); const coin = coinAliasesMap[normalizedId]; if (coin) return coin; - if (normalizedId.includes('bitcoin') && normalizedId.includes('cash') || + if (normalizedId.includes('bitcoin') && normalizedId.includes('cash') || normalizedId === 'bch') { return symbolToInfo['bch']; } diff --git a/basicswap/static/js/modules/price-manager.js b/basicswap/static/js/modules/price-manager.js index f01739e..17fe22a 100644 --- a/basicswap/static/js/modules/price-manager.js +++ b/basicswap/static/js/modules/price-manager.js @@ -83,14 +83,14 @@ const PriceManager = (function() { throw new Error('Network is offline'); } - const coinSymbols = window.CoinManager + const coinSymbols = window.CoinManager ? window.CoinManager.getAllCoins().map(c => c.symbol).filter(symbol => symbol && symbol.trim() !== '') : (window.config.coins ? window.config.coins.map(c => c.symbol).filter(symbol => symbol && symbol.trim() !== '') : ['BTC', 'XMR', 'PART', 'BCH', 'PIVX', 'FIRO', 'DASH', 'LTC', 'DOGE', 'DCR', 'NMC', 'WOW']); console.log('PriceManager: lookupFiatRates ' + coinSymbols.join(', ')); - + if (!coinSymbols.length) { throw new Error('No valid coins configured'); } @@ -114,7 +114,7 @@ const PriceManager = (function() { if (!apiResponse.rates) { throw new Error('No rates found in API response'); } - + if (typeof apiResponse.rates !== 'object' || Object.keys(apiResponse.rates).length === 0) { throw new Error('Empty rates object in API response'); } @@ -122,12 +122,12 @@ const PriceManager = (function() { console.error('API call error:', apiError); throw new Error(`API error: ${apiError.message}`); } - + const processedData = {}; - + Object.entries(apiResponse.rates).forEach(([coinId, price]) => { let normalizedCoinId; - + if (window.CoinManager) { const coin = window.CoinManager.getCoinByAnyIdentifier(coinId); if (coin) { @@ -138,19 +138,19 @@ const PriceManager = (function() { } else { normalizedCoinId = coinId === 'bitcoincash' ? 'bitcoin-cash' : coinId.toLowerCase(); } - + if (coinId.toLowerCase() === 'zcoin') { normalizedCoinId = 'firo'; } - + processedData[normalizedCoinId] = { usd: price, btc: normalizedCoinId === 'bitcoin' ? 1 : price / (apiResponse.rates.bitcoin || 1) }; }); - + CacheManager.set(PRICES_CACHE_KEY, processedData, 'prices'); - + Object.entries(processedData).forEach(([coin, prices]) => { if (prices.usd) { if (window.tableRateModule) { @@ -158,18 +158,18 @@ const PriceManager = (function() { } } }); - + return processedData; } catch (error) { console.error('Error fetching prices:', error); NetworkManager.handleNetworkError(error); - + const cachedData = CacheManager.get(PRICES_CACHE_KEY); if (cachedData) { console.log('Using cached price data'); return cachedData.value; } - + try { const existingCache = localStorage.getItem(PRICES_CACHE_KEY); if (existingCache) { @@ -179,17 +179,17 @@ const PriceManager = (function() { } catch (e) { console.warn('Failed to parse existing cache:', e); } - + const emptyData = {}; - - const coinNames = window.CoinManager + + const coinNames = window.CoinManager ? window.CoinManager.getAllCoins().map(c => c.name.toLowerCase()) : ['bitcoin', 'bitcoin-cash', 'dash', 'dogecoin', 'decred', 'namecoin', 'litecoin', 'particl', 'pivx', 'monero', 'wownero', 'firo']; - + coinNames.forEach(coin => { emptyData[coin] = { usd: null, btc: null }; }); - + return emptyData; } }, @@ -198,14 +198,14 @@ const PriceManager = (function() { if (!coinSymbol) return null; const prices = this.getPrices(); if (!prices) return null; - + let normalizedSymbol; if (window.CoinManager) { normalizedSymbol = window.CoinManager.getPriceKey(coinSymbol); } else { normalizedSymbol = coinSymbol.toLowerCase(); } - + return prices[normalizedSymbol] || null; }, diff --git a/basicswap/static/js/modules/wallet-manager.js b/basicswap/static/js/modules/wallet-manager.js index 93512e5..4447765 100644 --- a/basicswap/static/js/modules/wallet-manager.js +++ b/basicswap/static/js/modules/wallet-manager.js @@ -45,7 +45,7 @@ const WalletManager = (function() { } const coin = window.CoinManager.getCoinByAnyIdentifier(coinName); - + if (!coin) { console.warn(`[WalletManager] No coin found for: ${coinName}`); return coinName; @@ -78,15 +78,15 @@ const WalletManager = (function() { document.querySelectorAll('.coinname-value').forEach(el => { const coinName = el.getAttribute('data-coinname'); - + if (!coinName || processedCoins.has(coinName)) return; - const adjustedName = coinName === 'Zcoin' ? 'Firo' : - coinName.includes('Particl') ? 'Particl' : + const adjustedName = coinName === 'Zcoin' ? 'Firo' : + coinName.includes('Particl') ? 'Particl' : coinName; const coinId = getCoingeckoId(adjustedName); - + if (coinId && (shouldIncludeWow || coinId !== 'WOW')) { coinsToFetch.push(coinId); processedCoins.add(coinName); @@ -116,8 +116,8 @@ const WalletManager = (function() { const coinName = el.getAttribute('data-coinname'); if (!coinName) return; - const adjustedName = coinName === 'Zcoin' ? 'Firo' : - coinName.includes('Particl') ? 'Particl' : + const adjustedName = coinName === 'Zcoin' ? 'Firo' : + coinName.includes('Particl') ? 'Particl' : coinName; const coinId = getCoingeckoId(adjustedName); diff --git a/basicswap/static/js/pricechart.js b/basicswap/static/js/pricechart.js index 3a0556b..3b2b15a 100644 --- a/basicswap/static/js/pricechart.js +++ b/basicswap/static/js/pricechart.js @@ -1260,7 +1260,7 @@ const app = { app.scheduleNextRefresh(); } }, - + updateNextRefreshTime: function() { const nextRefreshSpan = document.getElementById('next-refresh-time'); const labelElement = document.getElementById('next-refresh-label'); @@ -1601,7 +1601,7 @@ refreshAllData: async function() { console.log('Using previously cached BTC price after error:', app.btcPriceUSD); return true; } - + return false; } }, diff --git a/basicswap/templates/header.html b/basicswap/templates/header.html index 8cfc632..76197d7 100644 --- a/basicswap/templates/header.html +++ b/basicswap/templates/header.html @@ -18,7 +18,7 @@ {% endif %} (BSX) BasicSwap - v{{ version }} - > +