88} from "@/components/ui/accordion" ;
99import { Alert , AlertTitle } from "@/components/ui/alert" ;
1010import { Button } from "@/components/ui/button" ;
11+ import { Checkbox , CheckboxWithLabel } from "@/components/ui/checkbox" ;
1112import {
1213 Form ,
1314 FormControl ,
@@ -28,7 +29,7 @@ import { CircleAlertIcon } from "lucide-react";
2829import { useCallback } from "react" ;
2930import { useForm } from "react-hook-form" ;
3031import { toast } from "sonner" ;
31- import { sendAndConfirmTransaction } from "thirdweb" ;
32+ import { PreparedTransaction , sendAndConfirmTransaction } from "thirdweb" ;
3233import { isAddress } from "thirdweb" ;
3334import { MintableERC721 , MintableERC1155 } from "thirdweb/modules" ;
3435import { useReadContract } from "thirdweb/react" ;
@@ -46,7 +47,8 @@ export type UpdateFormValues = {
4647
4748// TODO - add form validation with zod schema for mint form
4849
49- export type MintFormValues = NFTMetadataInputLimited & {
50+ export type MintFormValues = NFTMetadat | | aInputLimited & {
51+ useNextTokenId : boolean ;
5052 recipient : string ;
5153 amount : number ;
5254 supply : number ;
@@ -79,20 +81,25 @@ function MintableModule(props: ModuleInstanceProps) {
7981 if ( ! ownerAccount ) {
8082 throw new Error ( "Not an owner account" ) ;
8183 }
82-
83- const mintTx = isErc721
84- ? MintableERC721 . mintWithRole ( {
84+
85+ let mintTx : PreparedTransaction ;
86+ if ( isErc721 ) {
87+ mintTx = MintableERC721 . mintWithRole ( {
8588 contract,
8689 to : values . recipient ,
8790 nfts : [ nft ] ,
8891 } )
89- : MintableERC1155 . mintWithRole ( {
92+ } else if ( values . useNextTokenId || values . tokenId ) {
93+ mintTx = MintableERC1155 . mintWithRole ( {
9094 contract,
9195 to : values . recipient ,
9296 amount : BigInt ( values . amount ) ,
93- tokenId : values . tokenId ? BigInt ( values . tokenId ) : undefined ,
97+ tokenId : values . useNextTokenId ? undefined : BigInt ( values . tokenId ) ,
9498 nft,
9599 } ) ;
100+ } else {
101+ throw new Error ( "Invalid token ID" ) ;
102+ }
96103
97104 await sendAndConfirmTransaction ( {
98105 account : ownerAccount ,
@@ -292,6 +299,7 @@ function MintNFTSection(props: {
292299} ) {
293300 const form = useForm < MintFormValues > ( {
294301 values : {
302+ useNextTokenId : false ,
295303 supply : 1 ,
296304 customImage : "" ,
297305 customAnimationUrl : "" ,
@@ -313,6 +321,8 @@ function MintNFTSection(props: {
313321 } ) ;
314322 } ;
315323
324+ const useNextTokenId = form . watch ( "useNextTokenId" ) ;
325+
316326 return (
317327 < Form { ...form } >
318328 < form onSubmit = { form . handleSubmit ( onSubmit ) } >
@@ -426,19 +436,39 @@ function MintNFTSection(props: {
426436 />
427437 ) }
428438
429- { ! props . isErc721 && ! props . isSequentialTokenIdInstalled && (
430- < FormField
431- control = { form . control }
432- name = "tokenId"
433- render = { ( { field } ) => (
434- < FormItem className = "flex-1" >
435- < FormLabel > Token ID</ FormLabel >
436- < FormControl >
437- < Input { ...field } />
438- </ FormControl >
439- </ FormItem >
440- ) }
441- />
439+ { ! props . isErc721 && (
440+ < div className = "relative flex-1" >
441+ < FormField
442+ control = { form . control }
443+ name = "tokenId"
444+ render = { ( { field } ) => (
445+ < FormItem className = "flex-1" >
446+ < FormLabel > Token ID</ FormLabel >
447+ < FormControl >
448+ < Input { ...field } disabled = { useNextTokenId } />
449+ </ FormControl >
450+ </ FormItem >
451+ ) }
452+ />
453+
454+ < FormField
455+ control = { form . control }
456+ name = "useNextTokenId"
457+ render = { ( { field } ) => (
458+ < FormItem className = "absolute top-0 right-0 flex items-center gap-2" >
459+ < CheckboxWithLabel >
460+ < Checkbox
461+ className = "mt-0"
462+ checked = { field . value }
463+ onCheckedChange = { field . onChange }
464+ />
465+ Use next token ID
466+ </ CheckboxWithLabel >
467+ < FormMessage />
468+ </ FormItem >
469+ ) }
470+ />
471+ </ div >
442472 ) }
443473 </ div >
444474
0 commit comments