UNPKG

@cross-nft-marketplace/auction-house-nft-components

Version:
62 lines (61 loc) 3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformPrices = void 0; const auction_house_nft_hooks_1 = require("@cross-nft-marketplace/auction-house-nft-hooks"); const big_js_1 = __importDefault(require("big.js")); const setCurrencyDecimal = (amount, decimals) => { return new big_js_1.default(amount) .div(new big_js_1.default(10).pow(parseInt(decimals, 10) || 18)) .toString(); }; const USDT_DECIMALS = 6; //todo use PriceDecimal or pass curren function getCurrencyComputedValue(currency, bidAmount) { if (!currency.price) { return undefined; } //todo use BN instead of float return { inUSD: (parseFloat(setCurrencyDecimal(bidAmount, currency.decimals)) * parseFloat(setCurrencyDecimal(currency.price, USDT_DECIMALS))).toString(), }; } ; function transformBid(bid) { return { ...bid, trasformedPricing: { prettyAmount: setCurrencyDecimal(bid.price, bid.currency.decimals), currency: bid.currency, computedValue: getCurrencyComputedValue(bid.currency, bid.price) } }; } function transformPrices(auction) { var _a, _b, _c, _d; let topBid = auction_house_nft_hooks_1.AuctionUtils.getTopBid(auction); return { ...auction, endedUsingBuyNow: (_c = (_b = (_a = auction.previousBids) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.buyNowActual) !== null && _c !== void 0 ? _c : false, isLikelyHasEnded: auction_house_nft_hooks_1.AuctionUtils.isLikelyHasEnded(auction), topBid: topBid ? transformBid(topBid) : undefined, trasformedPricing: auction.currencies != null //if include_currencies=true ? { reservePrice: { prettyAmount: setCurrencyDecimal(auction.reservePrice, auction.reserveAndBuyNowCurrency.decimals), currency: auction.reserveAndBuyNowCurrency, computedValue: getCurrencyComputedValue(auction.reserveAndBuyNowCurrency, auction.reservePrice) }, buyNowPrice: auction.buyNowPrice != "0" ? { prettyAmount: setCurrencyDecimal(auction.buyNowPrice, auction.reserveAndBuyNowCurrency.decimals), currency: auction.reserveAndBuyNowCurrency, computedValue: getCurrencyComputedValue(auction.reserveAndBuyNowCurrency, auction.buyNowPrice) } : undefined, previousBids: (_d = auction.previousBids) === null || _d === void 0 ? void 0 : _d.map(transformBid), currentBid: auction.currentBid ? transformBid(auction.currentBid) : undefined } : undefined, }; } exports.transformPrices = transformPrices;