Skip to content

Commit

Permalink
checkout modal
Browse files Browse the repository at this point in the history
  • Loading branch information
SamueleA committed Dec 16, 2024
1 parent 1cdb065 commit f1b8155
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
7 changes: 2 additions & 5 deletions examples/react/src/components/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -559,7 +557,6 @@ export const Connected = () => {
title="Checkout with Sequence Pay"
description="Purchase an NFT through various purchase methods"
onClick={onClickSelectPayment}
isPending={isLoadingCheckoutModal}
/>
</Box>

Expand Down
49 changes: 23 additions & 26 deletions packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ({
Expand Down Expand Up @@ -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()
})
})

Expand Down

0 comments on commit f1b8155

Please sign in to comment.