remove semicolons from last merge

This commit is contained in:
keyan 2023-01-27 18:08:58 -06:00
parent 4ab66a67ae
commit 816361bd96
2 changed files with 17 additions and 17 deletions

View File

@ -1,32 +1,32 @@
const cache = new Map(); const cache = new Map()
const expiresIn = 30000; // in milliseconds const expiresIn = 30000 // in milliseconds
async function getPrice(fiat) { async function getPrice (fiat) {
fiat ??= 'USD'; fiat ??= 'USD'
if (cache.has(fiat)) { if (cache.has(fiat)) {
const { price, createdAt } = cache.get(fiat) const { price, createdAt } = cache.get(fiat)
const expired = createdAt + expiresIn < Date.now() const expired = createdAt + expiresIn < Date.now()
if (!expired) { if (!expired) {
return price; return price
} }
} }
const url = `https://api.coinbase.com/v2/prices/BTC-${fiat}/spot`; const url = `https://api.coinbase.com/v2/prices/BTC-${fiat}/spot`
const price = await fetch(url) const price = await fetch(url)
.then((res) => res.json()) .then((res) => res.json())
.then((body) => parseFloat(body.data.amount)) .then((body) => parseFloat(body.data.amount))
.catch((err) => { .catch((err) => {
console.error(err); console.error(err)
return -1; return -1
}); })
cache.set(fiat, { price, createdAt: Date.now() }); cache.set(fiat, { price, createdAt: Date.now() })
return price; return price
} }
export default { export default {
Query: { Query: {
price: async (parent, { fiatCurrency }, ctx) => { price: async (parent, { fiatCurrency }, ctx) => {
const price = await getPrice(fiatCurrency); const price = await getPrice(fiatCurrency)
return price; return price
}, }
}, }
}; }

View File

@ -26,7 +26,7 @@ export function usePrice () {
export function PriceProvider ({ price, children }) { export function PriceProvider ({ price, children }) {
const me = useMe() const me = useMe()
const fiatCurrency = me?.fiatCurrency; const fiatCurrency = me?.fiatCurrency
const { data } = useQuery(PRICE, { variables: { fiatCurrency }, pollInterval: 30000, fetchPolicy: 'cache-and-network' }) const { data } = useQuery(PRICE, { variables: { fiatCurrency }, pollInterval: 30000, fetchPolicy: 'cache-and-network' })
const contextValue = { const contextValue = {