Workflow updating files of btcwallet
This commit is contained in:
parent
eba749b867
commit
5970da20ac
@ -1274,9 +1274,19 @@
|
|||||||
try {
|
try {
|
||||||
if (!dates.length) return [];
|
if (!dates.length) return [];
|
||||||
if (!Array.isArray(dates)) dates = [dates];
|
if (!Array.isArray(dates)) dates = [dates];
|
||||||
|
let timeout
|
||||||
const datesToFetch = dates.filter(date => !mappedHistoricPrices.has(date));
|
const datesToFetch = dates.filter(date => !mappedHistoricPrices.has(date));
|
||||||
|
const abortController = new AbortController();
|
||||||
|
const { signal } = abortController;
|
||||||
if (datesToFetch.length) {
|
if (datesToFetch.length) {
|
||||||
const historicPrices = await fetch(`${historicPriceApis.list[historicPriceApis.active]}/price-history?dates=${dates.join()}`).then(res => res.json())
|
timeout = setTimeout(() => {
|
||||||
|
abortController.abort()
|
||||||
|
throw new Error(`Historic price data is taking longer than usual to load. Historic prices won't be shown`)
|
||||||
|
}, 8000)
|
||||||
|
const historicPrices = await fetch(`${historicPriceApis.list[historicPriceApis.active]}/price-history?dates=${dates.join()}`, {
|
||||||
|
signal
|
||||||
|
}).then(res => res.json())
|
||||||
|
clearTimeout(timeout)
|
||||||
historicPrices.forEach(price => {
|
historicPrices.forEach(price => {
|
||||||
// map historic price to txs
|
// map historic price to txs
|
||||||
// historic price is per day, so we need to find the price for the day of the tx
|
// historic price is per day, so we need to find the price for the day of the tx
|
||||||
@ -1292,11 +1302,11 @@
|
|||||||
historicPriceApis.active++
|
historicPriceApis.active++
|
||||||
return getHistoricPrice(dates)
|
return getHistoricPrice(dates)
|
||||||
} else {
|
} else {
|
||||||
selectedCurrency = 'btc'
|
showCurrentValue = true;
|
||||||
showCurrentValue = false
|
localStorage.setItem('btc-wallet-show-current-value', showCurrentValue);
|
||||||
localStorage.setItem('btc-wallet-currency', selectedCurrency)
|
document.getElementById('show_current_value').checked = showCurrentValue;
|
||||||
localStorage.setItem('btc-wallet-show-current-value', showCurrentValue)
|
notify('Could not fetch historic price data. Showing current value instead', 'error')
|
||||||
notify('There was an error fetching historic price data. Please try again later.', 'error')
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1323,7 +1333,7 @@
|
|||||||
// render transactions
|
// render transactions
|
||||||
if (txs.length) {
|
if (txs.length) {
|
||||||
const dates = txs.map(tx => toYDM(tx.time))
|
const dates = txs.map(tx => toYDM(tx.time))
|
||||||
await getHistoricPrice(dates)
|
await getHistoricPrice(dates);
|
||||||
txs.forEach(tx => {
|
txs.forEach(tx => {
|
||||||
const historicPrice = mappedHistoricPrices.get(toYDM(tx.time))
|
const historicPrice = mappedHistoricPrices.get(toYDM(tx.time))
|
||||||
if (historicPrice) {
|
if (historicPrice) {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user