Skip to content

Commit

Permalink
feat: remove simple sales and support new architecture (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor authored Sep 21, 2022
1 parent 2f07757 commit 80d87aa
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 904 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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;
};
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 80d87aa

Please sign in to comment.