Skip to content

Commit 5d856fd

Browse files
committed
Add ability to change default project server wallet
Introduces a new action to list project server wallets and updates ProjectWalletControls to allow users to select and change the default server wallet for a project. Updates related types and props, and improves label handling in getProjectWallet. Also updates the ProjectFTUX story to include managementAccessToken.
1 parent 5595cd7 commit 5d856fd

File tree

5 files changed

+310
-23
lines changed

5 files changed

+310
-23
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"use server";
2+
3+
import { createVaultClient, listEoas } from "@thirdweb-dev/vault-sdk";
4+
import { NEXT_PUBLIC_THIRDWEB_VAULT_URL } from "@/constants/public-envs";
5+
import type { ProjectWalletSummary } from "@/lib/server/project-wallet";
6+
7+
interface VaultWalletListItem {
8+
id: string;
9+
address: string;
10+
metadata?: {
11+
label?: string;
12+
projectId?: string;
13+
teamId?: string;
14+
type?: string;
15+
} | null;
16+
}
17+
18+
export async function listProjectServerWallets(params: {
19+
managementAccessToken: string;
20+
projectId: string;
21+
pageSize?: number;
22+
}): Promise<ProjectWalletSummary[]> {
23+
const { managementAccessToken, projectId, pageSize = 100 } = params;
24+
25+
if (!managementAccessToken || !NEXT_PUBLIC_THIRDWEB_VAULT_URL) {
26+
return [];
27+
}
28+
29+
try {
30+
const vaultClient = await createVaultClient({
31+
baseUrl: NEXT_PUBLIC_THIRDWEB_VAULT_URL,
32+
});
33+
34+
const response = await listEoas({
35+
client: vaultClient,
36+
request: {
37+
auth: {
38+
accessToken: managementAccessToken,
39+
},
40+
options: {
41+
page: 0,
42+
// @ts-expect-error - Vault SDK expects snake_case pagination fields
43+
page_size: pageSize,
44+
},
45+
},
46+
});
47+
48+
if (!response.success || !response.data?.items) {
49+
return [];
50+
}
51+
52+
const items = response.data.items as VaultWalletListItem[];
53+
54+
return items
55+
.filter((item) => {
56+
return (
57+
item.metadata?.projectId === projectId &&
58+
(!item.metadata?.type || item.metadata.type === "server-wallet")
59+
);
60+
})
61+
.map<ProjectWalletSummary>((item) => ({
62+
id: item.id,
63+
address: item.address,
64+
label: item.metadata?.label ?? undefined,
65+
}));
66+
} catch (error) {
67+
console.error("Failed to list project server wallets", error);
68+
return [];
69+
}
70+
}

apps/dashboard/src/@/lib/server/project-wallet.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export async function getProjectWallet(
3131

3232
const managementAccessToken =
3333
engineCloudService?.managementAccessToken || undefined;
34-
const projectWalletAddress = engineCloudService?.projectWalletAddress;
34+
const projectWalletAddress = (
35+
engineCloudService as { projectWalletAddress?: string } | undefined
36+
)?.projectWalletAddress;
3537

3638
if (
3739
!managementAccessToken ||
@@ -70,7 +72,7 @@ export async function getProjectWallet(
7072
return undefined;
7173
}
7274

73-
const expectedLabel = getProjectWalletLabel(project.name);
75+
const defaultLabel = getProjectWalletLabel(project.name);
7476

7577
const serverWallets = items.filter(
7678
(item) => item.metadata?.projectId === project.id,
@@ -88,7 +90,7 @@ export async function getProjectWallet(
8890
return {
8991
id: defaultWallet.id,
9092
address: defaultWallet.address,
91-
label: defaultWallet.metadata?.label,
93+
label: defaultWallet.metadata?.label ?? defaultLabel,
9294
};
9395
} catch (error) {
9496
console.error("Failed to load project wallet", error);

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/components/ProjectFTUX/ProjectFTUX.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ export const Default: Story = {
3131
],
3232
},
3333
teamSlug: "bar",
34+
managementAccessToken: undefined,
3435
},
3536
};

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/components/ProjectFTUX/ProjectFTUX.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ export function ProjectWalletSection(props: {
9494
<>
9595
<ProjectWalletControls
9696
label={label}
97-
project={{
98-
id: props.project.id,
99-
publishableKey: props.project.publishableKey,
100-
services: props.project.services,
101-
teamId: props.project.teamId,
102-
}}
97+
project={props.project}
10398
walletAddress={walletAddress}
10499
/>
105100
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-end">

0 commit comments

Comments
 (0)