Skip to content

Commit 248ca0b

Browse files
committed
Refactor send tokens action to use thirdweb API
Replaces the custom proxy with thirdweb's sendTokens API and configures the base URL. Updates error handling and response parsing in sendProjectWalletTokens. Also improves error messaging and transaction ID display in ProjectWalletControls.
1 parent 496ecb7 commit 248ca0b

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

apps/dashboard/src/@/actions/project-wallet/send-tokens.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
"use server";
22

3-
import { apiServerProxy } from "@/actions/proxies";
3+
import { configure, sendTokens } from "@thirdweb-dev/api";
4+
import { THIRDWEB_API_HOST } from "@/constants/urls";
5+
6+
configure({
7+
override: {
8+
baseUrl: THIRDWEB_API_HOST,
9+
},
10+
});
411

512
export async function sendProjectWalletTokens(options: {
613
walletAddress: string;
@@ -32,11 +39,8 @@ export async function sendProjectWalletTokens(options: {
3239
} as const;
3340
}
3441

35-
const response = await apiServerProxy<{
36-
result?: { transactionIds: string[] };
37-
error?: { message?: string };
38-
}>({
39-
body: JSON.stringify({
42+
const response = await sendTokens({
43+
body: {
4044
chainId,
4145
from: walletAddress,
4246
recipients: [
@@ -46,19 +50,17 @@ export async function sendProjectWalletTokens(options: {
4650
},
4751
],
4852
...(tokenAddress ? { tokenAddress } : {}),
49-
}),
53+
},
5054
headers: {
5155
"Content-Type": "application/json",
5256
"x-client-id": publishableKey,
57+
"x-secret-key": secretKey,
5358
"x-team-id": teamId,
54-
...(secretKey ? { "x-secret-key": secretKey } : {}),
5559
...(vaultAccessToken ? { "x-vault-access-token": vaultAccessToken } : {}),
5660
},
57-
method: "POST",
58-
pathname: "/v1/wallets/send",
5961
});
6062

61-
if (!response.ok) {
63+
if (response.error || !response.data) {
6264
return {
6365
error: response.error || "Failed to submit transfer request.",
6466
ok: false,
@@ -67,6 +69,6 @@ export async function sendProjectWalletTokens(options: {
6769

6870
return {
6971
ok: true,
70-
transactionIds: response.data?.result?.transactionIds ?? [],
72+
transactionIds: response.data.result?.transactionIds ?? [],
7173
} as const;
7274
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ function SendProjectWalletModal(props: {
404404
});
405405

406406
if (!result.ok) {
407-
throw new Error(result.error ?? "Failed to send funds");
407+
const errorMessage =
408+
typeof result.error === "string"
409+
? result.error
410+
: "Failed to send funds";
411+
throw new Error(errorMessage);
408412
}
409413

410414
return result.transactionIds;
@@ -416,7 +420,7 @@ function SendProjectWalletModal(props: {
416420
toast.success("Transfer submitted", {
417421
description:
418422
transactionIds && transactionIds.length > 0
419-
? `Reference ID: ${transactionIds[0]}`
423+
? `Transaction ID: ${transactionIds[0]}`
420424
: undefined,
421425
});
422426
onSuccess();

0 commit comments

Comments
 (0)