From 733b4aa2a0ed5777bd8514ac9b2c31df9e473a5b Mon Sep 17 00:00:00 2001 From: aramalipoor Date: Sun, 25 Sep 2022 23:20:06 +0200 Subject: [PATCH] feat: use the new registry and contract reference model --- packages/metatx/src/meta-contract.ts | 39 +- .../metatx/src/meta-transactions.client.ts | 46 +- .../metatx/src/meta-transactions.mixin.ts | 23 +- packages/react/src/common/hooks/index.ts | 3 +- .../react/src/common/hooks/useContractAbi.ts | 27 +- .../src/common/hooks/useContractDefinition.ts | 35 - .../src/common/hooks/useContractManifest.ts | 30 + .../react/src/common/hooks/useContractRead.ts | 45 +- .../src/common/hooks/useSupportsInterface.ts | 51 - .../hooks/useVerificationSubmitter.ts | 25 +- .../core/contract-verification/types/index.ts | 6 +- .../hooks/useUnorderedForwarderAddress.ts | 16 +- .../common/components/CollectionImage.tsx | 27 - .../common/components/CollectionMaxSupply.tsx | 30 - .../components/CollectionSupplyCounter.tsx | 40 - .../common/components/CollectionTitle.tsx | 32 - .../components/CollectionTotalSupply.tsx | 30 - .../common/components/index.ts | 5 - .../nft-collections/common/hooks/index.ts | 2 - .../common/hooks/useNftCollection.tsx | 32 - .../common/hooks/useOpenSeaAddresses.ts | 28 - .../src/core/nft-collections/common/index.ts | 3 - .../common/providers/CollectionProvider.tsx | 193 - .../nft-collections/common/providers/index.ts | 1 - .../core/nft-collections/constants/backend.ts | 4 - .../core/nft-collections/constants/index.ts | 2 - .../core/nft-collections/constants/opensea.ts | 20 - .../core/nft-collections/extensions/index.ts | 5 - .../extensions/lockable/index.ts | 1 - .../lockable/useFilterUnlockedTokens.ts | 43 - .../extensions/metadata/index.ts | 6 - .../metadata/useCollectionMetadata.ts | 42 - .../metadata/useCollectionMetadataUri.ts | 15 - .../extensions/metadata/usePlaceholderUri.ts | 13 - .../metadata/useTokenMetadataUriFrozen.ts | 11 - .../metadata/useTokenMetadataUriPrefix.ts | 13 - .../metadata/useTokenMetadataUriSuffix.ts | 13 - .../extensions/minting/index.ts | 7 - .../extensions/minting/useAdminMinter.ts | 120 - .../extensions/minting/useMaxSupply.ts | 14 - .../extensions/minting/useOneOfOneMinter.ts | 47 - .../extensions/minting/useOwnerMinter.ts | 36 - .../extensions/minting/useRoleBasedMinter.ts | 36 - .../extensions/minting/useSaleMinter.ts | 78 - .../extensions/minting/useTotalSupply.ts | 11 - .../extensions/royalty/index.ts | 3 - .../extensions/royalty/useDefaultRoyalty.ts | 22 - .../components/CollectionIfWalletCanMint.tsx | 36 - .../CollectionSalesActiveStatus.tsx | 51 - .../CollectionSalesAllowlistStatus.tsx | 55 - .../components/CollectionSalesMintButton.tsx | 36 - .../components/CollectionSalesMintInput.tsx | 37 - .../CollectionSalesMintStatusBar.tsx | 45 - .../sales/components/CollectionSalesPrice.tsx | 61 - .../CollectionTierEligibleAmount.tsx | 42 - .../CollectionTierMaxAllocation.tsx | 46 - .../components/CollectionTierMaxSupply.tsx | 46 - .../CollectionTierRemainingSupply.tsx | 46 - .../CollectionTierReservedSupply.tsx | 46 - .../components/CollectionTierTotalSupply.tsx | 46 - .../components/CollectionTierWalletMints.tsx | 56 - .../extensions/sales/components/index.ts | 14 - .../extensions/sales/hooks/index.ts | 11 - .../extensions/sales/hooks/useSaleTiers.ts | 189 - .../hooks/useTierSaleAllowlistChecker.ts | 164 - .../sales/hooks/useTierSaleEligibleAmount.ts | 110 - .../sales/hooks/useTierSaleInformation.ts | 44 - .../sales/hooks/useTierSaleMaxAllocation.ts | 31 - .../sales/hooks/useTierSaleMaxSupply.tsx | 74 - .../sales/hooks/useTierSaleMinter.ts | 196 - .../sales/hooks/useTierSaleRemainingSupply.ts | 74 - .../sales/hooks/useTierSaleReservedSupply.ts | 31 - .../sales/hooks/useTierSaleTotalSupply.ts | 26 - .../sales/hooks/useTierSaleWalletMints.ts | 32 - .../nft-collections/extensions/sales/index.ts | 5 - .../CollectionSalesMintingProvider.tsx | 311 - .../extensions/sales/providers/index.ts | 1 - .../CollectionSalesMintingSection.tsx | 136 - .../extensions/sales/sections/index.ts | 1 - .../nft-collections/extensions/sales/types.ts | 24 - .../react/src/core/nft-collections/index.ts | 9 - .../src/core/nft-collections/types/index.ts | 48 - .../src/core/openzeppelin/access/index.ts | 5 - .../core/openzeppelin/access/useOzHasRole.ts | 25 - .../core/openzeppelin/access/useOzOwner.ts | 11 - .../openzeppelin/access/useOzRoleGranter.ts | 40 - .../openzeppelin/access/useOzRoleRenouncer.ts | 40 - .../openzeppelin/access/useOzRoleRevoker.ts | 40 - packages/react/src/core/openzeppelin/index.ts | 7 - .../core/openzeppelin/tokens/erc20/index.ts | 10 - .../tokens/erc20/useERC20BalanceOf.ts | 21 - .../tokens/erc20/useERC20Decimals.ts | 11 - .../openzeppelin/tokens/erc20/useERC20Name.ts | 11 - .../tokens/erc20/useERC20RoleBasedMint.ts | 42 - .../tokens/erc20/useERC20Symbol.ts | 11 - .../tokens/erc20/useERC20TotalSupply.ts | 11 - .../tokens/erc20/useERC20Transfer.ts | 42 - .../core/openzeppelin/tokens/erc721/index.ts | 12 - .../tokens/erc721/useERC721Approver.ts | 89 - .../erc721/useERC721IsApprovedForAll.ts | 25 - .../tokens/erc721/useERC721Name.ts | 11 - .../erc721/useERC721SetApprovalForAll.ts | 40 - .../tokens/erc721/useERC721Symbol.ts | 14 - .../tokens/erc721/useERC721TotalSupply.ts | 11 - .../tokens/erc721/useERC721TransferFrom.ts | 42 - .../src/core/openzeppelin/tokens/index.ts | 2 - .../StreamAccountSelectedTicketTokens.tsx | 26 - .../StreamAccountTotalTicketTokens.tsx | 26 - .../components/StreamClaimButton.tsx | 39 - .../components/StreamClaimTokenSelector.tsx | 76 - .../components/StreamClaimableAmount.tsx | 52 - .../components/StreamClaimingStatusBar.tsx | 72 - .../components/StreamCommonStatusBar.tsx | 39 - .../components/StreamEmissionAmount.tsx | 49 - .../components/StreamEmissionRate.tsx | 63 - .../components/StreamEmissionTimeUnit.tsx | 32 - .../components/StreamLockedNfts.tsx | 28 - .../components/StreamMinStakingDuration.tsx | 28 - .../components/StreamPrepareButton.tsx | 24 - .../components/StreamRateByTokens.tsx | 45 - .../components/StreamRewardAmount.tsx | 49 - .../components/StreamSharesAllocation.tsx | 62 - .../components/StreamSharesPercentage.tsx | 60 - .../components/StreamStakeButton.tsx | 33 - .../components/StreamStakedNfts.tsx | 30 - .../components/StreamStakingStatusBar.tsx | 110 - .../components/StreamTicketTokenSelector.tsx | 77 - .../components/StreamTotalClaimed.tsx | 48 - .../components/StreamTotalStakedDurations.tsx | 38 - .../components/StreamTotalSupply.tsx | 34 - .../components/StreamUnlockedNfts.tsx | 34 - .../components/StreamUnstakeButton.tsx | 27 - .../components/StreamUnstakeableNfts.tsx | 34 - .../core/token-streams/components/index.ts | 26 - .../core/token-streams/constants/backend.ts | 4 - .../src/core/token-streams/constants/index.ts | 1 - .../src/core/token-streams/hooks/index.ts | 27 - .../hooks/useStreamClaimLockedUntil.ts | 15 - .../hooks/useStreamClaimableAmount.ts | 25 - .../token-streams/hooks/useStreamClaimer.ts | 126 - .../hooks/useStreamEmissionAmountUntil.ts | 18 - .../hooks/useStreamEmissionEnd.ts | 16 - .../hooks/useStreamEmissionRate.ts | 16 - .../hooks/useStreamEmissionStart.ts | 16 - .../hooks/useStreamEmissionTimeUnit.ts | 16 - .../hooks/useStreamMaxStakingTotalDuration.ts | 15 - .../hooks/useStreamMinStakingDuration.ts | 15 - .../hooks/useStreamRateByToken.ts | 18 - .../hooks/useStreamReleasedAmountUntil.ts | 18 - .../hooks/useStreamRewardAmountByToken.ts | 18 - .../token-streams/hooks/useStreamShares.ts | 18 - .../token-streams/hooks/useStreamStaker.ts | 84 - .../hooks/useStreamStakerPrepare.ts | 83 - .../hooks/useStreamTicketToken.ts | 16 - .../hooks/useStreamTokensInCustody.ts | 145 - .../hooks/useStreamTotalClaimed.ts | 35 - .../hooks/useStreamTotalShares.ts | 15 - .../hooks/useStreamTotalStakedDurations.ts | 18 - .../hooks/useStreamTotalSupply.ts | 23 - .../hooks/useStreamUnlockingTime.ts | 17 - .../token-streams/hooks/useStreamUnstaker.ts | 84 - .../token-streams/hooks/useTokenStream.tsx | 30 - .../hooks/useTokenStreamCreator.tsx | 31 - .../hooks/useTokenStreamUpdater.tsx | 33 - .../token-streams/hooks/useTokenStreams.tsx | 32 - .../react/src/core/token-streams/index.ts | 11 - .../providers/StreamClaimingProvider.tsx | 291 - .../providers/StreamProvider.tsx | 342 - .../providers/StreamStakingProvider.tsx | 373 - .../src/core/token-streams/providers/index.ts | 3 - .../sections/StreamClaimingSection.tsx | 192 - .../sections/StreamStakingSection.tsx | 124 - .../src/core/token-streams/sections/index.ts | 2 - .../src/core/token-streams/types/index.tsx | 19 - packages/react/src/index.ts | 3 - packages/registry/package-lock.json | 10953 +--------------- packages/registry/src/contracts.ts | 56 +- packages/registry/src/facets.ts | 7 +- packages/registry/src/util.ts | 13 + 179 files changed, 815 insertions(+), 17947 deletions(-) delete mode 100644 packages/react/src/common/hooks/useContractDefinition.ts create mode 100644 packages/react/src/common/hooks/useContractManifest.ts delete mode 100644 packages/react/src/common/hooks/useSupportsInterface.ts delete mode 100644 packages/react/src/core/nft-collections/common/components/CollectionImage.tsx delete mode 100644 packages/react/src/core/nft-collections/common/components/CollectionMaxSupply.tsx delete mode 100644 packages/react/src/core/nft-collections/common/components/CollectionSupplyCounter.tsx delete mode 100644 packages/react/src/core/nft-collections/common/components/CollectionTitle.tsx delete mode 100644 packages/react/src/core/nft-collections/common/components/CollectionTotalSupply.tsx delete mode 100644 packages/react/src/core/nft-collections/common/components/index.ts delete mode 100644 packages/react/src/core/nft-collections/common/hooks/index.ts delete mode 100644 packages/react/src/core/nft-collections/common/hooks/useNftCollection.tsx delete mode 100644 packages/react/src/core/nft-collections/common/hooks/useOpenSeaAddresses.ts delete mode 100644 packages/react/src/core/nft-collections/common/index.ts delete mode 100644 packages/react/src/core/nft-collections/common/providers/CollectionProvider.tsx delete mode 100644 packages/react/src/core/nft-collections/common/providers/index.ts delete mode 100644 packages/react/src/core/nft-collections/constants/backend.ts delete mode 100644 packages/react/src/core/nft-collections/constants/index.ts delete mode 100644 packages/react/src/core/nft-collections/constants/opensea.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/lockable/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/lockable/useFilterUnlockedTokens.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/metadata/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/metadata/useCollectionMetadata.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/metadata/useCollectionMetadataUri.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/metadata/usePlaceholderUri.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriFrozen.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriPrefix.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriSuffix.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/minting/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/minting/useAdminMinter.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/minting/useMaxSupply.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/minting/useOneOfOneMinter.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/minting/useOwnerMinter.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/minting/useRoleBasedMinter.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/minting/useSaleMinter.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/minting/useTotalSupply.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/royalty/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/royalty/useDefaultRoyalty.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionIfWalletCanMint.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesActiveStatus.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesAllowlistStatus.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintButton.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintInput.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintStatusBar.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesPrice.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierEligibleAmount.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierMaxAllocation.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierMaxSupply.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierRemainingSupply.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierReservedSupply.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierTotalSupply.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierWalletMints.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/components/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useSaleTiers.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleAllowlistChecker.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleEligibleAmount.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleInformation.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMaxAllocation.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMaxSupply.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMinter.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleRemainingSupply.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleReservedSupply.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleTotalSupply.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleWalletMints.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/providers/CollectionSalesMintingProvider.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/providers/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/sections/CollectionSalesMintingSection.tsx delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/sections/index.ts delete mode 100644 packages/react/src/core/nft-collections/extensions/sales/types.ts delete mode 100644 packages/react/src/core/nft-collections/index.ts delete mode 100644 packages/react/src/core/nft-collections/types/index.ts delete mode 100644 packages/react/src/core/openzeppelin/access/index.ts delete mode 100644 packages/react/src/core/openzeppelin/access/useOzHasRole.ts delete mode 100644 packages/react/src/core/openzeppelin/access/useOzOwner.ts delete mode 100644 packages/react/src/core/openzeppelin/access/useOzRoleGranter.ts delete mode 100644 packages/react/src/core/openzeppelin/access/useOzRoleRenouncer.ts delete mode 100644 packages/react/src/core/openzeppelin/access/useOzRoleRevoker.ts delete mode 100644 packages/react/src/core/openzeppelin/index.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc20/index.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc20/useERC20BalanceOf.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc20/useERC20Decimals.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc20/useERC20Name.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc20/useERC20RoleBasedMint.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc20/useERC20Symbol.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc20/useERC20TotalSupply.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc20/useERC20Transfer.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc721/index.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc721/useERC721Approver.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc721/useERC721IsApprovedForAll.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc721/useERC721Name.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc721/useERC721SetApprovalForAll.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc721/useERC721Symbol.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc721/useERC721TotalSupply.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/erc721/useERC721TransferFrom.ts delete mode 100644 packages/react/src/core/openzeppelin/tokens/index.ts delete mode 100644 packages/react/src/core/token-streams/components/StreamAccountSelectedTicketTokens.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamAccountTotalTicketTokens.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamClaimButton.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamClaimTokenSelector.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamClaimableAmount.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamClaimingStatusBar.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamCommonStatusBar.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamEmissionAmount.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamEmissionRate.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamEmissionTimeUnit.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamLockedNfts.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamMinStakingDuration.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamPrepareButton.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamRateByTokens.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamRewardAmount.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamSharesAllocation.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamSharesPercentage.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamStakeButton.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamStakedNfts.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamStakingStatusBar.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamTicketTokenSelector.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamTotalClaimed.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamTotalStakedDurations.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamTotalSupply.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamUnlockedNfts.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamUnstakeButton.tsx delete mode 100644 packages/react/src/core/token-streams/components/StreamUnstakeableNfts.tsx delete mode 100644 packages/react/src/core/token-streams/components/index.ts delete mode 100644 packages/react/src/core/token-streams/constants/backend.ts delete mode 100644 packages/react/src/core/token-streams/constants/index.ts delete mode 100644 packages/react/src/core/token-streams/hooks/index.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamClaimLockedUntil.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamClaimableAmount.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamClaimer.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamEmissionAmountUntil.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamEmissionEnd.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamEmissionRate.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamEmissionStart.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamEmissionTimeUnit.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamMaxStakingTotalDuration.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamMinStakingDuration.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamRateByToken.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamReleasedAmountUntil.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamRewardAmountByToken.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamShares.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamStaker.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamStakerPrepare.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamTicketToken.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamTokensInCustody.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamTotalClaimed.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamTotalShares.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamTotalStakedDurations.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamTotalSupply.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamUnlockingTime.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useStreamUnstaker.ts delete mode 100644 packages/react/src/core/token-streams/hooks/useTokenStream.tsx delete mode 100644 packages/react/src/core/token-streams/hooks/useTokenStreamCreator.tsx delete mode 100644 packages/react/src/core/token-streams/hooks/useTokenStreamUpdater.tsx delete mode 100644 packages/react/src/core/token-streams/hooks/useTokenStreams.tsx delete mode 100644 packages/react/src/core/token-streams/index.ts delete mode 100644 packages/react/src/core/token-streams/providers/StreamClaimingProvider.tsx delete mode 100644 packages/react/src/core/token-streams/providers/StreamProvider.tsx delete mode 100644 packages/react/src/core/token-streams/providers/StreamStakingProvider.tsx delete mode 100644 packages/react/src/core/token-streams/providers/index.ts delete mode 100644 packages/react/src/core/token-streams/sections/StreamClaimingSection.tsx delete mode 100644 packages/react/src/core/token-streams/sections/StreamStakingSection.tsx delete mode 100644 packages/react/src/core/token-streams/sections/index.ts delete mode 100644 packages/react/src/core/token-streams/types/index.tsx create mode 100644 packages/registry/src/util.ts diff --git a/packages/metatx/src/meta-contract.ts b/packages/metatx/src/meta-contract.ts index a5eb66e32..6fbce6e32 100644 --- a/packages/metatx/src/meta-contract.ts +++ b/packages/metatx/src/meta-contract.ts @@ -1,11 +1,6 @@ import { Provider } from '@ethersproject/providers'; import { Environment } from '@flair-sdk/common'; -import { - ContractFqn, - ContractVersion, - LATEST_VERSION, - loadContract, -} from '@flair-sdk/registry'; +import { ContractFqn } from '@flair-sdk/registry'; import { BaseContract, Contract, @@ -46,26 +41,11 @@ export class MetaContract< constructor( metaTransactionsClient: MetaTransactionsClient, chainId: number, - contractFqn: ContractFqn, - contractVersion: ContractVersion = LATEST_VERSION, - addressOrName?: string, + addressOrName: string, + abi: any, signerOrProvider?: Signer | Provider, ) { - const contractDefinition = loadContract(contractFqn, contractVersion); - const contractAddressOrName = - addressOrName || contractDefinition?.address?.[String(chainId)]; - - if (!contractAddressOrName) { - throw new Error( - `Could not determine contract address from constructor (${addressOrName}) nor from definition (${contractDefinition?.address})`, - ); - } - - super( - contractAddressOrName, - contractDefinition?.artifact.abi || [], - signerOrProvider, - ); + super(addressOrName, abi, signerOrProvider); this.metaTransaction = {}; Object.keys(this.interface.functions).forEach((signature) => { @@ -95,23 +75,22 @@ export class MetaContract< env?: Environment; chainId: number; flairClientId: string; - contractFqn: ContractFqn; - contractVersion?: ContractVersion; - addressOrName?: string; + forwarder: string; + addressOrName: string; + abi: any; signerOrProvider?: Signer | Provider; }): T { const metaTxClient = new MetaTransactionsClient({ env: config.env || Environment.PROD, - chainId: config.chainId, flairClientId: config.flairClientId, + forwarder: config.forwarder, }); return new MetaContract( metaTxClient, config.chainId, - config.contractFqn, - config.contractVersion, config.addressOrName, + config.abi, config.signerOrProvider, ) as unknown as T; } diff --git a/packages/metatx/src/meta-transactions.client.ts b/packages/metatx/src/meta-transactions.client.ts index 191694678..2a08b171b 100644 --- a/packages/metatx/src/meta-transactions.client.ts +++ b/packages/metatx/src/meta-transactions.client.ts @@ -1,9 +1,4 @@ import { Environment } from '@flair-sdk/common'; -import { - ContractVersion, - LATEST_VERSION, - loadContract, -} from '@flair-sdk/registry'; import axios from 'axios'; import { Signer } from 'ethers'; import { Required } from 'utility-types'; @@ -14,23 +9,12 @@ import { generateRandomUint256 } from './random-uint256'; import { MetaTransactionSignedData } from './types'; import { MetaTransaction } from './types/meta-transaction'; -type Config = - | { - env?: Environment; - chainId: number; - contractVersion?: ContractVersion; - forwarder?: string; - flairClientId: string; - defaults?: Partial; - } - | { - env?: Environment; - chainId?: number; - contractVersion?: ContractVersion; - forwarder: string; - flairClientId: string; - defaults?: Partial; - }; +type Config = { + env?: Environment; + forwarder: string; + flairClientId: string; + defaults?: Partial; +}; export class MetaTransactionsClient { public forwarder: string; @@ -38,25 +22,9 @@ export class MetaTransactionsClient { constructor(private readonly config: Config) { this.forwarder = config.forwarder as string; - if (!config.forwarder && config.chainId) { - try { - const forwarderDefinition = loadContract( - 'common/UnorderedForwarder', - LATEST_VERSION, - ); - this.forwarder = forwarderDefinition?.address?.[ - String(config.chainId) - ] as string; - } catch (e) { - console.warn( - `Could not load contract (chain ${config.chainId}) to determine forwarder: ${e}`, - ); - } - } - if (!this.forwarder) { throw new Error( - `Could not determine meta transactions forwarder address, please either specify chainId (given ${config.chainId}) or forwarder address (given ${config.forwarder})`, + `Could not determine meta transactions forwarder address, please specify forwarder address (given ${config.forwarder})`, ); } } diff --git a/packages/metatx/src/meta-transactions.mixin.ts b/packages/metatx/src/meta-transactions.mixin.ts index 441a21a93..4bd9ddb35 100644 --- a/packages/metatx/src/meta-transactions.mixin.ts +++ b/packages/metatx/src/meta-transactions.mixin.ts @@ -1,9 +1,4 @@ import { Environment } from '@flair-sdk/common'; -import { - ContractFqn, - ContractVersion, - FlairContract, -} from '@flair-sdk/registry'; import { Contract, Contract as EthersContract, @@ -80,35 +75,25 @@ export const applyMetaTransactions = ( return castedContract; }; -export const createFlairContractWithMetaTransactions = < +export const augmentContractWithMetaTransactions = < T extends EthersContract, >(config: { env?: Environment; chainId: number; flairClientId: string; - contractFqn: ContractFqn; - contractVersion?: ContractVersion; + contract: T; + forwarder: string; addressOrName?: string; signer?: Signer; - forwarder?: string; }): MetaTransactionsAugmentedContract => { const metaTxClient = new MetaTransactionsClient({ env: config.env || Environment.PROD, - chainId: config.chainId, flairClientId: config.flairClientId, forwarder: config.forwarder, }); - const contract = new FlairContract( - config.chainId, - config.contractFqn, - config.signer, - config.contractVersion, - config.addressOrName, - ); - const augmentedContract = applyMetaTransactions( - contract as unknown as T, // TODO fix this to get proper typing! + config.contract, config.chainId, metaTxClient, ); diff --git a/packages/react/src/common/hooks/index.ts b/packages/react/src/common/hooks/index.ts index 21696ac99..2d48c9ab3 100644 --- a/packages/react/src/common/hooks/index.ts +++ b/packages/react/src/common/hooks/index.ts @@ -3,7 +3,7 @@ export * from './useAddressOfSigner'; export * from './useChainId'; export * from './useChainInfo'; export * from './useContractAbi'; -export * from './useContractDefinition'; +export * from './useContractManifest'; export * from './useContractRead'; export * from './useContractWriteAndWait'; export * from './useFeatureRead'; @@ -14,7 +14,6 @@ export * from './useFunctionFeature'; export * from './useHasAnyOfFeatures'; export * from './useNormalizedFunctionCall'; export * from './useSmartContract'; -export * from './useSupportsInterface'; export * from './useWaitForTransaction'; // web2 diff --git a/packages/react/src/common/hooks/useContractAbi.ts b/packages/react/src/common/hooks/useContractAbi.ts index f5c997dbd..a93820a0b 100644 --- a/packages/react/src/common/hooks/useContractAbi.ts +++ b/packages/react/src/common/hooks/useContractAbi.ts @@ -1,23 +1,22 @@ import { - ContractFqn, - ContractVersion, - loadContract, + ContractReference, + findContractByReference, } from '@flair-sdk/registry'; import { useMemo } from 'react'; export type Config = { - contractVersion?: ContractVersion; - contractFqn: ContractFqn; + contractReference: ContractReference; }; -export const useContractAbi = ({ - contractVersion = 'v1', - contractFqn, -}: Config) => { - const contract = useMemo( - () => loadContract(contractFqn, contractVersion), - [contractFqn, contractVersion], - ); +export const useContractAbi = ({ contractReference }: Config) => { + const contract = useMemo(() => { + try { + return findContractByReference(contractReference); + } catch (error) { + console.warn(`Failed to find contract manifest for ${contractReference}`); + return undefined; + } + }, [contractReference]); - return contract?.artifact.abi || []; + return contract?.artifact?.abi; }; diff --git a/packages/react/src/common/hooks/useContractDefinition.ts b/packages/react/src/common/hooks/useContractDefinition.ts deleted file mode 100644 index cb4b2aad9..000000000 --- a/packages/react/src/common/hooks/useContractDefinition.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - ContractDefinition, - ContractFqn, - ContractVersion, - loadContract, -} from '@flair-sdk/registry'; -import { useEffect, useState } from 'react'; - -type Config = { - contractFqn?: ContractFqn; - contractVersion: ContractVersion; -}; - -export const useContractDefinition = ({ - contractFqn, - contractVersion = 'v1', -}: Config) => { - const [definition, setDefinition] = useState(); - - useEffect(() => { - if (!contractFqn) { - setDefinition(undefined); - return; - } - - try { - const definition = loadContract(contractFqn, contractVersion); - setDefinition(definition); - } catch (error) { - setDefinition(undefined); - } - }, [contractFqn, contractVersion]); - - return definition; -}; diff --git a/packages/react/src/common/hooks/useContractManifest.ts b/packages/react/src/common/hooks/useContractManifest.ts new file mode 100644 index 000000000..2ce74fa73 --- /dev/null +++ b/packages/react/src/common/hooks/useContractManifest.ts @@ -0,0 +1,30 @@ +import { + ContractManifest, + ContractReference, + findContractByReference, +} from '@flair-sdk/registry'; +import { useEffect, useState } from 'react'; + +type Config = { + contractReference?: ContractReference; +}; + +export const useContractManifest = ({ contractReference }: Config) => { + const [manifest, setManifest] = useState(); + + useEffect(() => { + if (!contractReference) { + setManifest(undefined); + return; + } + + try { + const manifest = findContractByReference(contractReference); + setManifest(manifest); + } catch (error) { + setManifest(undefined); + } + }, [contractReference]); + + return manifest; +}; diff --git a/packages/react/src/common/hooks/useContractRead.ts b/packages/react/src/common/hooks/useContractRead.ts index 4518c9379..651c03fd1 100644 --- a/packages/react/src/common/hooks/useContractRead.ts +++ b/packages/react/src/common/hooks/useContractRead.ts @@ -2,9 +2,8 @@ import 'react-query'; import { ZERO_ADDRESS } from '@flair-sdk/common'; import { - ContractFqn, - ContractVersion, - loadContract, + ContractReference, + findContractByReference, } from '@flair-sdk/registry'; import { ReadContractConfig as ReadContractConfigWagmi } from '@wagmi/core'; import { ethers } from 'ethers'; @@ -16,8 +15,7 @@ export type ReadContractConfig = Partial< Omit > & UseContractReadConfig & { - contractVersion?: ContractVersion; - contractFqn: ContractFqn; + contractReference?: ContractReference; contractAddress?: string; functionName: string; args?: ArgsType; @@ -27,13 +25,12 @@ export type ReadContractConfig = Partial< export type PredefinedReadContractConfig = Omit< ReadContractConfig, - 'contractFqn' | 'functionName' + 'contractReference' | 'functionName' >; export const useContractRead = ({ - contractVersion = 'v1', enabled = true, - contractFqn, + contractReference, contractAddress, functionName, args, @@ -41,10 +38,19 @@ export const useContractRead = ({ cacheOnBlock, ...restOfConfig }: ReadContractConfig) => { - const contractDefinition = useMemo( - () => loadContract(contractFqn, contractVersion), - [contractFqn, contractVersion], - ); + const contractDefinition = useMemo(() => { + try { + return contractReference + ? findContractByReference(contractReference) + : undefined; + } catch (e) { + console.warn( + `Failed to find contract definition for ${contractReference}`, + ); + return undefined; + } + }, [contractReference]); + const readyToRead = Boolean( enabled && contractAddress && contractAddress !== ZERO_ADDRESS, ); @@ -52,7 +58,9 @@ export const useContractRead = ({ const result = useContractReadWagmi( { addressOrName: contractAddress as string, - contractInterface: contractDefinition?.artifact.abi || [], + contractInterface: contractDefinition?.artifact?.abi || [ + `function ${functionName}`, + ], }, functionName as string, { @@ -68,16 +76,21 @@ export const useContractRead = ({ chainId: restOfConfig.chainId, }); const contract = useMemo(() => { - if (!contractAddress || !provider || !contractDefinition?.artifact.abi) { + if (!contractAddress || !provider) { return; } return new ethers.Contract( contractAddress, - contractDefinition.artifact.abi, + contractDefinition?.artifact?.abi || ['function ' + functionName], provider, ); - }, [contractAddress, contractDefinition?.artifact.abi, provider]); + }, [ + contractAddress, + contractDefinition?.artifact?.abi, + functionName, + provider, + ]); const call = useCallback( async (overrides?: { args?: ArgsType }) => { diff --git a/packages/react/src/common/hooks/useSupportsInterface.ts b/packages/react/src/common/hooks/useSupportsInterface.ts deleted file mode 100644 index aae4f01ad..000000000 --- a/packages/react/src/common/hooks/useSupportsInterface.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { getInterfaceId } from '@flair-sdk/common'; -import { ContractFqn, loadContract } from '@flair-sdk/registry'; -import { BigNumberish, ethers } from 'ethers'; -import { useMemo } from 'react'; -import reactQuery from 'react-query'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from './useContractRead'; - -type Config = PredefinedReadContractConfig<[BigNumberish]> & { - extensionFqn?: ContractFqn; -}; - -export const useSupportsInterface = ({ - contractAddress, - contractVersion = 'v1', - extensionFqn, - ...restOfConfig -}: Config) => { - const interfaceId = useMemo(() => { - if (!extensionFqn) { - return null; - } - - try { - const definition = loadContract(extensionFqn, contractVersion); - const iface = new ethers.utils.Interface(definition?.artifact.abi || []); - - return getInterfaceId(iface); - } catch (e) { - return null; - } - }, [extensionFqn, contractVersion]); - - const result = useContractRead({ - contractVersion, - contractAddress, - contractFqn: 'openzeppelin/utils/introspection/ERC165', - functionName: 'supportsInterface', - args: interfaceId ? [interfaceId] : undefined, - enabled: Boolean(interfaceId && contractAddress), - ...restOfConfig, - }); - - return { - ...result, - interfaceId, - } as const; -}; diff --git a/packages/react/src/core/contract-verification/hooks/useVerificationSubmitter.ts b/packages/react/src/core/contract-verification/hooks/useVerificationSubmitter.ts index 1b5606f41..1ea10acf7 100644 --- a/packages/react/src/core/contract-verification/hooks/useVerificationSubmitter.ts +++ b/packages/react/src/core/contract-verification/hooks/useVerificationSubmitter.ts @@ -1,8 +1,7 @@ import { Environment } from '@flair-sdk/common'; import { - ContractFqn, - ContractVersion, - loadContract, + ContractReference, + findContractByReference, } from '@flair-sdk/registry'; import * as axios from 'axios'; import { ethers } from 'ethers'; @@ -15,8 +14,7 @@ import { FLAIR_CONTRACT_VERIFICATION_BACKEND } from '../constants'; type Props = { env?: Environment; chainId?: number; - contractFqn?: ContractFqn; - contractVersion?: ContractVersion; + contractReference?: ContractReference; contractAddress?: string; constructorArguments?: any[]; }; @@ -24,8 +22,7 @@ type Props = { export const useVerificationSubmitter = ({ env = Environment.PROD, chainId, - contractFqn, - contractVersion = 'v1', + contractReference, contractAddress, constructorArguments, }: Props) => { @@ -33,18 +30,18 @@ export const useVerificationSubmitter = ({ const encodedConstructorArguments = useMemo(() => { try { - if (!contractFqn || !constructorArguments) { + if (!contractReference || !constructorArguments) { return ''; } - const definition = loadContract(contractFqn, contractVersion); - const iface = new ethers.utils.Interface(definition?.artifact.abi || []); + const definition = findContractByReference(contractReference); + const iface = new ethers.utils.Interface(definition?.artifact?.abi || []); return iface.encodeDeploy(constructorArguments); } catch (e) { console.warn(e); return ''; } - }, [contractFqn, contractVersion, constructorArguments]); + }, [contractReference, constructorArguments]); const headers = useMemo(() => { return { @@ -56,15 +53,13 @@ export const useVerificationSubmitter = ({ return { chainId, contractAddress, - contractFqn, - contractVersion, + contractReference, encodedConstructorArguments, }; }, [ chainId, contractAddress, - contractFqn, - contractVersion, + contractReference, encodedConstructorArguments, ]); diff --git a/packages/react/src/core/contract-verification/types/index.ts b/packages/react/src/core/contract-verification/types/index.ts index ad62762b0..25deb280a 100644 --- a/packages/react/src/core/contract-verification/types/index.ts +++ b/packages/react/src/core/contract-verification/types/index.ts @@ -1,11 +1,9 @@ -import { ContractFqn, ContractVersion } from '@flair-sdk/registry'; - export type ContractVerification = { chainId: number; ownerAddress: string; address: string; - contractFqn: ContractFqn; - contractVersion?: ContractVersion; + contractFqn: string; + contractVersion?: string; encodedConstructorArguments?: string; guid?: string; state?: 'submitted' | 'pending' | 'failed' | 'succeeded'; diff --git a/packages/react/src/core/meta-transactions/hooks/useUnorderedForwarderAddress.ts b/packages/react/src/core/meta-transactions/hooks/useUnorderedForwarderAddress.ts index ad51b7303..1305239a3 100644 --- a/packages/react/src/core/meta-transactions/hooks/useUnorderedForwarderAddress.ts +++ b/packages/react/src/core/meta-transactions/hooks/useUnorderedForwarderAddress.ts @@ -1,8 +1,7 @@ import { ZERO_ADDRESS } from '@flair-sdk/common'; import { - ContractVersion, - LATEST_VERSION, - loadContract, + ContractReference, + findContractByReference, } from '@flair-sdk/registry'; import { useMemo } from 'react'; @@ -10,7 +9,7 @@ import { useChainId } from '../../../common'; export const useUnorderedForwarderAddress = ( chainId?: number, - contractVersion: ContractVersion = LATEST_VERSION, + contractReference?: ContractReference, ) => { const resolvedChainId = useChainId(chainId); @@ -20,12 +19,11 @@ export const useUnorderedForwarderAddress = ( } try { - const definition = loadContract( - 'common/UnorderedForwarder', - contractVersion, + const manifest = findContractByReference( + contractReference || 'flair-sdk:common/UnorderedForwarder', ); - return definition?.address?.[resolvedChainId] ?? ZERO_ADDRESS; + return manifest?.address?.[resolvedChainId] ?? ZERO_ADDRESS; } catch (e) { console.warn( `Could not load UnorderedForwarder contract for chain ${resolvedChainId}: `, @@ -33,5 +31,5 @@ export const useUnorderedForwarderAddress = ( ); return ZERO_ADDRESS; } - }, [contractVersion, resolvedChainId]); + }, [contractReference, resolvedChainId]); }; diff --git a/packages/react/src/core/nft-collections/common/components/CollectionImage.tsx b/packages/react/src/core/nft-collections/common/components/CollectionImage.tsx deleted file mode 100644 index f4815a476..000000000 --- a/packages/react/src/core/nft-collections/common/components/CollectionImage.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { normalizeIpfsUrl } from '@flair-sdk/ipfs'; - -import { useCollectionContext } from '../providers/CollectionProvider'; - -type Props = { - loadingMask?: React.ReactNode; -} & React.HTMLAttributes; - -export const CollectionImage = (props: Props) => { - const { - data: { collection, collectionMetadata }, - isLoading: { collectionLoading, collectionMetadataLoading }, - } = useCollectionContext(); - - return props.loadingMask && - (collectionLoading || collectionMetadataLoading) && - !collectionMetadata?.image ? ( - <>{props.loadingMask} - ) : ( - - ); -}; diff --git a/packages/react/src/core/nft-collections/common/components/CollectionMaxSupply.tsx b/packages/react/src/core/nft-collections/common/components/CollectionMaxSupply.tsx deleted file mode 100644 index 428cda1d9..000000000 --- a/packages/react/src/core/nft-collections/common/components/CollectionMaxSupply.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../common'; -import { useCollectionContext } from '../providers/CollectionProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; -}; - -export const CollectionMaxSupply = ({ - as, - loadingMask = '...', - ...attributes -}: Props) => { - const { - data: { maxSupply }, - isLoading: { maxSupplyLoading }, - } = useCollectionContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && maxSupplyLoading && maxSupply === undefined - ? loadingMask - : maxSupply?.toString()} - - ); -}; diff --git a/packages/react/src/core/nft-collections/common/components/CollectionSupplyCounter.tsx b/packages/react/src/core/nft-collections/common/components/CollectionSupplyCounter.tsx deleted file mode 100644 index 1004ab370..000000000 --- a/packages/react/src/core/nft-collections/common/components/CollectionSupplyCounter.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../common'; -import { useCollectionContext } from '../providers/CollectionProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - separator?: React.ReactNode; -}; - -export const CollectionSupplyCounter = ({ - as, - loadingMask, - separator = <> / , - ...attributes -}: Props) => { - const { - data: { totalSupply, maxSupply }, - isLoading: { maxSupplyLoading, totalSupplyLoading }, - } = useCollectionContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && - (maxSupplyLoading || totalSupplyLoading) && - (totalSupply === undefined || maxSupply === undefined) ? ( - loadingMask - ) : ( - <> - {totalSupply?.toString()} - {separator} - {maxSupply?.toString()} - - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/common/components/CollectionTitle.tsx b/packages/react/src/core/nft-collections/common/components/CollectionTitle.tsx deleted file mode 100644 index 72b0bbed5..000000000 --- a/packages/react/src/core/nft-collections/common/components/CollectionTitle.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../common'; -import { useCollectionContext } from '../providers/CollectionProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; -}; - -export const CollectionTitle = ({ - as, - loadingMask = '...', - ...attributes -}: Props) => { - const { - data: { collection, collectionMetadata }, - isLoading: { collectionLoading, collectionMetadataLoading }, - } = useCollectionContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && - (collectionLoading || collectionMetadataLoading) && - !collectionMetadata?.name - ? loadingMask - : collectionMetadata?.name || collection?.config?.collectionName} - - ); -}; diff --git a/packages/react/src/core/nft-collections/common/components/CollectionTotalSupply.tsx b/packages/react/src/core/nft-collections/common/components/CollectionTotalSupply.tsx deleted file mode 100644 index 5b1c2278b..000000000 --- a/packages/react/src/core/nft-collections/common/components/CollectionTotalSupply.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../common'; -import { useCollectionContext } from '../providers/CollectionProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; -}; - -export const CollectionTotalSupply = ({ - as, - loadingMask = '...', - ...attributes -}: Props) => { - const { - data: { totalSupply }, - isLoading: { totalSupplyLoading }, - } = useCollectionContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && totalSupplyLoading && totalSupply === undefined - ? loadingMask - : totalSupply?.toString()} - - ); -}; diff --git a/packages/react/src/core/nft-collections/common/components/index.ts b/packages/react/src/core/nft-collections/common/components/index.ts deleted file mode 100644 index 3d14b787c..000000000 --- a/packages/react/src/core/nft-collections/common/components/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './CollectionImage'; -export * from './CollectionMaxSupply'; -export * from './CollectionSupplyCounter'; -export * from './CollectionTitle'; -export * from './CollectionMaxSupply'; diff --git a/packages/react/src/core/nft-collections/common/hooks/index.ts b/packages/react/src/core/nft-collections/common/hooks/index.ts deleted file mode 100644 index f853d7d95..000000000 --- a/packages/react/src/core/nft-collections/common/hooks/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './useNftCollection'; -export * from './useOpenSeaAddresses'; diff --git a/packages/react/src/core/nft-collections/common/hooks/useNftCollection.tsx b/packages/react/src/core/nft-collections/common/hooks/useNftCollection.tsx deleted file mode 100644 index 8d25775c7..000000000 --- a/packages/react/src/core/nft-collections/common/hooks/useNftCollection.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { Environment } from '@flair-sdk/common'; - -import { useAxiosGet } from '../../../../common'; -import { FLAIR_NFT_COLLECTIONS_BACKEND } from '../../constants'; -import { NftCollection } from '../../types'; - -type Config = { - env?: Environment; - enabled?: boolean; - chainId?: number; - contractAddress?: string; - collectionId?: string; -}; - -export function useNftCollection< - TCollectionConfig extends Record, ->({ - env = Environment.PROD, - enabled = true, - collectionId, - chainId, - contractAddress, -}: Config) { - const url = collectionId - ? `${FLAIR_NFT_COLLECTIONS_BACKEND[env]}/v1/nft-collections/${collectionId}` - : `${FLAIR_NFT_COLLECTIONS_BACKEND[env]}/v1/nft-collections/${chainId}/${contractAddress}`; - - return useAxiosGet>({ - url, - enabled: Boolean(enabled && (collectionId || (chainId && contractAddress))), - }); -} diff --git a/packages/react/src/core/nft-collections/common/hooks/useOpenSeaAddresses.ts b/packages/react/src/core/nft-collections/common/hooks/useOpenSeaAddresses.ts deleted file mode 100644 index bd36f19c7..000000000 --- a/packages/react/src/core/nft-collections/common/hooks/useOpenSeaAddresses.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { ZERO_ADDRESS } from '@flair-sdk/common'; - -import { useChainId } from '../../../../common'; -import { - FLAIR_OPENSEA_ADDRESSES, - SupportedOpenSeaChains, -} from '../../constants'; - -export const useOpenSeaAddresses = (chainId?: number) => { - const resolvedChainId = useChainId(chainId) as - | SupportedOpenSeaChains - | undefined; - - return { - openSeaProxyRegistryAddress: - resolvedChainId && - FLAIR_OPENSEA_ADDRESSES[resolvedChainId] && - FLAIR_OPENSEA_ADDRESSES[resolvedChainId].registryAddress - ? FLAIR_OPENSEA_ADDRESSES[resolvedChainId].registryAddress - : ZERO_ADDRESS, - openSeaExchangeAddress: - resolvedChainId && - FLAIR_OPENSEA_ADDRESSES[resolvedChainId] && - FLAIR_OPENSEA_ADDRESSES[resolvedChainId].exchangeAddress - ? FLAIR_OPENSEA_ADDRESSES[resolvedChainId].exchangeAddress - : ZERO_ADDRESS, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/common/index.ts b/packages/react/src/core/nft-collections/common/index.ts deleted file mode 100644 index 6ad3bb22a..000000000 --- a/packages/react/src/core/nft-collections/common/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './components'; -export * from './hooks'; -export * from './providers'; diff --git a/packages/react/src/core/nft-collections/common/providers/CollectionProvider.tsx b/packages/react/src/core/nft-collections/common/providers/CollectionProvider.tsx deleted file mode 100644 index 2d2a961d1..000000000 --- a/packages/react/src/core/nft-collections/common/providers/CollectionProvider.tsx +++ /dev/null @@ -1,193 +0,0 @@ -import { Environment } from '@flair-sdk/common'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumberish, BytesLike } from 'ethers'; -import * as React from 'react'; -import { ReactNode } from 'react'; -import { Chain, useProvider } from 'wagmi'; - -import { useChainInfo } from '../../../../common'; -import { useRemoteJsonReader } from '../../../ipfs'; -import { useCollectionMetadataUri } from '../../extensions/metadata/useCollectionMetadataUri'; -import { useMaxSupply } from '../../extensions/minting/useMaxSupply'; -import { useTotalSupply } from '../../extensions/minting/useTotalSupply'; -import { NftCollection, NftCollectionMetadata } from '../../types'; -import { useNftCollection } from '../hooks/useNftCollection'; - -type CollectionContextValue = { - data: { - // Resources - env?: Environment; - chainId?: number; - chainInfo?: Chain; - contractAddress?: string; - contractVersion?: ContractVersion; - collection?: NftCollection | null; - collectionMetadata?: NftCollectionMetadata | null; - - // On-chain values - metadataUri?: BytesLike; - maxSupply?: BigNumberish; - totalSupply?: BigNumberish; - }; - - isLoading: { - // Resources - collectionLoading?: boolean; - collectionMetadataLoading?: boolean; - - // On-chain values - metadataUriLoading?: boolean; - maxSupplyLoading?: boolean; - totalSupplyLoading?: boolean; - }; - - error: { - // Resources - collectionError?: string | Error | null; - collectionMetadataError?: string | Error | null; - - // On-chain values - metadataUriError?: string | Error | null; - maxSupplyError?: string | Error | null; - totalSupplyError?: string | Error | null; - }; -}; - -export const CollectionContext = - React.createContext(null); - -type FunctionalChildren = ( - contextValue: CollectionContextValue, -) => ReactNode | ReactNode[]; - -type Props = { - /** Environment can be either 'prod' (default) or 'env' */ - env?: Environment; - - /** ChainID where the token stream is deployed */ - chainId: number | string; - - /** Contract address of the token stream */ - contractAddress: string; - - /** Optional contract version which defaults to stored value on backend, and falls back to latest */ - contractVersion?: ContractVersion; - - /** Child elements or a factory function that returns child elements */ - children: FunctionalChildren | ReactNode | ReactNode[]; -}; - -export const CollectionProvider = ({ - env = Environment.PROD, - chainId: rawChainId, - contractAddress, - contractVersion: _contractVersion, - children, -}: Props) => { - const chainId = Number(rawChainId); - const chainInfo = useChainInfo(chainId); - - const { - data: collection, - error: collectionError, - isLoading: collectionLoading, - } = useNftCollection({ - env, - chainId, - contractAddress, - }); - - const contractVersion = _contractVersion || collection?.presetVersion; - - const { - data: metadataUri, - error: metadataUriError, - isLoading: metadataUriLoading, - } = useCollectionMetadataUri({ - chainId, - contractVersion, - contractAddress, - }); - - const { - data: collectionMetadata, - error: collectionMetadataError, - isLoading: collectionMetadataLoading, - } = useRemoteJsonReader({ - uri: metadataUri, - }); - - const { - data: maxSupply, - error: maxSupplyError, - isLoading: maxSupplyLoading, - } = useMaxSupply({ - chainId, - contractVersion, - contractAddress, - watch: false, - }); - - const { - data: totalSupply, - error: totalSupplyError, - isLoading: totalSupplyLoading, - } = useTotalSupply({ - chainId, - contractVersion, - contractAddress, - watch: true, - }); - - const value = { - data: { - // Resources - env, - chainId, - chainInfo, - contractAddress, - contractVersion, - collection, - collectionMetadata, - - // On-chain values - metadataUri, - maxSupply, - totalSupply, - }, - - isLoading: { - // Resources - collectionLoading, - collectionMetadataLoading, - - // On-chain values - metadataUriLoading, - maxSupplyLoading, - totalSupplyLoading, - }, - - error: { - // Resources - collectionError, - collectionMetadataError, - - // On-chain values - metadataUriError, - maxSupplyError, - totalSupplyError, - }, - }; - - return React.createElement( - CollectionContext.Provider, - { value }, - typeof children === 'function' ? children(value) : children, - ); -}; - -export const useCollectionContext = () => { - const context = React.useContext(CollectionContext); - if (!context) throw Error('Must be used within '); - return context; -}; diff --git a/packages/react/src/core/nft-collections/common/providers/index.ts b/packages/react/src/core/nft-collections/common/providers/index.ts deleted file mode 100644 index 6e9466f01..000000000 --- a/packages/react/src/core/nft-collections/common/providers/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './CollectionProvider'; diff --git a/packages/react/src/core/nft-collections/constants/backend.ts b/packages/react/src/core/nft-collections/constants/backend.ts deleted file mode 100644 index b420db5d1..000000000 --- a/packages/react/src/core/nft-collections/constants/backend.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const FLAIR_NFT_COLLECTIONS_BACKEND = { - dev: 'http://localhost:3000', - prod: 'https://api.flair.finance', -}; diff --git a/packages/react/src/core/nft-collections/constants/index.ts b/packages/react/src/core/nft-collections/constants/index.ts deleted file mode 100644 index 8f426a2ca..000000000 --- a/packages/react/src/core/nft-collections/constants/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './backend'; -export * from './opensea'; diff --git a/packages/react/src/core/nft-collections/constants/opensea.ts b/packages/react/src/core/nft-collections/constants/opensea.ts deleted file mode 100644 index 1d0c79b74..000000000 --- a/packages/react/src/core/nft-collections/constants/opensea.ts +++ /dev/null @@ -1,20 +0,0 @@ -export type SupportedOpenSeaChains = keyof typeof FLAIR_OPENSEA_ADDRESSES; - -export const FLAIR_OPENSEA_ADDRESSES = { - 1: { - registryAddress: '0x1E0049783F008A0085193E00003D00cd54003c71', // <- SeaPort, old Wyvern: 0xa5409ec958c83c3f309868babaca7c86dcb077c1 - exchangeAddress: '0x0000000000000000000000000000000000000000', - }, - 4: { - registryAddress: '0xF57B2c51dED3A29e6891aba85459d600256Cf317', - exchangeAddress: '0x0000000000000000000000000000000000000000', - }, - 137: { - registryAddress: '0x0000000000000000000000000000000000000000', - exchangeAddress: '0x58807baD0B376efc12F5AD86aAc70E78ed67deaE', - }, - 80001: { - registryAddress: '0x0000000000000000000000000000000000000000', - exchangeAddress: '0x2545943C4d9f6F4A617cEAbA91bd13eD37DeF1aD', - }, -}; diff --git a/packages/react/src/core/nft-collections/extensions/index.ts b/packages/react/src/core/nft-collections/extensions/index.ts deleted file mode 100644 index 7b553bea7..000000000 --- a/packages/react/src/core/nft-collections/extensions/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './metadata'; -export * from './minting'; -export * from './royalty'; -export * from './sales'; -export * from './lockable'; diff --git a/packages/react/src/core/nft-collections/extensions/lockable/index.ts b/packages/react/src/core/nft-collections/extensions/lockable/index.ts deleted file mode 100644 index c0a7cc5a7..000000000 --- a/packages/react/src/core/nft-collections/extensions/lockable/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './useFilterUnlockedTokens'; diff --git a/packages/react/src/core/nft-collections/extensions/lockable/useFilterUnlockedTokens.ts b/packages/react/src/core/nft-collections/extensions/lockable/useFilterUnlockedTokens.ts deleted file mode 100644 index 4a194c645..000000000 --- a/packages/react/src/core/nft-collections/extensions/lockable/useFilterUnlockedTokens.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { BigNumberish } from 'ethers'; -import { useMemo } from 'react'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../common'; - -type ArgsType = [BigNumberish[] | []]; - -export const useFilterUnlockedTokens = ( - config: PredefinedReadContractConfig, -) => { - const result = useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721LockableExtension', - functionName: 'filterUnlocked', - ...config, - }); - - // The way filterUnlocked works is to return 0 if the token is not locked, - // this means if collection has a token ID zero and it is passed in args, we have to take care of it separately. - const hasTokenTokenZero = - config.args?.[0].find((arg: any) => arg.toString() === '0') !== undefined; - const tokenZero = useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721LockableExtension', - functionName: 'locked', - ...config, - args: ['0'], - enabled: hasTokenTokenZero, - }); - - const joinedData = useMemo(() => { - return [ - ...(result.data?.filter((item) => Number(item) > 0) || []), - ...(hasTokenTokenZero && !tokenZero.data ? ['0'] : []), - ]; - }, [result.data, hasTokenTokenZero, tokenZero.data]); - - return { - ...result, - data: joinedData, - }; -}; diff --git a/packages/react/src/core/nft-collections/extensions/metadata/index.ts b/packages/react/src/core/nft-collections/extensions/metadata/index.ts deleted file mode 100644 index f545d2fab..000000000 --- a/packages/react/src/core/nft-collections/extensions/metadata/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './useCollectionMetadata'; -export * from './useCollectionMetadataUri'; -export * from './usePlaceholderUri'; -export * from './useTokenMetadataUriFrozen'; -export * from './useTokenMetadataUriPrefix'; -export * from './useTokenMetadataUriSuffix'; diff --git a/packages/react/src/core/nft-collections/extensions/metadata/useCollectionMetadata.ts b/packages/react/src/core/nft-collections/extensions/metadata/useCollectionMetadata.ts deleted file mode 100644 index 3ac58ada6..000000000 --- a/packages/react/src/core/nft-collections/extensions/metadata/useCollectionMetadata.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { useCallback } from 'react'; - -import { PredefinedReadContractConfig } from '../../../../common'; -import { useRemoteJsonReader } from '../../../ipfs'; -import { NftCollectionMetadata } from '../../types'; -import { useCollectionMetadataUri } from './useCollectionMetadataUri'; - -export const useCollectionMetadata = ({ - enabled, - ...config -}: PredefinedReadContractConfig) => { - const { - data: contractURI, - error: contractURIError, - isLoading: contractURILoading, - refetch: contractURIRefetch, - } = useCollectionMetadataUri(config); - - const { - data: collectionMetadata, - error: collectionMetadataError, - isLoading: collectionMetadataLoading, - sendRequest: fetchContractMetadata, - } = useRemoteJsonReader({ - uri: contractURI, - enabled, - }); - - const readCollectionMetadata = useCallback(async () => { - await contractURIRefetch(); - return await fetchContractMetadata(); - }, [contractURIRefetch, fetchContractMetadata]); - - return { - data: collectionMetadata, - error: !collectionMetadata - ? collectionMetadataError || contractURIError - : undefined, - isLoading: collectionMetadataLoading || contractURILoading, - readCollectionMetadata, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/metadata/useCollectionMetadataUri.ts b/packages/react/src/core/nft-collections/extensions/metadata/useCollectionMetadataUri.ts deleted file mode 100644 index bb76e0033..000000000 --- a/packages/react/src/core/nft-collections/extensions/metadata/useCollectionMetadataUri.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../common'; - -export const useCollectionMetadataUri = ( - config: PredefinedReadContractConfig, -) => { - return useContractRead({ - contractFqn: - 'collections/ERC721/extensions/ERC721CollectionMetadataExtension', - functionName: 'contractURI', - ...config, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/metadata/usePlaceholderUri.ts b/packages/react/src/core/nft-collections/extensions/metadata/usePlaceholderUri.ts deleted file mode 100644 index 1ce88f10a..000000000 --- a/packages/react/src/core/nft-collections/extensions/metadata/usePlaceholderUri.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../common'; - -export const usePlaceholderUri = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: - 'collections/ERC721/extensions/ERC721PrefixedMetadataExtension', - functionName: 'placeholderURI', - ...config, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriFrozen.ts b/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriFrozen.ts deleted file mode 100644 index 25f3c34d5..000000000 --- a/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriFrozen.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { - FeatureReadByTagConfig, - useFeatureReadByTag, -} from '../../../../common'; - -export const useTokenMetadataUriFrozen = (config: FeatureReadByTagConfig) => { - return useFeatureReadByTag({ - tag: 'token_metadata_uri_frozen', - ...config, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriPrefix.ts b/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriPrefix.ts deleted file mode 100644 index af8ec2b98..000000000 --- a/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriPrefix.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { - FeatureReadByTagConfig, - useFeatureReadByTag, -} from '../../../../common'; - -export const useTokenMetadataUriPrefix = (config: FeatureReadByTagConfig) => { - return useFeatureReadByTag({ - tag: 'token_metadata_uri_prefix', - ...config, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriSuffix.ts b/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriSuffix.ts deleted file mode 100644 index f6ac9d9d5..000000000 --- a/packages/react/src/core/nft-collections/extensions/metadata/useTokenMetadataUriSuffix.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { - FeatureReadByTagConfig, - useFeatureReadByTag, -} from '../../../../common'; - -export const useTokenMetadataUriSuffix = (config: FeatureReadByTagConfig) => { - return useFeatureReadByTag({ - tag: 'token_metadata_uri_suffix', - ...config, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/minting/index.ts b/packages/react/src/core/nft-collections/extensions/minting/index.ts deleted file mode 100644 index 0dc925631..000000000 --- a/packages/react/src/core/nft-collections/extensions/minting/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './useAdminMinter'; -export * from './useMaxSupply'; -export * from './useOneOfOneMinter'; -export * from './useOwnerMinter'; -export * from './useRoleBasedMinter'; -export * from './useSaleMinter'; -export * from './useTotalSupply'; diff --git a/packages/react/src/core/nft-collections/extensions/minting/useAdminMinter.ts b/packages/react/src/core/nft-collections/extensions/minting/useAdminMinter.ts deleted file mode 100644 index 3f78bc541..000000000 --- a/packages/react/src/core/nft-collections/extensions/minting/useAdminMinter.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { Environment } from '@flair-sdk/common'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumberish, BytesLike, Signer } from 'ethers'; -import { keccak256, toUtf8Bytes } from 'ethers/lib/utils'; -import { useCallback } from 'react'; - -import { useOzHasRole, useOzOwner } from '../../../openzeppelin'; -import { useOwnerMinter } from './useOwnerMinter'; -import { useRoleBasedMinter } from './useRoleBasedMinter'; - -type Config = { - env?: Environment; - chainId?: number; - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - minterAddress?: string; - toAddress?: BytesLike; - mintCount?: BigNumberish; -}; - -type ArgsType = [toAddress: BytesLike, mintCount: BigNumberish]; - -/** - * Consolidated function for minting as admin without paying (either contract owner, or having minter role). - */ -export const useAdminMinter = ({ - contractVersion, - contractAddress, - signerOrProvider, - minterAddress, - toAddress, - mintCount, -}: Config) => { - const { - data: ownerData, - error: ownerError, - isLoading: ownerLoading, - } = useOzOwner({ - contractVersion, - contractAddress, - }); - const { - data: hasMinterRole, - error: hasMinterRoleError, - isLoading: hasMinterRoleLoading, - } = useOzHasRole({ - contractVersion, - contractAddress, - address: minterAddress, - role: keccak256(toUtf8Bytes('MINTER_ROLE')), - }); - - const isOwner = - ownerData?.toString().toLowerCase() === - minterAddress?.toString().toLowerCase(); - - const { - data: mintByOwnerData, - error: mintByOwnerError, - isLoading: mintByOwnerLoading, - writeAndWait: mintByOwnerWrite, - } = useOwnerMinter({ - contractVersion, - contractAddress, - signerOrProvider, - toAddress, - mintCount, - }); - - const { - data: mintByRoleData, - error: mintByRoleError, - isLoading: mintByRoleLoading, - writeAndWait: mintByRoleWrite, - } = useRoleBasedMinter({ - contractVersion, - contractAddress, - signerOrProvider, - toAddress, - mintCount, - }); - - const mintAsAdmin = useCallback( - (args?: ArgsType) => { - if (isOwner) { - mintByOwnerWrite(args || ([toAddress, mintCount] as ArgsType)); - } else if (hasMinterRole) { - mintByRoleWrite(args || ([toAddress, mintCount] as ArgsType)); - } - }, - [ - hasMinterRole, - isOwner, - mintByOwnerWrite, - mintByRoleWrite, - mintCount, - toAddress, - ], - ); - - return { - data: { - isOwner, - hasMinterRole, - ...(mintByOwnerData.txResponse || mintByOwnerData.txReceipt - ? mintByOwnerData - : mintByRoleData), - }, - error: - mintByOwnerError || mintByRoleError || ownerError || hasMinterRoleError, - isLoading: - mintByOwnerLoading || - mintByRoleLoading || - ownerLoading || - hasMinterRoleLoading, - mintAsAdmin, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/minting/useMaxSupply.ts b/packages/react/src/core/nft-collections/extensions/minting/useMaxSupply.ts deleted file mode 100644 index e2e2ac6f4..000000000 --- a/packages/react/src/core/nft-collections/extensions/minting/useMaxSupply.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../common'; - -export const useMaxSupply = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721AutoIdMinterExtension', - functionName: 'maxSupply', - ...config, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/minting/useOneOfOneMinter.ts b/packages/react/src/core/nft-collections/extensions/minting/useOneOfOneMinter.ts deleted file mode 100644 index 2062505cd..000000000 --- a/packages/react/src/core/nft-collections/extensions/minting/useOneOfOneMinter.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../common'; - -type Config = { - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - toAddress?: BytesLike; - mintCount?: BigNumberish; - tokenURIs?: BytesLike[]; - access?: 'ByRole' | 'ByOwner'; -}; - -type ArgsType = [ - toAddress: BytesLike, - mintCount: BigNumberish, - tokenURIs: BytesLike[], -]; - -export const useOneOfOneMinter = ({ - contractVersion, - contractAddress, - signerOrProvider, - toAddress, - mintCount, - tokenURIs, - access = 'ByOwner', -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'collections/ERC721/extensions/ERC721OneOfOneMintExtension', - }); - - return useContractWriteAndWait({ - contractInterface, - contractAddress, - signerOrProvider, - functionName: - access === 'ByRole' - ? 'mintWithTokenURIsByRole' - : 'mintWithTokenURIsByOwner', - args: [toAddress, mintCount, tokenURIs] as ArgsType, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/minting/useOwnerMinter.ts b/packages/react/src/core/nft-collections/extensions/minting/useOwnerMinter.ts deleted file mode 100644 index d2984f708..000000000 --- a/packages/react/src/core/nft-collections/extensions/minting/useOwnerMinter.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../common'; - -type Config = { - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - toAddress?: BytesLike; - mintCount?: BigNumberish; -}; - -type ArgsType = [toAddress: BytesLike, mintCount: BigNumberish]; - -export const useOwnerMinter = ({ - contractVersion, - contractAddress, - signerOrProvider, - toAddress, - mintCount, -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'collections/ERC721/extensions/ERC721OwnerMintExtension', - }); - - return useContractWriteAndWait({ - contractInterface, - contractAddress, - signerOrProvider, - functionName: 'mintByOwner', - args: [toAddress, mintCount] as ArgsType, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/minting/useRoleBasedMinter.ts b/packages/react/src/core/nft-collections/extensions/minting/useRoleBasedMinter.ts deleted file mode 100644 index 4ab365f68..000000000 --- a/packages/react/src/core/nft-collections/extensions/minting/useRoleBasedMinter.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../common'; - -type Config = { - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - toAddress?: BytesLike; - mintCount?: BigNumberish; -}; - -type ArgsType = [toAddress: BytesLike, mintCount: BigNumberish]; - -export const useRoleBasedMinter = ({ - contractVersion, - contractAddress, - signerOrProvider, - toAddress, - mintCount, -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'collections/ERC721/extensions/ERC721RoleBasedMintExtension', - }); - - return useContractWriteAndWait({ - contractInterface, - contractAddress, - signerOrProvider, - functionName: 'mintByRole', - args: [toAddress, mintCount] as ArgsType, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/minting/useSaleMinter.ts b/packages/react/src/core/nft-collections/extensions/minting/useSaleMinter.ts deleted file mode 100644 index ebcba1883..000000000 --- a/packages/react/src/core/nft-collections/extensions/minting/useSaleMinter.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { Environment } from '@flair-sdk/common'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useTierSaleMinter } from '../sales/hooks/useTierSaleMinter'; - -type Config = { - env?: Environment; - chainId?: number; - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - tierId?: BigNumberish; - minterAddress?: BytesLike; - mintCount?: BigNumberish; -}; - -/** - * Consolidated function for sales minting - */ -export const useSaleMinter = ({ - env, - chainId, - contractVersion, - contractAddress, - signerOrProvider, - tierId, - minterAddress, - mintCount, -}: Config) => { - const { - data: tierSaleData, - error: tierSaleError, - isLoading: tierSaleLoading, - mint, - } = useTierSaleMinter({ - env, - chainId, - contractAddress, - contractVersion, - mintCount, - minterAddress, - signerOrProvider, - tierId, - }); - - return { - data: { - // Transaction - txReceipt: tierSaleData.txReceipt, - txResponse: tierSaleData.txResponse, - - // Common Info - start: tierSaleData.start, - end: tierSaleData.end, - price: tierSaleData.price, - isActive: tierSaleData.isActive, - hasAllowlist: tierSaleData.hasAllowlist, - - // 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/core/nft-collections/extensions/minting/useTotalSupply.ts b/packages/react/src/core/nft-collections/extensions/minting/useTotalSupply.ts deleted file mode 100644 index 8293e258d..000000000 --- a/packages/react/src/core/nft-collections/extensions/minting/useTotalSupply.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -export const useTotalSupply = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721AutoIdMinterExtension', - functionName: 'totalSupply', - ...config, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/royalty/index.ts b/packages/react/src/core/nft-collections/extensions/royalty/index.ts deleted file mode 100644 index a2f08ac9f..000000000 --- a/packages/react/src/core/nft-collections/extensions/royalty/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import '@ethersproject/abi'; - -export * from './useDefaultRoyalty'; diff --git a/packages/react/src/core/nft-collections/extensions/royalty/useDefaultRoyalty.ts b/packages/react/src/core/nft-collections/extensions/royalty/useDefaultRoyalty.ts deleted file mode 100644 index 6a220982f..000000000 --- a/packages/react/src/core/nft-collections/extensions/royalty/useDefaultRoyalty.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { BigNumberish, BytesLike } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -export const useDefaultRoyalty = (config: PredefinedReadContractConfig) => { - const { data, ...rest } = useContractRead< - [receiver: BytesLike, bps: BigNumberish] - >({ - contractFqn: 'collections/ERC721/extensions/ERC721RoyaltyExtension', - functionName: 'defaultRoyalty', - ...config, - }); - - return { - data: { - receiver: data?.[0], - bps: data?.[1], - percent: data?.[1] !== undefined ? Number(data[1]) / 100 : undefined, - }, - ...rest, - }; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionIfWalletCanMint.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionIfWalletCanMint.tsx deleted file mode 100644 index 7abcdae3d..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionIfWalletCanMint.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { Fragment, PropsWithChildren } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionSalesMintingContext } from '../providers/CollectionSalesMintingProvider'; - -type Props = PropsWithChildren< - BareComponentProps & { - loadingMask?: React.ReactNode; - tierId?: number; - } ->; - -export const CollectionIfWalletCanMint = ({ - as, - loadingMask = '...', - tierId, - children, - ...attributes -}: Props) => { - const { - data: { canMint }, - } = useCollectionSalesMintingContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && canMint === undefined ? ( - <>{loadingMask} - ) : canMint ? ( - <>{children} - ) : null} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesActiveStatus.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesActiveStatus.tsx deleted file mode 100644 index 5b4db0632..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesActiveStatus.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionSalesMintingContext } from '../providers'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - soldOutClassName?: string; - activeClassName?: string; - notActiveClassName?: string; -}; - -export const CollectionSalesActiveStatus = ({ - as, - loadingMask = '...', - ...attributes -}: Props) => { - const { - data: { isActive, soldOut }, - isLoading: { mintLoading, isAutoDetectingTier }, - } = useCollectionSalesMintingContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && isAutoDetectingTier ? ( - <>{loadingMask} - ) : ( - <> - {soldOut ? ( - - Sold out - - ) : null} - {!soldOut && isActive ? ( - - Sale is active - - ) : null} - {!soldOut && !isActive && !mintLoading ? ( - - Sale not active yet - - ) : null} - - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesAllowlistStatus.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesAllowlistStatus.tsx deleted file mode 100644 index 7f7a30534..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesAllowlistStatus.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { Fragment, ReactNode } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionSalesMintingContext } from '../providers'; - -type Props = BareComponentProps & { - loadingMask?: ReactNode; - allowlistedContent?: ReactNode; - notAllowlistedContent?: ReactNode; - allowlistNotConfiguredContent?: ReactNode; -}; - -export const CollectionSalesAllowlistStatus = ({ - as, - loadingMask = '...', - allowlistedContent = ( - - You are allowlisted - - ), - notAllowlistedContent = ( - - You are not allowlisted - - ), - allowlistNotConfiguredContent = <>, - ...attributes -}: Props) => { - const { - data: { hasAllowlist, isAllowlisted }, - isLoading: { isAutoDetectingTier, tiersLoading, mintLoading }, - } = useCollectionSalesMintingContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && - (isAutoDetectingTier || tiersLoading || mintLoading) && - hasAllowlist === undefined && - isAllowlisted === undefined ? ( - loadingMask - ) : ( - <> - {hasAllowlist - ? isAllowlisted - ? allowlistedContent - : notAllowlistedContent - : allowlistNotConfiguredContent} - - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintButton.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintButton.tsx deleted file mode 100644 index a023fc4ab..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintButton.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { BigNumberish } from 'ethers'; -import { Fragment, PropsWithChildren } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionSalesMintingContext } from '../providers'; - -type Props = PropsWithChildren & { - soldOutContent?: React.ReactNode; - mintCount?: BigNumberish; -}; - -export const CollectionSalesMintButton = ({ - as = 'button', - children = 'Mint', - soldOutContent = 'Sold Out', - mintCount = 1, - ...attributes -}: Props) => { - const { - data: { canMint, soldOut }, - mint, - } = useCollectionSalesMintingContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - mint({ mintCount })} - disabled={!canMint} - {...attributes} - > - {soldOut && soldOutContent ? soldOutContent : children} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintInput.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintInput.tsx deleted file mode 100644 index 74a7b6691..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintInput.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { useCollectionSalesMintingContext } from '../providers'; - -type Props = { - className?: string; - mintCount?: BigNumberish; - setMintCount: (mintCount: BigNumberish) => void; -}; - -export const CollectionSalesMintInput = ({ - className, - mintCount = '1', - setMintCount, -}: Props) => { - const { - data: { canMint, maxSupply, eligibleAmount }, - } = useCollectionSalesMintingContext(); - - const maxAllowedMintCount = Math.min( - Number(maxSupply?.toString() || Infinity), - Number(eligibleAmount?.toString() || Infinity), - ); - - return ( - setMintCount(e.target.value)} - className={className} - /> - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintStatusBar.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintStatusBar.tsx deleted file mode 100644 index 09bd83e8c..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesMintStatusBar.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { Errors, Spinner, TransactionLink } from '../../../../ui'; -import { useCollectionSalesMintingContext } from '../providers'; - -type Props = { - className?: string; -}; - -export const CollectionSalesMintStatusBar = ({ className }: Props) => { - const { - data: { txReceipt, txResponse }, - isLoading: { isAutoDetectingTier, mintLoading }, - error: { mintError, collectionMetadataError }, - } = useCollectionSalesMintingContext(); - - return ( -
- {isAutoDetectingTier ? ( -
- Checking your wallet eligibility... -
- ) : ( - <> - {mintLoading && ( -
- {' '} - {txReceipt || txResponse ? 'Minting...' : 'Preparing...'} -
- )} - {txReceipt || txResponse ? ( - - ) : null} - {!mintLoading && mintError && ( - - )} - {collectionMetadataError && ( - - )} - - )} -
- ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesPrice.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesPrice.tsx deleted file mode 100644 index 5b975b9ec..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionSalesPrice.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { BigNumber } from 'ethers'; -import { Fragment, ReactNode } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { CryptoUnits, CryptoValue } from '../../../../crypto-currency'; -import { useCollectionSalesMintingContext } from '../providers'; - -type Props = BareComponentProps & { - loadingMask?: ReactNode; - showPrice?: boolean; - showSymbol?: boolean; - freeElement?: ReactNode; - mintCount?: number; - fractionDigits?: number; -}; - -export const CollectionSalesPrice = ({ - as, - loadingMask = '...', - showPrice = true, - showSymbol = true, - freeElement = <>Free, - mintCount = 1, - fractionDigits, - ...attributes -}: Props) => { - const { - data: { price, chainInfo, currentTierId }, - isLoading: { isAutoDetectingTier }, - } = useCollectionSalesMintingContext(); - - const mintNo = Number(mintCount || '1'); - const finalPrice = - price !== undefined && mintCount !== undefined - ? BigNumber.from(price).mul(mintNo === NaN ? 1 : mintNo) - : undefined; - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {finalPrice !== undefined && !isAutoDetectingTier ? ( - Number(finalPrice.toString()) > 0 || !freeElement ? ( - - ) : ( - freeElement - ) - ) : ( - loadingMask - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierEligibleAmount.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierEligibleAmount.tsx deleted file mode 100644 index 9da4ca4a3..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierEligibleAmount.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionSalesMintingContext } from '../providers/CollectionSalesMintingProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - tierId?: number; -}; - -export const CollectionTierEligibleAmount = ({ - as, - loadingMask = '...', - tierId, - ...attributes -}: Props) => { - const { - data: { currentTierId, tiers }, - isLoading: { isAutoDetectingTier, tiersLoading }, - } = useCollectionSalesMintingContext(); - const resolvedTierId = Number( - tierId !== undefined ? tierId : currentTierId || '0', - ); - const eligibleAmount = tiers?.[resolvedTierId] - ? tiers[resolvedTierId].eligibleAmount - : undefined; - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && - (isAutoDetectingTier || tiersLoading) && - eligibleAmount == undefined ? ( - <>{loadingMask} - ) : ( - eligibleAmount?.toLocaleString() - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierMaxAllocation.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierMaxAllocation.tsx deleted file mode 100644 index 3c5ed6650..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierMaxAllocation.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionContext } from '../../../common'; -import { useTierSaleMaxAllocation } from '../hooks/useTierSaleMaxAllocation'; -import { useCollectionSalesMintingContext } from '../providers/CollectionSalesMintingProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - tierId?: number; -}; - -export const CollectionTierMaxAllocation = ({ - as, - loadingMask = '...', - tierId, - ...attributes -}: Props) => { - const { - data: { chainId, contractAddress, contractVersion }, - } = useCollectionContext(); - - const { - data: { currentTierId }, - } = useCollectionSalesMintingContext(); - - const { data, isLoading } = useTierSaleMaxAllocation({ - chainId, - contractAddress, - contractVersion, - tierId: tierId !== undefined ? tierId : currentTierId || '0', - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && isLoading && data === undefined ? ( - <>{loadingMask} - ) : ( - data?.toLocaleString() - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierMaxSupply.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierMaxSupply.tsx deleted file mode 100644 index 36ca104ce..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierMaxSupply.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionContext } from '../../../common'; -import { useTierSaleMaxSupply } from '../hooks/useTierSaleMaxSupply'; -import { useCollectionSalesMintingContext } from '../providers/CollectionSalesMintingProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - tierId?: number; -}; - -export const CollectionTierMaxSupply = ({ - as, - loadingMask = '...', - tierId, - ...attributes -}: Props) => { - const { - data: { chainId, contractAddress, contractVersion }, - } = useCollectionContext(); - - const { - data: { currentTierId }, - } = useCollectionSalesMintingContext(); - - const { data, isLoading } = useTierSaleMaxSupply({ - chainId, - contractAddress, - contractVersion, - tierId: tierId !== undefined ? tierId : currentTierId || '0', - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && isLoading && data === undefined ? ( - <>{loadingMask} - ) : ( - data?.toLocaleString() - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierRemainingSupply.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierRemainingSupply.tsx deleted file mode 100644 index cab0754fe..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierRemainingSupply.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionContext } from '../../../common'; -import { useTierSaleRemainingSupply } from '../hooks/useTierSaleRemainingSupply'; -import { useCollectionSalesMintingContext } from '../providers/CollectionSalesMintingProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - tierId?: number; -}; - -export const CollectionTierRemainingSupply = ({ - as, - loadingMask = '...', - tierId, - ...attributes -}: Props) => { - const { - data: { chainId, contractAddress, contractVersion }, - } = useCollectionContext(); - - const { - data: { currentTierId }, - } = useCollectionSalesMintingContext(); - - const { data, isLoading } = useTierSaleRemainingSupply({ - chainId, - contractAddress, - contractVersion, - tierId: tierId !== undefined ? tierId : currentTierId || '0', - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && isLoading && data === undefined ? ( - <>{loadingMask} - ) : ( - data?.toLocaleString() - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierReservedSupply.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierReservedSupply.tsx deleted file mode 100644 index 99b24b6d0..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierReservedSupply.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionContext } from '../../../common'; -import { useTierSaleReservedSupply } from '../hooks/useTierSaleReservedSupply'; -import { useCollectionSalesMintingContext } from '../providers/CollectionSalesMintingProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - tierId?: number; -}; - -export const CollectionTierReservedSupply = ({ - as, - loadingMask = '...', - tierId, - ...attributes -}: Props) => { - const { - data: { chainId, contractAddress, contractVersion }, - } = useCollectionContext(); - - const { - data: { currentTierId }, - } = useCollectionSalesMintingContext(); - - const { data, isLoading } = useTierSaleReservedSupply({ - chainId, - contractAddress, - contractVersion, - tierId: tierId !== undefined ? tierId : currentTierId || '0', - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && isLoading && data === undefined ? ( - <>{loadingMask} - ) : ( - data?.toLocaleString() - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierTotalSupply.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierTotalSupply.tsx deleted file mode 100644 index 3bc138b30..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierTotalSupply.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionContext } from '../../../common'; -import { useTierSaleTotalSupply } from '../hooks/useTierSaleTotalSupply'; -import { useCollectionSalesMintingContext } from '../providers/CollectionSalesMintingProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - tierId?: number; -}; - -export const CollectionTierTotalSupply = ({ - as, - loadingMask = '...', - tierId, - ...attributes -}: Props) => { - const { - data: { chainId, contractAddress, contractVersion }, - } = useCollectionContext(); - - const { - data: { currentTierId }, - } = useCollectionSalesMintingContext(); - - const { data, isLoading } = useTierSaleTotalSupply({ - chainId, - contractAddress, - contractVersion, - tierId: tierId !== undefined ? tierId : currentTierId || '0', - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && isLoading && data === undefined ? ( - <>{loadingMask} - ) : ( - data?.toLocaleString() - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierWalletMints.tsx b/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierWalletMints.tsx deleted file mode 100644 index ac8e16c9a..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/CollectionTierWalletMints.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { BytesLike } from 'ethers'; -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../../../common'; -import { useCollectionContext } from '../../../common'; -import { useTierSaleWalletMints } from '../hooks/useTierSaleWalletMints'; -import { useCollectionSalesMintingContext } from '../providers/CollectionSalesMintingProvider'; - -type Props = BareComponentProps & { - loadingMask?: React.ReactNode; - tierId?: number; - walletAddress?: BytesLike; -}; - -export const CollectionTierWalletMints = ({ - as, - loadingMask = '...', - tierId, - walletAddress, - ...attributes -}: Props) => { - const { - data: { chainId, contractAddress, contractVersion }, - } = useCollectionContext(); - - const { - data: { currentTierId, minterAddress }, - } = useCollectionSalesMintingContext(); - - const finalTierId = tierId !== undefined ? tierId : currentTierId || '0'; - const finalWalletAddress = walletAddress || minterAddress; - - const canCheck = Boolean(finalTierId !== undefined && finalWalletAddress); - const { data, isLoading } = useTierSaleWalletMints({ - chainId, - contractAddress, - contractVersion, - tierId: finalTierId, - walletAddress: finalWalletAddress, - watch: canCheck, - enabled: canCheck, - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {loadingMask && isLoading && data === undefined ? ( - <>{loadingMask} - ) : ( - data?.toLocaleString() - )} - - ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/components/index.ts b/packages/react/src/core/nft-collections/extensions/sales/components/index.ts deleted file mode 100644 index 6f3a0af5c..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/components/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -export * from './CollectionIfWalletCanMint'; -export * from './CollectionSalesActiveStatus'; -export * from './CollectionSalesAllowlistStatus'; -export * from './CollectionSalesMintButton'; -export * from './CollectionSalesMintInput'; -export * from './CollectionSalesMintStatusBar'; -export * from './CollectionSalesPrice'; -export * from './CollectionTierEligibleAmount'; -export * from './CollectionTierMaxAllocation'; -export * from './CollectionTierMaxSupply'; -export * from './CollectionTierRemainingSupply'; -export * from './CollectionTierReservedSupply'; -export * from './CollectionTierTotalSupply'; -export * from './CollectionTierWalletMints'; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/index.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/index.ts deleted file mode 100644 index 763275f5c..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -export * from './useSaleTiers'; -export * from './useTierSaleMinter'; -export * from './useTierSaleAllowlistChecker'; -export * from './useTierSaleEligibleAmount'; -export * from './useTierSaleInformation'; -export * from './useTierSaleMaxAllocation'; -export * from './useTierSaleMaxSupply'; -export * from './useTierSaleRemainingSupply'; -export * from './useTierSaleReservedSupply'; -export * from './useTierSaleTotalSupply'; -export * from './useTierSaleWalletMints'; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useSaleTiers.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useSaleTiers.ts deleted file mode 100644 index 7669ea7ae..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useSaleTiers.ts +++ /dev/null @@ -1,189 +0,0 @@ -import { Environment, ZERO_BYTES32 } from '@flair-sdk/common'; -import { V1_ERC721TieringExtension__factory } from '@flair-sdk/registry'; -import { BigNumberish, BytesLike } from 'ethers'; -import { useCallback, useEffect, useMemo, useState } from 'react'; -import { useProvider } from 'wagmi'; - -import { PredefinedReadContractConfig } from '../../../../../common'; -import { Tier } from '../types'; -import { useTierSaleAllowlistChecker } from './useTierSaleAllowlistChecker'; -import { useTierSaleEligibleAmount } from './useTierSaleEligibleAmount'; - -type ArgsType = [tierId: BigNumberish]; - -type Config = { - env?: Environment; - chainId?: number; - contractAddress?: string; - enabled?: boolean; - minterAddress?: BytesLike; -} & PredefinedReadContractConfig; - -export const useSaleTiers = ({ - env, - chainId, - contractAddress, - enabled, - minterAddress, -}: Config) => { - const [error, setError] = useState(); - const [isLoading, setIsLoading] = useState(false); - const [tiers, setTiers] = useState>({}); - - const { - error: allowlistCheckerError, - isLoading: allowlistCheckerLoading, - call: checkAllowlist, - } = useTierSaleAllowlistChecker({ - env, - chainId, - contractAddress, - minterAddress, - enabled: false, - }); - - const { - error: eligibleAmountError, - isLoading: eligibleAmountLoading, - call: getEligibleAmount, - } = useTierSaleEligibleAmount({ - chainId, - contractAddress, - minterAddress, - enabled: false, - }); - - const provider = useProvider({ - chainId, - }); - const contract = useMemo(() => { - if (!contractAddress || !provider) { - return; - } - return V1_ERC721TieringExtension__factory.connect( - contractAddress, - provider, - ); - }, [contractAddress, provider]); - - const fetchTierById = useCallback( - async (tierId: BigNumberish) => { - if (!contract) { - return; - } - - const tier = (await contract.tiers(tierId)) as Tier; - - const now = new Date(); - - const start = - tier?.start !== undefined - ? new Date(Number(tier?.start.toString()) * 1000) - : undefined; - const end = - tier?.end !== undefined - ? new Date(Number(tier?.end.toString()) * 1000) - : undefined; - const isActive = start && end ? start <= now && end > now : undefined; - const hasAllowlist = tier?.merkleRoot - ? tier.merkleRoot !== ZERO_BYTES32 - : undefined; - - const { isAllowlisted, merkleMetadata, merkleProof } = - isActive && hasAllowlist - ? await checkAllowlist({ - tierId, - merkleRoot: tier.merkleRoot, - }) - : ({} as any); - - const eligibleAmount = isActive - ? await getEligibleAmount({ - tierId, - maxAllowance: merkleMetadata?.maxAllowance, - merkleProof, - }) - : undefined; - - return { - ...tier, - isSavedOnChain: true, - isActive, - hasAllowlist, - isAllowlisted, - eligibleAmount, - isEligible: - eligibleAmount !== undefined - ? Boolean( - !eligibleAmountError && Number(eligibleAmount.toString()) > 0, - ) - : undefined, - }; - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [contract, minterAddress], - ); - - const refetchTiers = useCallback(async () => { - if (isLoading) { - return; - } - - setIsLoading(true); - setError(undefined); - - try { - 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); - } catch (error: any) { - setError(error); - } - - setIsLoading(false); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [minterAddress]); - - useEffect(() => { - if ( - enabled && - !isLoading && - !error && - (!tiers || !Object.keys(tiers).length) - ) { - refetchTiers(); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [enabled, env, chainId, contractAddress]); - - return { - data: tiers, - error: - // top-level - error || - // tiered sales - allowlistCheckerError || - eligibleAmountError, - isLoading: - // top-level - isLoading || - // tiered sales - allowlistCheckerLoading || - eligibleAmountLoading, - refetchTiers, - }; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleAllowlistChecker.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleAllowlistChecker.ts deleted file mode 100644 index bc91d8e9b..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleAllowlistChecker.ts +++ /dev/null @@ -1,164 +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'; - -type Config = { - env?: Environment; - enabled?: boolean; - chainId?: number; - contractVersion?: ContractVersion; - contractAddress?: string; - merkleRoot?: BytesLike; - tierId?: BigNumberish; - minterAddress?: BytesLike; -}; - -export const useTierSaleAllowlistChecker = ({ - env = Environment.PROD, - enabled = true, - chainId, - contractVersion, - contractAddress, - merkleRoot, - tierId, - minterAddress, -}: Config) => { - const readyToRead = Boolean( - tierId !== undefined && - enabled && - minterAddress && - contractAddress && - chainId, - ); - - const { - data: { merkleProof, merkleMetadata }, - error: merkleProofError, - isLoading: merkleProofLoading, - refetch: refetchMerkleProof, - call: getMerkleProof, - } = useAddressListMerkleProof({ - env, - address: minterAddress, - rootHash: merkleRoot, - enabled: readyToRead, - }); - - const { - data: isTierAllowlisted, - error: onTierAllowlistError, - isLoading: onTierAllowlistLoading, - refetch: refetchOnTierAllowlist, - call: callOnTierAllowlist, - } = useContractRead< - boolean, - [BigNumberish, BytesLike, BigNumberish, BytesLike[]] - >({ - chainId, - contractVersion, - enabled: Boolean( - readyToRead && - tierId !== undefined && - minterAddress && - merkleMetadata?.maxAllowance !== undefined && - merkleProof, - ), - contractFqn: 'collections/ERC721/extensions/ERC721TieringExtension', - functionName: 'onTierAllowlist', - contractAddress, - cacheOnBlock: false, - cacheTime: 0, - staleTime: 0, - args: - tierId !== undefined && - minterAddress && - merkleMetadata?.maxAllowance !== undefined && - merkleProof - ? [tierId, minterAddress, merkleMetadata.maxAllowance, merkleProof] - : undefined, - }); - - const refetch = useCallback( - () => refetchMerkleProof().then(() => refetchOnTierAllowlist()), - [refetchMerkleProof, refetchOnTierAllowlist], - ); - - const call = useCallback( - async (overrides?: { - merkleRoot?: BytesLike; - tierId?: BigNumberish; - minterAddress?: BytesLike; - }) => { - const minterAddressFinal = - overrides?.minterAddress !== undefined - ? overrides?.minterAddress - : minterAddress; - const merkleRootFinal = - overrides?.merkleRoot !== undefined - ? overrides?.merkleRoot - : merkleRoot; - const tierIdFinal = - overrides?.tierId !== undefined ? overrides?.tierId : tierId; - - const proof = await getMerkleProof({ - address: minterAddressFinal, - rootHash: merkleRootFinal, - }); - - const merkleProofFinal = proof?.merkleProof || merkleProof; - const merkleMetadataFinal = proof?.merkleMetadata || merkleMetadata; - const maxAllowanceFinal = merkleMetadataFinal?.maxAllowance; - - if ( - proof == undefined || - tierIdFinal == undefined || - minterAddressFinal == undefined || - maxAllowanceFinal == undefined || - merkleProofFinal == undefined - ) { - return {}; - } - - const response = await callOnTierAllowlist({ - args: [ - tierIdFinal as BigNumberish, - minterAddressFinal as BytesLike, - maxAllowanceFinal as BigNumberish, - merkleProofFinal as BytesLike[], - ], - }); - - return { - isAllowlisted: response, - merkleMetadata: merkleMetadataFinal, - merkleProof: merkleProofFinal, - }; - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [ - // callOnTierAllowlist, - // getMerkleProof, - merkleMetadata, - merkleProof, - merkleRoot, - minterAddress, - tierId, - ], - ); - - return { - data: { - isAllowlisted: isTierAllowlisted, - merkleProof, - merkleMetadata, - }, - error: onTierAllowlistError || merkleProofError, - isLoading: onTierAllowlistLoading || merkleProofLoading, - refetch, - call, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleEligibleAmount.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleEligibleAmount.ts deleted file mode 100644 index 0ab780d1e..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleEligibleAmount.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { ZERO_ADDRESS } from '@flair-sdk/common'; -import { BigNumberish, BytesLike } from 'ethers'; -import { useCallback, useMemo, useState } from 'react'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -type ArgsType = [ - tierId: BigNumberish, - minterAddress: BytesLike, - maxAllowance: BigNumberish, - merkleProof: BytesLike[], -]; - -type Config = { - tierId?: BigNumberish; - minterAddress?: BytesLike; - maxAllowance?: BigNumberish; - merkleProof?: BytesLike[]; -} & PredefinedReadContractConfig; - -export const useTierSaleEligibleAmount = (config: Config) => { - const [data, setData] = useState(); - const [error, setError] = useState(); - - useMemo(() => { - setData(undefined); - setError(undefined); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [config.tierId]); - - const result = useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721TieringExtension', - functionName: 'eligibleForTier', - cacheOnBlock: false, - cacheTime: 0, - staleTime: 0, - args: [ - config.tierId || 0, - config.minterAddress || ZERO_ADDRESS, - config.maxAllowance || 1, - config.merkleProof || [], - ] as ArgsType, - enabled: - config.enabled && - config.tierId !== undefined && - config.minterAddress !== undefined, - onSettled(data: any, error: any) { - if (error) { - if (!['NOT_STARTED', 'NOT_ALLOWLISTED'].includes(error?.reason)) { - setError(error); - } - } else { - setData(data); - setError(undefined); - } - }, - ...config, - }); - - const call = useCallback( - async (overrides?: { - tierId?: BigNumberish; - minterAddress?: BytesLike; - maxAllowance?: BigNumberish; - merkleProof?: BytesLike[]; - }) => { - setData(undefined); - setError(undefined); - - try { - return await result.call({ - args: [ - overrides?.tierId !== undefined - ? overrides?.tierId - : config.tierId || 0, - overrides?.minterAddress || config.minterAddress || ZERO_ADDRESS, - overrides?.maxAllowance || config.maxAllowance || 1, - overrides?.merkleProof || config.merkleProof || [], - ] as ArgsType, - }); - } catch (error: any) { - if ( - [ - 'NOT_STARTED', - 'MAXED_ALLOWANCE', - 'ALREADY_ENDED', - 'NOT_ALLOWLISTED', - ].includes(error?.reason) - ) { - return 0; - } - - setData(undefined); - setError(undefined); - } - }, - [ - config.maxAllowance, - config.merkleProof, - config.minterAddress, - config.tierId, - result, - ], - ); - - return { ...result, error, data, call } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleInformation.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleInformation.ts deleted file mode 100644 index a199c443c..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleInformation.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; -import { Tier } from '../types'; - -type ArgsType = [tierId: BigNumberish]; - -type Config = { - tierId?: BigNumberish; -} & PredefinedReadContractConfig; - -export const useTierSaleInformation = (config: Config) => { - const result = useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721TieringExtension', - functionName: 'tiers', - args: [config.tierId] as ArgsType, - enabled: - config.enabled && - config.tierId !== undefined && - config.tierId !== null && - config.tierId !== '', - ...config, - }); - - return { - ...result, - data: result?.data - ? ({ - start: result.data[0], - end: result.data[1], - currency: result.data[2], - price: result.data[3].toString(), - maxPerWallet: result.data[4], - merkleRoot: result.data[5], - reserved: result.data[6], - maxAllocation: result.data[7], - isSavedOnChain: true, - } as Tier) - : undefined, - }; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMaxAllocation.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMaxAllocation.ts deleted file mode 100644 index bdf5e7bfe..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMaxAllocation.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { PredefinedReadContractConfig } from '../../../../../common'; -import { useTierSaleInformation } from './useTierSaleInformation'; - -type ArgsType = [tierId: BigNumberish]; - -type Config = { - tierId?: BigNumberish; -} & PredefinedReadContractConfig; - -export const useTierSaleMaxAllocation = ({ - chainId, - contractAddress, - enabled, - tierId, - ...restOfConfig -}: Config) => { - const result = useTierSaleInformation({ - chainId, - contractAddress, - tierId, - enabled, - ...restOfConfig, - }); - - return { - ...result, - data: result.data?.maxAllocation, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMaxSupply.tsx b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMaxSupply.tsx deleted file mode 100644 index 2ff6d0c10..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMaxSupply.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import { BigNumber, BigNumberish } from 'ethers'; -import { useMemo } from 'react'; - -import { PredefinedReadContractConfig } from '../../../../../common'; -import { useTierSaleRemainingSupply } from './useTierSaleRemainingSupply'; -import { useTierSaleReservedSupply } from './useTierSaleReservedSupply'; -import { useTierSaleTotalSupply } from './useTierSaleTotalSupply'; - -type Config = { - tierId?: BigNumberish; -} & PredefinedReadContractConfig; - -export const useTierSaleMaxSupply = ({ - tierId, - chainId, - contractAddress, - contractVersion, - ...restOfConfig -}: Config) => { - const { - data: totalMinted, - error: totalMintedError, - isLoading: totalMintedLoading, - } = useTierSaleTotalSupply({ - chainId, - contractAddress, - contractVersion, - tierId, - ...restOfConfig, - }); - - const { - data: totalRemaining, - error: totalRemainingError, - isLoading: totalRemainingLoading, - } = useTierSaleRemainingSupply({ - chainId, - contractAddress, - contractVersion, - tierId: tierId, - ...restOfConfig, - }); - - const { - data: totalReserved, - error: totalReservedError, - isLoading: totalReservedLoading, - } = useTierSaleReservedSupply({ - chainId, - contractAddress, - contractVersion, - tierId: tierId, - ...restOfConfig, - }); - - const data = useMemo(() => { - let data = BigNumber.from(totalMinted || '0').add( - BigNumber.from(totalRemaining || '0'), - ); - - if (BigNumber.from(totalReserved || '0').gt(data)) { - data = BigNumber.from(totalReserved || '0'); - } - - return data; - }, [totalMinted, totalRemaining, totalReserved]); - - return { - data, - error: totalMintedError || totalRemainingError || totalReservedError, - isLoading: - totalMintedLoading || totalRemainingLoading || totalReservedLoading, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMinter.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMinter.ts deleted file mode 100644 index e196dc728..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleMinter.ts +++ /dev/null @@ -1,196 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { Environment, ZERO_BYTES32 } from '@flair-sdk/common'; -import { ContractVersion } from '@flair-sdk/registry'; -import { BigNumber, BigNumberish, BytesLike, Signer } from 'ethers'; -import { useCallback } from 'react'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../../common'; -import { useTierSaleAllowlistChecker } from './useTierSaleAllowlistChecker'; -import { useTierSaleEligibleAmount } from './useTierSaleEligibleAmount'; -import { useTierSaleInformation } from './useTierSaleInformation'; - -type ArgsType = [ - tierId: BigNumberish, - mintCount: BigNumberish, - maxAllowance: BigNumberish, - merkleProof: BytesLike[], -]; - -type Config = { - env?: Environment; - chainId?: number; - contractVersion?: ContractVersion; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - tierId?: BigNumberish; - minterAddress?: BytesLike; - mintCount?: BigNumberish; - enabled?: boolean; -}; - -/** - * Consolidated function for minting of a specific tier. - */ -export const useTierSaleMinter = ({ - env, - chainId, - contractAddress, - signerOrProvider, - tierId, - minterAddress, - mintCount, - enabled = true, -}: Config) => { - const { - data: tier, - error: tierError, - isLoading: tierLoading, - } = useTierSaleInformation({ - chainId, - contractAddress, - tierId, - enabled, - }); - - const now = new Date(); - - const start = - tier?.start !== undefined - ? new Date(Number(tier?.start.toString()) * 1000) - : undefined; - const end = - tier?.end !== undefined - ? new Date(Number(tier?.end.toString()) * 1000) - : undefined; - const isActive = start && end ? start <= now && end > now : undefined; - const hasAllowlist = tier?.merkleRoot - ? tier.merkleRoot !== ZERO_BYTES32 - : undefined; - - const { - data: { merkleProof, merkleMetadata, isAllowlisted }, - error: allowlistCheckerError, - isLoading: allowlistCheckerLoading, - } = useTierSaleAllowlistChecker({ - env, - chainId, - contractAddress, - enabled: Boolean( - enabled && minterAddress && hasAllowlist && tier?.merkleRoot, - ), - merkleRoot: tier?.merkleRoot, - tierId, - minterAddress, - }); - - const { - data: eligibleAmount, - error: eligibleAmountError, - isLoading: eligibleAmountLoading, - } = useTierSaleEligibleAmount({ - chainId, - contractAddress, - tierId, - minterAddress, - maxAllowance: merkleMetadata?.maxAllowance || mintCount || 1, - merkleProof: merkleProof || [], - enabled: Boolean( - enabled && - minterAddress && - (hasAllowlist === false || - (hasAllowlist === true && merkleProof !== undefined)) && - (merkleMetadata?.maxAllowance || mintCount || 1), - ), - }); - - const contractInterface = useContractAbi({ - contractFqn: 'collections/ERC721/extensions/ERC721TieringExtension', - }); - - const { - data: mintData, - error: mintError, - isLoading: mintLoading, - writeAndWait: mintAndWait, - } = useContractWriteAndWait({ - contractInterface, - functionName: 'mintByTier', - contractAddress, - signerOrProvider, - args: [ - tierId, - mintCount, - merkleMetadata?.maxAllowance, - merkleProof, - ] as ArgsType, - overrides: { - value: - typeof tier?.price !== 'undefined' && mintCount - ? BigNumber.from(tier?.price).mul(BigNumber.from(mintCount)) - : undefined, - }, - }); - - const mint = useCallback( - (args?: { mintCount: BigNumberish }) => { - const count = args?.mintCount || mintCount; - return mintAndWait( - [ - tierId, - count, - merkleMetadata?.maxAllowance || count || 1, - merkleProof || [], - ] as ArgsType, - { - value: tier?.price - ? BigNumber.from(tier?.price).mul(BigNumber.from(count)) - : undefined, - }, - ); - }, - [ - merkleMetadata?.maxAllowance, - merkleProof, - mintAndWait, - mintCount, - tier?.price, - tierId, - ], - ); - - return { - data: { - txResponse: mintData.txResponse, - txReceipt: mintData.txReceipt, - tier, - start, - end, - price: tier?.price, - isActive, - merkleProof, - merkleMetadata, - hasAllowlist, - isAllowlisted, - eligibleAmount, - isEligible: - eligibleAmount !== undefined - ? Boolean( - !eligibleAmountError && Number(eligibleAmount.toString()) > 0, - ) - : undefined, - }, - error: { - tierError, - allowlistCheckerError, - eligibleAmountError, - mintError, - }, - isLoading: { - tierLoading, - allowlistCheckerLoading, - eligibleAmountLoading, - mintLoading, - }, - mint, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleRemainingSupply.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleRemainingSupply.ts deleted file mode 100644 index ec9e25c4b..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleRemainingSupply.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { BigNumber, BigNumberish } from 'ethers'; -import { useMemo } from 'react'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; -import { useTierSaleInformation } from './useTierSaleInformation'; -import { useTierSaleTotalSupply } from './useTierSaleTotalSupply'; - -type ArgsType = [tierId: BigNumberish]; - -type Config = { - tierId?: BigNumberish; -} & PredefinedReadContractConfig; - -export const useTierSaleRemainingSupply = ({ - chainId, - contractAddress, - enabled = true, - tierId, - ...restOfConfig -}: Config) => { - const { data: tierInfo } = useTierSaleInformation({ - chainId, - contractAddress, - tierId, - enabled: enabled && tierId !== undefined, - }); - - const { data: tierSupply } = useTierSaleTotalSupply({ - chainId, - contractAddress, - tierId, - enabled: enabled && tierId !== undefined, - }); - - const result = useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721TieringExtension', - functionName: 'remainingForTier', - chainId, - contractAddress, - args: [tierId] as ArgsType, - enabled: enabled && tierId !== undefined, - ...restOfConfig, - }); - - const data = useMemo(() => { - if ( - result.data === undefined || - tierInfo === undefined || - tierSupply === undefined - ) { - return undefined; - } - - const remainingForTier = BigNumber.from(result.data || 0); - const maxAllocation = BigNumber.from(tierInfo.maxAllocation || 0); - const mintedSupply = BigNumber.from(tierSupply || 0); - - if (maxAllocation.gt(0)) { - if (maxAllocation.sub(mintedSupply).lt(remainingForTier)) { - return maxAllocation.sub(mintedSupply); - } - } - - return remainingForTier; - }, [result, tierInfo, tierSupply]); - - return { - ...result, - data, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleReservedSupply.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleReservedSupply.ts deleted file mode 100644 index 671d994ba..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleReservedSupply.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { PredefinedReadContractConfig } from '../../../../../common'; -import { useTierSaleInformation } from './useTierSaleInformation'; - -type ArgsType = [tierId: BigNumberish]; - -type Config = { - tierId?: BigNumberish; -} & PredefinedReadContractConfig; - -export const useTierSaleReservedSupply = ({ - chainId, - contractAddress, - enabled, - tierId, - ...restOfConfig -}: Config) => { - const result = useTierSaleInformation({ - chainId, - contractAddress, - tierId, - enabled, - ...restOfConfig, - }); - - return { - ...result, - data: result.data?.reserved, - } as const; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleTotalSupply.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleTotalSupply.ts deleted file mode 100644 index ccc3fd07f..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleTotalSupply.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -type ArgsType = [tierId: BigNumberish]; - -type Config = { - tierId?: BigNumberish; -} & PredefinedReadContractConfig; - -export const useTierSaleTotalSupply = (config: Config) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721TieringExtension', - functionName: 'tierMints', - args: [config.tierId] as ArgsType, - enabled: - config.enabled && - config.tierId !== undefined && - config.tierId !== null && - config.tierId !== '', - ...config, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleWalletMints.ts b/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleWalletMints.ts deleted file mode 100644 index 30b8db09d..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/hooks/useTierSaleWalletMints.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { BigNumberish, BytesLike } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../../common'; - -type ArgsType = [tierId: BigNumberish, walletAddress: BytesLike]; - -type Config = { - tierId?: BigNumberish; - walletAddress?: BigNumberish; -} & PredefinedReadContractConfig; - -export const useTierSaleWalletMints = ({ - chainId, - contractAddress, - enabled = true, - tierId, - walletAddress, - ...restOfConfig -}: Config) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721TieringExtension', - functionName: 'walletMintedByTier', - chainId, - contractAddress, - args: [tierId, walletAddress] as ArgsType, - enabled: enabled && tierId !== undefined && walletAddress !== undefined, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/index.ts b/packages/react/src/core/nft-collections/extensions/sales/index.ts deleted file mode 100644 index 16ddf6a9b..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './components'; -export * from './hooks'; -export * from './providers'; -export * from './sections'; -export * from './types'; diff --git a/packages/react/src/core/nft-collections/extensions/sales/providers/CollectionSalesMintingProvider.tsx b/packages/react/src/core/nft-collections/extensions/sales/providers/CollectionSalesMintingProvider.tsx deleted file mode 100644 index 76c30eefa..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/providers/CollectionSalesMintingProvider.tsx +++ /dev/null @@ -1,311 +0,0 @@ -import { TransactionResponse } from '@ethersproject/abstract-provider'; -import { TransactionReceipt } from '@ethersproject/providers'; -import { ZERO_ADDRESS } from '@flair-sdk/common'; -import { BigNumberish, BytesLike } from 'ethers'; -import * as React from 'react'; -import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react'; -import { useAccount } from 'wagmi'; - -import { useCollectionContext } from '../../../common'; -import { useSaleMinter } from '../../minting/useSaleMinter'; -import { useSaleTiers } from '../hooks/useSaleTiers'; -import { Tier } from '../types'; - -type CollectionSalesMintingContextValue = { - data: ReturnType['data'] & { - // On-chain values - tiers?: Record; - - // Current tier - currentTierId?: BigNumberish; - start?: Date; - end?: Date; - price?: BigNumberish; - hasAllowlist?: boolean; - isActive?: boolean; - isAllowlisted?: boolean; - isEligible?: boolean; - eligibleAmount?: BigNumberish; - - // Helpers - autoDetectedTierId?: BigNumberish; - canMint?: boolean; - soldOut?: boolean; - minterAddress?: BytesLike; - - // Transaction - txReceipt?: TransactionReceipt; - txResponse?: TransactionResponse; - }; - - isLoading: ReturnType['isLoading'] & { - // Resources - collectionLoading?: boolean; - collectionMetadataLoading?: boolean; - - // On-chain values - isAutoDetectingTier?: boolean; - metadataUriLoading?: boolean; - maxSupplyLoading?: boolean; - totalSupplyLoading?: boolean; - tiersLoading?: boolean; - - // Transaction - mintLoading?: boolean; - }; - - error: ReturnType['error'] & { - // Resources - collectionError?: string | Error | null; - collectionMetadataError?: string | Error | null; - - // On-chain values - metadataUriError?: string | Error | null; - maxSupplyError?: string | Error | null; - totalSupplyError?: string | Error | null; - tiersError?: string | Error | null; - - // Transaction - mintError?: string | Error | null; - }; - - refetchTiers: () => void; - setCurrentTierId: (currentTierId: BigNumberish) => void; - - mint: (args?: { - mintCount: BigNumberish; - allowlistProof?: BytesLike[]; - }) => void; -}; - -export const CollectionSalesMintingContext = - React.createContext(null); - -type FunctionalChildren = ( - contextValue: CollectionSalesMintingContextValue, -) => ReactNode | ReactNode[]; - -type Props = { - /** Child elements or a factory function that returns child elements */ - children: FunctionalChildren | ReactNode | ReactNode[]; - - tierId?: BigNumberish; - - autoDetectEligibleTier?: boolean; - - minterAddress?: BytesLike; -}; - -export const CollectionSalesMintingProvider = ({ - children, - tierId, - autoDetectEligibleTier = true, - minterAddress, -}: Props) => { - const { data: account } = useAccount(); - const { data, isLoading, error } = useCollectionContext(); - const [currentTierId, setCurrentTierId] = useState( - tierId ? Number(tierId.toString()) : undefined, - ); - const [autoDetectedTierId, setAutoDetectedTierId] = useState(); - const [isAutoDetectingTier, setIsAutoDetectingTier] = useState( - autoDetectEligibleTier, - ); - - const finalMinterAddress = useMemo(() => { - return minterAddress || account?.address || ZERO_ADDRESS; - }, [account?.address, minterAddress]); - - const { - data: tiers, - error: tiersError, - isLoading: tiersLoading, - refetchTiers, - } = useSaleTiers({ - env: data.env, - chainId: Number(data.chainId), - contractVersion: data.contractVersion, - contractAddress: data.contractAddress, - minterAddress: finalMinterAddress, - enabled: Boolean(data.chainId && data.contractAddress), - }); - - const { - data: { - txReceipt, - txResponse, - start, - end, - price, - hasAllowlist, - isActive, - isAllowlisted, - isEligible, - eligibleAmount, - }, - error: mintError, - isLoading: mintLoading, - mint: doMint, - } = useSaleMinter({ - env: data.env, - chainId: Number(data.chainId), - contractVersion: data.contractVersion, - contractAddress: data.contractAddress, - tierId: currentTierId, - minterAddress: finalMinterAddress, - }); - - const soldOut = Boolean( - data.totalSupply && - data.maxSupply && - Number(data.totalSupply.toString()) >= Number(data.maxSupply.toString()), - ); - - const canMint = Boolean( - isActive && - isEligible && - (!hasAllowlist || isAllowlisted) && - !soldOut && - !mintLoading, - ); - - useEffect(() => { - if (!autoDetectEligibleTier && tierId !== undefined) { - if (tierId !== currentTierId) { - setCurrentTierId(tierId); - } - } else if (autoDetectEligibleTier && autoDetectedTierId !== undefined) { - if (currentTierId === undefined) { - setCurrentTierId(autoDetectedTierId); - } - } - }, [autoDetectEligibleTier, autoDetectedTierId, currentTierId, tierId]); - - useEffect(() => { - const tierIds = Object.keys(tiers || {}).map((id) => Number(id)); - - if (tiersLoading || mintLoading) { - return; - } - - if (!tierIds.length) { - setIsAutoDetectingTier(false); - return; - } - - // Find the first tier that is eligible and is active then set it as current tier - let tierId = tierIds.find((id) => { - return Boolean(tiers[id].isActive && tiers[id].isEligible); - }); - - // If not found, look for a tier that is active and does nto have allowlist - if (tierId === undefined) { - tierId = tierIds.find((id) => { - return Boolean(tiers[id].isActive && !tiers[id].hasAllowlist); - }); - } - - // If not found, look for a tier that is just active - if (tierId === undefined) { - tierId = tierIds.find((id) => { - return Boolean(tiers[id].isActive); - }); - } - - // If not found, look for a tier that is eligible - if (tierId === undefined) { - tierId = tierIds.find((id) => { - return Boolean(tiers[id].isEligible); - }); - } - - setAutoDetectedTierId(tierId); - setIsAutoDetectingTier(false); - }, [ - autoDetectEligibleTier, - isActive, - isEligible, - mintLoading, - tiers, - tiersLoading, - ]); - - const mint = useCallback( - async (args?: { mintCount: BigNumberish }) => { - await doMint(args); - await refetchTiers(); - }, - [doMint, refetchTiers], - ); - - const value = { - data: { - // Common - ...data, - - // On-chain values - tiers, - - // Current tier - currentTierId, - start, - end, - price, - hasAllowlist, - isActive, - isAllowlisted, - eligibleAmount, - isEligible, - - // Helpers - autoDetectedTierId, - canMint, - soldOut, - minterAddress: finalMinterAddress, - - // Transaction - txReceipt, - txResponse, - }, - - isLoading: { - // Common - ...isLoading, - - // Helpers - isAutoDetectingTier, - tiersLoading, - - // Transaction - mintLoading, - }, - - error: { - // Common - ...error, - - // Helpers - tiersError, - - // Transaction - mintError: mintError as Error, - }, - - refetchTiers, - setCurrentTierId, - mint, - }; - - return React.createElement( - CollectionSalesMintingContext.Provider, - { value }, - typeof children === 'function' ? children(value) : children, - ); -}; - -export const useCollectionSalesMintingContext = () => { - const context = React.useContext(CollectionSalesMintingContext); - if (!context) - throw Error('Must be used within '); - return context; -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/providers/index.ts b/packages/react/src/core/nft-collections/extensions/sales/providers/index.ts deleted file mode 100644 index b5f457c07..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/providers/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './CollectionSalesMintingProvider'; diff --git a/packages/react/src/core/nft-collections/extensions/sales/sections/CollectionSalesMintingSection.tsx b/packages/react/src/core/nft-collections/extensions/sales/sections/CollectionSalesMintingSection.tsx deleted file mode 100644 index 81f66bd23..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/sections/CollectionSalesMintingSection.tsx +++ /dev/null @@ -1,136 +0,0 @@ -import { BigNumberish, BytesLike } from 'ethers'; -import { useState } from 'react'; -import { useAccount } from 'wagmi'; - -import { useHasAnyOfFeatures } from '../../../../../common'; -import { ConnectButton, SwitchChainButton } from '../../../../wallet'; -import { CollectionSupplyCounter, useCollectionContext } from '../../../common'; -import { - CollectionSalesAllowlistStatus, - CollectionSalesMintButton, - CollectionSalesMintInput, - CollectionSalesMintStatusBar, - CollectionSalesPrice, - CollectionTierEligibleAmount, - CollectionTierWalletMints, -} from '../components'; -import { CollectionSalesActiveStatus } from '../components/CollectionSalesActiveStatus'; -import { CollectionSalesMintingProvider } from '../providers/CollectionSalesMintingProvider'; - -type Props = { - autoDetectEligibleTier?: boolean; - tierId?: BigNumberish; - minterAddress?: BytesLike; -}; - -export const CollectionSalesMintingSection = ({ - autoDetectEligibleTier = true, - tierId, - minterAddress, -}: Props) => { - const { - data: { env, chainId, contractAddress }, - } = useCollectionContext(); - - const { data: account } = useAccount(); - const [mintCount, setMintCount] = useState('1'); - - const { data: supportsTieredSales } = useHasAnyOfFeatures({ - env, - chainId, - contractAddress, - tags: [ - 'erc721_tiering_extension', - 'mint_by_tier_with_allowance_and_proof', - 'tiered_sales_facet', - ], - }); - - const mintButtonClass = - 'w-full bg-indigo-600 border border-transparent rounded-md py-3 px-8 flex items-center justify-center text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed'; - - return ( - -
-
- {/* Sale Information */} -
-
- - - - - {account || minterAddress ? ( - - ) : null} -
- -
-
- -
-
- {/* Mint count */} -
-
-

- How many to mint? -

-
- -
- Choose number of mints -
- -
-
-
- - {/* Mint button */} - -
- - - -
-
- - {/* Maximum eligible amount */} - - You can mint up to{' '} - .{' '} - {supportsTieredSales ? ( - <> - You have minted NFTs in this - tier. - - ) : null} - -
- - -
-
-
- ); -}; diff --git a/packages/react/src/core/nft-collections/extensions/sales/sections/index.ts b/packages/react/src/core/nft-collections/extensions/sales/sections/index.ts deleted file mode 100644 index cec523332..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/sections/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './CollectionSalesMintingSection'; diff --git a/packages/react/src/core/nft-collections/extensions/sales/types.ts b/packages/react/src/core/nft-collections/extensions/sales/types.ts deleted file mode 100644 index 6ccb55187..000000000 --- a/packages/react/src/core/nft-collections/extensions/sales/types.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { BigNumberish, BytesLike } from 'ethers'; - -export type Tier = { - // On-chain - start: BigNumberish; - end: BigNumberish; - currency: BytesLike; - price: BigNumberish; - maxPerWallet: BigNumberish; - merkleRoot: BytesLike; - reserved: BigNumberish; - maxAllocation: BigNumberish; - - // Off-chain helpers - isSavedOnChain?: boolean; - isActive?: boolean; - hasAllowlist?: boolean; - - // Wallet-specific - minterAddress?: BytesLike; - isAllowlisted?: boolean; - isEligible?: boolean; - eligibleAmount?: BigNumberish; -}; diff --git a/packages/react/src/core/nft-collections/index.ts b/packages/react/src/core/nft-collections/index.ts deleted file mode 100644 index 8f3d35b55..000000000 --- a/packages/react/src/core/nft-collections/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import 'axios'; -import 'react-query'; - -import React from 'react'; - -export * from './common'; -export * from './constants'; -export * from './extensions'; -export * from './types'; diff --git a/packages/react/src/core/nft-collections/types/index.ts b/packages/react/src/core/nft-collections/types/index.ts deleted file mode 100644 index 718dfa44a..000000000 --- a/packages/react/src/core/nft-collections/types/index.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { ContractFqn, ContractVersion } from '@flair-sdk/registry'; - -export type NftCollection< - TConfig extends Record = Record, -> = { - _id: string; - chainId: number; - contractAddress: string; - deployerAddress: string; - deployTransaction: string; - presetFqn: ContractFqn; - presetVersion: ContractVersion; - config?: TConfig; -}; - -export type NftCollectionMetadata = { - name?: string; - image?: string; - description?: string; - external_link?: string; - seller_fee_basis_points?: string; - fee_recipient?: string; -}; - -export type NftTokenMetadata = { - name?: string; - image?: string; - image_data?: string; - background_color?: string; - animation_url?: string; - youtube_url?: string; - description?: string; - creator?: string; - external_uri?: string; - attributes?: NftTokenAttribute[]; -}; - -export type NftTokenAttribute = { - display_type?: NftAttributeDisplayType; - trait_type?: string; - value?: string; -}; - -export type NftAttributeDisplayType = - | 'number' - | 'boost_percentage' - | 'boost_number' - | 'date'; diff --git a/packages/react/src/core/openzeppelin/access/index.ts b/packages/react/src/core/openzeppelin/access/index.ts deleted file mode 100644 index 0ff3d2a63..000000000 --- a/packages/react/src/core/openzeppelin/access/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './useOzHasRole'; -export * from './useOzOwner'; -export * from './useOzRoleGranter'; -export * from './useOzRoleRenouncer'; -export * from './useOzRoleRevoker'; diff --git a/packages/react/src/core/openzeppelin/access/useOzHasRole.ts b/packages/react/src/core/openzeppelin/access/useOzHasRole.ts deleted file mode 100644 index 4ad737e67..000000000 --- a/packages/react/src/core/openzeppelin/access/useOzHasRole.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../common'; - -type Config = PredefinedReadContractConfig & { - role?: BytesLike; - address?: BytesLike; -}; - -type Args = [role: BytesLike, address: BytesLike]; - -export const useOzHasRole = ({ - enabled = true, - role, - address, - ...restOfConfig -}: Config) => { - return useContractRead({ - contractFqn: 'openzeppelin/access/AccessControl', - functionName: 'hasRole', - args: role && address ? [role, address] : undefined, - enabled: Boolean(enabled && role && address), - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/access/useOzOwner.ts b/packages/react/src/core/openzeppelin/access/useOzOwner.ts deleted file mode 100644 index 0ae5dc4d1..000000000 --- a/packages/react/src/core/openzeppelin/access/useOzOwner.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../common'; - -export const useOzOwner = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'openzeppelin/access/Ownable', - functionName: 'owner', - ...config, - }); -}; diff --git a/packages/react/src/core/openzeppelin/access/useOzRoleGranter.ts b/packages/react/src/core/openzeppelin/access/useOzRoleGranter.ts deleted file mode 100644 index e6956774f..000000000 --- a/packages/react/src/core/openzeppelin/access/useOzRoleGranter.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { ReadContractConfig } from '@wagmi/core'; -import { BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../common'; - -type Config = Partial & { - contractVersion?: ContractVersion; - enabled?: boolean; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - role?: BytesLike; - address?: BytesLike; -}; - -type ArgsType = [role?: BytesLike, address?: BytesLike]; - -export const useOzRoleGranter = ({ - contractVersion, - contractAddress, - signerOrProvider, - role, - address, - ...restOfConfig -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'openzeppelin/access/AccessControl', - }); - - return useContractWriteAndWait({ - contractInterface, - functionName: 'grantRole', - args: [role, address], - contractAddress, - signerOrProvider, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/access/useOzRoleRenouncer.ts b/packages/react/src/core/openzeppelin/access/useOzRoleRenouncer.ts deleted file mode 100644 index 75d9ffeff..000000000 --- a/packages/react/src/core/openzeppelin/access/useOzRoleRenouncer.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { ReadContractConfig } from '@wagmi/core'; -import { BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../common'; - -type Config = Partial & { - contractVersion?: ContractVersion; - enabled?: boolean; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - role?: BytesLike; - address?: BytesLike; -}; - -type ArgsType = [role?: BytesLike, address?: BytesLike]; - -export const useOzRoleRenouncer = ({ - contractVersion, - contractAddress, - signerOrProvider, - role, - address, - ...restOfConfig -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'openzeppelin/access/AccessControl', - }); - - return useContractWriteAndWait({ - contractInterface, - functionName: 'renounceRole', - args: [role, address], - contractAddress, - signerOrProvider, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/access/useOzRoleRevoker.ts b/packages/react/src/core/openzeppelin/access/useOzRoleRevoker.ts deleted file mode 100644 index 4d4c7a644..000000000 --- a/packages/react/src/core/openzeppelin/access/useOzRoleRevoker.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { ReadContractConfig } from '@wagmi/core'; -import { BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../common'; - -type Config = Partial & { - contractVersion?: ContractVersion; - enabled?: boolean; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - role?: BytesLike; - address?: BytesLike; -}; - -type ArgsType = [role?: BytesLike, address?: BytesLike]; - -export const useOzRoleRevoker = ({ - contractVersion, - contractAddress, - signerOrProvider, - role, - address, - ...restOfConfig -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'openzeppelin/access/AccessControl', - }); - - return useContractWriteAndWait({ - contractInterface, - functionName: 'revokeRole', - args: [role, address], - contractAddress, - signerOrProvider, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/index.ts b/packages/react/src/core/openzeppelin/index.ts deleted file mode 100644 index 8ee326c28..000000000 --- a/packages/react/src/core/openzeppelin/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import '@flair-sdk/common'; -import '@ethersproject/abi'; -import 'ethers'; -import 'react-query'; - -export * from './access'; -export * from './tokens'; diff --git a/packages/react/src/core/openzeppelin/tokens/erc20/index.ts b/packages/react/src/core/openzeppelin/tokens/erc20/index.ts deleted file mode 100644 index 020196454..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc20/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -// ERC20 -export * from './useERC20BalanceOf'; -export * from './useERC20Decimals'; -export * from './useERC20Name'; -export * from './useERC20Symbol'; -export * from './useERC20TotalSupply'; -export * from './useERC20Transfer'; - -// Presets -export * from './useERC20RoleBasedMint'; diff --git a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20BalanceOf.ts b/packages/react/src/core/openzeppelin/tokens/erc20/useERC20BalanceOf.ts deleted file mode 100644 index 9d7b1be15..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20BalanceOf.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { BigNumberish, BytesLike } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -type Config = PredefinedReadContractConfig & { - accountAddress?: BytesLike; -}; - -type Args = [accountAddress?: BytesLike]; - -export const useERC20BalanceOf = ({ - accountAddress, - ...restOfConfig -}: Config) => { - return useContractRead({ - contractFqn: 'openzeppelin/token/ERC20/ERC20', - functionName: 'balanceOf', - args: accountAddress ? [accountAddress] : undefined, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Decimals.ts b/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Decimals.ts deleted file mode 100644 index 9b4b5d1df..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Decimals.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -export const useERC20Decimals = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'openzeppelin/token/ERC20/ERC20', - functionName: 'decimals', - ...config, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Name.ts b/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Name.ts deleted file mode 100644 index fc6f7b3c7..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Name.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -export const useERC20Name = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'openzeppelin/token/ERC20/ERC20', - functionName: 'name', - ...config, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20RoleBasedMint.ts b/packages/react/src/core/openzeppelin/tokens/erc20/useERC20RoleBasedMint.ts deleted file mode 100644 index 305f222f8..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20RoleBasedMint.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { ReadContractConfig } from '@wagmi/core'; -import { BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../common'; - -type Config = Partial & { - contractVersion?: ContractVersion; - enabled?: boolean; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - role?: BytesLike; - to?: BytesLike; - amount?: BigNumberish; -}; - -type ArgsType = [to?: BytesLike, amount?: BigNumberish]; - -export const useERC20RoleBasedMint = ({ - contractVersion, - contractAddress, - signerOrProvider, - role, - to, - amount, - ...restOfConfig -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'openzeppelin/token/ERC20/presets/ERC20PresetMinterPauser', - }); - - return useContractWriteAndWait({ - contractInterface, - functionName: 'mint', - args: [to, amount], - contractAddress, - signerOrProvider, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Symbol.ts b/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Symbol.ts deleted file mode 100644 index 88583f178..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Symbol.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -export const useERC20Symbol = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'openzeppelin/token/ERC20/ERC20', - functionName: 'symbol', - ...config, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20TotalSupply.ts b/packages/react/src/core/openzeppelin/tokens/erc20/useERC20TotalSupply.ts deleted file mode 100644 index d8087ea94..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20TotalSupply.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -export const useERC20TotalSupply = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'openzeppelin/token/ERC20/ERC20', - functionName: 'totalSupply', - ...config, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Transfer.ts b/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Transfer.ts deleted file mode 100644 index 3aa707db5..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc20/useERC20Transfer.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { WriteContractConfig } from '@wagmi/core'; -import { BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../common'; - -type Config = Partial & { - contractVersion?: ContractVersion; - enabled?: boolean; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - role?: BytesLike; - to?: BytesLike; - amount?: BigNumberish; -}; - -type ArgsType = [to?: BytesLike, amount?: BigNumberish]; - -export const useERC20Transfer = ({ - contractVersion, - contractAddress, - signerOrProvider, - role, - to, - amount, - ...restOfConfig -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'openzeppelin/token/ERC20/ERC20', - }); - - return useContractWriteAndWait({ - contractInterface, - functionName: 'transfer', - args: [to, amount], - contractAddress, - signerOrProvider, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc721/index.ts b/packages/react/src/core/openzeppelin/tokens/erc721/index.ts deleted file mode 100644 index beb5b3b26..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc721/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// ERC721 Standard -export * from './useERC721Name'; -export * from './useERC721Symbol'; -export * from './useERC721TransferFrom'; -export * from './useERC721IsApprovedForAll'; -export * from './useERC721SetApprovalForAll'; - -// ERC721 Helpers -export * from './useERC721Approver'; - -// Presets -export * from './useERC721TotalSupply'; diff --git a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Approver.ts b/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Approver.ts deleted file mode 100644 index bc6d86f0c..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Approver.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { WriteContractConfig } from '@wagmi/core'; -import { BytesLike, Signer } from 'ethers'; -import { useCallback } from 'react'; - -import { useERC721IsApprovedForAll } from './useERC721IsApprovedForAll'; -import { useERC721SetApprovalForAll } from './useERC721SetApprovalForAll'; - -type Config = { - // Common - contractAddress?: string; - contractVersion?: ContractVersion; - - // Read-only - chainId?: number; - enabled?: boolean; - watch?: boolean; - cacheOnBlock?: boolean; - - // Args - owner?: BytesLike; - operator?: BytesLike; - - // Write-only - signerOrProvider?: Signer | Provider | null; - writeOverrides?: WriteContractConfig['overrides']; -}; - -export const useERC721Approver = ({ - contractAddress, - contractVersion, - chainId, - enabled, - watch, - cacheOnBlock, - signerOrProvider, - owner, - operator, - writeOverrides, -}: Config) => { - const { - data: isApprovedForAll, - error: isApprovedForAllError, - isLoading: isApprovedForAllLoading, - refetch: fetchIsApprovedForAll, - } = useERC721IsApprovedForAll({ - chainId, - contractAddress, - contractVersion, - owner, - operator, - enabled, - watch, - cacheOnBlock, - }); - - const { - data: setApprovalForAllData, - error: setApprovalForAllError, - isLoading: setApprovalForAllLoading, - writeAndWait, - } = useERC721SetApprovalForAll({ - contractAddress, - contractVersion, - signerOrProvider, - overrides: writeOverrides, - }); - - const setApprovalForAll = useCallback( - (approved: boolean = true) => { - return writeAndWait([operator, approved]).then(() => { - fetchIsApprovedForAll(); - setTimeout(() => { - fetchIsApprovedForAll(); - }, 500); - }); - }, - [fetchIsApprovedForAll, operator, writeAndWait], - ); - - return { - data: { isApprovedForAll, ...setApprovalForAllData }, - error: setApprovalForAllError || isApprovedForAllError, - isLoading: setApprovalForAllLoading || isApprovedForAllLoading, - fetchIsApprovedForAll, - setApprovalForAll, - } as const; -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721IsApprovedForAll.ts b/packages/react/src/core/openzeppelin/tokens/erc721/useERC721IsApprovedForAll.ts deleted file mode 100644 index 83855a603..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721IsApprovedForAll.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BigNumberish, BytesLike } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -type ArgsType = [owner: string, operator: string]; - -type Config = { - owner?: BytesLike; - operator?: BytesLike; -} & PredefinedReadContractConfig; - -export const useERC721IsApprovedForAll = ({ - owner, - operator, - enabled, - ...rest -}: Config) => { - return useContractRead({ - contractFqn: 'openzeppelin/token/ERC721/ERC721', - functionName: 'isApprovedForAll', - args: [owner, operator] as ArgsType, - enabled: Boolean(enabled && owner && operator), - ...rest, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Name.ts b/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Name.ts deleted file mode 100644 index 2d302a8d7..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Name.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -export const useERC721Name = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'openzeppelin/token/ERC721/extensions/IERC721Metadata', - functionName: 'name', - ...config, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721SetApprovalForAll.ts b/packages/react/src/core/openzeppelin/tokens/erc721/useERC721SetApprovalForAll.ts deleted file mode 100644 index 332ecc248..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721SetApprovalForAll.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { WriteContractConfig } from '@wagmi/core'; -import { BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../common'; - -type Config = Partial & { - contractVersion?: ContractVersion; - enabled?: boolean; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - operator?: BytesLike; - approved?: boolean; -}; - -type ArgsType = [operator?: BytesLike, approved?: boolean]; - -export const useERC721SetApprovalForAll = ({ - contractVersion, - contractAddress, - signerOrProvider, - operator, - approved, - ...restOfConfig -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'openzeppelin/token/ERC721/ERC721', - }); - - return useContractWriteAndWait({ - contractInterface, - functionName: 'setApprovalForAll', - args: [operator, approved], - contractAddress, - signerOrProvider, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Symbol.ts b/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Symbol.ts deleted file mode 100644 index 5b7774308..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721Symbol.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BytesLike } from 'ethers'; - -import { - PredefinedReadContractConfig, - useContractRead, -} from '../../../../common'; - -export const useERC721Symbol = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'openzeppelin/token/ERC721/extensions/IERC721Metadata', - functionName: 'symbol', - ...config, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721TotalSupply.ts b/packages/react/src/core/openzeppelin/tokens/erc721/useERC721TotalSupply.ts deleted file mode 100644 index afc23907d..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721TotalSupply.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BigNumberish } from 'ethers'; - -import { PredefinedReadContractConfig, useContractRead } from '../../../../common'; - -export const useERC721TotalSupply = (config: PredefinedReadContractConfig) => { - return useContractRead({ - contractFqn: 'collections/ERC721/extensions/ERC721AutoIdMinterExtension', - functionName: 'totalSupply', - ...config, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721TransferFrom.ts b/packages/react/src/core/openzeppelin/tokens/erc721/useERC721TransferFrom.ts deleted file mode 100644 index 00a4b5191..000000000 --- a/packages/react/src/core/openzeppelin/tokens/erc721/useERC721TransferFrom.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Provider } from '@ethersproject/providers'; -import { ContractVersion } from '@flair-sdk/registry'; -import { WriteContractConfig } from '@wagmi/core'; -import { BigNumberish, BytesLike, Signer } from 'ethers'; - -import { useContractAbi, useContractWriteAndWait } from '../../../../common'; - -type Config = Partial & { - contractVersion?: ContractVersion; - enabled?: boolean; - contractAddress?: string; - signerOrProvider?: Signer | Provider | null; - from?: BytesLike; - to?: BytesLike; - tokenId?: BigNumberish; -}; - -type ArgsType = [from?: BytesLike, to?: BytesLike, tokenId?: BigNumberish]; - -export const useERC721TransferFrom = ({ - contractVersion, - contractAddress, - signerOrProvider, - from, - to, - tokenId, - ...restOfConfig -}: Config) => { - const contractInterface = useContractAbi({ - contractVersion, - contractFqn: 'openzeppelin/token/ERC721/ERC721', - }); - - return useContractWriteAndWait({ - contractInterface, - functionName: 'transferFrom', - args: [from, to, tokenId], - contractAddress, - signerOrProvider, - ...restOfConfig, - }); -}; diff --git a/packages/react/src/core/openzeppelin/tokens/index.ts b/packages/react/src/core/openzeppelin/tokens/index.ts deleted file mode 100644 index 09241e396..000000000 --- a/packages/react/src/core/openzeppelin/tokens/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './erc20'; -export * from './erc721'; diff --git a/packages/react/src/core/token-streams/components/StreamAccountSelectedTicketTokens.tsx b/packages/react/src/core/token-streams/components/StreamAccountSelectedTicketTokens.tsx deleted file mode 100644 index 43016bd4e..000000000 --- a/packages/react/src/core/token-streams/components/StreamAccountSelectedTicketTokens.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = BareComponentProps; - -export const StreamAccountSelectedTicketTokens = ({ - as, - ...attributes -}: Props) => { - const { - data: { selectedTicketTokens }, - } = useStreamContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {selectedTicketTokens === undefined || selectedTicketTokens === null - ? '...' - : selectedTicketTokens.length} - - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamAccountTotalTicketTokens.tsx b/packages/react/src/core/token-streams/components/StreamAccountTotalTicketTokens.tsx deleted file mode 100644 index 4c6e65695..000000000 --- a/packages/react/src/core/token-streams/components/StreamAccountTotalTicketTokens.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = BareComponentProps; - -export const StreamAccountTotalTicketTokens = ({ - as, - ...attributes -}: Props) => { - const { - data: { ticketTokens }, - } = useStreamContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {ticketTokens === undefined || ticketTokens === null - ? '...' - : ticketTokens.length} - - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamClaimButton.tsx b/packages/react/src/core/token-streams/components/StreamClaimButton.tsx deleted file mode 100644 index ceab3cff3..000000000 --- a/packages/react/src/core/token-streams/components/StreamClaimButton.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { BigNumberish, BytesLike } from 'ethers'; - -import { BareComponentProps } from '../../../common'; -import { useStreamContext } from '../providers'; -import { useStreamClaimingContext } from '../providers/StreamClaimingProvider'; - -type Props = { - ticketTokenIds?: BigNumberish[]; - claimToken?: BytesLike; -} & BareComponentProps; - -export const StreamClaimButton = ({ - as, - ticketTokenIds, - claimToken, - children, - ...attributes -}: Props) => { - const { - data: { walletAddress }, - } = useStreamContext(); - const { - data: { canClaim }, - claim, - } = useStreamClaimingContext(); - - const Component = as || 'button'; - - return ( - - claim({ ticketTokenIds, claimToken, owner: walletAddress }) - } - disabled={!canClaim} - children={`Claim`} - {...attributes} - /> - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamClaimTokenSelector.tsx b/packages/react/src/core/token-streams/components/StreamClaimTokenSelector.tsx deleted file mode 100644 index 4af99cda2..000000000 --- a/packages/react/src/core/token-streams/components/StreamClaimTokenSelector.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import { classNames } from '@flair-sdk/common'; -import { RadioGroup } from '@headlessui/react'; - -import { BareComponentProps } from '../../../common'; -import { useStreamClaimingContext } from '../providers/StreamClaimingProvider'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = BareComponentProps; - -export const StreamClaimTokenSelector = ({ as, ...attributes }: Props) => { - const { - data: { tokenBalances }, - } = useStreamContext(); - - const { - data: { currentClaimTokenAddress }, - setCurrentClaimTokenAddress, - } = useStreamClaimingContext(); - - return ( - setCurrentClaimTokenAddress(v.toString())} - > -
- {tokenBalances - ? tokenBalances.map((token) => ( - - classNames( - 'cursor-pointer focus:outline-none', - checked ? 'border-transparent' : 'border-gray-300', - active ? 'border-indigo-500 ring-2 ring-indigo-500' : '', - 'relative block bg-white border rounded-lg shadow-sm px-3 py-2 cursor-pointer sm:flex sm:justify-between focus:outline-none', - ) - } - > - {({ active, checked }) => ( - <> - - {token.icon && ( - - )} - - {token.name}{' '} - ({token.symbol}) - - - - )) - : '...'} -
-
- ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamClaimableAmount.tsx b/packages/react/src/core/token-streams/components/StreamClaimableAmount.tsx deleted file mode 100644 index d59caafe5..000000000 --- a/packages/react/src/core/token-streams/components/StreamClaimableAmount.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { BigNumber } from 'ethers'; -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { CryptoUnits, CryptoValue } from '../../crypto-currency'; -import { useStreamClaimingContext } from '../providers'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = { - calculationMode?: 'BY_ACCOUNT' | 'OVERALL'; -} & BareComponentProps; - -export const StreamClaimableAmount = ({ - as, - calculationMode = 'BY_ACCOUNT', - ...attributes -}: Props) => { - const { - data: { chainInfo }, - } = useStreamContext(); - const { - data: { - totalClaimableAmountByAccount, - totalSupplyAmountOverall, - totalClaimedAmountOverall, - currentClaimTokenSymbol, - }, - } = useStreamClaimingContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - - - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamClaimingStatusBar.tsx b/packages/react/src/core/token-streams/components/StreamClaimingStatusBar.tsx deleted file mode 100644 index d75d6620b..000000000 --- a/packages/react/src/core/token-streams/components/StreamClaimingStatusBar.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { Fragment, PropsWithChildren } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { Errors, Spinner, TransactionLink } from '../../ui'; -import { useStreamClaimingContext } from '../providers/StreamClaimingProvider'; - -type Props = PropsWithChildren; - -export const StreamClaimingStatusBar = ({ - as, - children, - ...attributes -}: Props) => { - const { - data: { txReceipt, txResponse }, - error: { - totalClaimableAmountByAccountError, - totalClaimedAmountByAccountError, - totalClaimedOverallError, - claimError, - }, - isLoading: { - totalClaimedAmountByAccountLoading, - totalClaimableAmountByAccountLoading, - totalClaimedOverallLoading, - claimLoading, - }, - } = useStreamClaimingContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {totalClaimedAmountByAccountLoading || - totalClaimableAmountByAccountLoading || - totalClaimedOverallLoading ? ( -
- Loading claiming information... -
- ) : null} - {claimLoading && ( -
- {txReceipt || txResponse ? 'Claiming...' : 'Preparing...'} -
- )} - {txReceipt || txResponse ? ( - - ) : null} - {claimError && } - {totalClaimableAmountByAccountError && ( - - )} - {totalClaimedAmountByAccountError && ( - - )} - {totalClaimedOverallError && ( - - )} - {children} -
- ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamCommonStatusBar.tsx b/packages/react/src/core/token-streams/components/StreamCommonStatusBar.tsx deleted file mode 100644 index 52ffe8508..000000000 --- a/packages/react/src/core/token-streams/components/StreamCommonStatusBar.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { Fragment, PropsWithChildren } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { Errors, Spinner } from '../../ui'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = PropsWithChildren; - -export const StreamCommonStatusBar = ({ - as, - children, - ...attributes -}: Props) => { - const { - error: { walletNftsError, tokenIdsInCustodyError, streamError }, - isLoading: { walletNftsLoading, tokenIdsInCustodyLoading }, - } = useStreamContext(); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {walletNftsLoading || tokenIdsInCustodyLoading ? ( -
- Loading your NFTs... -
- ) : null} - {streamError && } - {walletNftsError && ( - - )} - {tokenIdsInCustodyError && ( - - )} - {children} -
- ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamEmissionAmount.tsx b/packages/react/src/core/token-streams/components/StreamEmissionAmount.tsx deleted file mode 100644 index d1d8f8d6b..000000000 --- a/packages/react/src/core/token-streams/components/StreamEmissionAmount.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { CryptoUnits, CryptoValue } from '../../crypto-currency'; -import { useStreamEmissionAmountUntil } from '../hooks'; -import { useStreamClaimingContext } from '../providers'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = BareComponentProps; - -export const StreamEmissionAmount = ({ as, ...attributes }: Props) => { - const { - data: { chainInfo, env, chainId, contractAddress }, - } = useStreamContext(); - - const { - data: { currentClaimTokenSymbol }, - } = useStreamClaimingContext(); - - const { - data: totalEmissionAmountUntilNow, - error: totalEmissionAmountUntilNowError, - isLoading: totalEmissionAmountUntilNowLoading, - } = useStreamEmissionAmountUntil({ - env, - chainId, - contractAddress, - args: { - calculateUntil: Math.floor(+new Date() / 1000), - }, - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - - - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamEmissionRate.tsx b/packages/react/src/core/token-streams/components/StreamEmissionRate.tsx deleted file mode 100644 index a2229c4ae..000000000 --- a/packages/react/src/core/token-streams/components/StreamEmissionRate.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import moment from 'moment'; -import { Fragment, ReactNode } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { CryptoUnits, CryptoValue } from '../../crypto-currency'; -import { useStreamEmissionRate } from '../hooks/useStreamEmissionRate'; -import { useStreamEmissionTimeUnit } from '../hooks/useStreamEmissionTimeUnit'; -import { useStreamClaimingContext } from '../providers'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = BareComponentProps & { - separator?: ReactNode; -}; - -export const StreamEmissionRate = ({ - as, - separator = <>/, - ...attributes -}: Props) => { - const { - data: { env, chainId, contractAddress }, - } = useStreamContext(); - const { - data: { currentClaimTokenSymbol }, - } = useStreamClaimingContext(); - - const { data: emissionRate, isLoading: emissionRateLoading } = - useStreamEmissionRate({ - env, - chainId, - contractAddress, - }); - const { data: emissionTimeUnit, isLoading: emissionTimeUnitLoading } = - useStreamEmissionTimeUnit({ - env, - chainId, - contractAddress, - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - {emissionRateLoading ? ( - '...' - ) : ( - - )}{' '} - {separator}{' '} - {emissionTimeUnitLoading - ? '...' - : moment - .duration(emissionTimeUnit?.toString(), 'seconds') - .humanize(false)} - - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamEmissionTimeUnit.tsx b/packages/react/src/core/token-streams/components/StreamEmissionTimeUnit.tsx deleted file mode 100644 index 76698d8e6..000000000 --- a/packages/react/src/core/token-streams/components/StreamEmissionTimeUnit.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import humanizeDuration from 'humanize-duration'; -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { useStreamEmissionTimeUnit } from '../hooks/useStreamEmissionTimeUnit'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = BareComponentProps; - -export const StreamEmissionTimeUnit = ({ as, ...attributes }: Props) => { - const { - data: { env, chainId, contractAddress }, - } = useStreamContext(); - - const { data: emissionTimeUnit } = useStreamEmissionTimeUnit({ - env, - chainId, - contractAddress, - }); - - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - - return ( - - every{' '} - {emissionTimeUnit - ? humanizeDuration(Number(emissionTimeUnit.toString()) * 1000) - : '...'} - - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamLockedNfts.tsx b/packages/react/src/core/token-streams/components/StreamLockedNfts.tsx deleted file mode 100644 index a77482199..000000000 --- a/packages/react/src/core/token-streams/components/StreamLockedNfts.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { useStreamContext } from '../providers/StreamProvider'; -import { useStreamStakingContext } from '../providers/StreamStakingProvider'; - -type Props = { - hideSymbol?: boolean; -} & BareComponentProps; - -export const StreamLockedNfts = ({ as, hideSymbol, ...attributes }: Props) => { - const { - data: { ticketTokenSymbol }, - } = useStreamContext(); - const { - data: { lockedNfts }, - } = useStreamStakingContext(); - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - return ( - - {lockedNfts === undefined || lockedNfts === null - ? '...' - : lockedNfts.length}{' '} - {hideSymbol ? null : ticketTokenSymbol?.toString() || '...'} - - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamMinStakingDuration.tsx b/packages/react/src/core/token-streams/components/StreamMinStakingDuration.tsx deleted file mode 100644 index 2f6f01aa8..000000000 --- a/packages/react/src/core/token-streams/components/StreamMinStakingDuration.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import humanizeDuration from 'humanize-duration'; -import { Fragment } from 'react'; - -import { BareComponentProps } from '../../../common'; -import { useStreamMinStakingDuration } from '../hooks/useStreamMinStakingDuration'; -import { useStreamContext } from '../providers/StreamProvider'; - -type Props = BareComponentProps; - -export const StreamMinStakingDuration = ({ as, ...attributes }: Props) => { - const { - data: { env, chainId, contractAddress }, - } = useStreamContext(); - - const { data: minStakingDuration } = useStreamMinStakingDuration({ - chainId, - contractAddress, - }); - const Component = - as || (attributes.className || attributes.style ? 'span' : Fragment); - return ( - - {minStakingDuration - ? humanizeDuration(Number(minStakingDuration.toString()) * 1000) - : '...'} - - ); -}; diff --git a/packages/react/src/core/token-streams/components/StreamPrepareButton.tsx b/packages/react/src/core/token-streams/components/StreamPrepareButton.tsx deleted file mode 100644 index ad20a189f..000000000 --- a/packages/react/src/core/token-streams/components/StreamPrepareButton.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { Button } from '../../ui'; -import { useStreamStakingContext } from '../providers/StreamStakingProvider'; - -type Props = { - className?: string; - label?: string; -}; - -export const StreamPrepareButton = ({ className, label }: Props) => { - const { - data: { needsPrepare }, - isLoading: { prepareLoading }, - prepare, - } = useStreamStakingContext(); - - return ( -