Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Aug 10, 2025


PR-Codex overview

This PR focuses on enhancing the TransactionWidget, BuyWidget, and CheckoutWidget components by adding support for customizable payment tokens. It also improves error handling and refines sorting logic for payment methods.

Detailed summary

  • Added supportedTokens prop to TransactionWidget, BuyWidget, and CheckoutWidget components.
  • Updated documentation to include examples for customizing supported tokens.
  • Improved error handling in BridgeOrchestrator with console.error.
  • Refined sorting logic in usePaymentMethods for better token handling.

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

Summary by CodeRabbit

  • New Features

    • Added support for customizing the tokens users can pay with in BuyWidget, CheckoutWidget, and TransactionWidget components via a new optional supportedTokens property.
  • Bug Fixes

    • Improved token address comparison to be case-insensitive when filtering supported tokens.
    • Filtered out payment quotes with insufficient balance to improve payment method accuracy.
  • Documentation

    • Expanded usage examples and added detailed documentation for customizing supported tokens and other widget options.
  • Chores

    • Added error logging to enhance debugging in the Bridge component.

@vercel
Copy link

vercel bot commented Aug 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2025 11:10pm
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2025 11:10pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2025 11:10pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2025 11:10pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2025 11:10pm

@changeset-bot
Copy link

changeset-bot bot commented Aug 10, 2025

🦋 Changeset detected

Latest commit: 2bf979b

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

Walkthrough

This update introduces a patch changeset for the "thirdweb" package and enhances several UI widget components by documenting and exposing a new optional supportedTokens property. Internal logic in the usePaymentMethods hook is updated for case-insensitive address comparison, and error handling in the bridge orchestrator now logs errors to the console. Most changes are documentation or type enhancements.

Changes

Cohort / File(s) Change Summary
Changeset Documentation
.changeset/violet-readers-warn.md
Adds a patch changeset describing a fix for supported token address comparison in the "thirdweb" package.
Payment Methods Logic
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
Updates token address comparison to be case-insensitive by converting both addresses to lowercase before comparison in the filtering logic. Removes filtering out quotes with insufficient balance.
Bridge Orchestrator Error Handling
packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx
Adds a console error log in the handleError callback before invoking the error handler and sending an error event. No other logic is changed.
BuyWidget Prop & Docs
packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx
Adds an optional supportedTokens prop to BuyWidgetProps with documentation. Expands example usage comments to demonstrate customizing supported tokens and clarifies the meaning of the amount prop. No logic changes.
CheckoutWidget Prop & Docs
packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx
Adds a JSDoc comment for the supportedTokens prop in CheckoutWidgetProps. Significantly expands the main JSDoc with detailed usage examples, including customizing supported tokens, UI theme, and wallet connection options. No logic changes.
TransactionWidget Prop & Docs
packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx
Adds a JSDoc comment for the supportedTokens prop in TransactionWidgetProps and extends the main JSDoc with a section and example for customizing supported tokens. No logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BuyWidget/CheckoutWidget/TransactionWidget
    participant usePaymentMethods

    User->>BuyWidget/CheckoutWidget/TransactionWidget: Pass supportedTokens prop (optional)
    BuyWidget/CheckoutWidget/TransactionWidget->>usePaymentMethods: Call with supportedTokens
    usePaymentMethods->>usePaymentMethods: Filter tokens (case-insensitive address comparison)
    usePaymentMethods-->>BuyWidget/CheckoutWidget/TransactionWidget: Return filtered tokens
    BuyWidget/CheckoutWidget/TransactionWidget-->>User: Render UI with supported tokens
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

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.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between def410b and 2bf979b.

📒 Files selected for processing (6)
  • .changeset/violet-readers-warn.md (1 hunks)
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (2 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx (1 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx (3 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx (4 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx
🚧 Files skipped from review as they are similar to previous changes (5)
  • .changeset/violet-readers-warn.md
  • packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
  • packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx
⏰ 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: Size
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Build Packages
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Fix_supportedTokens_address_comparison_in_usePaymentMethods

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Aug 10, 2025
Copy link
Member Author


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.

@joaquim-verges joaquim-verges changed the title Fix supportedTokens address comparison in usePaymentMethods [SDK] Fix supportedTokens address comparison in usePaymentMethods Aug 10, 2025
@joaquim-verges joaquim-verges marked this pull request as ready for review August 10, 2025 22:33
@joaquim-verges joaquim-verges requested review from a team as code owners August 10, 2025 22:33
@github-actions
Copy link
Contributor

github-actions bot commented Aug 10, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.03 KB (0%) 1.3 s (0%) 204 ms (+112.08% 🔺) 1.5 s
thirdweb (cjs) 357.38 KB (0%) 7.2 s (0%) 353 ms (+5.74% 🔺) 7.5 s
thirdweb (minimal + tree-shaking) 5.72 KB (0%) 115 ms (0%) 136 ms (+763.62% 🔺) 250 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 77 ms (+1129.57% 🔺) 87 ms
thirdweb/react (minimal + tree-shaking) 19.16 KB (0%) 384 ms (0%) 128 ms (+318.68% 🔺) 511 ms

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: 0

🧹 Nitpick comments (11)
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (1)

125-145: Pre-normalize and use a Set for O(1) membership (avoid O(n·m) and repeated toLowerCase)

The current filter scans tokensToInclude for every quote and lowercases on each comparison. Build a Set of normalized keys once and check membership.

Apply this diff:

-      // Filter out quotes that are not included in the supportedTokens (if provided)
-      const tokensToInclude = supportedTokens
-        ? Object.keys(supportedTokens).flatMap(
-            (c: string) =>
-              supportedTokens[Number(c)]?.map((t) => ({
-                chainId: Number(c),
-                address: t.address,
-              })) ?? [],
-          )
-        : [];
-      const finalQuotes = supportedTokens
-        ? [...sufficientBalanceQuotes, ...insufficientBalanceQuotes].filter(
-            (q) =>
-              tokensToInclude.find(
-                (t) =>
-                  t.chainId === q.originToken.chainId &&
-                  t.address.toLowerCase() === q.originToken.address.toLowerCase(),
-              ),
-          )
-        : [...sufficientBalanceQuotes, ...insufficientBalanceQuotes];
+      // Filter out quotes that are not included in the supportedTokens (if provided)
+      const allQuotes = [
+        ...sufficientBalanceQuotes,
+        ...insufficientBalanceQuotes,
+      ];
+      const finalQuotes = supportedTokens
+        ? (() => {
+            const tokensToIncludeSet = new Set(
+              Object.entries(supportedTokens).flatMap(([c, tokens]) =>
+                (tokens ?? []).map(
+                  (t) => `${Number(c)}:${t.address.toLowerCase()}`,
+                ),
+              ),
+            );
+            return allQuotes.filter((q) =>
+              tokensToIncludeSet.has(
+                `${q.originToken.chainId}:${q.originToken.address.toLowerCase()}`,
+              ),
+            );
+          })()
+        : allQuotes;

Pros: faster membership checks, fewer string allocations. Cons: slight increase in upfront allocation for the Set.

.changeset/violet-readers-warn.md (1)

1-6: Changeset looks good; optional: be more specific in the summary

Consider “usePaymentMethods: make supportedTokens address comparison case-insensitive” to improve traceability in changelogs.

packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx (1)

195-197: Avoid noisy production logs; add prefix and gate in dev

Console logging is helpful during development. To keep production logs clean and add context, gate and prefix it.

Apply this diff:

-      console.error(error);
+      if (process.env.NODE_ENV !== "production") {
+        console.error("[BridgeOrchestrator] error:", error);
+      }
packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx (3)

36-39: Clarify supportedTokens semantics

Add that addresses are case-insensitive and chain IDs refer to payer origin chains the user can spend from (not necessarily the destination chain).

Apply this diff to the JSDoc:

 /**
  * Customize the supported tokens that users can pay with.
+ * Addresses are matched case-insensitively.
+ * Chain IDs map to the payer’s origin chain(s) the user can spend from.
  */

223-224: Grammar nit in example comment

Use “i.e.” capitalization and comma.

- *   amount="0.1" // in native tokens (ie. ETH)
+ *   amount="0.1" // in native tokens (i.e., ETH)

239-260: Clarify example intent for supportedTokens

To reduce confusion when destination chain differs from listed chains, note that supportedTokens chain IDs correspond to the payer’s origin chains.

 * You can customize the supported tokens that users can pay with by passing a `supportedTokens` object to the `BuyWidget` component.
 
 ```tsx
 * <BuyWidget
   client={client}
   chain={ethereum}
   amount="0.1"
-  // user will only be able to pay with these tokens
+  // Users will only be able to pay with these tokens.
+  // Note: chain IDs here refer to the payer's origin chains they can spend from.
   supportedTokens={{
     [8453]: [
       {
         address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
         name: "USDC",
         symbol: "USDC",
       },
     ],
   }}
 />

</blockquote></details>
<details>
<summary>packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx (2)</summary><blockquote>

`39-44`: **Clarify supportedTokens semantics**

Mention case-insensitive address matching and that chain IDs represent payer origin chains.


```diff
 /**
  * Customize the supported tokens that users can pay with.
+ * Addresses are matched case-insensitively.
+ * Chain IDs map to the payer’s origin chain(s) the user can spend from.
  */

237-260: Clarify example intent for supportedTokens

Add a brief note to avoid confusion when the transaction’s chain differs from the allowed payer chains.

 * You can customize the supported tokens that users can pay with by passing a `supportedTokens` object to the `TransactionWidget` component.
 
 ```tsx
 * <TransactionWidget
   client={client}
   transaction={prepareTransaction({
     to: "0x...",
     chain: ethereum,
     client: client,
   })}
-  supportedTokens={{
+  // Note: chain IDs below refer to the payer's origin chains they can spend from.
+  supportedTokens={{
     [8453]: [
       {
         address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
         name: "USDC",
         symbol: "USDC",
       },
     ],
   }}
 />

</blockquote></details>
<details>
<summary>packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx (3)</summary><blockquote>

`32-35`: **Clarify supportedTokens semantics**

Add note on case-insensitive addresses and origin-chain mapping.


```diff
 /**
  * Customize the supported tokens that users can pay with.
+ * Addresses are matched case-insensitively.
+ * Chain IDs map to the payer’s origin chain(s) the user can spend from.
  */

221-221: Grammar nit

“allows user” → “allows users”.

- * The `CheckoutWidget` component allows user to pay a given wallet for any product or service. You can register webhooks to get notified for every purchase done via the widget.
+ * The `CheckoutWidget` component allows users to pay a given wallet for any product or service. You can register webhooks to get notified for every purchase done via the widget.

238-259: Clarify example intent for supportedTokens

Add a brief comment noting that chain IDs refer to payer origin chains.

 * You can customize the supported tokens that users can pay with by passing a `supportedTokens` object to the `CheckoutWidget` component.
 
 ```tsx
 * <CheckoutWidget
   client={client}
   chain={arbitrum}
   amount="0.01"
   seller="0x123...abc"
-  // user will only be able to pay with these tokens
+  // Users will only be able to pay with these tokens.
+  // Note: chain IDs here refer to the payer's origin chains they can spend from.
   supportedTokens={{
     [8453]: [
       {
         address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
         name: "USDC",
         symbol: "USDC",
       },
     ],
   }}
  />

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between a3909e17947419728d5fecce1f83cfa50678a095 and def410b295095056032ac02767093c222e50028a.

</details>

<details>
<summary>📒 Files selected for processing (6)</summary>

* `.changeset/violet-readers-warn.md` (1 hunks)
* `packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts` (1 hunks)
* `packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx` (1 hunks)
* `packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx` (3 hunks)
* `packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx` (4 hunks)
* `packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx` (2 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>📓 Path-based instructions (2)</summary>

<details>
<summary>**/*.{ts,tsx}</summary>


**📄 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

Files:
- `packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts`
- `packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx`
- `packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx`
- `packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx`
- `packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx`

</details>
<details>
<summary>**/*.{ts,tsx,js,jsx}</summary>


**📄 CodeRabbit Inference Engine (CLAUDE.md)**

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

Files:
- `packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts`
- `packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx`
- `packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx`
- `packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx`
- `packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx`

</details>

</details><details>
<summary>🧠 Learnings (1)</summary>

<details>
<summary>📓 Common learnings</summary>

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules


</details>

</details>

</details>

<details>
<summary>⏰ 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)</summary>

* GitHub Check: Size
* GitHub Check: E2E Tests (pnpm, vite)
* GitHub Check: E2E Tests (pnpm, esbuild)
* GitHub Check: Lint Packages
* GitHub Check: E2E Tests (pnpm, webpack)
* GitHub Check: Unit Tests
* GitHub Check: Build Packages
* GitHub Check: Analyze (javascript)

</details>

<details>
<summary>🔇 Additional comments (1)</summary><blockquote>

<details>
<summary>packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (1)</summary>

`141-141`: **Correct: case-insensitive address comparison**

Lowercasing both sides fixes checksum/lowercase mismatches when filtering supported tokens. Good catch.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

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.

2 participants