From f1b81551c11ce83eb1a668274cfd1f873a500133 Mon Sep 17 00:00:00 2001 From: samuelea Date: Wed, 11 Dec 2024 17:54:12 -0500 Subject: [PATCH] checkout modal --- examples/react/src/components/Connected.tsx | 7 +-- .../hooks/useERC1155SaleContractCheckout.ts | 49 +++++++++---------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/examples/react/src/components/Connected.tsx b/examples/react/src/components/Connected.tsx index 141e4f84..eb181c85 100644 --- a/examples/react/src/components/Connected.tsx +++ b/examples/react/src/components/Connected.tsx @@ -47,10 +47,8 @@ export const Connected = () => { const { setOpenWalletModal } = useOpenWalletModal() const { triggerCheckout } = useCheckoutModal() const { triggerAddFunds } = useAddFundsModal() - const { openERC1155SaleContractPaymentModal } = useERC1155SaleContractPaymentModal() - const { openCheckoutModal, isLoading: isLoadingCheckoutModal } = useERC1155SaleContractCheckout( - getErc1155SaleContractConfig(address || '') - ) + // const { openERC1155SaleContractPaymentModal } = useERC1155SaleContractPaymentModal() + const { openCheckoutModal } = useERC1155SaleContractCheckout(getErc1155SaleContractConfig(address || '')) const { data: walletClient } = useWalletClient() const storage = useStorage() @@ -559,7 +557,6 @@ export const Connected = () => { title="Checkout with Sequence Pay" description="Purchase an NFT through various purchase methods" onClick={onClickSelectPayment} - isPending={isLoadingCheckoutModal} /> diff --git a/packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts b/packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts index b0d365bc..811a1aec 100644 --- a/packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts +++ b/packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts @@ -44,9 +44,6 @@ export const useERC1155SaleContractCheckout = ({ const { data: saleConfigData, isLoading: isLoadingSaleConfig, isError: isErrorSaleConfig } = useSaleContractConfig({ chainId, contractAddress, tokenIds: items.map(i => i.tokenId) }) - // Get sale contract currency data... - // Get token sale data - // Pass wrapper to open select modal const isLoading = isLoadingCheckoutOptions || isLoadingSaleConfig const error = isErrorCheckoutOptions || isErrorSaleConfig @@ -56,27 +53,27 @@ export const useERC1155SaleContractCheckout = ({ return } - return () => { - openERC1155SaleContractPaymentModal({ - collectibles: items.map(item => ({ - tokenId: item.tokenId, - quantity: item.quantity - })), - chain: chainId, - price: items.reduce((acc, item) => { - const price = BigInt(saleConfigData?.saleConfigs.find(sale => sale.tokenId === item.tokenId)?.price || 0) - return acc + BigInt(item.quantity) * price - }, BigInt(0)).toString(), - currencyAddress: saleConfigData?.currencyAddress || '', - recipientAddress: wallet, - collectionAddress, - targetContractAddress: contractAddress, - enableMainCurrencyPayment: true, - enableSwapPayments: checkoutOptions?.options.swap.includes(TransactionSwapProvider.zerox) || false, - creditCardProviders: checkoutOptions?.options.nftCheckout || [], - ...restArgs - }) - } + openERC1155SaleContractPaymentModal({ + collectibles: items.map(item => ({ + tokenId: item.tokenId, + quantity: item.quantity + })), + chain: chainId, + price: items.reduce((acc, item) => { + const price = BigInt(saleConfigData?.saleConfigs.find(sale => sale.tokenId === item.tokenId)?.price || 0) + console.log('price...', price) + + return acc + BigInt(item.quantity) * price + }, BigInt(0)).toString(), + currencyAddress: saleConfigData?.currencyAddress || '', + recipientAddress: wallet, + collectionAddress, + targetContractAddress: contractAddress, + enableMainCurrencyPayment: true, + enableSwapPayments: checkoutOptions?.options?.swap?.includes(TransactionSwapProvider.zerox) || false, + creditCardProviders: checkoutOptions?.options.nftCheckout || [], + ...restArgs + }) } return ({ @@ -167,12 +164,12 @@ export const useSaleContractConfig = ({ chainId, contractAddress, tokenIds, }: U // So we need to check if the global sale is set, and if it is, use that // Otherwise, we use the token sale const { cost: globalCost, startTime, endTime } = globalSaleDetailsERC1155 as SaleDetailsERC1155 - const isGlobalSaleValid = endTime === BigInt(0) || (startTime <= BigInt(Math.floor(Date.now() / 1000)) || endTime >= BigInt(Math.floor(Date.now() / 1000))) + const isGlobalSaleInvalid = endTime === BigInt(0) || (BigInt(Math.floor(Date.now() / 1000)) <= startTime || BigInt(Math.floor(Date.now() / 1000)) >= endTime) saleInfos = tokenIds.map((tokenId, index) => { const tokenPrice = (tokenSaleDetailsERC1155?.[index].result as SaleDetailsERC1155)['cost'] || BigInt(0) return ({ tokenId, - price: (isGlobalSaleValid ? globalCost : tokenPrice).toString() + price: (!isGlobalSaleInvalid ? globalCost : tokenPrice).toString() }) })