Merge pull request #4097 from MetaMask/i4096-token-rates-error

Return 0 for token rate fetch failures
feature/default_network_editable
Kevin Serrano 7 years ago committed by GitHub
commit 387ec5b553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/scripts/controllers/token-rates.js

@ -1,4 +1,5 @@
const ObservableStore = require('obs-store') const ObservableStore = require('obs-store')
const { warn } = require('loglevel')
// By default, poll every 3 minutes // By default, poll every 3 minutes
const DEFAULT_INTERVAL = 180 * 1000 const DEFAULT_INTERVAL = 180 * 1000
@ -42,7 +43,10 @@ class TokenRatesController {
const response = await fetch(`https://metamask.balanc3.net/prices?from=${address}&to=ETH&autoConversion=false&summaryOnly=true`) const response = await fetch(`https://metamask.balanc3.net/prices?from=${address}&to=ETH&autoConversion=false&summaryOnly=true`)
const json = await response.json() const json = await response.json()
return json && json.length ? json[0].averagePrice : 0 return json && json.length ? json[0].averagePrice : 0
} catch (error) { } } catch (error) {
warn(`MetaMask - TokenRatesController exchange rate fetch failed for ${address}.`, error)
return 0
}
} }
/** /**

Loading…
Cancel
Save