UNPKG

@yoroi/swap

Version:
33 lines (32 loc) 956 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPtPrice = void 0; var _common = require("@yoroi/common"); 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 < _common.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 => (0, _common.isRight)(res) ? res.value.data.netPrice : 0); priceCache[id] = { price, timestamp: now }; return price; }; }; exports.getPtPrice = getPtPrice; //# sourceMappingURL=getPtPrice.js.map