11"use client" ;
22
33import { useMutation } from "@tanstack/react-query" ;
4+ import { Badge } from "@workspace/ui/components/badge" ;
45import { CodeClient } from "@workspace/ui/components/code/code.client" ;
56import { CodeIcon , LockIcon } from "lucide-react" ;
6- import { arbitrumSepolia } from "thirdweb/chains" ;
77import {
88 ConnectButton ,
9- getDefaultToken ,
109 useActiveAccount ,
1110 useActiveWallet ,
1211} from "thirdweb/react" ;
1312import { wrapFetchWithPayment } from "thirdweb/x402" ;
1413import { Button } from "@/components/ui/button" ;
1514import { Card } from "@/components/ui/card" ;
1615import { THIRDWEB_CLIENT } from "../../../../lib/client" ;
17-
18- const chain = arbitrumSepolia ;
19- const token = getDefaultToken ( chain , "USDC" ) ;
16+ import { chain , token } from "./constants" ;
2017
2118export function X402ClientPreview ( ) {
2219 const activeWallet = useActiveWallet ( ) ;
@@ -30,8 +27,21 @@ export function X402ClientPreview() {
3027 fetch ,
3128 THIRDWEB_CLIENT ,
3229 activeWallet ,
30+ BigInt ( 1 * 10 ** 18 ) ,
3331 ) ;
34- const response = await fetchWithPay ( "/api/paywall" ) ;
32+ const searchParams = new URLSearchParams ( ) ;
33+ searchParams . set ( "chainId" , chain . id . toString ( ) ) ;
34+ searchParams . set ( "payTo" , activeWallet . getAccount ( ) ?. address || "" ) ;
35+ // TODO (402): dynamic from playground config
36+ // if (token) {
37+ // searchParams.set("amount", "0.01");
38+ // searchParams.set("tokenAddress", token.address);
39+ // searchParams.set("decimals", token.decimals.toString());
40+ // }
41+ const url =
42+ "/api/paywall" +
43+ ( searchParams . size > 0 ? "?" + searchParams . toString ( ) : "" ) ;
44+ const response = await fetchWithPay ( url . toString ( ) ) ;
3545 return response . json ( ) ;
3646 } ,
3747 } ) ;
@@ -47,18 +57,20 @@ export function X402ClientPreview() {
4757 chain = { chain }
4858 detailsButton = { {
4959 displayBalanceToken : {
50- [ chain . id ] : token ! . address ,
60+ [ chain . id ] : token . address ,
5161 } ,
5262 } }
5363 supportedTokens = { {
54- [ chain . id ] : [ token ! ] ,
64+ [ chain . id ] : [ token ] ,
5565 } }
5666 />
5767 < Card className = "p-6" >
5868 < div className = "flex items-center gap-3 mb-4" >
5969 < LockIcon className = "w-5 h-5 text-muted-foreground" />
6070 < span className = "text-lg font-medium" > Paid API Call</ span >
61- < span className = "text-xl font-bold text-red-600" > $0.01</ span >
71+ < Badge variant = "success" >
72+ < span className = "text-xl font-bold" > 0.1 { token . symbol } </ span >
73+ </ Badge >
6274 </ div >
6375
6476 < Button
@@ -67,19 +79,25 @@ export function X402ClientPreview() {
6779 size = "lg"
6880 disabled = { paidApiCall . isPending || ! activeAccount }
6981 >
70- Pay Now
82+ Access Premium Content
7183 </ Button >
7284 < p className = "text-sm text-muted-foreground" >
73- { " " }
74- < a
75- className = "underline"
76- href = { "https://faucet.circle.com/" }
77- target = "_blank"
78- rel = "noopener noreferrer"
79- >
80- Click here to get USDC on { chain . name }
81- </ a >
85+ Pay for access with { token . symbol } on{ " " }
86+ { chain . name || `chain ${ chain . id } ` }
8287 </ p >
88+ { chain . testnet && token . symbol . toLowerCase ( ) === "usdc" && (
89+ < p className = "text-sm text-muted-foreground" >
90+ { " " }
91+ < a
92+ className = "underline"
93+ href = { "https://faucet.circle.com/" }
94+ target = "_blank"
95+ rel = "noopener noreferrer"
96+ >
97+ Click here to get testnet { token . symbol } on { chain . name }
98+ </ a >
99+ </ p >
100+ ) }
83101 </ Card >
84102 < Card className = "p-6" >
85103 < div className = "flex items-center gap-3 mb-2" >
0 commit comments