mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
Fix: Eslint.
This commit is contained in:
@@ -497,48 +497,48 @@ const CacheManager = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get: function(key) {
|
get: function(key) {
|
||||||
try {
|
try {
|
||||||
const itemStr = localStorage.getItem(key);
|
const itemStr = localStorage.getItem(key);
|
||||||
if (!itemStr) {
|
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);
|
|
||||||
}
|
|
||||||
return null;
|
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) {
|
cleanup: function(aggressive = false) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@@ -1001,37 +1001,6 @@ function filterAndSortData() {
|
|||||||
return filteredData;
|
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) {
|
async function calculateProfitLoss(fromCoin, toCoin, fromAmount, toAmount, isOwnOffer) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (!latestPrices) {
|
if (!latestPrices) {
|
||||||
@@ -1136,7 +1105,7 @@ async function fetchLatestPrices() {
|
|||||||
try {
|
try {
|
||||||
console.log('Initiating fresh price data fetch...');
|
console.log('Initiating fresh price data fetch...');
|
||||||
const existingCache = CacheManager.get(PRICES_CACHE_KEY, true);
|
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 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', {
|
const response = await fetch('/json/readurl', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ displayCoinData: (coin, data) => {
|
|||||||
if (coin === 'BTC') {
|
if (coin === 'BTC') {
|
||||||
btcPriceDiv.style.display = 'none';
|
btcPriceDiv.style.display = 'none';
|
||||||
} else {
|
} else {
|
||||||
priceBtcElement.textContent = isError ? 'N/A' : `${priceBTC.toFixed(8)}`;
|
priceBtcElement.textContent = isError ? 'N/A' : `${priceBTC.toFixed(8)} BTC`;
|
||||||
btcPriceDiv.style.display = 'flex';
|
btcPriceDiv.style.display = 'flex';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -419,8 +419,9 @@ displayCoinData: (coin, data) => {
|
|||||||
}
|
}
|
||||||
updateUI(false);
|
updateUI(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
updateUI(true);
|
logger.error('Failed to parse cache item:', error.message);
|
||||||
}
|
localStorage.removeItem(key);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
showLoader: () => {
|
showLoader: () => {
|
||||||
@@ -525,7 +526,7 @@ displayCoinData: (coin, data) => {
|
|||||||
if (price < 0.001) return price.toFixed(8);
|
if (price < 0.001) return price.toFixed(8);
|
||||||
if (price < 1) return price.toFixed(4);
|
if (price < 1) return price.toFixed(4);
|
||||||
if (price < 1000) return price.toFixed(2);
|
if (price < 1000) return price.toFixed(2);
|
||||||
return price.toFixed(0);
|
return price.toFixed(1);
|
||||||
},
|
},
|
||||||
|
|
||||||
setActiveContainer: (containerId) => {
|
setActiveContainer: (containerId) => {
|
||||||
@@ -1002,7 +1003,6 @@ const app = {
|
|||||||
await chartModule.updateChart('BTC');
|
await chartModule.updateChart('BTC');
|
||||||
app.updateResolutionButtons('BTC');
|
app.updateResolutionButtons('BTC');
|
||||||
|
|
||||||
|
|
||||||
const chartTitle = document.getElementById('chart-title');
|
const chartTitle = document.getElementById('chart-title');
|
||||||
if (chartTitle) {
|
if (chartTitle) {
|
||||||
chartTitle.textContent = 'Price Chart (BTC)';
|
chartTitle.textContent = 'Price Chart (BTC)';
|
||||||
|
|||||||
Reference in New Issue
Block a user