Skip to content

Commit 76ce72c

Browse files
label for server wallets
1 parent ba64760 commit 76ce72c

File tree

3 files changed

+93
-11
lines changed

3 files changed

+93
-11
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/engine/server-wallets/components/create-server-wallet.client.tsx

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
"use client";
22
import type { Project } from "@/api/projects";
33
import { Button } from "@/components/ui/button";
4+
import {
5+
Dialog,
6+
DialogContent,
7+
DialogDescription,
8+
DialogHeader,
9+
DialogTitle,
10+
} from "@/components/ui/dialog";
11+
import { Input } from "@/components/ui/input";
412
import { useDashboardRouter } from "@/lib/DashboardRouter";
513
import { useMutation } from "@tanstack/react-query";
614
import { createEoa } from "@thirdweb-dev/vault-sdk";
715
import { Loader2 } from "lucide-react";
16+
import { useState } from "react";
817
import { toast } from "sonner";
918
import { initVaultClient } from "../../lib/vault.client";
1019

@@ -13,11 +22,16 @@ export default function CreateServerWallet(props: {
1322
managementAccessToken: string | undefined;
1423
}) {
1524
const router = useDashboardRouter();
25+
const [label, setLabel] = useState("");
26+
const [modalOpen, setModalOpen] = useState(false);
27+
1628
const createEoaMutation = useMutation({
1729
mutationFn: async ({
1830
managementAccessToken,
31+
label,
1932
}: {
2033
managementAccessToken: string;
34+
label: string;
2135
}) => {
2236
const vaultClient = await initVaultClient();
2337

@@ -28,6 +42,7 @@ export default function CreateServerWallet(props: {
2842
projectId: props.project.id,
2943
teamId: props.project.teamId,
3044
type: "server-wallet",
45+
label,
3146
},
3247
},
3348
auth: {
@@ -42,6 +57,7 @@ export default function CreateServerWallet(props: {
4257
}
4358

4459
router.refresh();
60+
setModalOpen(false);
4561

4662
return eoa;
4763
},
@@ -56,6 +72,7 @@ export default function CreateServerWallet(props: {
5672
} else {
5773
await createEoaMutation.mutateAsync({
5874
managementAccessToken: props.managementAccessToken,
75+
label,
5976
});
6077
}
6178
};
@@ -66,13 +83,59 @@ export default function CreateServerWallet(props: {
6683
<>
6784
<Button
6885
variant={"primary"}
69-
onClick={handleCreateServerWallet}
70-
disabled={isLoading}
86+
onClick={() =>
87+
props.managementAccessToken
88+
? setModalOpen(true)
89+
: router.push("vault")
90+
}
7191
className="flex flex-row items-center gap-2"
7292
>
73-
{isLoading && <Loader2 className="animate-spin" />}
7493
{props.managementAccessToken ? "Create Server Wallet" : "Get Started"}
7594
</Button>
95+
96+
<Dialog open={modalOpen} onOpenChange={setModalOpen}>
97+
<DialogContent className="p-0">
98+
<DialogHeader className="px-6 pt-6">
99+
<DialogTitle>Create server wallet</DialogTitle>
100+
<DialogDescription>
101+
Enter a label for your server wallet.
102+
</DialogDescription>
103+
</DialogHeader>
104+
<div className="flex flex-col gap-4 px-6">
105+
<div>
106+
<Input
107+
placeholder="Wallet label (optional)"
108+
value={label}
109+
onChange={(e) => setLabel(e.target.value)}
110+
className="w-full"
111+
/>
112+
</div>
113+
</div>
114+
<div className="flex justify-end gap-3 border-t bg-card px-6 py-4">
115+
<Button
116+
variant="outline"
117+
onClick={() => setModalOpen(false)}
118+
disabled={isLoading}
119+
>
120+
Cancel
121+
</Button>
122+
<Button
123+
variant="primary"
124+
onClick={handleCreateServerWallet}
125+
disabled={isLoading}
126+
>
127+
{isLoading ? (
128+
<>
129+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
130+
Creating...
131+
</>
132+
) : (
133+
"Create"
134+
)}
135+
</Button>
136+
</div>
137+
</DialogContent>
138+
</Dialog>
76139
</>
77140
);
78141
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/engine/server-wallets/wallet-table/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type Wallet = {
44
metadata: {
55
type: string;
66
projectId: string;
7-
name?: string;
7+
label?: string;
88
};
99
createdAt: string;
1010
updatedAt: string;

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/engine/server-wallets/wallet-table/wallet-table-ui.client.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ import { getThirdwebClient } from "@/constants/thirdweb.server";
1717
import { useQuery } from "@tanstack/react-query";
1818
import { formatDistanceToNowStrict } from "date-fns";
1919
import { format } from "date-fns/format";
20+
import { useState } from "react";
2021
import {
2122
DEFAULT_ACCOUNT_FACTORY_V0_7,
2223
predictSmartAccountAddress,
2324
} from "thirdweb/wallets/smart";
25+
import { Badge } from "../../../../../../../../@/components/ui/badge";
26+
import { Switch } from "../../../../../../../../@/components/ui/switch";
2427
import { useV5DashboardChain } from "../../../../../../../../lib/v5-adapter";
2528
import CreateServerWallet from "../components/create-server-wallet.client";
2629
import type { Wallet } from "./types";
@@ -34,6 +37,7 @@ export function ServerWalletsTableUI({
3437
project: Project;
3538
managementAccessToken: string | undefined;
3639
}) {
40+
const [showSigners, setShowSigners] = useState(false);
3741
return (
3842
<div className="overflow-hidden rounded-lg border border-border bg-card">
3943
<div className="flex flex-row items-center gap-4 px-6 py-6">
@@ -47,6 +51,16 @@ export function ServerWalletsTableUI({
4751
</p>
4852
</div>
4953
</div>
54+
<div className="flex items-center justify-end gap-2">
55+
<label htmlFor="show-signers" className="cursor-pointer text-sm">
56+
Show Signer Addresses
57+
</label>
58+
<Switch
59+
id="show-signers"
60+
checked={showSigners}
61+
onCheckedChange={() => setShowSigners(!showSigners)}
62+
/>
63+
</div>
5064
<CreateServerWallet
5165
project={project}
5266
managementAccessToken={managementAccessToken}
@@ -57,8 +71,8 @@ export function ServerWalletsTableUI({
5771
<Table>
5872
<TableHeader>
5973
<TableRow>
60-
<TableHead>Signer</TableHead>
61-
<TableHead>Smart Account</TableHead>
74+
<TableHead>Address</TableHead>
75+
<TableHead>Label</TableHead>
6276
<TableHead>Created At</TableHead>
6377
<TableHead>Updated At</TableHead>
6478
</TableRow>
@@ -74,11 +88,13 @@ export function ServerWalletsTableUI({
7488
wallets.map((wallet) => (
7589
<TableRow key={wallet.id} className="hover:bg-accent/50">
7690
<TableCell>
77-
<WalletAddress address={wallet.address} />
78-
</TableCell>
79-
<TableCell>
80-
<SmartAccountCell wallet={wallet} />
91+
{showSigners ? (
92+
<WalletAddress address={wallet.address} />
93+
) : (
94+
<SmartAccountCell wallet={wallet} />
95+
)}
8196
</TableCell>
97+
<TableCell>{wallet.metadata.label || "none"}</TableCell>
8298
<TableCell>
8399
<WalletDateCell date={wallet.createdAt} />
84100
</TableCell>
@@ -115,7 +131,10 @@ function SmartAccountCell({ wallet }: { wallet: Wallet }) {
115131
return (
116132
<div>
117133
{smartAccountAddressQuery.data ? (
118-
<WalletAddress address={smartAccountAddressQuery.data} />
134+
<div className="flex items-center gap-2">
135+
<WalletAddress address={smartAccountAddressQuery.data} />
136+
<Badge variant={"default"}>Smart Account</Badge>
137+
</div>
119138
) : (
120139
<Spinner className="h-4 w-4" />
121140
)}

0 commit comments

Comments
 (0)