diff --git a/frontend/package.json b/frontend/package.json index a23d9c88..f2538cd9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -17,7 +17,6 @@ "@types/react-dom": "^17.0.0", "@types/styled-components": "^5.1.9", "bnc-onboard": "^1.25.0", - "coingecko-api": "^1.0.10", "graphql": "^15.5.0", "numeral-es6": "^1.0.0", "react": "^17.0.2", diff --git a/frontend/src/utils/price.ts b/frontend/src/utils/price.ts index 4053f2e2..49b9e823 100644 --- a/frontend/src/utils/price.ts +++ b/frontend/src/utils/price.ts @@ -1,4 +1,3 @@ -import CGApi from 'coingecko-api' import { HOUR_IN_MS } from '../constants' import * as ls from './cache' @@ -46,30 +45,18 @@ const SYMBOL_TO_QUERY: Record = { FORTH: 'ampleforth-governance-token', } +const URL = "https://web-api.ampleforth.org/util/get-price" + export const getCurrentPrice = async (symbol: string) => { const cacheKey = `geyser|${symbol}|spot` const TTL = HOUR_IN_MS try { - const query = SYMBOL_TO_QUERY[symbol] - if (!query) { - throw new Error(`Can't fetch price for ${symbol}`) - } + const response = await fetch(`${URL}?symbol=${symbol}`); + const price = await response.json(); return await ls.computeAndCache( - async () => { - const client = new CGApi() - const reqTimeoutSec = 10 - const p: any = await Promise.race([ - client.simple.price({ - ids: [query], - vs_currencies: ['usd'], - }), - new Promise((_, reject) => setTimeout(() => reject(new Error('request timeout')), reqTimeoutSec * 1000)), - ]) - const price = p.data[query].usd - return price as number - }, + async () => price as number, cacheKey, TTL, ) diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 3109bf9d..f132f1f5 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -5761,11 +5761,6 @@ coa@^2.0.2: chalk "^2.4.1" q "^1.1.2" -coingecko-api@^1.0.10: - version "1.0.10" - resolved "https://registry.yarnpkg.com/coingecko-api/-/coingecko-api-1.0.10.tgz#ac8694d5999f00727fe55f0078ce2917603076b2" - integrity sha512-7YLLC85+daxAw5QlBWoHVBVpJRwoPr4HtwanCr8V/WRjoyHTa1Lb9DQAvv4MDJZHiz4no6HGnDQnddtjV35oRA== - collect-v8-coverage@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz#cc2c8e94fc18bbdffe64d6534570c8a673b27f59"