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 expiresIn = 30000; // in milliseconds
const cache = new Map()
const expiresIn = 30000 // in milliseconds
async function getPrice(fiat) {
fiat ??= 'USD';
async function getPrice (fiat) {
fiat ??= 'USD'
if (cache.has(fiat)) {
const { price, createdAt } = cache.get(fiat)
const expired = createdAt + expiresIn < Date.now()
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)
.then((res) => res.json())
.then((body) => parseFloat(body.data.amount))
.catch((err) => {
console.error(err);
return -1;
});
cache.set(fiat, { price, createdAt: Date.now() });
return price;
console.error(err)
return -1
})
cache.set(fiat, { price, createdAt: Date.now() })
return price
}
export default {
Query: {
price: async (parent, { fiatCurrency }, ctx) => {
const price = await getPrice(fiatCurrency);
return price;
},
},
};
const price = await getPrice(fiatCurrency)
return price
}
}
}

View File

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