commit
31a1224311
@ -1092,11 +1092,29 @@ const chart = new Chart(ctx, {
|
|||||||
|
|
||||||
const cryptoValue = parseFloat(cryptoCell.textContent);
|
const cryptoValue = parseFloat(cryptoCell.textContent);
|
||||||
const usdCell = cryptoCell.nextElementSibling;
|
const usdCell = cryptoCell.nextElementSibling;
|
||||||
|
if (usdCell) {
|
||||||
|
// Check if the exchange rate is in the cache and is not expired
|
||||||
|
if (exchangeRateCache[coinSymbol] && !isCacheExpired(coinSymbol)) {
|
||||||
|
console.log(`Using cached exchange rate for ${coinSymbol}`);
|
||||||
|
const exchangeRate = exchangeRateCache[coinSymbol].rate;
|
||||||
|
const cryptoValue = parseFloat(cryptoCell.textContent);
|
||||||
|
const usdValue = cryptoValue * exchangeRate;
|
||||||
|
usdCell.textContent = `${usdValue.toFixed(2)} USD`;
|
||||||
|
|
||||||
|
updateProfitLoss(cryptoCell.closest('tr'));
|
||||||
|
updateProfitValue(cryptoCell.closest('tr'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
if (isRate) {
|
if (isRate) {
|
||||||
const rateCell = usdCell.nextElementSibling;
|
const rateCell = usdCell.nextElementSibling;
|
||||||
|
if (rateCell) {
|
||||||
const usdValue = rateCell.previousElementSibling.textContent * cryptoValue;
|
const usdValue = rateCell.previousElementSibling.textContent * cryptoValue;
|
||||||
usdCell.textContent = `${usdValue.toFixed(2)} USD`;
|
usdCell.textContent = `${usdValue.toFixed(2)} USD`;
|
||||||
|
} else {
|
||||||
|
console.error("Rate cell does not exist.");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const apiUrl = `https://min-api.cryptocompare.com/data/price?fsym=${coinSymbol}&tsyms=USD`;
|
const apiUrl = `https://min-api.cryptocompare.com/data/price?fsym=${coinSymbol}&tsyms=USD`;
|
||||||
|
|
||||||
@ -1134,8 +1152,6 @@ const chart = new Chart(ctx, {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error retrieving exchange rate:', error);
|
|
||||||
usdCell.textContent = 'Error retrieving exchange rate';
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1184,19 +1200,12 @@ function updateProfitLoss(row) {
|
|||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
const coinNameValues = document.querySelectorAll('.coinname-value');
|
const coinNameValues = document.querySelectorAll('.coinname-value');
|
||||||
for (let i = 0; i < coinNameValues.length; i++) {
|
coinNameValues.forEach(coinNameValue => {
|
||||||
const coinFullName = coinNameValues[i].getAttribute('data-coinname');
|
const coinFullName = coinNameValue.getAttribute('data-coinname');
|
||||||
const isRate = coinNameValues[i].textContent.includes('rate');
|
const isRateElement = coinNameValue.parentElement.querySelector('.ratetype');
|
||||||
updateUsdValue(coinNameValues[i], coinFullName, isRate);
|
const isRate = isRateElement ? isRateElement.textContent.includes('rate') : false;
|
||||||
|
updateUsdValue(coinNameValue, coinFullName, isRate);
|
||||||
if (!isRate) {
|
|
||||||
coinNameValues[i].addEventListener('input', () => {
|
|
||||||
console.log(`Clearing cache for ${coinNameToSymbol[coinFullName]}`);
|
|
||||||
exchangeRateCache[coinNameToSymbol[coinFullName]] = undefined;
|
|
||||||
updateUsdValue(coinNameValues[i], coinFullName);
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% include 'footer.html' %}
|
{% include 'footer.html' %}
|
||||||
|
Loading…
Reference in New Issue
Block a user