Skip to content

Commit 67616c2

Browse files
committed
[MNY-127] Dashboard: Remove unnecessary server action for fetching token list (#7940)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refactoring the token management in the universal bridge API, including the introduction of a new `TokenMetadata` type and the relocation of the `getUniversalBridgeTokens` function to a new file. It also updates import paths for consistency. ### Detailed summary - Added `TokenMetadata` type in `apps/dashboard/src/@/api/universal-bridge/types.ts`. - Updated import path for `getUniversalBridgeTokens` in `apps/dashboard/src/@/hooks/tokens.ts` and `apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/payments/links/components/CreatePaymentLinkButton.client.tsx`. - Created `getUniversalBridgeTokens` function in `apps/dashboard/src/@/api/universal-bridge/token-list.ts`. - Removed old `getUniversalBridgeTokens` function and `TokenMetadata` type from `apps/dashboard/src/@/api/universal-bridge/tokens.ts`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 51f7418 commit 67616c2

File tree

6 files changed

+47
-44
lines changed

6 files changed

+47
-44
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { NEXT_PUBLIC_DASHBOARD_CLIENT_ID } from "@/constants/public-envs";
2+
import { UB_BASE_URL } from "./constants";
3+
import type { TokenMetadata } from "./types";
4+
5+
export async function getUniversalBridgeTokens(props: {
6+
chainId?: number;
7+
address?: string;
8+
}) {
9+
const url = new URL(`${UB_BASE_URL}/v1/tokens`);
10+
11+
if (props.chainId) {
12+
url.searchParams.append("chainId", String(props.chainId));
13+
}
14+
if (props.address) {
15+
url.searchParams.append("tokenAddress", props.address);
16+
}
17+
url.searchParams.append("limit", "1000");
18+
url.searchParams.append("includePrices", "false");
19+
20+
const res = await fetch(url.toString(), {
21+
headers: {
22+
"Content-Type": "application/json",
23+
"x-client-id": NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
24+
} as Record<string, string>,
25+
method: "GET",
26+
});
27+
28+
if (!res.ok) {
29+
const text = await res.text();
30+
throw new Error(text);
31+
}
32+
33+
const json = await res.json();
34+
return json.data as Array<TokenMetadata>;
35+
}

apps/dashboard/src/@/api/universal-bridge/tokens.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,8 @@
11
"use server";
22
import type { ProjectResponse } from "@thirdweb-dev/service-utils";
33
import { getAuthToken } from "@/api/auth-token";
4-
import { DASHBOARD_THIRDWEB_SECRET_KEY } from "@/constants/server-envs";
54
import { UB_BASE_URL } from "./constants";
6-
7-
export type TokenMetadata = {
8-
name: string;
9-
symbol: string;
10-
address: string;
11-
decimals: number;
12-
chainId: number;
13-
iconUri?: string;
14-
};
15-
16-
export async function getUniversalBridgeTokens(props: {
17-
chainId?: number;
18-
address?: string;
19-
}) {
20-
const url = new URL(`${UB_BASE_URL}/v1/tokens`);
21-
22-
if (props.chainId) {
23-
url.searchParams.append("chainId", String(props.chainId));
24-
}
25-
if (props.address) {
26-
url.searchParams.append("tokenAddress", props.address);
27-
}
28-
url.searchParams.append("limit", "1000");
29-
30-
const res = await fetch(url.toString(), {
31-
headers: {
32-
"Content-Type": "application/json",
33-
"x-secret-key": DASHBOARD_THIRDWEB_SECRET_KEY,
34-
} as Record<string, string>,
35-
method: "GET",
36-
});
37-
38-
if (!res.ok) {
39-
const text = await res.text();
40-
throw new Error(text);
41-
}
42-
43-
const json = await res.json();
44-
return json.data as Array<TokenMetadata>;
45-
}
5+
import type { TokenMetadata } from "./types";
466

477
export async function addUniversalBridgeTokenRoute(props: {
488
chainId: number;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type TokenMetadata = {
2+
name: string;
3+
symbol: string;
4+
address: string;
5+
decimals: number;
6+
chainId: number;
7+
iconUri?: string;
8+
};

apps/dashboard/src/@/components/blocks/TokenSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type ThirdwebClient,
66
} from "thirdweb";
77
import { shortenAddress } from "thirdweb/utils";
8-
import type { TokenMetadata } from "@/api/universal-bridge/tokens";
8+
import type { TokenMetadata } from "@/api/universal-bridge/types";
99
import { Img } from "@/components/blocks/Img";
1010
import { SelectWithSearch } from "@/components/blocks/select-with-search";
1111
import { Badge } from "@/components/ui/badge";

apps/dashboard/src/@/hooks/tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useQuery } from "@tanstack/react-query";
2-
import { getUniversalBridgeTokens } from "@/api/universal-bridge/tokens";
2+
import { getUniversalBridgeTokens } from "@/api/universal-bridge/token-list";
33

44
export function useTokensData({
55
chainId,

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/payments/links/components/CreatePaymentLinkButton.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { checksumAddress } from "thirdweb/utils";
1111
import z from "zod";
1212
import { reportPaymentLinkCreated } from "@/analytics/report";
1313
import { createPaymentLink } from "@/api/universal-bridge/developer";
14-
import { getUniversalBridgeTokens } from "@/api/universal-bridge/tokens";
14+
import { getUniversalBridgeTokens } from "@/api/universal-bridge/token-list";
1515
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
1616
import { TokenSelector } from "@/components/blocks/TokenSelector";
1717
import { Button } from "@/components/ui/button";

0 commit comments

Comments
 (0)