diff --git a/packages/checkout/src/hooks/useSaleContractCheckout.ts b/packages/checkout/src/hooks/useSaleContractCheckout.ts index 8cae246d..efe94c7f 100644 --- a/packages/checkout/src/hooks/useSaleContractCheckout.ts +++ b/packages/checkout/src/hooks/useSaleContractCheckout.ts @@ -1,7 +1,7 @@ import { CheckoutOptionsSalesContractArgs } from '@0xsequence/marketplace' -import { useContractInfo } from '@0xsequence/kit' import { findSupportedNetwork } from '@0xsequence/network' +import { useSelectPaymentModal } from './useSelectPaymentModal' import { useCheckoutOptionsSalesContract } from "./useCheckoutOptionsSalesContract" import { ERC_1155_SALE_CONTRACT, ERC_721_SALE_CONTRACT } from '../constants/abi' @@ -44,6 +44,14 @@ export const useSaleContractCheckout = ({ const isLoading = isLoadingCheckoutOptions || isLoadingSaleConfig const error = isErrorCheckoutOtions || isErrorSaleConfig + + const openCheckoutModal = () => { + if (isLoading || error) return + + // return openCheckoutModal({ + // }) + } + return ({ data: undefined, isLoading, @@ -135,8 +143,6 @@ export const useSaleContractConfig = ({ chainId, tokenType, contractAddress, tok const isErrorERC1155 = isErrorPaymentTokenERC1155 || isErrorGlobalSaleDetailsERC1155 || isErrorTokenSaleDetailsERC1155 const isErrorERC721 = isErrorSaleDetailsERC721 - let saleInfos: SaleConfig[] = [] - if (isLoadingERC1155 || isLoadingERC721 || isErrorERC1155 || isErrorERC721) { return ({ data: undefined, @@ -145,8 +151,11 @@ export const useSaleContractConfig = ({ chainId, tokenType, contractAddress, tok }) } - const getPrice = () => { - if (isLoadingERC1155 || isLoadingERC721 || isErrorERC1155 || isErrorERC721) return + const getSaleConfigs = (): SaleConfig[] => { + let saleInfos: SaleConfig[] = [] + + if (isLoadingERC1155 || isLoadingERC721 || isErrorERC1155 || isErrorERC721) return saleInfos + if (tokenType === 'ERC1155') { // In the sale contract, the global sale has priority over the token sale // So we need to check if the global sale is set, and if it is, use that @@ -169,12 +178,14 @@ export const useSaleContractConfig = ({ chainId, tokenType, contractAddress, tok }) }) } + + return saleInfos } return ({ data: { currencyAddress: tokenType === 'ERC1155' ? (paymentTokenERC1155 as string) : (saleDetailsERC721 as SaleDetailsERC721)[2], - saleConfigs: saleInfos + saleConfigs: getSaleConfigs() }, isLoading: tokenType === 'ERC1155' ? isLoadingERC1155 : isLoadingERC721, isError: tokenType === 'ERC1155' ? isErrorERC1155 : isErrorERC721 diff --git a/packages/checkout/src/hooks/useSelectPaymentModal.ts b/packages/checkout/src/hooks/useSelectPaymentModal.ts index 0da8a8e0..bdef8c26 100644 --- a/packages/checkout/src/hooks/useSelectPaymentModal.ts +++ b/packages/checkout/src/hooks/useSelectPaymentModal.ts @@ -10,7 +10,7 @@ export const useSelectPaymentModal = () => { return { openSelectPaymentModal, closeSelectPaymentModal, selectPaymentSettings } } -type ERC1155SaleContractSettings = Omit +type SaleContractSettings = Omit export const getERC1155SaleContractConfig = ({ chain, @@ -21,7 +21,7 @@ export const getERC1155SaleContractConfig = ({ collectionAddress, isDev = false, ...restProps -}: ERC1155SaleContractSettings): SelectPaymentSettings => { +}: SaleContractSettings): SelectPaymentSettings => { const erc1155SalesContractAbi = [ { type: 'function', @@ -61,7 +61,7 @@ export const getERC1155SaleContractConfig = ({ export const useERC1155SaleContractPaymentModal = () => { const { openSelectPaymentModal, closeSelectPaymentModal, selectPaymentSettings } = useSelectPaymentModal() - const openERC1155SaleContractPaymentModal = (saleContractSettings: ERC1155SaleContractSettings) => { + const openERC1155SaleContractPaymentModal = (saleContractSettings: SaleContractSettings) => { openSelectPaymentModal(getERC1155SaleContractConfig(saleContractSettings)) } @@ -71,3 +71,64 @@ export const useERC1155SaleContractPaymentModal = () => { selectPaymentSettings } } + +// TODO: ERC721 utility +// export const getERC1155SaleContractConfig = ({ +// chain, +// price, +// currencyAddress = ethers.ZeroAddress, +// recipientAddress, +// collectibles, +// collectionAddress, +// isDev = false, +// ...restProps +// }: SaleContractSettings): SelectPaymentSettings => { +// const erc1155SalesContractAbi = [ +// { +// type: 'function', +// name: 'mint', +// inputs: [ +// { name: 'to', type: 'address', internalType: 'address' }, +// { name: 'tokenIds', type: 'uint256[]', internalType: 'uint256[]' }, +// { name: 'amounts', type: 'uint256[]', internalType: 'uint256[]' }, +// { name: 'data', type: 'bytes', internalType: 'bytes' }, +// { name: 'expectedPaymentToken', type: 'address', internalType: 'address' }, +// { name: 'maxTotal', type: 'uint256', internalType: 'uint256' }, +// { name: 'proof', type: 'bytes32[]', internalType: 'bytes32[]' } +// ], +// outputs: [], +// stateMutability: 'payable' +// } +// ] + +// const purchaseTransactionData = encodeFunctionData({ +// abi: erc1155SalesContractAbi, +// functionName: 'mint', +// args: [recipientAddress, collectibles.map(c => BigInt(c.tokenId)), collectibles.map(c => BigInt(c.quantity)), toHex(0), currencyAddress, price, [toHex(0, { size: 32 })]] +// }) + +// return { +// chain, +// price, +// currencyAddress, +// recipientAddress, +// collectibles, +// collectionAddress, +// isDev, +// txData: purchaseTransactionData, +// ...restProps +// } +// } + +export const useERC721SaleContractPaymentModal = () => { + const { openSelectPaymentModal, closeSelectPaymentModal, selectPaymentSettings } = useSelectPaymentModal() + const openERC721SaleContractPaymentModal = (saleContractSettings: SaleContractSettings) => { + openSelectPaymentModal(getERC721SaleContractConfig(saleContractSettings)) + } + + return { + openERC721SaleContractPaymentModal, + closeERC721SaleContractPaymentModal: closeSelectPaymentModal, + selectPaymentSettings + } +} \ No newline at end of file