@@ -5,6 +5,7 @@ import { createThirdwebClient, defineChain, getContract } from "thirdweb";
5
5
import { getCurrencyMetadata } from "thirdweb/extensions/erc20" ;
6
6
import { checksumAddress } from "thirdweb/utils" ;
7
7
import { CheckoutEmbed } from "./components/client/CheckoutEmbed.client" ;
8
+ import type { CheckoutParams } from "./components/types" ;
8
9
9
10
const title = "thirdweb Checkout" ;
10
11
const description = "Fast, secure, and simple payments." ;
@@ -20,68 +21,68 @@ export const metadata: Metadata = {
20
21
21
22
export default async function RoutesPage ( {
22
23
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 ;
32
26
33
- if ( ! chainId || Array . isArray ( chainId ) ) {
27
+ if ( ! params . chainId || Array . isArray ( params . chainId ) ) {
34
28
throw new Error ( "A single chainId parameter is required." ) ;
35
29
}
36
- if ( ! recipientAddress || Array . isArray ( recipientAddress ) ) {
30
+ if ( ! params . recipientAddress || Array . isArray ( params . recipientAddress ) ) {
37
31
throw new Error ( "A single recipientAddress parameter is required." ) ;
38
32
}
39
- if ( ! tokenAddress || Array . isArray ( tokenAddress ) ) {
33
+ if ( ! params . tokenAddress || Array . isArray ( params . tokenAddress ) ) {
40
34
throw new Error ( "A single tokenAddress parameter is required." ) ;
41
35
}
42
- if ( ! amount || Array . isArray ( amount ) ) {
36
+ if ( ! params . amount || Array . isArray ( params . amount ) ) {
43
37
throw new Error ( "A single amount parameter is required." ) ;
44
38
}
45
- if ( Array . isArray ( clientId ) ) {
39
+ if ( Array . isArray ( params . clientId ) ) {
46
40
throw new Error ( "A single clientId parameter is required." ) ;
47
41
}
48
- if ( Array . isArray ( redirectUri ) ) {
42
+ if ( Array . isArray ( params . redirectUri ) ) {
49
43
throw new Error ( "A single redirectUri parameter is required." ) ;
50
44
}
51
45
52
46
// Use any provided clientId or use the dashboard client
53
47
const client =
54
- clientId && ! Array . isArray ( clientId )
55
- ? createThirdwebClient ( { clientId } )
48
+ params . clientId && ! Array . isArray ( params . clientId )
49
+ ? createThirdwebClient ( { clientId : params . clientId } )
56
50
: getThirdwebClient ( undefined ) ;
57
51
58
52
const tokenContract = getContract ( {
59
- client,
53
+ client : getThirdwebClient ( undefined ) , // for this RPC call, use the dashboard client
60
54
// 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 ,
63
57
} ) ;
64
- const { symbol, decimals, name } = await getCurrencyMetadata ( {
58
+ const {
59
+ symbol,
60
+ decimals,
61
+ name : tokenName ,
62
+ } = await getCurrencyMetadata ( {
65
63
contract : tokenContract ,
66
64
} ) ;
67
65
const token = {
68
66
symbol,
69
67
decimals,
70
- name,
71
- address : checksumAddress ( tokenAddress ) ,
72
- chainId : Number ( chainId ) ,
68
+ name : tokenName ,
69
+ address : checksumAddress ( params . tokenAddress ) ,
70
+ chainId : Number ( params . chainId ) ,
73
71
} ;
74
72
75
73
return (
76
74
< div className = "relative mx-auto flex h-screen w-screen flex-col items-center justify-center overflow-hidden border py-10" >
77
75
< main className = "container z-10 flex justify-center" >
78
76
< 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 ) }
83
81
token = { token }
84
82
clientId = { client . clientId }
83
+ name = { params . name }
84
+ image = { params . image }
85
+ theme = { params . theme === "light" ? "light" : "dark" }
85
86
/>
86
87
</ main >
87
88
0 commit comments