UNPKG

@yoroi/swap

Version:
28 lines (27 loc) 822 B
"use strict"; import { isRight, time } from '@yoroi/common'; export const getPtPrice = (primaryTokenInfo, api) => { // TODO: react-query now has persistance, we can drop it here and move to client. const priceCache = {}; return async id => { if (primaryTokenInfo.id === id) return 1; const cached = priceCache[id]; const now = Date.now(); if (cached && now - cached.timestamp < time.minutes(5)) { return cached.price; } const price = await api.estimate({ tokenIn: primaryTokenInfo.id, tokenOut: id, // NOTE: arbritraty to return a price amountIn: 50, slippage: 0 }).then(res => isRight(res) ? res.value.data.netPrice : 0); priceCache[id] = { price, timestamp: now }; return price; }; }; //# sourceMappingURL=getPtPrice.js.map