Skip to content

Commit a997834

Browse files
committed
[MNY-257] Dashboard: Add query params in bridge page to configure token selection
1 parent 6a7b556 commit a997834

File tree

1 file changed

+71
-3
lines changed

1 file changed

+71
-3
lines changed

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

Lines changed: 71 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,67 @@ 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+
const inputChain = getStringFromSearchParams(searchParams, "inputChain");
27+
const outputChain = getStringFromSearchParams(searchParams, "outputChain");
28+
const _inputCurrency = getStringFromSearchParams(
29+
searchParams,
30+
"inputCurrency",
31+
);
32+
const _outputCurrency = getStringFromSearchParams(
33+
searchParams,
34+
"outputCurrency",
35+
);
36+
37+
const inputCurrency =
38+
_inputCurrency && isAddress(_inputCurrency) ? _inputCurrency : undefined;
39+
const outputCurrency =
40+
_outputCurrency && isAddress(_outputCurrency) ? _outputCurrency : undefined;
41+
42+
const inputChainParsed = Number(inputChain);
43+
const outputChainParsed = Number(outputChain);
44+
45+
const inputChainNumber = Number.isNaN(inputChainParsed)
46+
? undefined
47+
: inputChainParsed;
48+
49+
const outputChainNumber = Number.isNaN(outputChainParsed)
50+
? undefined
51+
: outputChainParsed;
52+
53+
// output is buy, input is sell
54+
1855
return (
1956
<BridgePageUI
20-
buyTab={undefined}
21-
swapTab={undefined}
57+
buyTab={{
58+
buyToken: outputChainNumber
59+
? {
60+
chainId: outputChainNumber,
61+
tokenAddress: outputCurrency || NATIVE_TOKEN_ADDRESS,
62+
}
63+
: undefined,
64+
}}
65+
swapTab={{
66+
sellToken: inputChainNumber
67+
? {
68+
chainId: inputChainNumber,
69+
tokenAddress: inputCurrency || NATIVE_TOKEN_ADDRESS,
70+
}
71+
: undefined,
72+
buyToken: outputChainNumber
73+
? {
74+
chainId: outputChainNumber,
75+
tokenAddress: outputCurrency || NATIVE_TOKEN_ADDRESS,
76+
}
77+
: undefined,
78+
}}
2279
title={
2380
<h1 className="text-3xl md:text-6xl font-semibold tracking-tighter text-balance text-center">
2481
Bridge and Swap tokens <br className="max-sm:hidden" /> across any
@@ -28,3 +85,14 @@ export default function Page() {
2885
/>
2986
);
3087
}
88+
89+
function getStringFromSearchParams(
90+
searchParams: SearchParams,
91+
key: string,
92+
): string | undefined {
93+
const value = searchParams[key];
94+
if (typeof value === "string") {
95+
return value;
96+
}
97+
return undefined;
98+
}

0 commit comments

Comments
 (0)