diff --git a/packages/react/src/features/nft-collections/extensions/minting/useSaleMinter.ts b/packages/react/src/features/nft-collections/extensions/minting/useSaleMinter.ts index 757572ac9..ebcba1883 100644 --- a/packages/react/src/features/nft-collections/extensions/minting/useSaleMinter.ts +++ b/packages/react/src/features/nft-collections/extensions/minting/useSaleMinter.ts @@ -2,10 +2,7 @@ import { Provider } from '@ethersproject/providers'; import { Environment } from '@flair-sdk/common'; import { ContractVersion } from '@flair-sdk/registry'; import { BigNumberish, BytesLike, Signer } from 'ethers'; -import { useCallback } from 'react'; -import { useHasAnyOfFeatures } from '../../../../common'; -import { useSimpleSaleMinter } from '../sales/hooks/useSimpleSaleMinter'; import { useTierSaleMinter } from '../sales/hooks/useTierSaleMinter'; type Config = { @@ -20,7 +17,7 @@ type Config = { }; /** - * Consolidated function for sales minting (supports both simple and tiered sales). + * Consolidated function for sales minting */ export const useSaleMinter = ({ env, @@ -32,56 +29,11 @@ export const useSaleMinter = ({ minterAddress, mintCount, }: Config) => { - const { - data: supportsSimpleSales, - error: supportsSimpleSalesError, - isLoading: supportsSimpleSalesLoading, - } = useHasAnyOfFeatures({ - env, - chainId, - contractAddress, - tags: [ - 'erc721_public_sale_extension', - 'erc721_presale_extension', - 'mint_amount_by_merkle_proof', - ], - }); - - const { - data: supportsTieredSales, - error: supportsTieredSalesError, - isLoading: supportsTieredSalesLoading, - } = useHasAnyOfFeatures({ - env, - chainId, - contractAddress, - tags: ['erc721_tiering_extension', 'mint_by_tier_with_allowance_and_proof'], - }); - - const loadingSaleType = - supportsSimpleSalesLoading || supportsTieredSalesLoading; - - const { - data: simpleSaleData, - error: simpleSaleError, - isLoading: simpleSaleLoading, - mint: simpleMint, - } = useSimpleSaleMinter({ - env, - chainId, - contractAddress, - contractVersion, - mintCount, - minterAddress, - signerOrProvider, - enabled: !loadingSaleType && supportsSimpleSales, - }); - const { data: tierSaleData, error: tierSaleError, isLoading: tierSaleLoading, - mint: tierMint, + mint, } = useTierSaleMinter({ env, chainId, @@ -91,110 +43,36 @@ export const useSaleMinter = ({ minterAddress, signerOrProvider, tierId, - enabled: !loadingSaleType && supportsTieredSales, }); - const mint = useCallback( - (args?: { mintCount: BigNumberish }) => { - if (supportsSimpleSales) { - return simpleMint(args); - } else if (supportsTieredSales) { - return tierMint(args); - } - }, - [supportsSimpleSales, simpleMint, supportsTieredSales, tierMint], - ); - return { - data: supportsTieredSales - ? { - /** - * Tiered Sales - */ - - // Transaction - txReceipt: tierSaleData.txReceipt, - txResponse: tierSaleData.txResponse, - - // Common Info - start: tierSaleData.start, - end: tierSaleData.end, - price: tierSaleData.price, - isActive: tierSaleData.isActive, - hasAllowlist: tierSaleData.hasAllowlist, + data: { + // Transaction + txReceipt: tierSaleData.txReceipt, + txResponse: tierSaleData.txResponse, - // Account-specific Info - isAllowlisted: tierSaleData.isAllowlisted, - isEligible: tierSaleData.isEligible, - eligibleAmount: tierSaleData.eligibleAmount, - } - : { - /** - * Simple Sales - */ + // Common Info + start: tierSaleData.start, + end: tierSaleData.end, + price: tierSaleData.price, + isActive: tierSaleData.isActive, + hasAllowlist: tierSaleData.hasAllowlist, - // Transaction - txReceipt: simpleSaleData.txReceipt, - txResponse: simpleSaleData.txResponse, - - // Common Info (for simple sales we assume pre-sale is tier 0 and public-sale is tier 1) - start: undefined, - end: undefined, - price: - tierId?.toString() === '0' - ? simpleSaleData.preSalePrice - : simpleSaleData.publicSalePrice, - isActive: - tierId?.toString() === '0' - ? simpleSaleData.preSaleStatus - : simpleSaleData.publicSaleStatus, - hasAllowlist: tierId?.toString() === '0' ? true : false, - - // Account-specific Info - isAllowlisted: - tierId?.toString() === '0' - ? simpleSaleData.preSaleIsAllowlisted - : undefined, - isEligible: - tierId?.toString() === '0' - ? simpleSaleData.preSaleStatus && - simpleSaleData.preSaleIsAllowlisted - : simpleSaleData.publicSaleStatus, - eligibleAmount: - tierId?.toString() === '0' - ? Number(simpleSaleData.preSaleMaxMintPerWallet?.toString()) - : Number(simpleSaleData.publicSaleMaxMintPerTx?.toString()), - }, - error: supportsTieredSales - ? supportsTieredSalesError || - // Tiered Sales - tierSaleError.allowlistCheckerError || - tierSaleError.eligibleAmountError || - tierSaleError.mintError || - tierSaleError.tierError - : supportsSimpleSalesError || - // Simple Sales - simpleSaleError.preSaleAllowlistCheckerError || - simpleSaleError.preSaleStatusError || - simpleSaleError.preSaleMintError || - simpleSaleError.publicSaleStatusError || - simpleSaleError.publicSaleMintError, - isLoading: supportsTieredSales - ? // Common - supportsTieredSalesLoading || - // Tiered Sales - tierSaleLoading.allowlistCheckerLoading || - tierSaleLoading.eligibleAmountLoading || - tierSaleLoading.mintLoading || - tierSaleLoading.tierLoading - : // Common - supportsSimpleSalesLoading || - // Simple Sales - simpleSaleLoading.preSaleAllowlistCheckerLoading || - simpleSaleLoading.preSaleStatusLoading || - simpleSaleLoading.preSaleMintLoading || - simpleSaleLoading.publicSaleStatusLoading || - simpleSaleLoading.publicSaleMintLoading, + // Account-specific Info + isAllowlisted: tierSaleData.isAllowlisted, + isEligible: tierSaleData.isEligible, + eligibleAmount: tierSaleData.eligibleAmount, + }, + error: + tierSaleError.allowlistCheckerError || + tierSaleError.eligibleAmountError || + tierSaleError.mintError || + tierSaleError.tierError, + isLoading: + tierSaleLoading.allowlistCheckerLoading || + tierSaleLoading.eligibleAmountLoading || + tierSaleLoading.mintLoading || + tierSaleLoading.tierLoading, mint, } as const; }; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/index.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/index.ts index 52a73d563..763275f5c 100644 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/index.ts +++ b/packages/react/src/features/nft-collections/extensions/sales/hooks/index.ts @@ -1,20 +1,5 @@ -export * from './usePreSaleAllowlistChecker'; -export * from './usePreSaleAllowlistMerkleRoot'; -export * from './usePreSaleMaxMintPerWallet'; -export * from './usePreSaleMinter'; -export * from './usePreSalePrice'; -export * from './usePreSaleStatus'; - -export * from './usePublicSaleMaxMintPerTx'; -export * from './usePublicSaleMinter'; -export * from './usePublicSalePrice'; -export * from './usePublicSaleStatus'; - export * from './useSaleTiers'; - -export * from './useSimpleSaleMinter'; export * from './useTierSaleMinter'; - export * from './useTierSaleAllowlistChecker'; export * from './useTierSaleEligibleAmount'; export * from './useTierSaleInformation'; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleAllowlistChecker.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleAllowlistChecker.ts deleted file mode 100644 index ef9d94962..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleAllowlistChecker.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { Environment } from '@flair-sdk/common'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumberish, BytesLike } from 'ethers'; -import { useCallback } from 'react'; - -import { useContractRead } from '../../../../../common'; -import { useAddressListMerkleProof } from '../../../../address-lists'; -import { usePreSaleAllowlistMerkleRoot } from './usePreSaleAllowlistMerkleRoot'; - -type Config = { - env?: Environment; - enabled?: boolean; - chainId?: number; - contractVersion?: ContractVersion; - contractAddress?: string; - minterAddress?: BytesLike; -}; - -export const usePreSaleAllowlistChecker = ({ - env = Environment.PROD, - enabled = true, - chainId, - contractVersion, - contractAddress, - minterAddress, -}: Config) => { - const readyToRead = Boolean( - enabled && minterAddress && contractAddress && chainId, - ); - - const leafMode = 'address-only'; - // TODO Use this when simple sale supports allowance in allowlists - // const leafMode = - // !contractVersion || versioning.gte(contractVersion, 'v1.19') - // ? 'address-with-allowance' - // : 'address-only'; - - const { - data: merkleRoot, - error: merkleRootError, - isLoading: merkleRootLoading, - } = usePreSaleAllowlistMerkleRoot({ - chainId, - contractAddress, - enabled: readyToRead, - }); - - const { - data: proofData, - error: proofError, - isLoading: proofLoading, - refetch: fetchProof, - } = useAddressListMerkleProof({ - env, - address: minterAddress, - leafMode, - rootHash: merkleRoot, - enabled: readyToRead, - }); - - const { - data: isPreSaleAllowListed, - error: onPreSaleAllowListError, - isLoading: onPreSaleAllowListLoading, - refetch: onPreSaleAllowListRead, - } = useContractRead< - boolean, - [BytesLike, BytesLike[]] | [BytesLike, BigNumberish, BytesLike[]] - >({ - chainId, - contractVersion, - enabled: Boolean(readyToRead && minterAddress && proofData?.merkleProof), - contractFqn: 'collections/ERC721/extensions/ERC721PreSaleExtension', - functionName: 'onPreSaleAllowList', - contractAddress, - cacheOnBlock: false, - cacheTime: 0, - staleTime: 0, - args: - minterAddress && proofData?.merkleProof - ? leafMode === 'address-only' - ? [minterAddress, proofData.merkleProof] - : [ - minterAddress, - Number(proofData.merkleMetadata?.maxAllowance), - proofData.merkleProof, - ] - : undefined, - }); - - const onPreSaleAllowList = useCallback(() => { - fetchProof().then(() => { - return onPreSaleAllowListRead(); - }); - }, [fetchProof, onPreSaleAllowListRead]); - - return { - data: { - isAllowlisted: isPreSaleAllowListed, - allowlistProof: proofData.merkleProof || undefined, - allowlistMetadata: proofData.merkleMetadata || undefined, - }, - error: onPreSaleAllowListError || proofError || merkleRootError, - isLoading: onPreSaleAllowListLoading || proofLoading || merkleRootLoading, - reCheck: onPreSaleAllowList, - } as const; -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleAllowlistMerkleRoot.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleAllowlistMerkleRoot.ts deleted file mode 100644 index e58ad047c..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleAllowlistMerkleRoot.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -export const usePreSaleAllowlistMerkleRoot = ( - config: PredefinedReadContractConfig, -) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721PreSaleExtension', - functionName: 'preSaleAllowlistMerkleRoot', - ...config, - }); -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleMaxMintPerWallet.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleMaxMintPerWallet.ts deleted file mode 100644 index 6f8f64c5b..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleMaxMintPerWallet.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -export const usePreSaleMaxMintPerWallet = ( - config: PredefinedReadContractConfig, -) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721PreSaleExtension', - functionName: 'preSaleMaxMintPerWallet', - ...config, - }); -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleMinter.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleMinter.ts deleted file mode 100644 index 19f9350a9..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleMinter.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumber, BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../../common'; -import { usePreSalePrice } from './usePreSalePrice'; - -type Config = { - chainId?: number; - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - enabled?: boolean; - mintCount?: BigNumberish; - allowlistProof?: BytesLike[]; -}; - -type ArgsType = [mintCount: BigNumberish, allowlistProof: BytesLike[]]; - -export const usePreSaleMinter = ({ - chainId, - contractVersion, - contractAddress, - signerOrProvider, - enabled, - mintCount, - allowlistProof, -}: Config) => { - const { - data: preSalePrice, - isLoading, - error, - } = usePreSalePrice({ - chainId, - contractVersion, - contractAddress, - enabled, - }); - - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'collections/ERC721/extensions/ERC721PreSaleExtension', - }); - - const result = useContractWriteAndWait({ - contractInterface, - functionName: 'mintPreSale', - contractAddress, - signerOrProvider, - args: [mintCount, allowlistProof] as ArgsType, - overrides: { - value: - typeof preSalePrice !== 'undefined' && mintCount - ? BigNumber.from(preSalePrice).mul(BigNumber.from(mintCount)) - : undefined, - }, - }); - - return { - ...result, - isLoading: result.isLoading || isLoading, - error: result.error || error, - data: { - ...result.data, - preSalePrice, - }, - }; -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSalePrice.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSalePrice.ts deleted file mode 100644 index c68818dff..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSalePrice.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -export const usePreSalePrice = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721PreSaleExtension', - functionName: 'preSalePrice', - ...config, - }); -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleStatus.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleStatus.ts deleted file mode 100644 index 4146c525a..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePreSaleStatus.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -export const usePreSaleStatus = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721PreSaleExtension', - functionName: 'preSaleStatus', - cacheOnBlock: false, - cacheTime: 0, - staleTime: 0, - ...config, - }); -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleMaxMintPerTx.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleMaxMintPerTx.ts deleted file mode 100644 index 58d70ab5d..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleMaxMintPerTx.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -export const usePublicSaleMaxMintPerTx = ( - config: PredefinedReadContractConfig, -) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721PublicSaleExtension', - functionName: 'publicSaleMaxMintPerTx', - ...config, - }); -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleMinter.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleMinter.ts deleted file mode 100644 index 261bb4a89..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleMinter.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumber, BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../../common'; -import { usePublicSalePrice } from './usePublicSalePrice'; - -type Config = { - chainId?: number; - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - enabled?: boolean; - toAddress?: string; - mintCount?: BigNumberish; -}; - -type ArgsType = [toAddress: BytesLike, mintCount: BigNumberish]; - -export const usePublicSaleMinter = ({ - chainId, - contractVersion, - contractAddress, - signerOrProvider, - enabled, - toAddress, - mintCount, -}: Config) => { - const { - data: publicSalePrice, - error, - isLoading, - } = usePublicSalePrice({ - chainId, - contractVersion, - contractAddress, - enabled, - }); - - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'collections/ERC721/extensions/ERC721PublicSaleExtension', - }); - - const result = useContractWriteAndWait({ - contractInterface, - functionName: 'mintPublicSale', - contractAddress, - signerOrProvider, - args: [toAddress, mintCount] as ArgsType, - overrides: { - value: - typeof publicSalePrice !== 'undefined' && mintCount - ? BigNumber.from(publicSalePrice).mul(BigNumber.from(mintCount)) - : undefined, - }, - }); - - return { - ...result, - isLoading: result.isLoading || isLoading, - error: result.error || error, - data: { - ...result.data, - publicSalePrice, - }, - }; -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSalePrice.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSalePrice.ts deleted file mode 100644 index e5fb0e8e4..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSalePrice.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -export const usePublicSalePrice = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721PublicSaleExtension', - functionName: 'publicSalePrice', - ...config, - }); -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleStatus.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleStatus.ts deleted file mode 100644 index f83c7d265..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/usePublicSaleStatus.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -export const usePublicSaleStatus = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721PublicSaleExtension', - functionName: 'publicSaleStatus', - cacheOnBlock: false, - cacheTime: 0, - staleTime: 0, - ...config, - }); -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/useSaleTiers.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/useSaleTiers.ts index 69db93287..89b36fce6 100644 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/useSaleTiers.ts +++ b/packages/react/src/features/nft-collections/extensions/sales/hooks/useSaleTiers.ts @@ -4,12 +4,8 @@ import { BigNumberish, BytesLike } from 'ethers'; import { useCallback, useMemo, useState } from 'react'; import { useProvider } from 'wagmi'; -import { - PredefinedReadContractConfig, - useHasAnyOfFeatures, -} from '../../../../../common'; +import { PredefinedReadContractConfig } from '../../../../../common'; import { Tier } from '../types'; -import { useSimpleSaleMinter } from './useSimpleSaleMinter'; import { useTierSaleAllowlistChecker } from './useTierSaleAllowlistChecker'; import { useTierSaleEligibleAmount } from './useTierSaleEligibleAmount'; @@ -25,32 +21,6 @@ export const useSaleTiers = (config: Config) => { const [isLoading, setIsLoading] = useState(false); const [tiers, setTiers] = useState>([]); - const { - data: supportsSimpleSales, - error: supportsSimpleSalesError, - isLoading: supportsSimpleSalesLoading, - } = useHasAnyOfFeatures({ - env: config.env, - chainId: config.chainId, - contractAddress: config.contractAddress, - tags: [ - 'erc721_public_sale_extension', - 'erc721_presale_extension', - 'mint_amount_by_merkle_proof', - ], - }); - - const { - data: supportsTieredSales, - error: supportsTieredSalesError, - isLoading: supportsTieredSalesLoading, - } = useHasAnyOfFeatures({ - env: config.env, - chainId: config.chainId, - contractAddress: config.contractAddress, - tags: ['erc721_tiering_extension', 'mint_by_tier_with_allowance_and_proof'], - }); - const { error: allowlistCheckerError, isLoading: allowlistCheckerLoading, @@ -74,42 +44,6 @@ export const useSaleTiers = (config: Config) => { enabled: false, }); - const { - data: { - preSaleStatus, - preSalePrice, - preSaleMaxMintPerWallet, - preSaleIsAllowlisted, - publicSaleStatus, - publicSalePrice, - publicSaleMaxMintPerTx, - }, - error: { - preSaleStatusError, - preSaleAllowlistCheckerError, - preSaleMaxMintPerWalletError, - preSaleMintError, - publicSaleMaxMintPerTxError, - publicSaleMintError, - publicSaleStatusError, - }, - isLoading: { - preSaleAllowlistCheckerLoading, - preSaleMaxMintPerWalletLoading, - preSaleMintLoading, - preSaleStatusLoading, - publicSaleMaxMintPerTxLoading, - publicSaleMintLoading, - publicSaleStatusLoading, - }, - } = useSimpleSaleMinter({ - chainId: config.chainId, - contractAddress: config.contractAddress, - contractVersion: config.contractVersion, - minterAddress: config.minterAddress, - enabled: supportsSimpleSales, - }); - const provider = useProvider({ chainId: config.chainId, }); @@ -190,136 +124,45 @@ export const useSaleTiers = (config: Config) => { setError(undefined); try { - if (supportsTieredSales) { - const fetchedTiers: Record = {}; - - for (let i = 0, l = 10; i < l; i++) { - const tier = await fetchTierById(i); - - if ( - tier && - tier.maxPerWallet && - Number(tier.maxPerWallet.toString()) > 0 - ) { - fetchedTiers[i] = tier; - } else { - break; - } + const fetchedTiers: Record = {}; + + for (let i = 0, l = 10; i < l; i++) { + const tier = await fetchTierById(i); + + if ( + tier && + tier.maxPerWallet && + Number(tier.maxPerWallet.toString()) > 0 + ) { + fetchedTiers[i] = tier; + } else { + break; } - - setTiers(fetchedTiers); - } else if (supportsSimpleSales) { - const past = +new Date() - 100 * 60 * 60 * 1000; - const future = +new Date() + 100 * 60 * 60 * 1000; - const preSaleTier: Tier = { - start: preSaleStatus ? past : future, - end: future, - currency: ZERO_BYTES32, - maxAllocation: Infinity, - maxPerWallet: preSaleMaxMintPerWallet || Infinity, - merkleRoot: ZERO_BYTES32, - hasAllowlist: true, - price: preSalePrice || 0, - isSavedOnChain: true, - reserved: Infinity, - isActive: preSaleStatus, - isAllowlisted: preSaleIsAllowlisted, - isEligible: preSaleStatus && preSaleIsAllowlisted, - eligibleAmount: preSaleMaxMintPerWallet, - minterAddress: config.minterAddress, - }; - const publicSaleTier: Tier = { - start: publicSaleStatus ? past : future, - end: future, - currency: ZERO_BYTES32, - maxAllocation: Infinity, - maxPerWallet: publicSaleMaxMintPerTx || Infinity, - merkleRoot: ZERO_BYTES32, - hasAllowlist: false, - price: publicSalePrice || 0, - isSavedOnChain: true, - reserved: Infinity, - isActive: publicSaleStatus, - isAllowlisted: undefined, - isEligible: publicSaleStatus, - eligibleAmount: publicSaleMaxMintPerTx, - minterAddress: config.minterAddress, - }; - - setTiers({ - 0: preSaleTier, - 1: publicSaleTier, - }); } + + setTiers(fetchedTiers); } catch (error: any) { setError(error); } setIsLoading(false); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [ - config.minterAddress, - supportsSimpleSales, - supportsTieredSales, - preSaleAllowlistCheckerLoading, - preSaleMintLoading, - preSaleStatusLoading, - publicSaleStatusLoading, - preSaleStatus, - preSaleIsAllowlisted, - publicSaleStatus, - ]); - - useMemo(() => { - if (supportsSimpleSalesLoading || supportsTieredSalesLoading) { - return; - } - - refetchTiers(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [ - config.minterAddress, - supportsSimpleSalesLoading, - supportsTieredSalesLoading, - preSaleStatus, - preSaleIsAllowlisted, - publicSaleStatus, - ]); + }, [config.minterAddress]); return { data: tiers, error: // top-level error || - supportsSimpleSalesError || - supportsTieredSalesError || // tiered sales allowlistCheckerError || - eligibleAmountError || - // simple sales - preSaleStatusError || - preSaleAllowlistCheckerError || - preSaleMaxMintPerWalletError || - preSaleMintError || - publicSaleMaxMintPerTxError || - publicSaleMintError || - publicSaleStatusError, + eligibleAmountError, isLoading: // top-level isLoading || - supportsSimpleSalesLoading || - supportsTieredSalesLoading || // tiered sales allowlistCheckerLoading || - eligibleAmountLoading || - // simple sales - preSaleStatusLoading || - preSaleAllowlistCheckerLoading || - preSaleMaxMintPerWalletLoading || - preSaleMintLoading || - publicSaleMaxMintPerTxLoading || - publicSaleMintLoading || - publicSaleStatusLoading, + eligibleAmountLoading, refetchTiers, }; }; diff --git a/packages/react/src/features/nft-collections/extensions/sales/hooks/useSimpleSaleMinter.ts b/packages/react/src/features/nft-collections/extensions/sales/hooks/useSimpleSaleMinter.ts deleted file mode 100644 index 48e7c7d31..000000000 --- a/packages/react/src/features/nft-collections/extensions/sales/hooks/useSimpleSaleMinter.ts +++ /dev/null @@ -1,214 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { Environment } from '@flair-sdk/common'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumber, BigNumberish, BytesLike, Signer } from 'ethers'; -import { useCallback } from 'react'; -import { useAccount } from 'wagmi'; - -import { usePreSaleAllowlistChecker } from './usePreSaleAllowlistChecker'; -import { usePreSaleMaxMintPerWallet } from './usePreSaleMaxMintPerWallet'; -import { usePreSaleMinter } from './usePreSaleMinter'; -import { usePreSaleStatus } from './usePreSaleStatus'; -import { usePublicSaleMaxMintPerTx } from './usePublicSaleMaxMintPerTx'; -import { usePublicSaleMinter } from './usePublicSaleMinter'; -import { usePublicSaleStatus } from './usePublicSaleStatus'; - -type Config = { - env?: Environment; - chainId?: number; - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - minterAddress?: BytesLike; - mintCount?: BigNumberish; - enabled?: boolean; -}; - -/** - * Consolidated function for minting as collectors by paying price of pre-sale or public-sale. - */ -export const useSimpleSaleMinter = ({ - env, - chainId, - contractVersion, - contractAddress, - signerOrProvider, - minterAddress, - mintCount, - enabled, -}: Config) => { - const { data: account } = useAccount(); - - const { - data: preSaleStatus, - error: preSaleStatusError, - isLoading: preSaleStatusLoading, - } = usePreSaleStatus({ - chainId, - contractVersion, - contractAddress, - enabled, - }); - - const { - data: preSaleMaxMintPerWallet, - error: preSaleMaxMintPerWalletError, - isLoading: preSaleMaxMintPerWalletLoading, - } = usePreSaleMaxMintPerWallet({ - chainId, - contractVersion, - contractAddress, - enabled, - }); - - const { - data: publicSaleStatus, - error: publicSaleStatusError, - isLoading: publicSaleStatusLoading, - } = usePublicSaleStatus({ - chainId, - contractVersion, - contractAddress, - enabled, - }); - - const { - data: publicSaleMaxMintPerTx, - error: publicSaleMaxMintPerTxError, - isLoading: publicSaleMaxMintPerTxLoading, - } = usePublicSaleMaxMintPerTx({ - chainId, - contractVersion, - contractAddress, - enabled, - }); - - const { - data: { allowlistProof, allowlistMetadata, isAllowlisted }, - error: allowlistCheckerError, - isLoading: allowlistCheckerLoading, - } = usePreSaleAllowlistChecker({ - env, - chainId, - contractVersion, - contractAddress, - enabled, - minterAddress, - }); - - const { - data: preSaleMintData, - error: preSaleMintError, - isLoading: preSaleMintLoading, - writeAndWait: preSaleMintWrite, - } = usePreSaleMinter({ - chainId, - contractVersion, - contractAddress, - enabled, - signerOrProvider, - mintCount, - allowlistProof, - }); - - const { - data: publicSaleMintData, - error: publicSaleMintError, - isLoading: publicSaleMintLoading, - writeAndWait: publicSaleMintWrite, - } = usePublicSaleMinter({ - chainId, - contractVersion, - contractAddress, - enabled, - signerOrProvider, - mintCount, - }); - - const mint = useCallback( - (args?: { mintCount: BigNumberish; allowlistProof?: BytesLike[] }) => { - let overrides; - - if (isAllowlisted && preSaleStatus) { - if (args?.mintCount) { - overrides = { - value: BigNumber.from(preSaleMintData.preSalePrice).mul( - BigNumber.from(args?.mintCount), - ), - }; - } - - return preSaleMintWrite( - [ - (args?.mintCount || mintCount) as BigNumberish, - (args?.allowlistProof || allowlistProof) as BytesLike[], - ], - overrides, - ); - } else if (publicSaleStatus) { - if (args?.mintCount) { - overrides = { - value: BigNumber.from(publicSaleMintData.publicSalePrice).mul( - BigNumber.from(args?.mintCount), - ), - }; - } - - return publicSaleMintWrite( - [ - account?.address as BytesLike, - (args?.mintCount || mintCount) as BigNumberish, - ], - overrides, - ); - } - }, - [ - account?.address, - allowlistProof, - isAllowlisted, - mintCount, - preSaleMintData.preSalePrice, - preSaleMintWrite, - preSaleStatus, - publicSaleMintData.publicSalePrice, - publicSaleMintWrite, - publicSaleStatus, - ], - ); - - return { - data: { - txResponse: preSaleMintData.txResponse || publicSaleMintData.txResponse, - txReceipt: preSaleMintData.txReceipt || publicSaleMintData.txReceipt, - preSaleStatus, - preSalePrice: preSaleMintData.preSalePrice, - preSaleIsAllowlisted: isAllowlisted, - preSaleAllowlistProof: allowlistProof, - preSaleAllowlistMetadata: allowlistMetadata, - preSaleMaxMintPerWallet, - publicSaleStatus, - publicSalePrice: publicSaleMintData.publicSalePrice, - publicSaleMaxMintPerTx, - }, - error: { - preSaleStatusError, - preSaleMintError, - preSaleAllowlistCheckerError: allowlistCheckerError, - preSaleMaxMintPerWalletError, - publicSaleStatusError, - publicSaleMintError, - publicSaleMaxMintPerTxError, - }, - isLoading: { - preSaleStatusLoading, - preSaleMintLoading, - preSaleAllowlistCheckerLoading: allowlistCheckerLoading, - preSaleMaxMintPerWalletLoading, - publicSaleStatusLoading, - publicSaleMintLoading, - publicSaleMaxMintPerTxLoading, - }, - mint, - } as const; -}; diff --git a/packages/react/src/features/nft-collections/extensions/sales/sections/CollectionSalesMintingSection.tsx b/packages/react/src/features/nft-collections/extensions/sales/sections/CollectionSalesMintingSection.tsx index 51672f99d..ad065a2e8 100644 --- a/packages/react/src/features/nft-collections/extensions/sales/sections/CollectionSalesMintingSection.tsx +++ b/packages/react/src/features/nft-collections/extensions/sales/sections/CollectionSalesMintingSection.tsx @@ -39,7 +39,11 @@ export const CollectionSalesMintingSection = ({ env, chainId, contractAddress, - tags: ['erc721_tiering_extension', 'mint_by_tier_with_allowance_and_proof'], + tags: [ + 'erc721_tiering_extension', + 'mint_by_tier_with_allowance_and_proof', + 'tiered_sales_facet', + ], }); const mintButtonClass =