diff --git a/apps/dashboard/src/app/bridge/page.tsx b/apps/dashboard/src/app/bridge/page.tsx index c6121b422ab..9c3d796c9dd 100644 --- a/apps/dashboard/src/app/bridge/page.tsx +++ b/apps/dashboard/src/app/bridge/page.tsx @@ -1,4 +1,5 @@ import type { Metadata } from "next"; +import { isAddress, NATIVE_TOKEN_ADDRESS } from "thirdweb"; import { BridgePageUI } from "./components/bridge-page"; const title = "thirdweb Bridge: Buy, Bridge & Swap Crypto on 85+ Chains"; @@ -14,11 +15,50 @@ export const metadata: Metadata = { title, }; -export default function Page() { +type SearchParams = { + [key: string]: string | string[] | undefined; +}; + +export default async function Page(props: { + searchParams: Promise; +}) { + const searchParams = await props.searchParams; + + const onlyAddress = (v: string) => (isAddress(v) ? v : undefined); + const onlyNumber = (v: string) => + Number.isNaN(Number(v)) ? undefined : Number(v); + + // output is buy, input is sell + const sellChain = parse(searchParams.inputChain, onlyNumber); + const sellCurrency = parse(searchParams.inputCurrency, onlyAddress); + + const buyChain = parse(searchParams.outputChain, onlyNumber); + const buyCurrency = parse(searchParams.outputCurrency, onlyAddress); + return ( Bridge and Swap tokens
across any @@ -28,3 +68,13 @@ export default function Page() { /> ); } + +function parse( + value: string | string[] | undefined, + fn: (value: string) => T | undefined, +): T | undefined { + if (typeof value === "string") { + return fn(value); + } + return undefined; +}