diff --git a/docs/react.delayedreveallazymintinput.md b/docs/react.delayedreveallazymintinput.md new file mode 100644 index 0000000..9f55bc3 --- /dev/null +++ b/docs/react.delayedreveallazymintinput.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [DelayedRevealLazyMintInput](./react.delayedreveallazymintinput.md) + +## DelayedRevealLazyMintInput type + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +The params for the [useDelayedRevealLazyMint()](./react.usedelayedreveallazymint.md) hook mutation. + +Signature: + +```typescript +export declare type DelayedRevealLazyMintInput = { + placeholder: NFTMetadataInput; + metadatas: NFTMetadataInput[]; + password: string; +}; +``` diff --git a/docs/react.md b/docs/react.md index d6d2b9b..7b726a4 100644 --- a/docs/react.md +++ b/docs/react.md @@ -20,6 +20,7 @@ import { useAddress } from "@thirdweb-dev/react" | [useAllRoleMembers(contract)](./react.useallrolemembers.md) | (BETA) Use this to get the roles of a | | [useAuctionWinner(contract, listingId)](./react.useauctionwinner.md) | (BETA) Use this to get the winner of an auction listing from your marketplace contract. | | [useBalance(tokenAddress)](./react.usebalance.md) | (BETA) A hook to get the native or (optional) ERC20 token balance of the connected wallet. | +| [useBatchesToReveal(contract)](./react.usebatchestoreveal.md) | | | [useBidBuffer(contract)](./react.usebidbuffer.md) | (BETA) Use this to get the buffer in basis points between offers from your marketplace contract. | | [useBurnNFT(contract)](./react.useburnnft.md) | (BETA) Use this to burn an NFT on your [NFTContract](./react.nftcontract.md) | | [useBurnToken(contract)](./react.useburntoken.md) | (BETA) Use this to burn tokens on your contract | @@ -49,6 +50,7 @@ import { useCoinbaseWallet } from "@thirdweb-dev/react" | [useContractType(contractAddress)](./react.usecontracttype.md) | (BETA) Use this to get the contract type for a (built-in or custom) contract. | | [useCreateAuctionListing(contract)](./react.usecreateauctionlisting.md) | (BETA) Use this to create a new Auction Listing on your marketplace contract. | | [useCreateDirectListing(contract)](./react.usecreatedirectlisting.md) | (BETA) Use this to create a new Direct Listing on your marketplace contract. | +| [useDelayedRevealLazyMint(contract, onProgress)](./react.usedelayedreveallazymint.md) | (BETA) Use this to lazy mint a batch of delayed reveal NFTs on your [DropContract](./react.dropcontract.md) | | [useDisconnect(options)](./react.usedisconnect.md) |

Hook for disconnecting the currently connected wallet

```javascript import { useDisconnect } from "@thirdweb-dev/react" @@ -102,6 +104,7 @@ import { useNetworkMistmatch } from "@thirdweb-dev/react" | [usePrimarySaleRecipient(contract)](./react.useprimarysalerecipient.md) | (BETA) | | [useResetClaimConditions(\[contract, tokenId\])](./react.useresetclaimconditions.md) | (BETA) Use this to reset claim conditions on your [NFTContract](./react.nftcontract.md) | | [useResolvedMediaType(uri)](./react.useresolvedmediatype.md) | | +| [useRevealLazyMint(contract)](./react.usereveallazymint.md) | (BETA) Use this to reveal a batch of delayed reveal NFTs on your [DropContract](./react.dropcontract.md) | | [useRevokeRole(contract)](./react.userevokerole.md) | (BETA) Use this to revoke a [WalletAddress](./react.walletaddress.md) a specific role on a | | [useRoleMembers(contract, role)](./react.userolemembers.md) | (BETA) Use this to get the members of a role on a | | [useRoyaltySettings(contract)](./react.useroyaltysettings.md) | (BETA) Use this to get the royalty settings of your | @@ -169,6 +172,7 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [ClaimNFTReturnType](./react.claimnftreturntype.md) | (BETA) The return type of the [useClaimNFT()](./react.useclaimnft.md) hook. | | [ClaimTokenParams](./react.claimtokenparams.md) | | | [ContractAddress](./react.contractaddress.md) | (BETA) A contract address. | +| [DelayedRevealLazyMintInput](./react.delayedreveallazymintinput.md) | (BETA) The params for the [useDelayedRevealLazyMint()](./react.usedelayedreveallazymint.md) hook mutation. | | [DropContract](./react.dropcontract.md) | (BETA) The possible DROP contract types. | | [MakeBidParams](./react.makebidparams.md) | | | [MintNFTParams](./react.mintnftparams.md) | (BETA) The params for the [useMintNFT()](./react.usemintnft.md) hook mutation. | @@ -177,6 +181,7 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [NFT](./react.nft.md) | (BETA) A single NFT token | | [NFTContract](./react.nftcontract.md) | (BETA) The possible NFT contract types. | | [RequiredParam](./react.requiredparam.md) | (BETA) Makes a parameter required to be passed, but still allowes it to be undefined. | +| [RevealLazyMintInput](./react.reveallazymintinput.md) | (BETA) The params for the [useRevealLazyMint()](./react.usereveallazymint.md) hook mutation. | | [SetClaimConditionsParams](./react.setclaimconditionsparams.md) | (BETA) The params for the [useSetClaimConditions()](./react.usesetclaimconditions.md) hook mutation. | | [TokenBurnParams](./react.tokenburnparams.md) | (BETA) The parameters to pass to the burn function. | | [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the mint and transfer functions. | diff --git a/docs/react.reveallazymintinput.md b/docs/react.reveallazymintinput.md new file mode 100644 index 0000000..5fd9125 --- /dev/null +++ b/docs/react.reveallazymintinput.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [RevealLazyMintInput](./react.reveallazymintinput.md) + +## RevealLazyMintInput type + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +The params for the [useRevealLazyMint()](./react.usereveallazymint.md) hook mutation. + +Signature: + +```typescript +export declare type RevealLazyMintInput = { + batchId: BigNumberish; + password: string; +}; +``` diff --git a/docs/react.usebatchestoreveal.md b/docs/react.usebatchestoreveal.md new file mode 100644 index 0000000..fd7d560 --- /dev/null +++ b/docs/react.usebatchestoreveal.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useBatchesToReveal](./react.usebatchestoreveal.md) + +## useBatchesToReveal() function + +Signature: + +```typescript +export declare function useBatchesToReveal(contract: RequiredParam): import("@tanstack/react-query").UseQueryResult; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| contract | [RequiredParam](./react.requiredparam.md)<TContract> | an instance of a [NFTContract](./react.nftcontract.md) | + +Returns: + +import("@tanstack/react-query").UseQueryResult<import("@thirdweb-dev/sdk/dist/browser").BatchToReveal\[\], unknown> + +a response object that gets the batches to still be revealed + diff --git a/docs/react.usedelayedreveallazymint.md b/docs/react.usedelayedreveallazymint.md new file mode 100644 index 0000000..9eedc41 --- /dev/null +++ b/docs/react.usedelayedreveallazymint.md @@ -0,0 +1,30 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useDelayedRevealLazyMint](./react.usedelayedreveallazymint.md) + +## useDelayedRevealLazyMint() function + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Use this to lazy mint a batch of delayed reveal NFTs on your [DropContract](./react.dropcontract.md) + +Signature: + +```typescript +export declare function useDelayedRevealLazyMint(contract: RequiredParam, onProgress?: (progress: UploadProgressEvent) => void): import("@tanstack/react-query").UseMutationResult[], unknown, DelayedRevealLazyMintInput, unknown>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| contract | [RequiredParam](./react.requiredparam.md)<TContract> | an instance of a [NFTContract](./react.nftcontract.md) with the drop extension | +| onProgress | (progress: UploadProgressEvent) => void | (Optional) an optional callback that will be called with the progress of the upload | + +Returns: + +import("@tanstack/react-query").UseMutationResult<import("@thirdweb-dev/sdk/dist/browser").TransactionResultWithId<never>\[\], unknown, [DelayedRevealLazyMintInput](./react.delayedreveallazymintinput.md), unknown> + +a mutation object that can be used to lazy mint a batch of NFTs + diff --git a/docs/react.usereveallazymint.md b/docs/react.usereveallazymint.md new file mode 100644 index 0000000..00fa5ea --- /dev/null +++ b/docs/react.usereveallazymint.md @@ -0,0 +1,32 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useRevealLazyMint](./react.usereveallazymint.md) + +## useRevealLazyMint() function + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Use this to reveal a batch of delayed reveal NFTs on your [DropContract](./react.dropcontract.md) + +Signature: + +```typescript +export declare function useRevealLazyMint(contract: RequiredParam): import("@tanstack/react-query").UseMutationResult Promise; +}, "data">, unknown, RevealLazyMintInput, unknown>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| contract | [RequiredParam](./react.requiredparam.md)<TContract> | an instance of a [NFTContract](./react.nftcontract.md) with the drop extension | + +Returns: + +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [RevealLazyMintInput](./react.reveallazymintinput.md), unknown> + +a mutation object that can be used to reveal a batch of delayed reveal NFTs + diff --git a/etc/react.api.md b/etc/react.api.md index ac34084..25b205b 100644 --- a/etc/react.api.md +++ b/etc/react.api.md @@ -9,6 +9,7 @@ import type { AirdropInput } from '@thirdweb-dev/sdk/dist/browser'; import type { Amount } from '@thirdweb-dev/sdk/dist/browser'; import { AuctionListing } from '@thirdweb-dev/sdk/dist/browser'; import { BaseContract } from 'ethers'; +import { BatchToReveal } from '@thirdweb-dev/sdk/dist/browser'; import { BigNumber } from 'ethers'; import { BigNumberish } from 'ethers'; import { CallOverrides } from 'ethers'; @@ -52,6 +53,7 @@ import { NFTCollection } from '@thirdweb-dev/sdk/dist/browser'; import { NFTDrop } from '@thirdweb-dev/sdk/dist/browser'; import { NFTMetadata } from '@thirdweb-dev/sdk/dist/browser'; import { NFTMetadataInput } from '@thirdweb-dev/sdk/dist/browser'; +import type { NFTMetadataInput as NFTMetadataInput_2 } from '@thirdweb-dev/sdk/dist/src/schema'; import type { NFTMetadataOrUri } from '@thirdweb-dev/sdk/dist/src/schema'; import { Offer } from '@thirdweb-dev/sdk/dist/browser'; import { Pack } from '@thirdweb-dev/sdk/dist/browser'; @@ -167,6 +169,13 @@ export { defaultChains } export { defaultL2Chains } +// @beta +export type DelayedRevealLazyMintInput = { + placeholder: NFTMetadataInput_2; + metadatas: NFTMetadataInput_2[]; + password: string; +}; + // @beta export type DropContract = NFTDrop | EditionDrop | SignatureDrop; @@ -263,6 +272,12 @@ export type NFTContract = Erc721 | Erc1155; // @beta export type RequiredParam = T | undefined; +// @beta +export type RevealLazyMintInput = { + batchId: BigNumberish; + password: string; +}; + // Warning: (ae-internal-missing-underscore) The name "RolesForContract" should be prefixed with an underscore because the declaration is marked as @internal // // @internal (undocumented) @@ -433,6 +448,12 @@ decimals: number; displayValue: string; } | undefined, unknown>; +// Warning: (ae-incompatible-release-tags) The symbol "useBatchesToReveal" is marked as @public, but its signature references "NFTContract" which is marked as @beta +// Warning: (ae-incompatible-release-tags) The symbol "useBatchesToReveal" is marked as @public, but its signature references "RequiredParam" which is marked as @beta +// +// @public (undocumented) +export function useBatchesToReveal(contract: RequiredParam): UseQueryResult; + // @beta export function useBidBuffer(contract: RequiredParam): UseQueryResult; @@ -1390,6 +1411,9 @@ export function useCreateAuctionListing(contract: RequiredParam): U // @beta export function useCreateDirectListing(contract: RequiredParam): UseMutationResult, unknown, NewDirectListing, unknown>; +// @beta +export function useDelayedRevealLazyMint(contract: RequiredParam, onProgress?: (progress: UploadProgressEvent) => void): UseMutationResult[], unknown, DelayedRevealLazyMintInput, unknown>; + // Warning: (ae-internal-missing-underscore) The name "useDesiredChainId" should be prefixed with an underscore because the declaration is marked as @internal // // @internal (undocumented) @@ -1607,6 +1631,12 @@ export function useResolvedMediaType(uri?: string): { mimeType: string | undefined; }; +// @beta +export function useRevealLazyMint(contract: RequiredParam): UseMutationResult Promise; +}, "data">, unknown, RevealLazyMintInput, unknown>; + // Warning: (ae-incompatible-release-tags) The symbol "useRevokeRole" is marked as @beta, but its signature references "ContractWithRoles" which is marked as @internal // // @beta @@ -1817,8 +1847,8 @@ export type WalletLinkConnectorType = "walletLink" | "coinbase" | { // dist/hooks/async/roles.d.ts:161:5 - (ae-incompatible-release-tags) The symbol "role" is marked as @beta, but its signature references "RolesForContract" which is marked as @internal // dist/hooks/auth/useUser.d.ts:12:5 - (ae-forgotten-export) The symbol "ThirdwebAuthUser" needs to be exported by the entry point index.d.ts // dist/hooks/useNetwork.d.ts:48:5 - (ae-forgotten-export) The symbol "SwitchChainError" needs to be exported by the entry point index.d.ts -// dist/types.d.ts:196:5 - (ae-incompatible-release-tags) The symbol "buyForWallet" is marked as @public, but its signature references "WalletAddress" which is marked as @beta -// dist/types.d.ts:202:5 - (ae-incompatible-release-tags) The symbol "to" is marked as @public, but its signature references "WalletAddress" which is marked as @beta +// dist/types.d.ts:215:5 - (ae-incompatible-release-tags) The symbol "buyForWallet" is marked as @public, but its signature references "WalletAddress" which is marked as @beta +// dist/types.d.ts:221:5 - (ae-incompatible-release-tags) The symbol "to" is marked as @public, but its signature references "WalletAddress" which is marked as @beta // (No @packageDocumentation comment for this package) diff --git a/src/hooks/async/drop.ts b/src/hooks/async/drop.ts index 49bc054..51978b0 100644 --- a/src/hooks/async/drop.ts +++ b/src/hooks/async/drop.ts @@ -2,9 +2,11 @@ import { useActiveChainId } from "../../Provider"; import { ClaimNFTParams, ClaimNFTReturnType, + DelayedRevealLazyMintInput, DropContract, NFTContract, RequiredParam, + RevealLazyMintInput, } from "../../types"; import { cacheKeys, @@ -128,6 +130,29 @@ export function useClaimedNFTSupply(contract: RequiredParam) { ); } +/** + * + * @param contract - an instance of a {@link NFTContract} + * @returns a response object that gets the batches to still be revealed + */ +export function useBatchesToReveal( + contract: RequiredParam, +) { + const contractAddress = contract?.getAddress(); + return useQueryWithNetwork( + cacheKeys.contract.nft.drop.revealer.getBatchesToReveal(contractAddress), + () => { + invariant(contract, "No Contract instance provided"); + invariant( + contract.drop?.revealer?.getBatchesToReveal, + "Contract instance does not support drop.revealer.getBatchesToReveal", + ); + return contract.drop.revealer.getBatchesToReveal(); + }, + { enabled: !!contract }, + ); +} + /** **********************/ /** WRITE HOOKS **/ /** **********************/ @@ -240,3 +265,82 @@ export function useLazyMint( }, ); } + +/** + * Use this to lazy mint a batch of delayed reveal NFTs on your {@link DropContract} + * + * @param contract - an instance of a {@link NFTContract} with the drop extension + * @param onProgress - an optional callback that will be called with the progress of the upload + * @returns a mutation object that can be used to lazy mint a batch of NFTs + * @beta + */ +export function useDelayedRevealLazyMint( + contract: RequiredParam, + onProgress?: (progress: UploadProgressEvent) => void, +) { + const activeChainId = useActiveChainId(); + const contractAddress = contract?.getAddress(); + const queryClient = useQueryClient(); + + return useMutation( + async (data: DelayedRevealLazyMintInput) => { + invariant( + contract?.drop?.revealer?.createDelayedRevealBatch, + "contract does not support drop.revealer.createDelayedRevealBatch", + ); + let options; + if (onProgress) { + options = { + onProgress, + }; + } + return await contract.drop.revealer.createDelayedRevealBatch( + data.placeholder, + data.metadatas, + data.password, + options, + ); + }, + { + onSettled: () => + invalidateContractAndBalances( + queryClient, + contractAddress, + activeChainId, + ), + }, + ); +} + +/** + * Use this to reveal a batch of delayed reveal NFTs on your {@link DropContract} + * + * @param contract - an instance of a {@link NFTContract} with the drop extension + * @returns a mutation object that can be used to reveal a batch of delayed reveal NFTs + * @beta + */ +export function useRevealLazyMint( + contract: RequiredParam, +) { + const activeChainId = useActiveChainId(); + const contractAddress = contract?.getAddress(); + const queryClient = useQueryClient(); + + return useMutation( + async (data: RevealLazyMintInput) => { + invariant( + contract?.drop?.revealer?.reveal, + "contract does not support drop.revealer.reveal", + ); + return await contract.drop.revealer.reveal(data.batchId, data.password); + }, + { + onSettled: () => + invalidateContractAndBalances( + queryClient, + contractAddress, + activeChainId, + ), + }, + ); +} diff --git a/src/types.ts b/src/types.ts index b1cdede..f6fdacf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,10 @@ import type { Price, SignatureDrop, } from "@thirdweb-dev/sdk/dist/browser"; -import type { NFTMetadataOrUri } from "@thirdweb-dev/sdk/dist/src/schema"; +import type { + NFTMetadataInput, + NFTMetadataOrUri, +} from "@thirdweb-dev/sdk/dist/src/schema"; import type { BigNumberish } from "ethers"; /** @@ -197,6 +200,27 @@ export type BurnNFTParams = */ export type DropContract = NFTDrop | EditionDrop | SignatureDrop; +/** + * The params for the {@link useDelayedRevealLazyMint} hook mutation. + * + * @beta + */ +export type DelayedRevealLazyMintInput = { + placeholder: NFTMetadataInput; + metadatas: NFTMetadataInput[]; + password: string; +}; + +/** + * The params for the {@link useRevealLazyMint} hook mutation. + * + * @beta + */ +export type RevealLazyMintInput = { + batchId: BigNumberish; + password: string; +}; + /** * The params for the {@link useClaimNFT} hook mutation. * diff --git a/src/utils/cache-keys.ts b/src/utils/cache-keys.ts index 685b71b..714c0ec 100644 --- a/src/utils/cache-keys.ts +++ b/src/utils/cache-keys.ts @@ -176,6 +176,16 @@ export const cacheKeys = { ) => createContractCacheKey(contractAddress, ["totalUnclaimedSupply"]), totalClaimedSupply: (contractAddress: RequiredParam) => createContractCacheKey(contractAddress, ["totalClaimedSupply"]), + revealer: { + getBatchesToReveal: ( + contractAddress: RequiredParam, + params?: QueryAllParams, + ) => + createContractCacheKey( + contractAddress, + params ? ["getBatchesToReveal", params] : ["getBatchesToReveal"], + ), + }, }, },