Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit d59b9d8

Browse files
authored
Jd/add drop lazy mint (#109)
* add lazy mint for drops * v2.5.0-0
1 parent 989ee89 commit d59b9d8

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed

docs/react.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { useGnosis } from "@thirdweb-dev/react"
6060
|
6161
| [useGrantRole(contract)](./react.usegrantrole.md) | <b><i>(BETA)</i></b> Use this to grant a [WalletAddress](./react.walletaddress.md) a specific role on a |
6262
| [useIsAddressRole(contract, role, walletAddress)](./react.useisaddressrole.md) | <b><i>(BETA)</i></b> Use this to check if a [WalletAddress](./react.walletaddress.md) is a member of a role on a |
63+
| [useLazyMint(contract, onProgress)](./react.uselazymint.md) | <b><i>(BETA)</i></b> Use this to lazy mint a batch of NFTs on your [DropContract](./react.dropcontract.md) |
6364
| [useListing(contract, listingId)](./react.uselisting.md) | <b><i>(BETA)</i></b> Use this to get a specific listing from the marketplace. |
6465
| [useListings(contract, filter)](./react.uselistings.md) | <b><i>(BETA)</i></b> Use this to get a list all listings from your marketplace contract. |
6566
| [useMagic()](./react.usemagic.md) | Hook for connecting to an email wallet using magic link. This enables users without their own wallets to connect to your application and sign transactions securely using their email.

docs/react.uselazymint.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@thirdweb-dev/react](./react.md) &gt; [useLazyMint](./react.uselazymint.md)
4+
5+
## useLazyMint() function
6+
7+
> 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.
8+
>
9+
10+
Use this to lazy mint a batch of NFTs on your [DropContract](./react.dropcontract.md)
11+
12+
<b>Signature:</b>
13+
14+
```typescript
15+
export declare function useLazyMint<TContract extends Erc721>(contract: RequiredParam<TContract>, onProgress?: (progress: UploadProgressEvent) => void): import("react-query").UseMutationResult<import("@thirdweb-dev/sdk/dist/browser").TransactionResultWithId<{
16+
[x: string]: import("@thirdweb-dev/sdk/dist/browser").Json;
17+
name?: string | undefined;
18+
description?: string | null | undefined;
19+
image?: string | null | undefined;
20+
external_url?: string | null | undefined;
21+
animation_url?: string | null | undefined;
22+
uri: string;
23+
id: import("ethers").BigNumber;
24+
}>[], unknown, {
25+
metadatas: NFTMetadataInput[];
26+
}, unknown>;
27+
```
28+
29+
## Parameters
30+
31+
| Parameter | Type | Description |
32+
| --- | --- | --- |
33+
| contract | [RequiredParam](./react.requiredparam.md)<!-- -->&lt;TContract&gt; | an instance of a with the drop extension |
34+
| onProgress | (progress: UploadProgressEvent) =&gt; void | <i>(Optional)</i> an optional callback that will be called with the progress of the upload |
35+
36+
<b>Returns:</b>
37+
38+
import("react-query").UseMutationResult&lt;import("@thirdweb-dev/sdk/dist/browser").TransactionResultWithId&lt;{ \[x: string\]: import("@thirdweb-dev/sdk/dist/browser").Json; name?: string \| undefined; description?: string \| null \| undefined; image?: string \| null \| undefined; external\_url?: string \| null \| undefined; animation\_url?: string \| null \| undefined; uri: string; id: import("ethers").BigNumber; }&gt;\[\], unknown, { metadatas: NFTMetadataInput\[\]; }, unknown&gt;
39+
40+
a mutation object that can be used to lazy mint a batch of NFTs
41+

etc/react.api.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { EditionDrop } from '@thirdweb-dev/sdk/dist/browser';
2929
import { Erc1155 } from '@thirdweb-dev/sdk/dist/browser';
3030
import type { Erc1155Mintable } from '@thirdweb-dev/sdk/dist/browser';
3131
import type { Erc20 } from '@thirdweb-dev/sdk/dist/browser';
32-
import type { Erc721 } from '@thirdweb-dev/sdk/dist/browser';
32+
import { Erc721 } from '@thirdweb-dev/sdk/dist/browser';
3333
import type { Erc721Mintable } from '@thirdweb-dev/sdk/dist/browser';
3434
import type { EventQueryFilter } from '@thirdweb-dev/sdk/dist/browser';
3535
import { FetchStatus } from 'react-query';
@@ -48,6 +48,7 @@ import type { NewDirectListing } from '@thirdweb-dev/sdk/dist/browser';
4848
import { NFTCollection } from '@thirdweb-dev/sdk/dist/browser';
4949
import { NFTDrop } from '@thirdweb-dev/sdk/dist/browser';
5050
import { NFTMetadata } from '@thirdweb-dev/sdk/dist/browser';
51+
import { NFTMetadataInput } from '@thirdweb-dev/sdk/dist/browser';
5152
import type { NFTMetadataOrUri } from '@thirdweb-dev/sdk/dist/src/schema';
5253
import { Offer } from '@thirdweb-dev/sdk/dist/browser';
5354
import { Pack } from '@thirdweb-dev/sdk/dist/browser';
@@ -71,6 +72,7 @@ import { Token } from '@thirdweb-dev/sdk/dist/browser';
7172
import { TokenDrop } from '@thirdweb-dev/sdk/dist/browser';
7273
import { TransactionReceipt } from '@ethersproject/abstract-provider';
7374
import { TransactionResultWithId } from '@thirdweb-dev/sdk/dist/browser';
75+
import { UploadProgressEvent } from '@thirdweb-dev/sdk/dist/browser';
7476
import { useAccount } from './hooks';
7577
import { UseMutationResult } from 'react-query';
7678
import { useProvider } from './hooks';
@@ -1341,6 +1343,20 @@ address: WalletAddress;
13411343
// @beta
13421344
export function useIsAddressRole<TContract extends ContractWithRoles>(contract: RequiredParam<TContract>, role: RolesForContract<TContract>, walletAddress: RequiredParam<WalletAddress>): boolean;
13431345

1346+
// @beta
1347+
export function useLazyMint<TContract extends Erc721>(contract: RequiredParam<TContract>, onProgress?: (progress: UploadProgressEvent) => void): UseMutationResult<TransactionResultWithId< {
1348+
[x: string]: Json;
1349+
name?: string | undefined;
1350+
description?: string | null | undefined;
1351+
image?: string | null | undefined;
1352+
external_url?: string | null | undefined;
1353+
animation_url?: string | null | undefined;
1354+
uri: string;
1355+
id: BigNumber;
1356+
}>[], unknown, {
1357+
metadatas: NFTMetadataInput[];
1358+
}, unknown>;
1359+
13441360
// @beta
13451361
export function useListing(contract: RequiredParam<Marketplace>, listingId: RequiredParam<BigNumberish>): UseQueryResult<AuctionListing | DirectListing, unknown>;
13461362

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@thirdweb-dev/react",
3-
"version": "2.4.9-1",
3+
"version": "2.5.0-0",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com:thirdweb-dev/react.git"

src/hooks/async/drop.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import {
1212
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
1313
import { useNFTs } from "./nft";
1414
import {
15+
Erc721,
1516
Erc1155,
1617
NFTDrop,
18+
NFTMetadataInput,
1719
QueryAllParams,
1820
SignatureDrop,
21+
UploadProgressEvent,
1922
} from "@thirdweb-dev/sdk/dist/browser";
2023
import { useMutation, useQueryClient } from "react-query";
2124
import invariant from "tiny-invariant";
@@ -196,3 +199,44 @@ export function useClaimNFT<TContract extends DropContract>(
196199
},
197200
);
198201
}
202+
203+
/**
204+
* Use this to lazy mint a batch of NFTs on your {@link DropContract}
205+
*
206+
* @param contract - an instance of a {@link ERC721} with the drop extension
207+
* @param onProgress - an optional callback that will be called with the progress of the upload
208+
* @returns a mutation object that can be used to lazy mint a batch of NFTs
209+
* @beta
210+
*/
211+
export function useLazyMint<TContract extends Erc721>(
212+
contract: RequiredParam<TContract>,
213+
onProgress?: (progress: UploadProgressEvent) => void,
214+
) {
215+
const activeChainId = useActiveChainId();
216+
const contractAddress = contract?.getAddress();
217+
const queryClient = useQueryClient();
218+
219+
return useMutation(
220+
async (data: { metadatas: NFTMetadataInput[] }) => {
221+
invariant(
222+
contract?.drop?.lazyMint,
223+
"contract does not support drop.lazyMint",
224+
);
225+
let options;
226+
if (onProgress) {
227+
options = {
228+
onProgress,
229+
};
230+
}
231+
return await contract.drop.lazyMint(data.metadatas, options);
232+
},
233+
{
234+
onSettled: () =>
235+
invalidateContractAndBalances(
236+
queryClient,
237+
contractAddress,
238+
activeChainId,
239+
),
240+
},
241+
);
242+
}

0 commit comments

Comments
 (0)