Skip to content

Commit c948e71

Browse files
authored
[Dashboard] Trim whitespace at the end of the input value for claim form (#5860)
1 parent 3b1ed73 commit c948e71

File tree

1 file changed

+21
-4
lines changed
  • apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components

1 file changed

+21
-4
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/claim-button.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { GemIcon } from "lucide-react";
1717
import { useState } from "react";
1818
import { useForm } from "react-hook-form";
1919
import { toast } from "sonner";
20-
import { type ThirdwebContract, ZERO_ADDRESS } from "thirdweb";
20+
import { type ThirdwebContract, ZERO_ADDRESS, isAddress } from "thirdweb";
2121
import { getApprovalForTransaction } from "thirdweb/extensions/erc20";
2222
import { claimTo } from "thirdweb/extensions/erc721";
2323
import { 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

Comments
 (0)