mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
feature: switch token pricing to CoinGecko API (#6424)
This commit is contained in:
parent
7e0006a7fd
commit
a973a7420a
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user