33import { FormControl , Input } from "@chakra-ui/react" ;
44import { TransactionButton } from "components/buttons/TransactionButton" ;
55import { useTrack } from "hooks/analytics/useTrack" ;
6- import { useTxNotifications } from "hooks/useTxNotifications" ;
76import { useForm } from "react-hook-form" ;
7+ import { toast } from "sonner" ;
88import type { ThirdwebContract } from "thirdweb" ;
99import { mintAdditionalSupplyTo } from "thirdweb/extensions/erc1155" ;
1010import { useActiveAccount , useSendAndConfirmTransaction } from "thirdweb/react" ;
@@ -15,6 +15,7 @@ interface MintSupplyTabProps {
1515 tokenId : string ;
1616}
1717
18+ // Intended for Edition contracts (not Edition Drop)
1819const MintSupplyTab : React . FC < MintSupplyTabProps > = ( { contract, tokenId } ) => {
1920 const trackEvent = useTrack ( ) ;
2021 const {
@@ -27,75 +28,83 @@ const MintSupplyTab: React.FC<MintSupplyTabProps> = ({ contract, tokenId }) => {
2728 } ) ;
2829
2930 const address = useActiveAccount ( ) ?. address ;
30- const { mutate, isPending } = useSendAndConfirmTransaction ( ) ;
31- const { onSuccess, onError } = useTxNotifications (
32- "Mint successful" ,
33- "Error minting additional supply" ,
34- contract ,
35- ) ;
31+ const { mutateAsync, isPending } = useSendAndConfirmTransaction ( ) ;
3632
3733 return (
38- < div className = "flex w-full flex-col gap-2" >
39- < form
40- onSubmit = { handleSubmit ( ( data ) => {
41- if ( address ) {
34+ < form
35+ className = "flex w-full flex-col gap-2"
36+ onSubmit = { handleSubmit ( ( data ) => {
37+ if ( ! address ) {
38+ return toast . error ( "No wallet connected." ) ;
39+ }
40+ trackEvent ( {
41+ category : "nft" ,
42+ action : "mint-supply" ,
43+ label : "attempt" ,
44+ } ) ;
45+ const transaction = mintAdditionalSupplyTo ( {
46+ contract,
47+ to : address ,
48+ tokenId : BigInt ( tokenId ) ,
49+ supply : BigInt ( data . amount ) ,
50+ } ) ;
51+ const promise = mutateAsync ( transaction , {
52+ onSuccess : ( ) => {
4253 trackEvent ( {
4354 category : "nft" ,
4455 action : "mint-supply" ,
45- label : "attempt" ,
46- } ) ;
47- const transaction = mintAdditionalSupplyTo ( {
48- contract,
49- to : address ,
50- tokenId : BigInt ( tokenId ) ,
51- supply : BigInt ( data . amount ) ,
56+ label : "success" ,
5257 } ) ;
53- mutate ( transaction , {
54- onSuccess : ( ) => {
55- trackEvent ( {
56- category : "nft" ,
57- action : "mint-supply" ,
58- label : "success" ,
59- } ) ;
60- onSuccess ( ) ;
61- reset ( ) ;
62- } ,
63- onError : ( error ) => {
64- trackEvent ( {
65- category : "nft" ,
66- action : "mint-supply" ,
67- label : "error" ,
68- error,
69- } ) ;
70- onError ( error ) ;
71- } ,
58+ reset ( ) ;
59+ } ,
60+ onError : ( error ) => {
61+ trackEvent ( {
62+ category : "nft" ,
63+ action : "mint-supply" ,
64+ label : "error" ,
65+ error,
7266 } ) ;
73- }
74- } ) }
75- >
76- < div className = "flex flex-col gap-3" >
77- < div className = "flex w-full flex-col gap-6 md:flex-row" >
78- < FormControl isRequired isInvalid = { ! ! errors . to } >
79- < FormLabel > Amount</ FormLabel >
80- < Input placeholder = "1" { ...register ( "amount" ) } />
81- < FormHelperText > How many would you like to mint?</ FormHelperText >
82- < FormErrorMessage > { errors . to ?. message } </ FormErrorMessage >
83- </ FormControl >
84- </ div >
85-
86- < TransactionButton
87- txChainID = { contract . chain . id }
88- transactionCount = { 1 }
89- isLoading = { isPending }
90- type = "submit"
91- colorScheme = "primary"
92- alignSelf = "flex-end"
93- >
94- Mint
95- </ TransactionButton >
67+ console . error ( error ) ;
68+ } ,
69+ } ) ;
70+ toast . promise ( promise , {
71+ loading : "Minting additional supply" ,
72+ success : "NFT(s) minted successfully" ,
73+ error : "Failed to mint NFT(s)" ,
74+ } ) ;
75+ } ) }
76+ >
77+ < div className = "flex flex-col gap-3" >
78+ < div className = "flex w-full flex-col gap-6 md:flex-row" >
79+ < FormControl isRequired isInvalid = { ! ! errors . to } >
80+ < FormLabel > Amount</ FormLabel >
81+ < Input placeholder = "1" { ...register ( "amount" ) } min = { 1 } />
82+ < FormHelperText > How many would you like to mint?</ FormHelperText >
83+ < FormLabel className = "mt-3" > Recipient</ FormLabel >
84+ < Input
85+ placeholder = "0x..."
86+ defaultValue = { address || "" }
87+ { ...register ( "to" ) }
88+ />
89+ < FormHelperText >
90+ Address to receive the NFT(s) - Defaults to your own wallet
91+ </ FormHelperText >
92+ < FormErrorMessage > { errors . to ?. message } </ FormErrorMessage >
93+ </ FormControl >
9694 </ div >
97- </ form >
98- </ div >
95+
96+ < TransactionButton
97+ txChainID = { contract . chain . id }
98+ transactionCount = { 1 }
99+ isLoading = { isPending }
100+ type = "submit"
101+ colorScheme = "primary"
102+ alignSelf = "flex-end"
103+ >
104+ Mint
105+ </ TransactionButton >
106+ </ div >
107+ </ form >
99108 ) ;
100109} ;
101110
0 commit comments