mirror of
https://github.com/basicswap/basicswap.git
synced 2025-03-20 22:28:50 +00:00
commit
31a1224311
1 changed files with 103 additions and 94 deletions
|
@ -1092,11 +1092,29 @@ const chart = new Chart(ctx, {
|
|||
|
||||
const cryptoValue = parseFloat(cryptoCell.textContent);
|
||||
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) {
|
||||
const rateCell = usdCell.nextElementSibling;
|
||||
if (rateCell) {
|
||||
const usdValue = rateCell.previousElementSibling.textContent * cryptoValue;
|
||||
usdCell.textContent = `${usdValue.toFixed(2)} USD`;
|
||||
} else {
|
||||
console.error("Rate cell does not exist.");
|
||||
}
|
||||
} else {
|
||||
const apiUrl = `https://min-api.cryptocompare.com/data/price?fsym=${coinSymbol}&tsyms=USD`;
|
||||
|
||||
|
@ -1134,8 +1152,6 @@ const chart = new Chart(ctx, {
|
|||
}
|
||||
})
|
||||
.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', () => {
|
||||
const coinNameValues = document.querySelectorAll('.coinname-value');
|
||||
for (let i = 0; i < coinNameValues.length; i++) {
|
||||
const coinFullName = coinNameValues[i].getAttribute('data-coinname');
|
||||
const isRate = coinNameValues[i].textContent.includes('rate');
|
||||
updateUsdValue(coinNameValues[i], coinFullName, isRate);
|
||||
|
||||
if (!isRate) {
|
||||
coinNameValues[i].addEventListener('input', () => {
|
||||
console.log(`Clearing cache for ${coinNameToSymbol[coinFullName]}`);
|
||||
exchangeRateCache[coinNameToSymbol[coinFullName]] = undefined;
|
||||
updateUsdValue(coinNameValues[i], coinFullName);
|
||||
coinNameValues.forEach(coinNameValue => {
|
||||
const coinFullName = coinNameValue.getAttribute('data-coinname');
|
||||
const isRateElement = coinNameValue.parentElement.querySelector('.ratetype');
|
||||
const isRate = isRateElement ? isRateElement.textContent.includes('rate') : false;
|
||||
updateUsdValue(coinNameValue, coinFullName, isRate);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% include 'footer.html' %}
|
||||
|
|
Loading…
Reference in a new issue