@cross-nft-marketplace/auction-house-nft-components
Version:
NFT Media Rendering Components
38 lines (37 loc) • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NFTDataProvider = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const auction_house_nft_hooks_1 = require("@cross-nft-marketplace/auction-house-nft-hooks");
const transformPrices_1 = require("../utils/transformPrices");
const NFTDataContext_1 = require("./NFTDataContext");
//todo use INftWithAuction as initialData
const NFTDataProvider = ({ children, nftId, auctionId, swrConfiguration, showBids = true, kIndexerEnabled = true, }) => {
const loadByAuctionId = auctionId != null;
const loadAuctionByNftId = !loadByAuctionId && kIndexerEnabled;
const loadNftByNftId = !loadByAuctionId && !kIndexerEnabled;
const auctionByAuctionId = (0, auction_house_nft_hooks_1.useAuction)(auctionId, swrConfiguration);
const auctionByNftId = (0, auction_house_nft_hooks_1.useAuctionByNftId)(loadAuctionByNftId ? nftId === null || nftId === void 0 ? void 0 : nftId.contract : undefined, loadAuctionByNftId ? nftId === null || nftId === void 0 ? void 0 : nftId.tokenId : undefined, swrConfiguration);
const nftByNftIdFromHook = (0, auction_house_nft_hooks_1.useNft)(loadNftByNftId ? nftId === null || nftId === void 0 ? void 0 : nftId.contract : undefined, loadNftByNftId ? nftId === null || nftId === void 0 ? void 0 : nftId.tokenId : undefined, swrConfiguration);
const auctionFromHook = loadByAuctionId
? auctionByAuctionId
: auctionByNftId;
const auction = auctionFromHook.data;
const transformedPrices = (auction != null && showBids)
? (0, transformPrices_1.transformPrices)(auction)
: undefined;
const nft = (auction === null || auction === void 0 ? void 0 : auction.nft) || nftByNftIdFromHook.data;
const nftWithPricing = nft ? {
...nft,
pricing: transformedPrices
} : undefined;
const actualHook = loadNftByNftId
? nftByNftIdFromHook
: auctionFromHook;
return ((0, jsx_runtime_1.jsx)(NFTDataContext_1.NFTDataContext.Provider, { value: {
nft: nftWithPricing,
error: actualHook.error,
loading: actualHook.loading
}, children: children }));
};
exports.NFTDataProvider = NFTDataProvider;