Skip to content

Commit

Permalink
Define starknet address + amount validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura committed Nov 15, 2024
1 parent c9a43a9 commit 27edabb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
21 changes: 13 additions & 8 deletions packages/profile/src/components/inventory/token/send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { useCallback, useMemo } from "react";
import { useForm } from "react-hook-form";
import { Link, useParams } from "react-router-dom";
import { validateChecksumAddress } from "starknet";
import { constants } from "starknet";
import { z } from "zod";

export function SendToken() {
Expand All @@ -37,18 +37,25 @@ export function SendToken() {
z.object({
to: z
.string()
.startsWith("0x")
.startsWith("0x", {
message: 'Starknet address must start with "0x"',
})
.min(62, {
message: "Starknet address must be at least 61 characters long",
})
.refine(
(addr) => {
try {
return validateChecksumAddress(addr);
return BigInt(addr) < constants.PRIME;
} catch {
return false;
}
},
{ message: "Invalid Starknet address" },
{
message: "Please input a valid Starknet address",
},
),
amount: z.coerce.number(),
amount: z.coerce.number({ message: "Amount is required" }).positive(),
}),
[],
);
Expand Down Expand Up @@ -124,9 +131,7 @@ export function SendToken() {
<div className="flex items-center justify-between">
<FormLabel>Amount</FormLabel>
<div className="flex items-center gap-2">
<FormLabel className="text-muted-foreground">
Balance:
</FormLabel>
<FormLabel>Balance:</FormLabel>
<div className="text-xs">
{t.balance.formatted} {t.meta.symbol}
</div>
Expand Down
9 changes: 2 additions & 7 deletions packages/ui-next/src/components/primitives/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,10 @@ const FormLabel = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
>(({ className, ...props }, ref) => {
const { error, formItemId } = useFormField();
const { formItemId } = useFormField();

return (
<Label
ref={ref}
className={cn(error && "text-destructive", className)}
htmlFor={formItemId}
{...props}
/>
<Label ref={ref} className={className} htmlFor={formItemId} {...props} />
);
});
FormLabel.displayName = "FormLabel";
Expand Down

0 comments on commit 27edabb

Please sign in to comment.