-
Notifications
You must be signed in to change notification settings - Fork 619
[MNY-127] Dashboard: Remove unnecessary server action for fetching token list #7940
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||
| import { NEXT_PUBLIC_DASHBOARD_CLIENT_ID } from "@/constants/public-envs"; | ||||||||||||||||||||||||||
| import { UB_BASE_URL } from "./constants"; | ||||||||||||||||||||||||||
| import type { TokenMetadata } from "./types"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export async function getUniversalBridgeTokens(props: { | ||||||||||||||||||||||||||
| chainId?: number; | ||||||||||||||||||||||||||
| address?: string; | ||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||
| const url = new URL(`${UB_BASE_URL}/v1/tokens`); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+9
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard missing UB_BASE_URL and build URL with a base. Avoid “Invalid URL” at runtime and produce a clear config error. - const url = new URL(`${UB_BASE_URL}/v1/tokens`);
+ if (!UB_BASE_URL) {
+ throw new Error("Missing NEXT_PUBLIC_THIRDWEB_BRIDGE_HOST for Universal Bridge.");
+ }
+ const url = new URL("/v1/tokens", UB_BASE_URL);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| if (props.chainId) { | ||||||||||||||||||||||||||
| url.searchParams.append("chainId", String(props.chainId)); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (props.address) { | ||||||||||||||||||||||||||
| url.searchParams.append("tokenAddress", props.address); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+11
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix truthy check for chainId (0 should be valid). Use a nullish check so chainId=0 isn’t dropped. - if (props.chainId) {
+ if (props.chainId != null) {
url.searchParams.append("chainId", String(props.chainId));
}
- if (props.address) {
+ if (props.address) {
url.searchParams.append("tokenAddress", props.address);
}Optional: normalize 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| url.searchParams.append("limit", "1000"); | ||||||||||||||||||||||||||
| url.searchParams.append("includePrices", "false"); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const res = await fetch(url.toString(), { | ||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||
| "Content-Type": "application/json", | ||||||||||||||||||||||||||
| "x-client-id": NEXT_PUBLIC_DASHBOARD_CLIENT_ID, | ||||||||||||||||||||||||||
| } as Record<string, string>, | ||||||||||||||||||||||||||
| method: "GET", | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!res.ok) { | ||||||||||||||||||||||||||
| const text = await res.text(); | ||||||||||||||||||||||||||
| throw new Error(text); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const json = await res.json(); | ||||||||||||||||||||||||||
| return json.data as Array<TokenMetadata>; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+33
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Return typed payload and validate shape. Avoids implicit any, aligns with “return typed results”. - const json = await res.json();
- return json.data as Array<TokenMetadata>;
+ const { data } = (await res.json()) as { data: TokenMetadata[] };
+ if (!Array.isArray(data)) {
+ throw new Error("Malformed response: expected data: TokenMetadata[].");
+ }
+ return data;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export type TokenMetadata = { | ||
| name: string; | ||
| symbol: string; | ||
| address: string; | ||
| decimals: number; | ||
| chainId: number; | ||
| iconUri?: string; | ||
| }; |
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
Add explicit return type (and optional AbortSignal).
Conform to TS guidelines and make cancellation possible without breaking callers.
📝 Committable suggestion
🤖 Prompt for AI Agents