aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-11-04 09:57:21 +0800
committerGitHub <noreply@github.com>2018-11-04 09:57:21 +0800
commit14852669ac31f119d14cc739f4ea01e85940133b (patch)
tree773a33cf327dc74b31c354957a36c4a062599c2d /app/scripts
parented4f612bdc490435b88feb26b2a9df8c9320d3bb (diff)
parent2c1bca1ab0a6284b89338d5fd36552583c960f36 (diff)
downloadtangerine-wallet-browser-14852669ac31f119d14cc739f4ea01e85940133b.tar
tangerine-wallet-browser-14852669ac31f119d14cc739f4ea01e85940133b.tar.gz
tangerine-wallet-browser-14852669ac31f119d14cc739f4ea01e85940133b.tar.bz2
tangerine-wallet-browser-14852669ac31f119d14cc739f4ea01e85940133b.tar.lz
tangerine-wallet-browser-14852669ac31f119d14cc739f4ea01e85940133b.tar.xz
tangerine-wallet-browser-14852669ac31f119d14cc739f4ea01e85940133b.tar.zst
tangerine-wallet-browser-14852669ac31f119d14cc739f4ea01e85940133b.zip
Merge pull request #5659 from MetaMask/token-rates-bugfix
token-rates - protect against bad token data
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/controllers/token-rates.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/app/scripts/controllers/token-rates.js b/app/scripts/controllers/token-rates.js
index 87d716aa6..b6f084841 100644
--- a/app/scripts/controllers/token-rates.js
+++ b/app/scripts/controllers/token-rates.js
@@ -1,5 +1,5 @@
const ObservableStore = require('obs-store')
-const { warn } = require('loglevel')
+const log = require('loglevel')
// By default, poll every 3 minutes
const DEFAULT_INTERVAL = 180 * 1000
@@ -26,8 +26,11 @@ class TokenRatesController {
async updateExchangeRates () {
if (!this.isActive) { return }
const contractExchangeRates = {}
- for (const i in this._tokens) {
- const address = this._tokens[i].address
+ // copy array to ensure its not modified during iteration
+ const tokens = this._tokens.slice()
+ for (const token of tokens) {
+ if (!token) return log.error(`TokenRatesController - invalid tokens state:\n${JSON.stringify(tokens, null, 2)}`)
+ const address = token.address
contractExchangeRates[address] = await this.fetchExchangeRate(address)
}
this.store.putState({ contractExchangeRates })
@@ -44,7 +47,7 @@ class TokenRatesController {
const json = await response.json()
return json && json.length ? json[0].averagePrice : 0
} catch (error) {
- warn(`MetaMask - TokenRatesController exchange rate fetch failed for ${address}.`, error)
+ log.warn(`MetaMask - TokenRatesController exchange rate fetch failed for ${address}.`, error)
return 0
}
}