@@ -5,6 +5,7 @@ import { createThirdwebClient, defineChain, getContract } from "thirdweb";
55import { getCurrencyMetadata } from "thirdweb/extensions/erc20" ;
66import { checksumAddress } from "thirdweb/utils" ;
77import { CheckoutEmbed } from "./components/client/CheckoutEmbed.client" ;
8+ import type { CheckoutParams } from "./components/types" ;
89
910const title = "thirdweb Checkout" ;
1011const description = "Fast, secure, and simple payments." ;
@@ -20,68 +21,68 @@ export const metadata: Metadata = {
2021
2122export default async function RoutesPage ( {
2223 searchParams,
23- } : { searchParams : Record < string , string | string [ ] > } ) {
24- const {
25- chainId,
26- recipientAddress,
27- tokenAddress,
28- amount,
29- clientId,
30- redirectUri,
31- } = searchParams ;
24+ } : { searchParams : Promise < CheckoutParams > } ) {
25+ const params = await searchParams ;
3226
33- if ( ! chainId || Array . isArray ( chainId ) ) {
27+ if ( ! params . chainId || Array . isArray ( params . chainId ) ) {
3428 throw new Error ( "A single chainId parameter is required." ) ;
3529 }
36- if ( ! recipientAddress || Array . isArray ( recipientAddress ) ) {
30+ if ( ! params . recipientAddress || Array . isArray ( params . recipientAddress ) ) {
3731 throw new Error ( "A single recipientAddress parameter is required." ) ;
3832 }
39- if ( ! tokenAddress || Array . isArray ( tokenAddress ) ) {
33+ if ( ! params . tokenAddress || Array . isArray ( params . tokenAddress ) ) {
4034 throw new Error ( "A single tokenAddress parameter is required." ) ;
4135 }
42- if ( ! amount || Array . isArray ( amount ) ) {
36+ if ( ! params . amount || Array . isArray ( params . amount ) ) {
4337 throw new Error ( "A single amount parameter is required." ) ;
4438 }
45- if ( Array . isArray ( clientId ) ) {
39+ if ( Array . isArray ( params . clientId ) ) {
4640 throw new Error ( "A single clientId parameter is required." ) ;
4741 }
48- if ( Array . isArray ( redirectUri ) ) {
42+ if ( Array . isArray ( params . redirectUri ) ) {
4943 throw new Error ( "A single redirectUri parameter is required." ) ;
5044 }
5145
5246 // Use any provided clientId or use the dashboard client
5347 const client =
54- clientId && ! Array . isArray ( clientId )
55- ? createThirdwebClient ( { clientId } )
48+ params . clientId && ! Array . isArray ( params . clientId )
49+ ? createThirdwebClient ( { clientId : params . clientId } )
5650 : getThirdwebClient ( undefined ) ;
5751
5852 const tokenContract = getContract ( {
59- client,
53+ client : getThirdwebClient ( undefined ) , // for this RPC call, use the dashboard client
6054 // eslint-disable-next-line no-restricted-syntax
61- chain : defineChain ( Number ( chainId ) ) ,
62- address : tokenAddress ,
55+ chain : defineChain ( Number ( params . chainId ) ) ,
56+ address : params . tokenAddress ,
6357 } ) ;
64- const { symbol, decimals, name } = await getCurrencyMetadata ( {
58+ const {
59+ symbol,
60+ decimals,
61+ name : tokenName ,
62+ } = await getCurrencyMetadata ( {
6563 contract : tokenContract ,
6664 } ) ;
6765 const token = {
6866 symbol,
6967 decimals,
70- name,
71- address : checksumAddress ( tokenAddress ) ,
72- chainId : Number ( chainId ) ,
68+ name : tokenName ,
69+ address : checksumAddress ( params . tokenAddress ) ,
70+ chainId : Number ( params . chainId ) ,
7371 } ;
7472
7573 return (
7674 < div className = "relative mx-auto flex h-screen w-screen flex-col items-center justify-center overflow-hidden border py-10" >
7775 < main className = "container z-10 flex justify-center" >
7876 < CheckoutEmbed
79- redirectUri = { redirectUri }
80- chainId = { Number ( chainId ) }
81- recipientAddress = { recipientAddress }
82- amount = { BigInt ( amount ) }
77+ redirectUri = { params . redirectUri }
78+ chainId = { Number ( params . chainId ) }
79+ recipientAddress = { params . recipientAddress }
80+ amount = { BigInt ( params . amount ) }
8381 token = { token }
8482 clientId = { client . clientId }
83+ name = { params . name }
84+ image = { params . image }
85+ theme = { params . theme === "light" ? "light" : "dark" }
8586 />
8687 </ main >
8788
0 commit comments