diff --git a/btcwallet/index.html b/btcwallet/index.html index d80ba3f..b168173 100644 --- a/btcwallet/index.html +++ b/btcwallet/index.html @@ -1274,9 +1274,19 @@ try { if (!dates.length) return []; if (!Array.isArray(dates)) dates = [dates]; + let timeout const datesToFetch = dates.filter(date => !mappedHistoricPrices.has(date)); + const abortController = new AbortController(); + const { signal } = abortController; 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 => { // map historic price to txs // historic price is per day, so we need to find the price for the day of the tx @@ -1292,11 +1302,11 @@ historicPriceApis.active++ return getHistoricPrice(dates) } else { - selectedCurrency = 'btc' - showCurrentValue = false - localStorage.setItem('btc-wallet-currency', selectedCurrency) - localStorage.setItem('btc-wallet-show-current-value', showCurrentValue) - notify('There was an error fetching historic price data. Please try again later.', 'error') + showCurrentValue = true; + localStorage.setItem('btc-wallet-show-current-value', showCurrentValue); + document.getElementById('show_current_value').checked = showCurrentValue; + notify('Could not fetch historic price data. Showing current value instead', 'error') + return [] } } } @@ -1323,7 +1333,7 @@ // render transactions if (txs.length) { const dates = txs.map(tx => toYDM(tx.time)) - await getHistoricPrice(dates) + await getHistoricPrice(dates); txs.forEach(tx => { const historicPrice = mappedHistoricPrices.get(toYDM(tx.time)) if (historicPrice) { diff --git a/btcwallet/index.min.html b/btcwallet/index.min.html index dd49312..b061a4d 100644 --- a/btcwallet/index.min.html +++ b/btcwallet/index.min.html @@ -1,5 +1,5 @@ -
If you have your private key, enter it here and recover your BTC address.