From 676e19ed1dc65fa01b6c5e5fb929f7adb186c00f Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 28 Oct 2022 12:11:46 +0800 Subject: [PATCH] remove price cache --- src/store/chains/index.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/store/chains/index.js b/src/store/chains/index.js index 8d766933..29b2fe4e 100644 --- a/src/store/chains/index.js +++ b/src/store/chains/index.js @@ -10,7 +10,7 @@ import { sha256 } from '@cosmjs/crypto' import { toHex } from '@cosmjs/encoding' let chains = {} - +const coingecko = {} let configs = require.context('../../chains/mainnet', false, /\.json$/) if (isTestnet()) { configs = require.context('../../chains/testnet', false, /\.json$/) @@ -21,6 +21,9 @@ configs.keys().forEach(k => { const c = configs(k) c.chain_name = String(c.chain_name).toLowerCase() update[c.chain_name] = c + c.assets.forEach(x => { + if (x.coingecko_id && x.coingecko_id !== '') coingecko[x.coingecko_id] = String(x.symbol).toUpperCase() + }) }) chains = update @@ -83,9 +86,24 @@ export default { }, actions: { async getQuotes(context) { - fetch('https://price.ping.pub/quotes').then(data => data.json()).then(data => { - context.commit('setQuotes', data) - }) + // fetch('https://price.ping.pub/quotes').then(data => data.json()).then(data => { + // context.commit('setQuotes', data) + // console.log(data) + // }) + console.log(coingecko) + const keys = Object.keys(coingecko) + if (keys.length > 0) { + const currencies = 'usd,cny,eur,jpy,krw,sgd,hkd' + fetch(`https://api.coingecko.com/api/v3/simple/price?vs_currencies=${currencies}&ids=${keys.join(',')}`).then(data => data.json()).then(data => { + // use symbol as key instead of coingecko id + const quotes = {} + Object.keys(data).forEach(k => { + quotes[coingecko[k]] = data[k] + }) + context.commit('setQuotes', quotes) + console.log(quotes) + }) + } }, async getAllIBCDenoms(context, _this) {