Skip to content

Commit

Permalink
updated pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Nov 17, 2023
1 parent c878fd6 commit 14cf664
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 5 additions & 18 deletions frontend/src/utils/price.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import CGApi from 'coingecko-api'
import { HOUR_IN_MS } from '../constants'
import * as ls from './cache'

Expand Down Expand Up @@ -46,30 +45,18 @@ const SYMBOL_TO_QUERY: Record<string, string> = {
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<number>(
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,
)
Expand Down
5 changes: 0 additions & 5 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 14cf664

Please sign in to comment.