UNPKG

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

Version:
54 lines (53 loc) 6.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PricingComponent = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const useMediaContext_1 = require("../context/useMediaContext"); const NFTDataContext_1 = require("../context/NFTDataContext"); const CountdownDisplay_1 = require("../components/CountdownDisplay"); const PricingString_1 = require("../utils/PricingString"); const date_1 = require("../utils/date"); function isInFuture(timestamp) { const timestampParsed = parseInt(timestamp); return timestampParsed > Math.floor(new Date().getTime() / 1000); } const dateWithComma = (date) => (0, date_1.dateFormat)(date).replace(' at', ','); const PricingComponent = ({ className, }) => { const { nft } = (0, react_1.useContext)(NFTDataContext_1.NFTDataContext); const { getStyles, getString } = (0, useMediaContext_1.useMediaContext)(); const pricing = nft === null || nft === void 0 ? void 0 : nft.pricing; if (!(nft === null || nft === void 0 ? void 0 : nft.pricing)) { return ((0, jsx_runtime_1.jsxs)("div", { ...getStyles("cardAuctionPricing", className, { type: "unknown" }), children: [(0, jsx_runtime_1.jsx)("div", { ...getStyles("textSubdued"), children: getString("RESERVE_PRICE") }), (0, jsx_runtime_1.jsx)("div", { ...getStyles("pricingAmount"), children: getString("NO_PRICING_PLACEHOLDER") }), (0, jsx_runtime_1.jsx)("div", { ...getStyles("textSubdued"), children: getString("HIGHEST_BID") }), (0, jsx_runtime_1.jsx)("div", { ...getStyles("pricingAmount"), children: getString("NO_PRICING_PLACEHOLDER") })] })); } if (pricing && pricing.trasformedPricing) { if (pricing.trasformedPricing.currentBid && !pricing.isLikelyHasEnded) { const highestBid = pricing.trasformedPricing.currentBid; const buyNow = pricing.trasformedPricing.buyNowPrice && ((0, jsx_runtime_1.jsxs)("div", { ...getStyles("auctionsBuyNowPrice"), children: [(0, jsx_runtime_1.jsx)("span", { ...getStyles("textSubdued"), children: getString("BUY_NOW_PRICE") }), (0, jsx_runtime_1.jsx)("span", { ...getStyles("auctionsBuyNowPriceAmount"), children: highestBid && ((0, jsx_runtime_1.jsx)(PricingString_1.PricingString, { showUSD: true, pricing: pricing.trasformedPricing.buyNowPrice })) })] })); return ((0, jsx_runtime_1.jsxs)("div", { ...getStyles("cardAuctionPricing", className, { type: "reserve-active", }), children: [(0, jsx_runtime_1.jsxs)("div", { ...getStyles("auctionsHighestBidPrice"), children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("span", { ...getStyles("textSubdued"), children: getString("TOP_BID") }), (0, jsx_runtime_1.jsx)("span", { ...getStyles("pricingAmount"), children: highestBid && ((0, jsx_runtime_1.jsx)(PricingString_1.PricingString, { pricing: highestBid === null || highestBid === void 0 ? void 0 : highestBid.trasformedPricing, showUSD: true })) })] }), buyNow] }), pricing.expectedEndTimestamp && isInFuture(pricing.expectedEndTimestamp.toString()) && ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { ...getStyles("textSubdued"), children: getString("ENDS_IN") }), (0, jsx_runtime_1.jsx)("span", { ...getStyles("pricingAmount"), children: (0, jsx_runtime_1.jsx)(CountdownDisplay_1.CountdownDisplay, { to: pricing.expectedEndTimestamp }) })] }))] })); } if (pricing.isLikelyHasEnded) { //todo not cancelled const highestBid = pricing.topBid; return ((0, jsx_runtime_1.jsxs)("div", { ...getStyles("cardAuctionPricing", className, { type: "reserve-finished", }), children: [(0, jsx_runtime_1.jsx)("span", { ...getStyles("textSubdued"), children: getString("AUCTION_SOLD_FOR") }), (0, jsx_runtime_1.jsx)("span", { ...getStyles("pricingAmount"), children: (0, jsx_runtime_1.jsx)(PricingString_1.PricingString, { showUSD: false, pricing: highestBid === null || highestBid === void 0 ? void 0 : highestBid.trasformedPricing }) }), (0, jsx_runtime_1.jsx)("span", { ...getStyles("textSubdued"), children: getString("SOLD_AT") }), (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)("time", { dateTime: (0, date_1.dateFromTimestamp)(highestBid.transactionInfo.blockTimestamp.toString()).toISOString(), children: dateWithComma(highestBid.transactionInfo.blockTimestamp.toString()) }) })] })); } let buyNowPrice = null; if (pricing.trasformedPricing.buyNowPrice) { buyNowPrice = ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("span", { ...getStyles("textSubdued"), children: getString("BUY_NOW_PRICE") }), (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(PricingString_1.PricingString, { showUSD: true, pricing: pricing.trasformedPricing.buyNowPrice }) })] })); } else { buyNowPrice = ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("span", { ...getStyles("textSubdued"), children: getString("BUY_NOW_PRICE") }), (0, jsx_runtime_1.jsx)("span", { children: getString("NOT_APPLICABLE") })] })); } return ((0, jsx_runtime_1.jsxs)("div", { ...getStyles("cardAuctionPricing", className, { type: "reserve-pending", }), children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("span", { ...getStyles("textSubdued"), children: getString("RESERVE_PRICE") }), (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(PricingString_1.PricingString, { showUSD: true, pricing: pricing.trasformedPricing.reservePrice }) })] }), buyNowPrice] })); } return ((0, jsx_runtime_1.jsxs)("div", { ...getStyles("cardAuctionPricing", className, { type: "unknown" }), children: [(0, jsx_runtime_1.jsx)("span", { ...getStyles("auctionsBuyNowPriceLabelLoading"), children: getString("PRICING_LOADING_LABEL") }), (0, jsx_runtime_1.jsx)("span", { ...getStyles("auctionsBuyNowPriceLoading"), children: getString("PRICING_LOADING") }), (0, jsx_runtime_1.jsx)("span", { ...getStyles("auctionsBuyNowPriceLabelLoading"), children: getString("PRICING_LOADING_LABEL") }), (0, jsx_runtime_1.jsx)("span", { ...getStyles("auctionsBuyNowPriceLoading"), children: getString("PRICING_LOADING") })] })); }; exports.PricingComponent = PricingComponent;