Skip to content

Commit a47bc22

Browse files
authored
[Update] Add address validation in WalletAddress and AddAdminButton components (#4575)
1 parent 3901805 commit a47bc22

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

apps/dashboard/src/@/components/blocks/wallet-address.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "@/components/ui/hover-card";
99
import { Check, Copy, ExternalLinkIcon } from "lucide-react";
1010
import { useMemo, useState } from "react";
11+
import { isAddress } from "thirdweb";
1112
import { ZERO_ADDRESS } from "thirdweb";
1213
import {
1314
Blobbie,
@@ -28,6 +29,7 @@ export function WalletAddress(props: {
2829
}) {
2930
// default back to zero address if no address provided
3031
const address = useMemo(() => props.address || ZERO_ADDRESS, [props.address]);
32+
3133
const [shortenedAddress, lessShortenedAddress] = useMemo(() => {
3234
return [
3335
props.shortenAddress !== false
@@ -44,6 +46,10 @@ export function WalletAddress(props: {
4446

4547
const [isCopied, setIsCopied] = useState(false);
4648

49+
if (!isAddress(address)) {
50+
return <span>Invalid Address ({address})</span>;
51+
}
52+
4753
const copyToClipboard = async () => {
4854
try {
4955
await navigator.clipboard.writeText(address);

apps/dashboard/src/components/engine/permissions/add-admin-button.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useTrack } from "hooks/analytics/useTrack";
2121
import { useTxNotifications } from "hooks/useTxNotifications";
2222
import { useForm } from "react-hook-form";
2323
import { AiOutlinePlusCircle } from "react-icons/ai";
24+
import { isAddress } from "thirdweb";
2425
import { Button, FormLabel } from "tw-components";
2526

2627
interface AddAdminButtonProps {
@@ -62,6 +63,9 @@ export const AddAdminButton: React.FC<AddAdminButtonProps> = ({
6263
className="!bg-background border border-border rounded-lg"
6364
as="form"
6465
onSubmit={form.handleSubmit((data) => {
66+
if (!isAddress(data.walletAddress)) {
67+
onError(new Error("Invalid wallet address"));
68+
}
6569
grantPermissions(data, {
6670
onSuccess: () => {
6771
onSuccess();

0 commit comments

Comments
 (0)