11import type { Metadata } from "next" ;
2+ import { isAddress , NATIVE_TOKEN_ADDRESS } from "thirdweb" ;
23import { BridgePageUI } from "./components/bridge-page" ;
34
45const 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