mirror of
https://github.com/basicswap/basicswap.git
synced 2025-01-22 10:34:34 +00:00
Fix: Eslint.
This commit is contained in:
parent
9e24d9a12a
commit
5d381d4b73
2 changed files with 64 additions and 95 deletions
|
@ -497,48 +497,48 @@ const CacheManager = {
|
|||
},
|
||||
|
||||
get: function(key) {
|
||||
try {
|
||||
const itemStr = localStorage.getItem(key);
|
||||
if (!itemStr) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let item;
|
||||
try {
|
||||
item = JSON.parse(itemStr);
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse cached item:', parseError);
|
||||
localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!item || typeof item.expiresAt !== 'number' || !item.hasOwnProperty('value')) {
|
||||
console.warn('Invalid cache item structure for key:', key);
|
||||
localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
if (now < item.expiresAt) {
|
||||
return {
|
||||
value: item.value,
|
||||
remainingTime: item.expiresAt - now
|
||||
};
|
||||
}
|
||||
|
||||
localStorage.removeItem(key);
|
||||
return null;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Cache retrieval error:", error);
|
||||
try {
|
||||
localStorage.removeItem(key);
|
||||
} catch (removeError) {
|
||||
console.error("Failed to remove invalid cache entry:", removeError);
|
||||
}
|
||||
try {
|
||||
const itemStr = localStorage.getItem(key);
|
||||
if (!itemStr) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
let item;
|
||||
try {
|
||||
item = JSON.parse(itemStr);
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse cached item:', parseError);
|
||||
localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!item || typeof item.expiresAt !== 'number' || !Object.prototype.hasOwnProperty.call(item, 'value')) {
|
||||
console.warn('Invalid cache item structure for key:', key);
|
||||
localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
if (now < item.expiresAt) {
|
||||
return {
|
||||
value: item.value,
|
||||
remainingTime: item.expiresAt - now
|
||||
};
|
||||
}
|
||||
|
||||
localStorage.removeItem(key);
|
||||
return null;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Cache retrieval error:", error);
|
||||
try {
|
||||
localStorage.removeItem(key);
|
||||
} catch (removeError) {
|
||||
console.error("Failed to remove invalid cache entry:", removeError);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
cleanup: function(aggressive = false) {
|
||||
const now = Date.now();
|
||||
|
@ -1001,37 +1001,6 @@ function filterAndSortData() {
|
|||
return filteredData;
|
||||
}
|
||||
|
||||
function getPriceWithFallback(coin, latestPrices) {
|
||||
const getPriceKey = (coin) => {
|
||||
const lowerCoin = coin.toLowerCase();
|
||||
if (lowerCoin === 'firo' || lowerCoin === 'zcoin') {
|
||||
return 'zcoin';
|
||||
}
|
||||
if (lowerCoin === 'bitcoin cash') {
|
||||
return 'bitcoin-cash';
|
||||
}
|
||||
if (lowerCoin === 'particl anon' || lowerCoin === 'particl blind') {
|
||||
return 'particl';
|
||||
}
|
||||
return coinNameToSymbol[coin] || lowerCoin;
|
||||
};
|
||||
|
||||
const priceKey = getPriceKey(coin);
|
||||
const livePrice = latestPrices[priceKey]?.usd;
|
||||
if (livePrice !== undefined && livePrice !== null) {
|
||||
return livePrice;
|
||||
}
|
||||
|
||||
if (window.tableRateModule) {
|
||||
const fallback = window.tableRateModule.getFallbackValue(priceKey);
|
||||
if (fallback !== null) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function calculateProfitLoss(fromCoin, toCoin, fromAmount, toAmount, isOwnOffer) {
|
||||
return new Promise((resolve) => {
|
||||
if (!latestPrices) {
|
||||
|
@ -1136,7 +1105,7 @@ async function fetchLatestPrices() {
|
|||
try {
|
||||
console.log('Initiating fresh price data fetch...');
|
||||
const existingCache = CacheManager.get(PRICES_CACHE_KEY, true);
|
||||
let fallbackData = existingCache ? existingCache.value : null;
|
||||
const fallbackData = existingCache ? existingCache.value : null;
|
||||
const url = `${offersConfig.apiEndpoints.coinGecko}/simple/price?ids=bitcoin,bitcoin-cash,dash,dogecoin,decred,litecoin,particl,pivx,monero,zano,wownero,zcoin&vs_currencies=USD,BTC&api_key=${offersConfig.apiKeys.coinGecko}`;
|
||||
const response = await fetch('/json/readurl', {
|
||||
method: 'POST',
|
||||
|
|
|
@ -397,7 +397,7 @@ displayCoinData: (coin, data) => {
|
|||
if (coin === 'BTC') {
|
||||
btcPriceDiv.style.display = 'none';
|
||||
} else {
|
||||
priceBtcElement.textContent = isError ? 'N/A' : `${priceBTC.toFixed(8)}`;
|
||||
priceBtcElement.textContent = isError ? 'N/A' : `${priceBTC.toFixed(8)} BTC`;
|
||||
btcPriceDiv.style.display = 'flex';
|
||||
}
|
||||
}
|
||||
|
@ -419,8 +419,9 @@ displayCoinData: (coin, data) => {
|
|||
}
|
||||
updateUI(false);
|
||||
} catch (error) {
|
||||
updateUI(true);
|
||||
}
|
||||
logger.error('Failed to parse cache item:', error.message);
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
},
|
||||
|
||||
showLoader: () => {
|
||||
|
@ -525,7 +526,7 @@ displayCoinData: (coin, data) => {
|
|||
if (price < 0.001) return price.toFixed(8);
|
||||
if (price < 1) return price.toFixed(4);
|
||||
if (price < 1000) return price.toFixed(2);
|
||||
return price.toFixed(0);
|
||||
return price.toFixed(1);
|
||||
},
|
||||
|
||||
setActiveContainer: (containerId) => {
|
||||
|
@ -1002,7 +1003,6 @@ const app = {
|
|||
await chartModule.updateChart('BTC');
|
||||
app.updateResolutionButtons('BTC');
|
||||
|
||||
|
||||
const chartTitle = document.getElementById('chart-title');
|
||||
if (chartTitle) {
|
||||
chartTitle.textContent = 'Price Chart (BTC)';
|
||||
|
|
Loading…
Reference in a new issue