Skip to content

Commit c36cfbb

Browse files
committed
[MNY-257] Dashboard: Add query params in bridge page to configure token selection (#8293)
<!-- ## 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 enhances the `Page` component in `apps/dashboard/src/app/bridge/page.tsx` by introducing asynchronous handling of search parameters and improving the logic for processing input and output chains and currencies. ### Detailed summary - Added a `SearchParams` type to define search parameters. - Updated `Page` to accept `searchParams` as a `Promise`. - Implemented `onlyAddress` and `onlyNumber` functions for validation. - Introduced a `parse` function to extract values from search parameters. - Updated the `BridgePageUI` props for `buyTab` and `swapTab` to handle dynamic token data. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 93a9ba9 commit c36cfbb

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

apps/dashboard/src/app/bridge/page.tsx

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Metadata } from "next";
2+
import { isAddress, NATIVE_TOKEN_ADDRESS } from "thirdweb";
23
import { BridgePageUI } from "./components/bridge-page";
34

45
const title = "thirdweb Bridge: Buy, Bridge & Swap Crypto on 85+ Chains";
@@ -14,11 +15,50 @@ export const metadata: Metadata = {
1415
title,
1516
};
1617

17-
export default function Page() {
18+
type SearchParams = {
19+
[key: string]: string | string[] | undefined;
20+
};
21+
22+
export default async function Page(props: {
23+
searchParams: Promise<SearchParams>;
24+
}) {
25+
const searchParams = await props.searchParams;
26+
27+
const onlyAddress = (v: string) => (isAddress(v) ? v : undefined);
28+
const onlyNumber = (v: string) =>
29+
Number.isNaN(Number(v)) ? undefined : Number(v);
30+
31+
// output is buy, input is sell
32+
const sellChain = parse(searchParams.inputChain, onlyNumber);
33+
const sellCurrency = parse(searchParams.inputCurrency, onlyAddress);
34+
35+
const buyChain = parse(searchParams.outputChain, onlyNumber);
36+
const buyCurrency = parse(searchParams.outputCurrency, onlyAddress);
37+
1838
return (
1939
<BridgePageUI
20-
buyTab={undefined}
21-
swapTab={undefined}
40+
buyTab={{
41+
buyToken: buyChain
42+
? {
43+
chainId: buyChain,
44+
tokenAddress: buyCurrency || NATIVE_TOKEN_ADDRESS,
45+
}
46+
: undefined,
47+
}}
48+
swapTab={{
49+
sellToken: sellChain
50+
? {
51+
chainId: sellChain,
52+
tokenAddress: sellCurrency || NATIVE_TOKEN_ADDRESS,
53+
}
54+
: undefined,
55+
buyToken: buyChain
56+
? {
57+
chainId: buyChain,
58+
tokenAddress: buyCurrency || NATIVE_TOKEN_ADDRESS,
59+
}
60+
: undefined,
61+
}}
2262
title={
2363
<h1 className="text-3xl md:text-6xl font-semibold tracking-tighter text-balance text-center">
2464
Bridge and Swap tokens <br className="max-sm:hidden" /> across any
@@ -28,3 +68,13 @@ export default function Page() {
2868
/>
2969
);
3070
}
71+
72+
function parse<T>(
73+
value: string | string[] | undefined,
74+
fn: (value: string) => T | undefined,
75+
): T | undefined {
76+
if (typeof value === "string") {
77+
return fn(value);
78+
}
79+
return undefined;
80+
}

0 commit comments

Comments
 (0)