-
Notifications
You must be signed in to change notification settings - Fork 615
Project Wallet (Default Server Wallet) #8212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b48949c
Project Wallet (Default Server Wallet)
0xFirekeeper 945ac3d
Add project wallet integration to payments UI
0xFirekeeper 1926e9e
Add project wallet controls with send/receive actions
0xFirekeeper 496ecb7
Remove positive number validation for amount field
0xFirekeeper 248ca0b
Refactor send tokens action to use thirdweb API
0xFirekeeper e5b63c7
sorry
0xFirekeeper b883eb3
Refactor ProjectFTUX to accept wallet prop and update usage
0xFirekeeper 8db3011
fmt
0xFirekeeper 3b32b8a
Remove unused projectId prop from SendProjectWalletModal
0xFirekeeper b8b70c7
fmt
0xFirekeeper 630f6cf
save address in project services, set as default from server wallets …
joaquim-verges 5595cd7
CR
joaquim-verges 5d856fd
Add ability to change default project server wallet
0xFirekeeper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
apps/dashboard/src/@/actions/project-wallet/list-server-wallets.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| "use server"; | ||
|
|
||
| import { createVaultClient, listEoas } from "@thirdweb-dev/vault-sdk"; | ||
| import { NEXT_PUBLIC_THIRDWEB_VAULT_URL } from "@/constants/public-envs"; | ||
| import type { ProjectWalletSummary } from "@/lib/server/project-wallet"; | ||
|
|
||
| interface VaultWalletListItem { | ||
| id: string; | ||
| address: string; | ||
| metadata?: { | ||
| label?: string; | ||
| projectId?: string; | ||
| teamId?: string; | ||
| type?: string; | ||
| } | null; | ||
| } | ||
|
|
||
| export async function listProjectServerWallets(params: { | ||
| managementAccessToken: string; | ||
| projectId: string; | ||
| pageSize?: number; | ||
| }): Promise<ProjectWalletSummary[]> { | ||
| const { managementAccessToken, projectId, pageSize = 100 } = params; | ||
|
|
||
| if (!managementAccessToken || !NEXT_PUBLIC_THIRDWEB_VAULT_URL) { | ||
| return []; | ||
| } | ||
|
|
||
| try { | ||
| const vaultClient = await createVaultClient({ | ||
| baseUrl: NEXT_PUBLIC_THIRDWEB_VAULT_URL, | ||
| }); | ||
|
|
||
| const response = await listEoas({ | ||
| client: vaultClient, | ||
| request: { | ||
| auth: { | ||
| accessToken: managementAccessToken, | ||
| }, | ||
| options: { | ||
| page: 0, | ||
| // @ts-expect-error - Vault SDK expects snake_case pagination fields | ||
| page_size: pageSize, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.success || !response.data?.items) { | ||
| return []; | ||
| } | ||
|
|
||
| const items = response.data.items as VaultWalletListItem[]; | ||
|
|
||
| return items | ||
| .filter((item) => { | ||
| return ( | ||
| item.metadata?.projectId === projectId && | ||
| (!item.metadata?.type || item.metadata.type === "server-wallet") | ||
| ); | ||
| }) | ||
| .map<ProjectWalletSummary>((item) => ({ | ||
| id: item.id, | ||
| address: item.address, | ||
| label: item.metadata?.label ?? undefined, | ||
| })); | ||
| } catch (error) { | ||
| console.error("Failed to list project server wallets", error); | ||
| return []; | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
apps/dashboard/src/@/actions/project-wallet/send-tokens.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| "use server"; | ||
|
|
||
| import { configure, sendTokens } from "@thirdweb-dev/api"; | ||
| import { THIRDWEB_API_HOST } from "@/constants/urls"; | ||
|
|
||
| configure({ | ||
| override: { | ||
| baseUrl: THIRDWEB_API_HOST, | ||
| }, | ||
| }); | ||
|
|
||
| export async function sendProjectWalletTokens(options: { | ||
| walletAddress: string; | ||
| recipientAddress: string; | ||
| chainId: number; | ||
| quantityWei: string; | ||
| publishableKey: string; | ||
| teamId: string; | ||
| tokenAddress?: string; | ||
| secretKey: string; | ||
| vaultAccessToken?: string; | ||
| }) { | ||
| const { | ||
| walletAddress, | ||
| recipientAddress, | ||
| chainId, | ||
| quantityWei, | ||
| publishableKey, | ||
| teamId, | ||
| tokenAddress, | ||
| secretKey, | ||
| vaultAccessToken, | ||
| } = options; | ||
|
|
||
| if (!secretKey) { | ||
| return { | ||
| error: "A project secret key is required to send funds.", | ||
| ok: false, | ||
| } as const; | ||
| } | ||
|
|
||
| const response = await sendTokens({ | ||
| body: { | ||
| chainId, | ||
| from: walletAddress, | ||
| recipients: [ | ||
| { | ||
| address: recipientAddress, | ||
| quantity: quantityWei, | ||
| }, | ||
| ], | ||
| ...(tokenAddress ? { tokenAddress } : {}), | ||
| }, | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-client-id": publishableKey, | ||
| "x-secret-key": secretKey, | ||
| "x-team-id": teamId, | ||
| ...(vaultAccessToken ? { "x-vault-access-token": vaultAccessToken } : {}), | ||
| }, | ||
| }); | ||
|
|
||
| if (response.error || !response.data) { | ||
| return { | ||
| error: response.error || "Failed to submit transfer request.", | ||
| ok: false, | ||
| } as const; | ||
| } | ||
|
|
||
| return { | ||
| ok: true, | ||
| transactionIds: response.data.result?.transactionIds ?? [], | ||
| } as const; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| const PROJECT_WALLET_LABEL_SUFFIX = " Wallet"; | ||
| const PROJECT_WALLET_LABEL_MAX_LENGTH = 32; | ||
|
|
||
| /** | ||
| * Builds the default label for a project's primary server wallet. | ||
| * Ensures a stable naming convention so the wallet can be identified across flows. | ||
| */ | ||
| export function getProjectWalletLabel(projectName: string | undefined) { | ||
| const baseName = projectName?.trim() || "Project"; | ||
| const maxBaseLength = Math.max( | ||
| 1, | ||
| PROJECT_WALLET_LABEL_MAX_LENGTH - PROJECT_WALLET_LABEL_SUFFIX.length, | ||
| ); | ||
|
|
||
| const normalizedBase = | ||
| baseName.length > maxBaseLength | ||
| ? baseName.slice(0, maxBaseLength).trimEnd() | ||
| : baseName; | ||
|
|
||
| return `${normalizedBase}${PROJECT_WALLET_LABEL_SUFFIX}`; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import "server-only"; | ||
|
|
||
| import { createVaultClient, listEoas } from "@thirdweb-dev/vault-sdk"; | ||
| import type { Project } from "@/api/project/projects"; | ||
| import { NEXT_PUBLIC_THIRDWEB_VAULT_URL } from "@/constants/public-envs"; | ||
| import { getProjectWalletLabel } from "@/lib/project-wallet"; | ||
|
|
||
| export type ProjectWalletSummary = { | ||
| id: string; | ||
| address: string; | ||
| label?: string; | ||
| }; | ||
|
|
||
| type VaultWalletListItem = { | ||
| id: string; | ||
| address: string; | ||
| metadata?: { | ||
| label?: string; | ||
| projectId?: string; | ||
| teamId?: string; | ||
| type?: string; | ||
| }; | ||
| }; | ||
|
|
||
| export async function getProjectWallet( | ||
| project: Project, | ||
| ): Promise<ProjectWalletSummary | undefined> { | ||
| const engineCloudService = project.services.find( | ||
| (service) => service.name === "engineCloud", | ||
| ); | ||
|
|
||
| const managementAccessToken = | ||
| engineCloudService?.managementAccessToken || undefined; | ||
| const projectWalletAddress = ( | ||
| engineCloudService as { projectWalletAddress?: string } | undefined | ||
| )?.projectWalletAddress; | ||
|
|
||
| if ( | ||
| !managementAccessToken || | ||
| !NEXT_PUBLIC_THIRDWEB_VAULT_URL || | ||
| !projectWalletAddress | ||
| ) { | ||
| return undefined; | ||
| } | ||
|
|
||
| try { | ||
| const vaultClient = await createVaultClient({ | ||
| baseUrl: NEXT_PUBLIC_THIRDWEB_VAULT_URL, | ||
| }); | ||
|
|
||
| const response = await listEoas({ | ||
| client: vaultClient, | ||
| request: { | ||
| auth: { | ||
| accessToken: managementAccessToken, | ||
| }, | ||
| options: { | ||
| page: 0, | ||
| // @ts-expect-error - SDK expects snake_case for pagination arguments | ||
| page_size: 100, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.success || !response.data) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const items = response.data.items as VaultWalletListItem[] | undefined; | ||
|
|
||
| if (!items?.length) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const defaultLabel = getProjectWalletLabel(project.name); | ||
|
|
||
| const serverWallets = items.filter( | ||
| (item) => item.metadata?.projectId === project.id, | ||
| ); | ||
|
|
||
| const defaultWallet = serverWallets.find( | ||
| (item) => | ||
| item.address.toLowerCase() === projectWalletAddress.toLowerCase(), | ||
| ); | ||
|
|
||
| if (!defaultWallet) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return { | ||
| id: defaultWallet.id, | ||
| address: defaultWallet.address, | ||
| label: defaultWallet.metadata?.label ?? defaultLabel, | ||
| }; | ||
| } catch (error) { | ||
| console.error("Failed to load project wallet", error); | ||
| return undefined; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,5 +31,6 @@ export const Default: Story = { | |
| ], | ||
| }, | ||
| teamSlug: "bar", | ||
| managementAccessToken: undefined, | ||
| }, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Add explicit return type annotation.
The function lacks an explicit return type. Per coding guidelines, TypeScript functions should have explicit return types.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents