@@ -17,7 +17,7 @@ import { GemIcon } from "lucide-react";
17
17
import { useState } from "react" ;
18
18
import { useForm } from "react-hook-form" ;
19
19
import { toast } from "sonner" ;
20
- import { type ThirdwebContract , ZERO_ADDRESS } from "thirdweb" ;
20
+ import { type ThirdwebContract , ZERO_ADDRESS , isAddress } from "thirdweb" ;
21
21
import { getApprovalForTransaction } from "thirdweb/extensions/erc20" ;
22
22
import { claimTo } from "thirdweb/extensions/erc721" ;
23
23
import { useActiveAccount , useSendAndConfirmTransaction } from "thirdweb/react" ;
@@ -40,7 +40,7 @@ export const NFTClaimButton: React.FC<NFTClaimButtonProps> = ({
40
40
} ) => {
41
41
const trackEvent = useTrack ( ) ;
42
42
const address = useActiveAccount ( ) ?. address ;
43
- const { register, handleSubmit, formState } = useForm ( {
43
+ const { register, handleSubmit, formState, setValue } = useForm ( {
44
44
defaultValues : { amount : "1" , to : address } ,
45
45
} ) ;
46
46
const { errors } = formState ;
@@ -67,7 +67,24 @@ export const NFTClaimButton: React.FC<NFTClaimButtonProps> = ({
67
67
< div className = "flex w-full flex-col gap-6 md:flex-row" >
68
68
< FormControl isRequired isInvalid = { ! ! errors . to } >
69
69
< FormLabel > To Address</ FormLabel >
70
- < Input placeholder = { ZERO_ADDRESS } { ...register ( "to" ) } />
70
+ < Input
71
+ placeholder = { ZERO_ADDRESS }
72
+ { ...register ( "to" , {
73
+ validate : ( value ) => {
74
+ if ( ! value ) {
75
+ return "Enter a recipient address" ;
76
+ }
77
+ if ( ! isAddress ( value . trim ( ) ) ) {
78
+ return "Invalid EVM address" ;
79
+ }
80
+ } ,
81
+ onChange : ( e ) => {
82
+ setValue ( "to" , e . target . value . trim ( ) , {
83
+ shouldValidate : true ,
84
+ } ) ;
85
+ } ,
86
+ } ) }
87
+ />
71
88
< FormHelperText > Enter the address to claim to.</ FormHelperText >
72
89
< FormErrorMessage > { errors . to ?. message } </ FormErrorMessage >
73
90
</ FormControl >
@@ -115,7 +132,7 @@ export const NFTClaimButton: React.FC<NFTClaimButtonProps> = ({
115
132
116
133
const transaction = claimTo ( {
117
134
contract,
118
- to : d . to ,
135
+ to : d . to . trim ( ) ,
119
136
quantity : BigInt ( d . amount ) ,
120
137
from : account . address ,
121
138
} ) ;
0 commit comments