@@ -17,7 +17,7 @@ import { GemIcon } from "lucide-react";
1717import { useState } from "react" ;
1818import { useForm } from "react-hook-form" ;
1919import { toast } from "sonner" ;
20- import { type ThirdwebContract , ZERO_ADDRESS } from "thirdweb" ;
20+ import { type ThirdwebContract , ZERO_ADDRESS , isAddress } from "thirdweb" ;
2121import { getApprovalForTransaction } from "thirdweb/extensions/erc20" ;
2222import { claimTo } from "thirdweb/extensions/erc721" ;
2323import { useActiveAccount , useSendAndConfirmTransaction } from "thirdweb/react" ;
@@ -40,7 +40,7 @@ export const NFTClaimButton: React.FC<NFTClaimButtonProps> = ({
4040} ) => {
4141 const trackEvent = useTrack ( ) ;
4242 const address = useActiveAccount ( ) ?. address ;
43- const { register, handleSubmit, formState } = useForm ( {
43+ const { register, handleSubmit, formState, setValue } = useForm ( {
4444 defaultValues : { amount : "1" , to : address } ,
4545 } ) ;
4646 const { errors } = formState ;
@@ -67,7 +67,24 @@ export const NFTClaimButton: React.FC<NFTClaimButtonProps> = ({
6767 < div className = "flex w-full flex-col gap-6 md:flex-row" >
6868 < FormControl isRequired isInvalid = { ! ! errors . to } >
6969 < 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+ />
7188 < FormHelperText > Enter the address to claim to.</ FormHelperText >
7289 < FormErrorMessage > { errors . to ?. message } </ FormErrorMessage >
7390 </ FormControl >
@@ -115,7 +132,7 @@ export const NFTClaimButton: React.FC<NFTClaimButtonProps> = ({
115132
116133 const transaction = claimTo ( {
117134 contract,
118- to : d . to ,
135+ to : d . to . trim ( ) ,
119136 quantity : BigInt ( d . amount ) ,
120137 from : account . address ,
121138 } ) ;
0 commit comments