diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-10-30 09:57:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 09:57:51 +0800 |
commit | 73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f (patch) | |
tree | 51b163f772d253b8e56588fd254ca918a8b058a2 /app/scripts/controllers/currency.js | |
parent | 310229d22e5e916e8d6e3b1a469b9b196e0f70c2 (diff) | |
parent | 7ae5a23b6c0e9839f63bba52ab5bf7da00bef173 (diff) | |
download | tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.gz tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.bz2 tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.lz tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.xz tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.zst tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.zip |
Merge pull request #5560 from MetaMask/sentry-enhancements2
Sentry - various enhancements to help debugging (alternate)
Diffstat (limited to 'app/scripts/controllers/currency.js')
-rw-r--r-- | app/scripts/controllers/currency.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/app/scripts/controllers/currency.js b/app/scripts/controllers/currency.js index 1e866d2c9..fce65fd9c 100644 --- a/app/scripts/controllers/currency.js +++ b/app/scripts/controllers/currency.js @@ -133,18 +133,40 @@ class CurrencyController { try { currentCurrency = this.getCurrentCurrency() nativeCurrency = this.getNativeCurrency() + // select api let apiUrl if (nativeCurrency === 'ETH') { + // ETH apiUrl = `https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}` } else { + // ETC apiUrl = `https://min-api.cryptocompare.com/data/price?fsym=${nativeCurrency.toUpperCase()}&tsyms=${currentCurrency.toUpperCase()}` } - const response = await fetch(apiUrl) - const parsedResponse = await response.json() + // attempt request + let response + try { + response = await fetch(apiUrl) + } catch (err) { + log.error(new Error(`CurrencyController - Failed to request currency from Infura:\n${err.stack}`)) + return + } + // parse response + let rawResponse + let parsedResponse + try { + rawResponse = await response.text() + parsedResponse = JSON.parse(rawResponse) + } catch (err) { + log.error(new Error(`CurrencyController - Failed to parse response "${rawResponse}"`)) + return + } + // set conversion rate if (nativeCurrency === 'ETH') { + // ETH this.setConversionRate(Number(parsedResponse.bid)) this.setConversionDate(Number(parsedResponse.timestamp)) } else { + // ETC if (parsedResponse[currentCurrency.toUpperCase()]) { this.setConversionRate(Number(parsedResponse[currentCurrency.toUpperCase()])) this.setConversionDate(parseInt((new Date()).getTime() / 1000)) @@ -154,9 +176,13 @@ class CurrencyController { } } } catch (err) { + // reset current conversion rate log.warn(`MetaMask - Failed to query currency conversion:`, nativeCurrency, currentCurrency, err) this.setConversionRate(0) this.setConversionDate('N/A') + // throw error + log.error(new Error(`CurrencyController - Failed to query rate for currency "${currentCurrency}":\n${err.stack}`)) + return } } |