11"use client" ;
22
3+ import {
4+ Sheet ,
5+ SheetContent ,
6+ SheetHeader ,
7+ SheetTitle ,
8+ SheetTrigger ,
9+ } from "@/components/ui/sheet" ;
310import { MinterOnly } from "@3rdweb-sdk/react/components/roles/minter-only" ;
4- import { useDisclosure } from "@chakra-ui/react" ;
511import { BatchLazyMint } from "core-ui/batch-upload/batch-lazy-mint" ;
612import { useTrack } from "hooks/analytics/useTrack" ;
713import { useTxNotifications } from "hooks/useTxNotifications" ;
814import { FileStackIcon } from "lucide-react" ;
15+ import { useState } from "react" ;
916import type { ThirdwebContract } from "thirdweb" ;
1017import * as ERC721Ext from "thirdweb/extensions/erc721" ;
1118import * as ERC1155Ext from "thirdweb/extensions/erc1155" ;
1219import { useReadContract , useSendAndConfirmTransaction } from "thirdweb/react" ;
13- import { Button , Drawer } from "tw-components" ;
20+ import { Button } from "tw-components" ;
1421
1522interface BatchLazyMintButtonProps {
1623 canCreateDelayedRevealBatch : boolean ;
@@ -24,7 +31,7 @@ export const BatchLazyMintButton: React.FC<BatchLazyMintButtonProps> = ({
2431 isErc721,
2532} ) => {
2633 const trackEvent = useTrack ( ) ;
27- const { isOpen , onOpen , onClose } = useDisclosure ( ) ;
34+ const [ open , setOpen ] = useState ( false ) ;
2835
2936 const nextTokenIdToMintQuery = useReadContract (
3037 isErc721 ? ERC721Ext . nextTokenIdToMint : ERC1155Ext . nextTokenIdToMint ,
@@ -43,88 +50,88 @@ export const BatchLazyMintButton: React.FC<BatchLazyMintButtonProps> = ({
4350 if ( ! contract ) {
4451 return null ;
4552 }
53+
4654 return (
4755 < MinterOnly contract = { contract } >
48- < Drawer
49- allowPinchZoom
50- preserveScrollBarGap
51- size = "full"
52- onClose = { onClose }
53- isOpen = { isOpen }
54- >
55- < BatchLazyMint
56- chainId = { contract . chain . id }
57- onSubmit = { async ( { revealType, data } ) => {
58- // nice, we can set up everything the same for both the only thing that changes is the action string
59- const action = `batch-upload-${ revealType } ` as const ;
60-
61- trackEvent ( {
62- category : "nft" ,
63- action,
64- label : "attempt" ,
65- } ) ;
66- try {
67- const tx = ( ( ) => {
68- switch ( true ) {
69- // lazy mint erc721
70- case revealType === "instant" && isErc721 : {
71- return ERC721Ext . lazyMint ( {
72- contract,
73- nfts : data . metadatas ,
74- } ) ;
75- }
76- // lazy mint erc1155
77- case revealType === "instant" && ! isErc721 : {
78- return ERC1155Ext . lazyMint ( {
79- contract,
80- nfts : data . metadatas ,
81- } ) ;
82- }
83- // delayed reveal erc721
84- case revealType === "delayed" : {
85- return ERC721Ext . createDelayedRevealBatch ( {
86- contract,
87- metadata : data . metadata ,
88- password : data . password ,
89- placeholderMetadata : data . placeholderMetadata ,
90- } ) ;
91- }
92- default : {
93- throw new Error ( "Invalid reveal type" ) ;
94- }
95- }
96- } ) ( ) ;
97-
98- await sendTxMutation . mutateAsync ( tx ) ;
99-
56+ < Sheet onOpenChange = { setOpen } open = { open } >
57+ < SheetTrigger asChild >
58+ < Button
59+ colorScheme = "primary"
60+ leftIcon = { < FileStackIcon className = "size-4" /> }
61+ >
62+ Batch Upload
63+ </ Button >
64+ </ SheetTrigger >
65+ < SheetContent className = "min-w-full overflow-y-auto" >
66+ < SheetHeader >
67+ < SheetTitle className = "text-left" > Upload NFTs</ SheetTitle >
68+ </ SheetHeader >
69+ < BatchLazyMint
70+ chainId = { contract . chain . id }
71+ onSubmit = { async ( { revealType, data } ) => {
72+ // nice, we can set up everything the same for both the only thing that changes is the action string
73+ const action = `batch-upload-${ revealType } ` as const ;
10074 trackEvent ( {
10175 category : "nft" ,
10276 action,
103- label : "success " ,
77+ label : "attempt " ,
10478 } ) ;
105- txNotifications . onSuccess ( ) ;
106- onClose ( ) ;
107- } catch ( error ) {
108- trackEvent ( {
109- category : "nft" ,
110- action,
111- label : "error" ,
112- error,
113- } ) ;
114- txNotifications . onError ( error ) ;
115- }
116- } }
117- nextTokenIdToMint = { nextTokenIdToMintQuery . data || 0n }
118- canCreateDelayedRevealBatch = { canCreateDelayedRevealBatch }
119- />
120- </ Drawer >
121- < Button
122- colorScheme = "primary"
123- leftIcon = { < FileStackIcon className = "size-4" /> }
124- onClick = { onOpen }
125- >
126- Batch Upload
127- </ Button >
79+ try {
80+ const tx = ( ( ) => {
81+ switch ( true ) {
82+ // lazy mint erc721
83+ case revealType === "instant" && isErc721 : {
84+ return ERC721Ext . lazyMint ( {
85+ contract,
86+ nfts : data . metadatas ,
87+ } ) ;
88+ }
89+ // lazy mint erc1155
90+ case revealType === "instant" && ! isErc721 : {
91+ return ERC1155Ext . lazyMint ( {
92+ contract,
93+ nfts : data . metadatas ,
94+ } ) ;
95+ }
96+ // delayed reveal erc721
97+ case revealType === "delayed" : {
98+ return ERC721Ext . createDelayedRevealBatch ( {
99+ contract,
100+ metadata : data . metadata ,
101+ password : data . password ,
102+ placeholderMetadata : data . placeholderMetadata ,
103+ } ) ;
104+ }
105+ default : {
106+ throw new Error ( "Invalid reveal type" ) ;
107+ }
108+ }
109+ } ) ( ) ;
110+
111+ await sendTxMutation . mutateAsync ( tx ) ;
112+
113+ trackEvent ( {
114+ category : "nft" ,
115+ action,
116+ label : "success" ,
117+ } ) ;
118+ txNotifications . onSuccess ( ) ;
119+ setOpen ( false ) ;
120+ } catch ( error ) {
121+ trackEvent ( {
122+ category : "nft" ,
123+ action,
124+ label : "error" ,
125+ error,
126+ } ) ;
127+ txNotifications . onError ( error ) ;
128+ }
129+ } }
130+ nextTokenIdToMint = { nextTokenIdToMintQuery . data || 0n }
131+ canCreateDelayedRevealBatch = { canCreateDelayedRevealBatch }
132+ />
133+ </ SheetContent >
134+ </ Sheet >
128135 </ MinterOnly >
129136 ) ;
130137} ;
0 commit comments