Skip to content

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Sep 30, 2025


PR-Codex overview

This PR introduces a new waitUntil parameter in the settlePayment() function, enhancing its flexibility by allowing users to specify when to wait for a payment settlement. It also updates type definitions and relevant function signatures to accommodate this change.

Detailed summary

  • Added WaitUntil type to represent payment wait states.
  • Updated SettlePaymentArgs to include waitUntil parameter.
  • Changed settlePayment function to accept SettlePaymentArgs.
  • Updated settle method in ThirdwebX402Facilitator to use waitUtil parameter.
  • Modified example configurations to demonstrate waitUntil usage.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • settlePayment now supports an optional waitUntil parameter ("simulated", "submitted", or "confirmed") for finer control over when the call resolves.
    • You can set a default waitUntil in the facilitator config or override it per call.
    • TypeScript improvements: new exported types for stronger typing and better DX (SettlePaymentArgs, ERC20TokenAmount, PaymentRequiredResult, SupportedSignatureType, WaitUntil).
  • Chores

    • Added a patch changeset entry reflecting the new waitUntil support in payment settlement.

Copy link

vercel bot commented Sep 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs-v2 Ready Ready Preview Comment Sep 30, 2025 0:46am
nebula Ready Ready Preview Comment Sep 30, 2025 0:46am
thirdweb_playground Ready Ready Preview Comment Sep 30, 2025 0:46am
thirdweb-www Ready Ready Preview Comment Sep 30, 2025 0:46am
wallet-ui Ready Ready Preview Comment Sep 30, 2025 0:46am

Copy link

changeset-bot bot commented Sep 30, 2025

🦋 Changeset detected

Latest commit: fbecb94

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 30, 2025

Walkthrough

Adds an optional waitUntil field to the x402 payment settlement API and threads it through types and runtime: new SettlePaymentArgs includes waitUntil, settlePayment forwards waitUntil to the facilitator, facilitator accepts an optional waitUtil config/arg, and request body includes waitUtil only when resolved.

Changes

Cohort / File(s) Summary
Changeset
.changeset/yellow-cameras-tease.md
Adds a patch changeset noting that waitUntil is exposed in settlePayment()
x402 public types & barrel
packages/thirdweb/src/exports/x402.ts, packages/thirdweb/src/x402/types.ts
Exports new types and adds SettlePaymentArgs which augments PaymentArgs with optional waitUntil?: WaitUntil. Adds type re-exports (ERC20TokenAmount, PaymentRequiredResult, SettlePaymentArgs, SupportedSignatureType, and WaitUntil).
settle flow wiring
packages/thirdweb/src/x402/settle-payment.ts, packages/thirdweb/src/x402/facilitator.ts
settlePayment signature changed to accept SettlePaymentArgs and forwards args.waitUntil to facilitator. Introduces `export type WaitUntil = "simulated"

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant SP as settlePayment
  participant F as Facilitator.settle
  participant API as X402 Service

  C->>SP: settlePayment({ ..., waitUntil? })
  SP->>F: settle(..., waitUtil=waitUntil)
  Note over F: waitUtilParam = arg.waitUtil ?? config.waitUtil
  alt waitUtilParam present
    F->>API: POST /settle { ..., waitUtil: waitUtilParam }
  else no waitUtilParam
    F->>API: POST /settle { ... } 
  end
  API-->>F: 200 Success / 402 Payment Required
  F-->>SP: SettlePaymentResult | PaymentRequiredResult
  SP-->>C: Result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description includes only the commented-out template and the auto-generated PR-Codex overview but fails to replace the template placeholders with actual content for the title, notes for the reviewer, and testing instructions, leaving required sections unfilled. Please update the PR description by replacing the commented template with real content for each section, including a descriptive title line, notes for the reviewer, testing instructions, and an issue or ticket reference if applicable.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the primary change by indicating that the waitUntil parameter is now exposed in the settlePayment function and includes the [SDK] context, making it clear and concise for reviewers scanning the history.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch _SDK_Expose_waitUntil_parameter_in_settlePayment_

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 635ae32 and fbecb94.

📒 Files selected for processing (5)
  • .changeset/yellow-cameras-tease.md (1 hunks)
  • packages/thirdweb/src/exports/x402.ts (1 hunks)
  • packages/thirdweb/src/x402/facilitator.ts (5 hunks)
  • packages/thirdweb/src/x402/settle-payment.ts (4 hunks)
  • packages/thirdweb/src/x402/types.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/yellow-cameras-tease.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/thirdweb/src/x402/settle-payment.ts
  • packages/thirdweb/src/x402/types.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from @/types where applicable
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size

Files:

  • packages/thirdweb/src/x402/facilitator.ts
  • packages/thirdweb/src/exports/x402.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • packages/thirdweb/src/x402/facilitator.ts
  • packages/thirdweb/src/exports/x402.ts
packages/thirdweb/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

packages/thirdweb/**/*.{ts,tsx}: Every public symbol must have comprehensive TSDoc with at least one compiling @example and a custom tag (@beta, @internal, @experimental, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
Lazy‑load heavy dependencies inside async paths (e.g., const { jsPDF } = await import("jspdf"))

Files:

  • packages/thirdweb/src/x402/facilitator.ts
  • packages/thirdweb/src/exports/x402.ts
packages/thirdweb/src/exports/**

📄 CodeRabbit inference engine (CLAUDE.md)

packages/thirdweb/src/exports/**: Export everything via exports/ directory, grouped by feature in the SDK public API
Every public symbol must have comprehensive TSDoc with at least one @example block that compiles and custom annotation tags (@beta, @internal, @experimental)

Files:

  • packages/thirdweb/src/exports/x402.ts
🧬 Code graph analysis (1)
packages/thirdweb/src/x402/facilitator.ts (3)
packages/thirdweb/src/exports/x402.ts (2)
  • WaitUntil (6-6)
  • ThirdwebX402FacilitatorConfig (5-5)
packages/thirdweb/src/exports/thirdweb.ts (1)
  • ThirdwebClient (25-25)
packages/thirdweb/src/x402/schemas.ts (1)
  • FacilitatorSettleResponse (56-58)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: Build Packages
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/thirdweb/src/x402/facilitator.ts (1)

12-13: Restore WaitUtil alias + add the required docs

Renaming WaitUtil to WaitUntil drops the public symbol people already import, so existing SDK consumers will hit compile errors. The new type is also missing the mandated TSDoc with an @example and custom tag for packages/thirdweb exports. Please keep WaitUtil as a deprecated alias while documenting WaitUntil per guidelines.

+/**
+ * Stage the facilitator should wait for before resolving a settlement.
+ * @beta
+ * @example
+ * ```ts
+ * const waitStage: WaitUntil = "submitted";
+ * ```
+ */
 export type WaitUntil = "simulated" | "submitted" | "confirmed";
+/**
+ * @deprecated Use {@link WaitUntil}.
+ * @beta
+ */
+export type WaitUtil = WaitUntil;

As per coding guidelines

packages/thirdweb/src/exports/x402.ts (1)

6-7: Continue exporting the legacy WaitUtil alias

Even after reintroducing the alias in facilitator.ts, we still need to surface it from the barrel so existing imports (import { WaitUtil } from "thirdweb/x402") keep compiling.

 export {
   facilitator,
   type ThirdwebX402Facilitator,
   type ThirdwebX402FacilitatorConfig,
   type WaitUntil,
+  /** @deprecated Use WaitUntil */
+  type WaitUtil,
 } from "../x402/facilitator.js";

As per coding guidelines

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

Comment @coderabbitai help to get the list of available commands and usage tips.

@joaquim-verges joaquim-verges marked this pull request as ready for review September 30, 2025 00:09
@joaquim-verges joaquim-verges requested review from a team as code owners September 30, 2025 00:09
@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Sep 30, 2025
Copy link
Member Author

joaquim-verges commented Sep 30, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

github-actions bot commented Sep 30, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.69 KB (0%) 1.3 s (0%) 231 ms (+71.96% 🔺) 1.6 s
thirdweb (cjs) 361.52 KB (0%) 7.3 s (0%) 1.3 s (+4.08% 🔺) 8.6 s
thirdweb (minimal + tree-shaking) 5.73 KB (0%) 115 ms (0%) 63 ms (+426.94% 🔺) 177 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 22 ms (+621.92% 🔺) 32 ms
thirdweb/react (minimal + tree-shaking) 19.14 KB (0%) 383 ms (0%) 57 ms (+854.37% 🔺) 440 ms

Copy link

codecov bot commented Sep 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.28%. Comparing base (ce9220e) to head (635ae32).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8153   +/-   ##
=======================================
  Coverage   56.28%   56.28%           
=======================================
  Files         906      906           
  Lines       59208    59208           
  Branches     4176     4180    +4     
=======================================
  Hits        33324    33324           
  Misses      25779    25779           
  Partials      105      105           
Flag Coverage Δ
packages 56.28% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/thirdweb/src/x402/facilitator.ts (1)

163-170: JSDoc: include the new wait param.

Add @param for the wait parameter to keep docs complete.

   /**
    * Settles a payment with the facilitator service
    *
    * @param payload - The payment payload to settle
    * @param paymentRequirements - The payment requirements for the settlement
+   * @param waitUntil - Optional stage ("simulated" | "submitted" | "confirmed") to wait for before responding
    * @returns A promise that resolves to the settlement response
    */
🧹 Nitpick comments (7)
packages/thirdweb/src/x402/types.ts (1)

6-6: Type ownership: define Wait type in types.ts to avoid cross-module coupling.

To keep types centralized and avoid types.ts → facilitator.ts dependency, move the wait type here and have facilitator import it from types.ts. Also align naming with the public arg name (“waitUntil”).

-import type { ThirdwebX402Facilitator, WaitUtil } from "./facilitator.js";
+import type { ThirdwebX402Facilitator } from "./facilitator.js";
+
+/** @public @beta */
+export type WaitUntil = "simulated" | "submitted" | "confirmed";
+/** @public @beta @deprecated Use WaitUntil */
+export type WaitUtil = WaitUntil;

Follow-up: update facilitator.ts to import WaitUntil from ./types.js and use it (see facilitator comments). Based on coding guidelines.

packages/thirdweb/src/x402/settle-payment.ts (1)

143-146: Naming consistency across API: waitUntil vs waitUtil.

You pass args.waitUntil to a parameter named waitUtil. Recommend standardizing on “waitUntil” everywhere (types, config, and method param) for clarity. Backward-compat alias can be maintained.

packages/thirdweb/src/x402/facilitator.ts (5)

17-17: Config property: standardize on waitUntil and preserve compat.

Align with SettlePaymentArgs.waitUntil and keep waitUtil as deprecated.

-  waitUtil?: WaitUtil;
+  /** @beta Preferred. Stage to wait for. */
+  waitUntil?: WaitUntil;
+  /** @deprecated Use waitUntil */
+  waitUtil?: WaitUntil;

42-43: Method param: standardize and document the param.

Align to waitUntil?: WaitUntil and add param docs on the type.

-    waitUtil?: WaitUtil,
+    /** Optional stage to wait for before responding. */
+    waitUntil?: WaitUntil,

170-175: Implementation param rename + docs.

Rename local param and document in the JSDoc block above.

-    async settle(
+    async settle(
       payload: RequestedPaymentPayload,
       paymentRequirements: RequestedPaymentRequirements,
-      waitUtil?: WaitUtil,
+      waitUntil?: WaitUntil,
     ): Promise<FacilitatorSettleResponse> {

180-181: Prefer nullish coalescing and support both config keys.

Handle both waitUntil and deprecated waitUtil.

-      const waitUtilParam = waitUtil || config.waitUtil;
+      const waitUntilParam =
+        waitUntil ?? config.waitUntil ?? config.waitUtil;

185-190: Body field name + stringify helper.

  • If adopting the rename, send waitUntil.
  • Use the shared stringify helper for consistency with verify.
-      const res = await fetch(`${url}/settle`, {
+      const res = await fetch(`${url}/settle`, {
         method: "POST",
         headers,
-        body: JSON.stringify({
+        body: stringify({
           x402Version: payload.x402Version,
           paymentPayload: payload,
           paymentRequirements: paymentRequirements,
-          ...(waitUtilParam ? { waitUtil: waitUtilParam } : {}),
+          ...(waitUntilParam ? { waitUntil: waitUntilParam } : {}),
         }),
       });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ce9220e and 635ae32.

📒 Files selected for processing (5)
  • .changeset/yellow-cameras-tease.md (1 hunks)
  • packages/thirdweb/src/exports/x402.ts (1 hunks)
  • packages/thirdweb/src/x402/facilitator.ts (4 hunks)
  • packages/thirdweb/src/x402/settle-payment.ts (3 hunks)
  • packages/thirdweb/src/x402/types.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
.changeset/*.md

📄 CodeRabbit inference engine (AGENTS.md)

.changeset/*.md: Each change in packages/* must include a changeset for the appropriate package
Version bump rules: patch for non‑API changes; minor for new/modified public API

Files:

  • .changeset/yellow-cameras-tease.md
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from @/types where applicable
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size

Files:

  • packages/thirdweb/src/x402/types.ts
  • packages/thirdweb/src/exports/x402.ts
  • packages/thirdweb/src/x402/facilitator.ts
  • packages/thirdweb/src/x402/settle-payment.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • packages/thirdweb/src/x402/types.ts
  • packages/thirdweb/src/exports/x402.ts
  • packages/thirdweb/src/x402/facilitator.ts
  • packages/thirdweb/src/x402/settle-payment.ts
**/types.ts

📄 CodeRabbit inference engine (AGENTS.md)

Provide and re‑use local type barrels in a types.ts file

Files:

  • packages/thirdweb/src/x402/types.ts
packages/thirdweb/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

packages/thirdweb/**/*.{ts,tsx}: Every public symbol must have comprehensive TSDoc with at least one compiling @example and a custom tag (@beta, @internal, @experimental, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
Lazy‑load heavy dependencies inside async paths (e.g., const { jsPDF } = await import("jspdf"))

Files:

  • packages/thirdweb/src/x402/types.ts
  • packages/thirdweb/src/exports/x402.ts
  • packages/thirdweb/src/x402/facilitator.ts
  • packages/thirdweb/src/x402/settle-payment.ts
packages/thirdweb/src/exports/**

📄 CodeRabbit inference engine (CLAUDE.md)

packages/thirdweb/src/exports/**: Export everything via exports/ directory, grouped by feature in the SDK public API
Every public symbol must have comprehensive TSDoc with at least one @example block that compiles and custom annotation tags (@beta, @internal, @experimental)

Files:

  • packages/thirdweb/src/exports/x402.ts
🧬 Code graph analysis (3)
packages/thirdweb/src/x402/types.ts (2)
packages/thirdweb/src/exports/x402.ts (2)
  • SettlePaymentArgs (13-13)
  • PaymentArgs (11-11)
packages/thirdweb/src/x402/facilitator.ts (1)
  • WaitUtil (12-12)
packages/thirdweb/src/x402/facilitator.ts (3)
packages/thirdweb/src/exports/thirdweb.ts (1)
  • ThirdwebClient (25-25)
packages/thirdweb/src/x402/schemas.ts (1)
  • FacilitatorSettleResponse (56-58)
packages/ai-sdk-provider/src/types.ts (1)
  • DEFAULT_BASE_URL (10-10)
packages/thirdweb/src/x402/settle-payment.ts (1)
packages/thirdweb/src/x402/types.ts (1)
  • SettlePaymentArgs (42-44)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/thirdweb/src/x402/facilitator.ts (1)

50-50: Nit: Confirm API expects waitUtil in the /settle payload (not waitUntil). No changes needed to DEFAULT_BASE_URL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant