aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Bouchon <mail@bitpshr.net>2019-04-11 06:37:15 +0800
committerGitHub <noreply@github.com>2019-04-11 06:37:15 +0800
commita973a7420abed55998b88c339d1c6a1c53bd63e2 (patch)
treedf8c508ae08ed29569ecf567966f56511d4eef0e
parent7e0006a7fd993cbeb2a6d916d6d47a4654eb5aa7 (diff)
downloadtangerine-wallet-browser-a973a7420abed55998b88c339d1c6a1c53bd63e2.tar
tangerine-wallet-browser-a973a7420abed55998b88c339d1c6a1c53bd63e2.tar.gz
tangerine-wallet-browser-a973a7420abed55998b88c339d1c6a1c53bd63e2.tar.bz2
tangerine-wallet-browser-a973a7420abed55998b88c339d1c6a1c53bd63e2.tar.lz
tangerine-wallet-browser-a973a7420abed55998b88c339d1c6a1c53bd63e2.tar.xz
tangerine-wallet-browser-a973a7420abed55998b88c339d1c6a1c53bd63e2.tar.zst
tangerine-wallet-browser-a973a7420abed55998b88c339d1c6a1c53bd63e2.zip
feature: switch token pricing to CoinGecko API (#6424)
-rw-r--r--app/scripts/controllers/token-rates.js16
1 files changed, 8 insertions, 8 deletions
diff --git a/app/scripts/controllers/token-rates.js b/app/scripts/controllers/token-rates.js
index 867d36433..4e396bb59 100644
--- a/app/scripts/controllers/token-rates.js
+++ b/app/scripts/controllers/token-rates.js
@@ -28,16 +28,16 @@ class TokenRatesController {
async updateExchangeRates () {
if (!this.isActive) { return }
const contractExchangeRates = {}
- const nativeCurrency = this.currency ? this.currency.getState().nativeCurrency.toUpperCase() : 'ETH'
- const pairs = this._tokens.map(token => `pairs[]=${token.address}/${nativeCurrency}`)
- const query = pairs.join('&')
+ const nativeCurrency = this.currency ? this.currency.getState().nativeCurrency.toLowerCase() : 'eth'
+ const pairs = this._tokens.map(token => token.address).join(',')
+ const query = `contract_addresses=${pairs}&vs_currencies=${nativeCurrency}`
if (this._tokens.length > 0) {
try {
- const response = await fetch(`https://exchanges.balanc3.net/pie?${query}&autoConversion=false`)
- const { prices = [] } = await response.json()
- prices.forEach(({ pair, price }) => {
- const address = pair.split('/')[0]
- contractExchangeRates[normalizeAddress(address)] = typeof price === 'number' ? price : 0
+ const response = await fetch(`https://api.coingecko.com/api/v3/simple/token_price/ethereum?${query}`)
+ const prices = await response.json()
+ this._tokens.forEach(token => {
+ const price = prices[token.address.toLowerCase()]
+ contractExchangeRates[normalizeAddress(token.address)] = price ? price[nativeCurrency] : 0
})
} catch (error) {
log.warn(`MetaMask - TokenRatesController exchange rate fetch failed.`, error)