File tree Expand file tree Collapse file tree 4 files changed +13
-9
lines changed
packages/thirdweb/src/x402 Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " thirdweb " : patch
3+ ---
4+
5+ Make maxAmount optional in wrapFetchWithPayment and loosen schema validation for payment payloads
Original file line number Diff line number Diff line change 11import type { ExactEvmPayload } from "x402/types" ;
2- import {
3- type RequestedPaymentPayload ,
4- RequestedPaymentPayloadSchema ,
5- } from "./schemas.js" ;
2+ import type { RequestedPaymentPayload } from "./schemas.js" ;
63
74/**
85 * Encodes a payment payload into a base64 string, ensuring bigint values are properly stringified
@@ -44,8 +41,7 @@ export function decodePayment(payment: string): RequestedPaymentPayload {
4441 ...parsed ,
4542 payload : parsed . payload as ExactEvmPayload ,
4643 } ;
47- const validated = RequestedPaymentPayloadSchema . parse ( obj ) ;
48- return validated ;
44+ return obj ;
4945}
5046
5147/**
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ export function wrapFetchWithPayment(
5252 fetch : typeof globalThis . fetch ,
5353 client : ThirdwebClient ,
5454 wallet : Wallet ,
55- maxValue : bigint = BigInt ( 1 * 10 ** 6 ) , // Default to 1 USDC
55+ maxValue ? : bigint ,
5656) {
5757 return async ( input : RequestInfo , init ?: RequestInit ) => {
5858 const response = await fetch ( input , init ) ;
@@ -91,7 +91,10 @@ export function wrapFetchWithPayment(
9191 ) ;
9292 }
9393
94- if ( BigInt ( selectedPaymentRequirements . maxAmountRequired ) > maxValue ) {
94+ if (
95+ maxValue &&
96+ BigInt ( selectedPaymentRequirements . maxAmountRequired ) > maxValue
97+ ) {
9598 throw new Error (
9699 `Payment amount exceeds maximum allowed (currently set to ${ maxValue } in base units)` ,
97100 ) ;
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ const FacilitatorNetworkSchema = z.string();
1515
1616export type FacilitatorNetwork = z . infer < typeof FacilitatorNetworkSchema > ;
1717
18- export const RequestedPaymentPayloadSchema = PaymentPayloadSchema . extend ( {
18+ const RequestedPaymentPayloadSchema = PaymentPayloadSchema . extend ( {
1919 network : FacilitatorNetworkSchema ,
2020} ) ;
2121
You can’t perform that action at this time.
0 commit comments