Skip to content

[SDK] Optimize payment token fetching in payment widgets #7536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Jul 7, 2025


PR-Codex overview

This PR focuses on optimizing the fetching of payment tokens and enhancing the insight functionality within the thirdweb package. It replaces the previous method of checking insight availability with a more efficient approach and introduces caching for improved performance.

Detailed summary

  • Updated the method for checking insight availability in assertInsightEnabled and isInsightEnabled.
  • Replaced getChainServices with getInsightEnabledChainIds for fetching enabled chains.
  • Introduced caching in the chains function for API responses.
  • Removed ChainService type and related code from utils.ts.
  • Optimized fetching logic in usePaymentMethods for better performance with owned tokens.

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

Summary by CodeRabbit

  • New Features

    • Improved optimization for fetching payment tokens in payment widgets.
    • Enhanced caching for chain data to improve performance and reduce network requests.
  • Refactor

    • Streamlined the process for identifying and filtering tokens with valid payment routes.
    • Centralized and simplified logic for detecting "insight"-enabled chains.
  • Bug Fixes

    • Added error handling for route fetching to ensure smoother operation during failures.
  • Chores

    • Updated internal documentation and metadata to reflect recent optimizations.

Copy link

changeset-bot bot commented Jul 7, 2025

🦋 Changeset detected

Latest commit: 23e55b5

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

vercel bot commented Jul 7, 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 Jul 7, 2025 8:56am
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2025 8:56am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2025 8:56am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2025 8:56am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2025 8:56am

Copy link
Contributor

coderabbitai bot commented Jul 7, 2025

Walkthrough

The changes introduce caching and refactor how insight-enabled chains and payment tokens are determined. Functions for fetching chain services are replaced by a unified approach using a new endpoint for insight-enabled chain IDs. The payment methods hook is reworked to fetch and filter tokens and routes more efficiently, and related types and utility functions are updated or removed accordingly.

Changes

File(s) Change Summary
.changeset/happy-pans-sneeze.md Added a changeset documenting a patch update for payment token fetching optimization.
packages/thirdweb/src/bridge/Chains.ts Wrapped chain data fetching in a cache, caching results for 1 hour.
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts Refactored token and route fetching/filtering logic for payment methods; improved batching and flow.
packages/thirdweb/src/chains/utils.ts Removed getChainServices; added getInsightEnabledChainIds for centralized insight checks.
packages/thirdweb/src/insight/common.ts Switched to using getInsightEnabledChainIds for insight checks, simplifying logic.
packages/thirdweb/src/chains/types.ts Removed the ChainService type definition.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant usePaymentMethods
    participant ChainsAPI
    participant InsightAPI
    participant TokenAPI
    participant RoutesAPI

    UI->>usePaymentMethods: Request payment methods
    usePaymentMethods->>ChainsAPI: Fetch all supported chains
    usePaymentMethods->>InsightAPI: Fetch insight-enabled chain IDs
    usePaymentMethods->>TokenAPI: Fetch owned tokens (across insight-enabled chains)
    loop For each chain with owned tokens
        usePaymentMethods->>RoutesAPI: Fetch routes for chain to destination token
    end
    usePaymentMethods-->>UI: Return filtered and sorted payment tokens
Loading
sequenceDiagram
    participant Consumer
    participant getInsightEnabledChainIds
    participant InsightAPI

    Consumer->>getInsightEnabledChainIds: Request enabled chain IDs
    getInsightEnabledChainIds->>InsightAPI: Fetch /chains/services?service=insight
    InsightAPI-->>getInsightEnabledChainIds: Return enabled chain ID map
    getInsightEnabledChainIds-->>Consumer: Return enabled chain ID list
Loading

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 6928c5a and 23e55b5.

📒 Files selected for processing (6)
  • .changeset/happy-pans-sneeze.md (1 hunks)
  • packages/thirdweb/src/bridge/Chains.ts (2 hunks)
  • packages/thirdweb/src/chains/types.ts (0 hunks)
  • packages/thirdweb/src/chains/utils.ts (1 hunks)
  • packages/thirdweb/src/insight/common.ts (1 hunks)
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (4 hunks)
💤 Files with no reviewable changes (1)
  • packages/thirdweb/src/chains/types.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/thirdweb/src/bridge/Chains.ts
  • packages/thirdweb/src/insight/common.ts
  • .changeset/happy-pans-sneeze.md
  • packages/thirdweb/src/chains/utils.ts
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
⏰ 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: Size
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: Build Packages
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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 Jul 7, 2025
@joaquim-verges joaquim-verges changed the title Optimize payment token fetching in payment widgets [SDK] Optimize payment token fetching in payment widgets Jul 7, 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.

Copy link
Contributor

github-actions bot commented Jul 7, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.23 KB (+0.05% 🔺) 1.3 s (+0.05% 🔺) 247 ms (+196.38% 🔺) 1.6 s
thirdweb (cjs) 352.81 KB (+0.04% 🔺) 7.1 s (+0.04% 🔺) 705 ms (+14.78% 🔺) 7.8 s
thirdweb (minimal + tree-shaking) 5.69 KB (0%) 114 ms (0%) 122 ms (+2291.2% 🔺) 236 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 40 ms (+2571.05% 🔺) 50 ms
thirdweb/react (minimal + tree-shaking) 19.57 KB (0%) 392 ms (0%) 92 ms (+612.44% 🔺) 484 ms

Copy link

codecov bot commented Jul 7, 2025

Codecov Report

Attention: Patch coverage is 24.39024% with 93 lines in your changes missing coverage. Please review.

Project coverage is 51.87%. Comparing base (0ec6142) to head (6928c5a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...thirdweb/src/react/core/hooks/usePaymentMethods.ts 2.56% 76 Missing ⚠️
packages/thirdweb/src/bridge/Chains.ts 60.86% 9 Missing ⚠️
packages/thirdweb/src/bridge/Routes.ts 25.00% 3 Missing ⚠️
packages/thirdweb/src/chains/utils.ts 70.00% 3 Missing ⚠️
packages/thirdweb/src/insight/common.ts 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7536      +/-   ##
==========================================
- Coverage   51.89%   51.87%   -0.03%     
==========================================
  Files         954      954              
  Lines       64342    64358      +16     
  Branches     4241     4238       -3     
==========================================
- Hits        33393    33386       -7     
- Misses      30841    30864      +23     
  Partials      108      108              
Flag Coverage Δ
packages 51.87% <24.39%> (-0.03%) ⬇️
Files with missing lines Coverage Δ
packages/thirdweb/src/insight/common.ts 76.47% <75.00%> (-23.53%) ⬇️
packages/thirdweb/src/bridge/Routes.ts 77.41% <25.00%> (-3.62%) ⬇️
packages/thirdweb/src/chains/utils.ts 90.58% <70.00%> (+2.94%) ⬆️
packages/thirdweb/src/bridge/Chains.ts 68.96% <60.86%> (+13.96%) ⬆️
...thirdweb/src/react/core/hooks/usePaymentMethods.ts 4.96% <2.56%> (-0.79%) ⬇️

... and 4 files with indirect coverage changes

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

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

132-158: Consider the performance implications of concurrent route fetching.

While the per-chain route fetching with error handling is well-implemented, the TODO comment suggests this approach may still be inefficient. The Promise.all with multiple concurrent API calls could impact performance if there are many chains with owned tokens.

Consider these optimizations:

  1. Batch route fetching using the chainIds parameter more effectively
  2. Implement request throttling or batching to avoid overwhelming the API
  3. Add metrics to measure performance impact
// Instead of fetching routes per chain individually, batch them:
- await Promise.all(
-   chainsWithOwnedTokens.map(async (chainId) => {
-     const routesForChain = await routes({
-       chainIds: chainsWithOwnedTokens,
-       // ... other params
-       originChainId: chainId,
-     });
+     const allRoutesForChains = await routes({
+       chainIds: chainsWithOwnedTokens,
+       client,
+       destinationChainId: destinationToken.chainId,
+       destinationTokenAddress: destinationToken.address,
+       includePrices: true,
+       limit: 500, // Higher limit for batched request
+       maxSteps: 3,
+       sortBy: "popularity",
+     });

163-174: Complex token filtering logic - consider extracting to helper function.

The token filtering logic is correct but complex. Consider extracting this to a separate helper function for better readability and testability.

+ function filterValidOwnedTokens(
+   allOwnedTokens: Array<{ balance: bigint; originToken: Token }>,
+   allValidOriginTokens: Map<string, Token>
+ ): OwnedTokenWithQuote[] {
+   const validOwnedTokens: OwnedTokenWithQuote[] = [];
+   
+   for (const ownedToken of allOwnedTokens) {
+     const tokenKey = `${ownedToken.originToken.chainId}-${ownedToken.originToken.address.toLowerCase()}`;
+     const validOriginToken = allValidOriginTokens.get(tokenKey);
+     
+     if (validOriginToken) {
+       validOwnedTokens.push({
+         balance: ownedToken.balance,
+         originAmount: 0n,
+         originToken: validOriginToken,
+       });
+     }
+   }
+   
+   return validOwnedTokens;
+ }

// 5. Filter owned tokens to only include valid origin tokens
- const validOwnedTokens: OwnedTokenWithQuote[] = [];
- 
- for (const ownedToken of allOwnedTokens) {
-   const tokenKey = `${ownedToken.originToken.chainId}-${ownedToken.originToken.address.toLowerCase()}`;
-   const validOriginToken = allValidOriginTokens.get(tokenKey);
- 
-   if (validOriginToken) {
-     validOwnedTokens.push({
-       balance: ownedToken.balance,
-       originAmount: 0n,
-       originToken: validOriginToken, // Use the token with pricing info from routes
-     });
-   }
- }
+ const validOwnedTokens = filterValidOwnedTokens(allOwnedTokens, allValidOriginTokens);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d23c9f2 and cd01e2c.

📒 Files selected for processing (4)
  • packages/thirdweb/src/bridge/Routes.ts (3 hunks)
  • packages/thirdweb/src/chains/utils.ts (1 hunks)
  • packages/thirdweb/src/insight/common.ts (1 hunks)
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: Write idiomatic TypeScript with explicit function declarations ...

**/*.{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
Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

📄 Source: CodeRabbit Inference Engine (CLAUDE.md)

List of files the instruction was applied to:

  • packages/thirdweb/src/bridge/Routes.ts
  • packages/thirdweb/src/chains/utils.ts
  • packages/thirdweb/src/insight/common.ts
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
🧠 Learnings (5)
📓 Common learnings
Learnt from: MananTank
PR: thirdweb-dev/js#7298
File: apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx:424-424
Timestamp: 2025-06-06T23:46:08.795Z
Learning: The thirdweb project has an ESLint rule that restricts direct usage of `defineChain`. When it's necessary to use `defineChain` directly, it's acceptable to disable the rule with `// eslint-disable-next-line no-restricted-syntax`.
packages/thirdweb/src/bridge/Routes.ts (1)
Learnt from: MananTank
PR: thirdweb-dev/js#7152
File: apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/table.tsx:304-313
Timestamp: 2025-05-26T16:27:26.443Z
Learning: The `useChainSlug` hook returns `string | number`, not `string | undefined` as previously assumed. It does not return undefined values.
packages/thirdweb/src/chains/utils.ts (2)
Learnt from: MananTank
PR: thirdweb-dev/js#7298
File: apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx:424-424
Timestamp: 2025-06-06T23:46:08.795Z
Learning: The thirdweb project has an ESLint rule that restricts direct usage of `defineChain`. When it's necessary to use `defineChain` directly, it's acceptable to disable the rule with `// eslint-disable-next-line no-restricted-syntax`.
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.488Z
Learning: Applies to **/*.test.{ts,tsx} : Use `FORKED_ETHEREUM_CHAIN` for mainnet interactions and `ANVIL_CHAIN` for isolated tests
packages/thirdweb/src/insight/common.ts (2)
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.488Z
Learning: Applies to **/*.test.{ts,tsx} : Use `FORKED_ETHEREUM_CHAIN` for mainnet interactions and `ANVIL_CHAIN` for isolated tests
Learnt from: MananTank
PR: thirdweb-dev/js#7298
File: apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx:424-424
Timestamp: 2025-06-06T23:46:08.795Z
Learning: The thirdweb project has an ESLint rule that restricts direct usage of `defineChain`. When it's necessary to use `defineChain` directly, it's acceptable to disable the rule with `// eslint-disable-next-line no-restricted-syntax`.
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (18)
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{tsx,ts} : Client Components: Handle interactive UI with React hooks (`useState`, `useEffect`, React Query, wallet hooks)
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to src/wallets/**/*.{ts,tsx} : Support EIP-1193, EIP-5792, EIP-7702 standards in wallet architecture
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to src/wallets/**/*.{ts,tsx} : Unified `Wallet` and `Account` interfaces in wallet architecture
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to src/wallets/**/*.{ts,tsx} : Support for in-app wallets (social/email login) in wallet architecture
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-06-30T10:26:04.389Z
Learning: Applies to dashboard/**/components/*.client.tsx : Interactive UI that relies on hooks (`useState`, `useEffect`, React Query, wallet hooks).
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to src/wallets/**/*.{ts,tsx} : Smart wallets with account abstraction in wallet architecture
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-06-30T10:26:04.389Z
Learning: Applies to dashboard/**/hooks/**/*.{ts,tsx} : Prefer API routes or server actions to keep tokens secret; the browser only sees relative paths.
Learnt from: MananTank
PR: thirdweb-dev/js#7152
File: apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/table.tsx:304-313
Timestamp: 2025-05-26T16:27:26.443Z
Learning: The `useChainSlug` hook returns `string | number`, not `string | undefined` as previously assumed. It does not return undefined values.
Learnt from: MananTank
PR: thirdweb-dev/js#7177
File: apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_hooks/useTokenPriceData.ts:49-49
Timestamp: 2025-05-27T19:55:25.056Z
Learning: In the ERC20 public pages token price data hook (`useTokenPriceData.ts`), direct array access on `json.data[0]` without optional chaining is intentionally correct and should not be changed to use safety checks.
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-06-30T10:26:04.389Z
Learning: Applies to dashboard/**/components/*.client.tsx : Anything that consumes hooks from `@tanstack/react-query` or thirdweb SDKs.
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{tsx,ts} : Client Side Data Fetching: Wrap calls in React Query (`@tanstack/react-query`)
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-06-30T10:26:04.389Z
Learning: Applies to dashboard/**/hooks/**/*.{ts,tsx} : Use React Query (`@tanstack/react-query`) for all client data fetching.
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{tsx,ts} : Client Side Data Fetching: Use descriptive, stable `queryKeys` for cache hits
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{tsx,ts} : Client Side Data Fetching: Keep tokens secret via internal API routes or server actions
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{tsx,ts} : Server Components: Perform heavy data fetching
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.489Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{tsx,ts} : Client Components: Support fast transitions with prefetched data
Learnt from: MananTank
PR: thirdweb-dev/js#7298
File: apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx:424-424
Timestamp: 2025-06-06T23:46:08.795Z
Learning: The thirdweb project has an ESLint rule that restricts direct usage of `defineChain`. When it's necessary to use `defineChain` directly, it's acceptable to disable the rule with `// eslint-disable-next-line no-restricted-syntax`.
Learnt from: joaquim-verges
PR: thirdweb-dev/js#7268
File: packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts:210-216
Timestamp: 2025-06-03T23:44:40.243Z
Learning: EIP7702 wallets do not need special handling for switching chains, unlike EIP4337 wallets which require reconnection when switching chains. In the switchChain method condition, EIP7702 should be intentionally excluded from the reconnection logic.
🧬 Code Graph Analysis (1)
packages/thirdweb/src/insight/common.ts (1)
packages/thirdweb/src/chains/utils.ts (1)
  • getInsightEnabledChainIds (387-406)
⏰ 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, vite)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Size
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
packages/thirdweb/src/bridge/Routes.ts (1)

135-135: LGTM! Clean implementation of chainIds filtering.

The addition of the chainIds parameter follows the established patterns in the codebase and correctly implements array-to-comma-separated string conversion for the query parameter. This enhancement supports the PR's optimization goal by allowing more targeted route fetching.

Also applies to: 167-169, 199-199

packages/thirdweb/src/chains/utils.ts (1)

387-406: LGTM! Well-implemented caching strategy for insight-enabled chains.

The function correctly implements the optimization mentioned in the PR objectives. The 1-day cache time is appropriate for this relatively stable data, and the error handling is robust. This centralized approach will reduce redundant API calls compared to checking services per chain.

packages/thirdweb/src/insight/common.ts (1)

2-2: Excellent refactor! More efficient insight-enabled checking.

The refactoring from per-chain service checks to a single cached list lookup significantly improves performance while maintaining the same functionality. The use of every() and includes() methods is appropriate, and the error message construction correctly identifies non-enabled chains.

Also applies to: 5-6, 10-12, 19-20

packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (3)

2-2: Good imports for the refactored approach.

The new imports support the optimized multi-step approach described in the PR objectives, leveraging caching mechanisms for better performance.

Also applies to: 5-8


63-72: Efficient parallel fetching and filtering strategy.

Using Promise.all to fetch chains and insight-enabled chain IDs in parallel, then filtering to insight-enabled chains is a good optimization that reduces unnecessary token fetching.


80-80: Good optimization: Increased token limit from 100 to 500.

This reduces pagination overhead and aligns with the PR's goal of optimizing payment token fetching.

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