mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
cleanup
This commit is contained in:
@@ -180,7 +180,7 @@ const CoinManager = (function() {
|
|||||||
const normalizedId = identifier.toString().toLowerCase().trim();
|
const normalizedId = identifier.toString().toLowerCase().trim();
|
||||||
const coin = coinAliasesMap[normalizedId];
|
const coin = coinAliasesMap[normalizedId];
|
||||||
if (coin) return coin;
|
if (coin) return coin;
|
||||||
if (normalizedId.includes('bitcoin') && normalizedId.includes('cash') ||
|
if (normalizedId.includes('bitcoin') && normalizedId.includes('cash') ||
|
||||||
normalizedId === 'bch') {
|
normalizedId === 'bch') {
|
||||||
return symbolToInfo['bch'];
|
return symbolToInfo['bch'];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,14 +83,14 @@ const PriceManager = (function() {
|
|||||||
throw new Error('Network is offline');
|
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.CoinManager.getAllCoins().map(c => c.symbol).filter(symbol => symbol && symbol.trim() !== '')
|
||||||
: (window.config.coins
|
: (window.config.coins
|
||||||
? window.config.coins.map(c => c.symbol).filter(symbol => symbol && symbol.trim() !== '')
|
? window.config.coins.map(c => c.symbol).filter(symbol => symbol && symbol.trim() !== '')
|
||||||
: ['BTC', 'XMR', 'PART', 'BCH', 'PIVX', 'FIRO', 'DASH', 'LTC', 'DOGE', 'DCR', 'NMC', 'WOW']);
|
: ['BTC', 'XMR', 'PART', 'BCH', 'PIVX', 'FIRO', 'DASH', 'LTC', 'DOGE', 'DCR', 'NMC', 'WOW']);
|
||||||
|
|
||||||
console.log('PriceManager: lookupFiatRates ' + coinSymbols.join(', '));
|
console.log('PriceManager: lookupFiatRates ' + coinSymbols.join(', '));
|
||||||
|
|
||||||
if (!coinSymbols.length) {
|
if (!coinSymbols.length) {
|
||||||
throw new Error('No valid coins configured');
|
throw new Error('No valid coins configured');
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ const PriceManager = (function() {
|
|||||||
if (!apiResponse.rates) {
|
if (!apiResponse.rates) {
|
||||||
throw new Error('No rates found in API response');
|
throw new Error('No rates found in API response');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof apiResponse.rates !== 'object' || Object.keys(apiResponse.rates).length === 0) {
|
if (typeof apiResponse.rates !== 'object' || Object.keys(apiResponse.rates).length === 0) {
|
||||||
throw new Error('Empty rates object in API response');
|
throw new Error('Empty rates object in API response');
|
||||||
}
|
}
|
||||||
@@ -122,12 +122,12 @@ const PriceManager = (function() {
|
|||||||
console.error('API call error:', apiError);
|
console.error('API call error:', apiError);
|
||||||
throw new Error(`API error: ${apiError.message}`);
|
throw new Error(`API error: ${apiError.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const processedData = {};
|
const processedData = {};
|
||||||
|
|
||||||
Object.entries(apiResponse.rates).forEach(([coinId, price]) => {
|
Object.entries(apiResponse.rates).forEach(([coinId, price]) => {
|
||||||
let normalizedCoinId;
|
let normalizedCoinId;
|
||||||
|
|
||||||
if (window.CoinManager) {
|
if (window.CoinManager) {
|
||||||
const coin = window.CoinManager.getCoinByAnyIdentifier(coinId);
|
const coin = window.CoinManager.getCoinByAnyIdentifier(coinId);
|
||||||
if (coin) {
|
if (coin) {
|
||||||
@@ -138,19 +138,19 @@ const PriceManager = (function() {
|
|||||||
} else {
|
} else {
|
||||||
normalizedCoinId = coinId === 'bitcoincash' ? 'bitcoin-cash' : coinId.toLowerCase();
|
normalizedCoinId = coinId === 'bitcoincash' ? 'bitcoin-cash' : coinId.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coinId.toLowerCase() === 'zcoin') {
|
if (coinId.toLowerCase() === 'zcoin') {
|
||||||
normalizedCoinId = 'firo';
|
normalizedCoinId = 'firo';
|
||||||
}
|
}
|
||||||
|
|
||||||
processedData[normalizedCoinId] = {
|
processedData[normalizedCoinId] = {
|
||||||
usd: price,
|
usd: price,
|
||||||
btc: normalizedCoinId === 'bitcoin' ? 1 : price / (apiResponse.rates.bitcoin || 1)
|
btc: normalizedCoinId === 'bitcoin' ? 1 : price / (apiResponse.rates.bitcoin || 1)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
CacheManager.set(PRICES_CACHE_KEY, processedData, 'prices');
|
CacheManager.set(PRICES_CACHE_KEY, processedData, 'prices');
|
||||||
|
|
||||||
Object.entries(processedData).forEach(([coin, prices]) => {
|
Object.entries(processedData).forEach(([coin, prices]) => {
|
||||||
if (prices.usd) {
|
if (prices.usd) {
|
||||||
if (window.tableRateModule) {
|
if (window.tableRateModule) {
|
||||||
@@ -158,18 +158,18 @@ const PriceManager = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return processedData;
|
return processedData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching prices:', error);
|
console.error('Error fetching prices:', error);
|
||||||
NetworkManager.handleNetworkError(error);
|
NetworkManager.handleNetworkError(error);
|
||||||
|
|
||||||
const cachedData = CacheManager.get(PRICES_CACHE_KEY);
|
const cachedData = CacheManager.get(PRICES_CACHE_KEY);
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
console.log('Using cached price data');
|
console.log('Using cached price data');
|
||||||
return cachedData.value;
|
return cachedData.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const existingCache = localStorage.getItem(PRICES_CACHE_KEY);
|
const existingCache = localStorage.getItem(PRICES_CACHE_KEY);
|
||||||
if (existingCache) {
|
if (existingCache) {
|
||||||
@@ -179,17 +179,17 @@ const PriceManager = (function() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to parse existing cache:', e);
|
console.warn('Failed to parse existing cache:', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
const emptyData = {};
|
const emptyData = {};
|
||||||
|
|
||||||
const coinNames = window.CoinManager
|
const coinNames = window.CoinManager
|
||||||
? window.CoinManager.getAllCoins().map(c => c.name.toLowerCase())
|
? window.CoinManager.getAllCoins().map(c => c.name.toLowerCase())
|
||||||
: ['bitcoin', 'bitcoin-cash', 'dash', 'dogecoin', 'decred', 'namecoin', 'litecoin', 'particl', 'pivx', 'monero', 'wownero', 'firo'];
|
: ['bitcoin', 'bitcoin-cash', 'dash', 'dogecoin', 'decred', 'namecoin', 'litecoin', 'particl', 'pivx', 'monero', 'wownero', 'firo'];
|
||||||
|
|
||||||
coinNames.forEach(coin => {
|
coinNames.forEach(coin => {
|
||||||
emptyData[coin] = { usd: null, btc: null };
|
emptyData[coin] = { usd: null, btc: null };
|
||||||
});
|
});
|
||||||
|
|
||||||
return emptyData;
|
return emptyData;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -198,14 +198,14 @@ const PriceManager = (function() {
|
|||||||
if (!coinSymbol) return null;
|
if (!coinSymbol) return null;
|
||||||
const prices = this.getPrices();
|
const prices = this.getPrices();
|
||||||
if (!prices) return null;
|
if (!prices) return null;
|
||||||
|
|
||||||
let normalizedSymbol;
|
let normalizedSymbol;
|
||||||
if (window.CoinManager) {
|
if (window.CoinManager) {
|
||||||
normalizedSymbol = window.CoinManager.getPriceKey(coinSymbol);
|
normalizedSymbol = window.CoinManager.getPriceKey(coinSymbol);
|
||||||
} else {
|
} else {
|
||||||
normalizedSymbol = coinSymbol.toLowerCase();
|
normalizedSymbol = coinSymbol.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
return prices[normalizedSymbol] || null;
|
return prices[normalizedSymbol] || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ const WalletManager = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const coin = window.CoinManager.getCoinByAnyIdentifier(coinName);
|
const coin = window.CoinManager.getCoinByAnyIdentifier(coinName);
|
||||||
|
|
||||||
if (!coin) {
|
if (!coin) {
|
||||||
console.warn(`[WalletManager] No coin found for: ${coinName}`);
|
console.warn(`[WalletManager] No coin found for: ${coinName}`);
|
||||||
return coinName;
|
return coinName;
|
||||||
@@ -78,15 +78,15 @@ const WalletManager = (function() {
|
|||||||
|
|
||||||
document.querySelectorAll('.coinname-value').forEach(el => {
|
document.querySelectorAll('.coinname-value').forEach(el => {
|
||||||
const coinName = el.getAttribute('data-coinname');
|
const coinName = el.getAttribute('data-coinname');
|
||||||
|
|
||||||
if (!coinName || processedCoins.has(coinName)) return;
|
if (!coinName || processedCoins.has(coinName)) return;
|
||||||
|
|
||||||
const adjustedName = coinName === 'Zcoin' ? 'Firo' :
|
const adjustedName = coinName === 'Zcoin' ? 'Firo' :
|
||||||
coinName.includes('Particl') ? 'Particl' :
|
coinName.includes('Particl') ? 'Particl' :
|
||||||
coinName;
|
coinName;
|
||||||
|
|
||||||
const coinId = getCoingeckoId(adjustedName);
|
const coinId = getCoingeckoId(adjustedName);
|
||||||
|
|
||||||
if (coinId && (shouldIncludeWow || coinId !== 'WOW')) {
|
if (coinId && (shouldIncludeWow || coinId !== 'WOW')) {
|
||||||
coinsToFetch.push(coinId);
|
coinsToFetch.push(coinId);
|
||||||
processedCoins.add(coinName);
|
processedCoins.add(coinName);
|
||||||
@@ -116,8 +116,8 @@ const WalletManager = (function() {
|
|||||||
const coinName = el.getAttribute('data-coinname');
|
const coinName = el.getAttribute('data-coinname');
|
||||||
if (!coinName) return;
|
if (!coinName) return;
|
||||||
|
|
||||||
const adjustedName = coinName === 'Zcoin' ? 'Firo' :
|
const adjustedName = coinName === 'Zcoin' ? 'Firo' :
|
||||||
coinName.includes('Particl') ? 'Particl' :
|
coinName.includes('Particl') ? 'Particl' :
|
||||||
coinName;
|
coinName;
|
||||||
|
|
||||||
const coinId = getCoingeckoId(adjustedName);
|
const coinId = getCoingeckoId(adjustedName);
|
||||||
|
|||||||
@@ -1260,7 +1260,7 @@ const app = {
|
|||||||
app.scheduleNextRefresh();
|
app.scheduleNextRefresh();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateNextRefreshTime: function() {
|
updateNextRefreshTime: function() {
|
||||||
const nextRefreshSpan = document.getElementById('next-refresh-time');
|
const nextRefreshSpan = document.getElementById('next-refresh-time');
|
||||||
const labelElement = document.getElementById('next-refresh-label');
|
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);
|
console.log('Using previously cached BTC price after error:', app.btcPriceUSD);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<title>(BSX) BasicSwap - v{{ version }}</title>
|
<title>(BSX) BasicSwap - v{{ version }}</title>
|
||||||
<link rel="icon" sizes="32x32" type="image/png" href="/static/images/favicon/favicon-32.png">
|
<link rel="icon" sizes="32x32" type="image/png" href="/static/images/favicon/favicon-32.png">
|
||||||
<!-- CSS Stylesheets -->>
|
<!-- CSS Stylesheets -->
|
||||||
<link type="text/css" media="all" href="/static/css/libs/flowbite.min.css" rel="stylesheet">
|
<link type="text/css" media="all" href="/static/css/libs/flowbite.min.css" rel="stylesheet">
|
||||||
<link type="text/css" media="all" href="/static/css/libs/tailwind.min.css" rel="stylesheet">
|
<link type="text/css" media="all" href="/static/css/libs/tailwind.min.css" rel="stylesheet">
|
||||||
<!-- Custom styles -->
|
<!-- Custom styles -->
|
||||||
|
|||||||
Reference in New Issue
Block a user