Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Dec 3, 2025


PR-Codex overview

This PR introduces caching and timeout mechanisms for fetching wallet capabilities, improving error handling and performance in the thirdweb package.

Detailed summary

  • Added caching for supportsAtomic results in supportAtomicCache.
  • Implemented a 5-second timeout for fetching capabilities.
  • Enhanced error handling in waitForCallsReceipt by logging errors.
  • Updated parameters for wallet_getCapabilities to include an optional chainIdFilter.
  • Threw an ApiError for transaction failures in useStepExecutor.

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

Summary by CodeRabbit

  • New Features

    • Introduced caching and timeout for capability checks to improve responsiveness and reduce repeated calls
    • Capability requests now support optional chain filtering for more accurate results
  • Bug Fixes

    • Improved error handling for failed transaction receipts with clearer reporting
    • Enhanced error logging to aid troubleshooting and prevent hangs during capability verification

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 3, 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 Dec 3, 2025 1:52am
nebula Ready Ready Preview Comment Dec 3, 2025 1:52am
thirdweb_playground Ready Ready Preview Comment Dec 3, 2025 1:52am
thirdweb-www Ready Ready Preview Comment Dec 3, 2025 1:52am
wallet-ui Ready Ready Preview Comment Dec 3, 2025 1:52am

@changeset-bot
Copy link

changeset-bot bot commented Dec 3, 2025

🦋 Changeset detected

Latest commit: 36aeb50

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

This PR includes changesets to release 4 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter Patch
wagmi-inapp 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 Dec 3, 2025

Walkthrough

Adds a caching layer and a 5s timeout for capabilities fetching in the step executor, improves error handling for failed transaction receipts, logs errors in calls-receipt polling, and allows chainId filtering when requesting injected wallet capabilities.

Changes

Cohort / File(s) Change Summary
Step executor — caching & timeout
packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
Added in-memory cache for supportsAtomic keyed by account address + chainId; use Promise.race with a 5s timeout when calling capabilitiesFn; cache only successful results; on timeout/error return false without caching; added throwing ApiError when transaction receipt indicates failure.
Calls receipt logging
packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.ts
Catch block now accepts and logs the error ("waitForCallsReceipt error") while preserving retry-on-next-block behavior.
Injected wallet capabilities request
packages/thirdweb/src/wallets/injected/index.ts
getCapabilities now includes an optional chainId filter in the params payload (adds numberToHex(chainIdFilter) or undefined), enabling capability queries scoped by chainId.
Release metadata
.changeset/twelve-grapes-drop.md
New changeset documenting a patch release that introduces caching and timeout mechanisms for capabilities.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Inspect cache key composition and expiration/eviction assumptions in useStepExecutor.ts.
  • Verify concurrency safety (simultaneous requests for same key) and whether duplicate inflight fetches are handled.
  • Confirm Promise.race timeout semantics won't leave unresolved promises causing resource issues.
  • Review the ApiError throwing path for correct propagation and user-facing message consistency.
  • Check the injected wallet params change for observables/serialization impacts when undefined is included.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The description includes a PR-Codex summary with detailed information about changes, but lacks the required template sections like issue tag, notes for reviewer, and how to test. Fill in the required template sections: add the Linear issue tag (TEAM-0000 format), provide notes for reviewers about important changes, and specify how to test these changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main changes: adding caching and timeout mechanisms for fetching capabilities.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch _SDK_Add_caching_and_timeout_for_fetching_capabilities

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.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Dec 3, 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

@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 (1)
packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (1)

727-763: Well-structured caching and timeout implementation.

The logic is sound:

  • Cache lookup correctly checks !== undefined to handle false values
  • 5-second timeout via Promise.race prevents hanging on slow/unresponsive wallets
  • Intentionally not caching failures allows retries to succeed later

One consideration: the module-level cache is unbounded. For typical usage this is fine, but in long-running apps with many accounts/chains, entries accumulate indefinitely.

If cache growth becomes a concern, consider using an LRU cache or adding a TTL:

-const supportsAtomicCache = new Map<string, boolean>();
+const supportsAtomicCache = new Map<string, { value: boolean; timestamp: number }>();
+const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes

Then check Date.now() - cached.timestamp < CACHE_TTL_MS before returning cached values.

📜 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 9e43da4 and 80503f5.

📒 Files selected for processing (3)
  • .changeset/twelve-grapes-drop.md (1 hunks)
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (2 hunks)
  • packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.ts (1 hunks)
🧰 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 TypeScript 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 in TypeScript
Avoid any and unknown in TypeScript unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.) in TypeScript

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

Files:

  • packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.ts
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
packages/thirdweb/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

packages/thirdweb/src/**/*.{ts,tsx}: Comment only ambiguous logic in SDK code; avoid restating TypeScript in prose
Load heavy dependencies inside async paths to keep initial bundle lean (e.g. const { jsPDF } = await import("jspdf");)

Lazy-load heavy dependencies inside async paths to keep the initial bundle lean (e.g., const { jsPDF } = await import('jspdf');)

Files:

  • packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.ts
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
**/*.{js,jsx,ts,tsx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Biome governs formatting and linting; its rules live in biome.json. Run pnpm fix & pnpm lint before committing, ensure there are no linting errors

Files:

  • packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.ts
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Lazy-import optional features; avoid top-level side-effects

Files:

  • packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.ts
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
🧬 Code graph analysis (1)
packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (1)
packages/thirdweb/src/bridge/types/Errors.ts (1)
  • ApiError (11-36)
⏰ 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). (3)
  • GitHub Check: Vercel Agent Review
  • GitHub Check: Size
  • GitHub Check: Unit Tests
🔇 Additional comments (3)
.changeset/twelve-grapes-drop.md (1)

1-5: LGTM!

Changeset correctly describes the feature and patch version bump is appropriate for this non-breaking enhancement.

packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.ts (1)

97-100: LGTM!

Good improvement to surface errors for debugging while preserving the retry behavior. The comment clearly explains the intent.

packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (1)

386-394: LGTM!

Properly handles transaction failure by throwing a typed ApiError with a user-friendly message. This ensures failures are propagated through the existing error handling flow.

@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

❌ Patch coverage is 7.69231% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.70%. Comparing base (9e43da4) to head (36aeb50).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/thirdweb/src/react/core/hooks/useStepExecutor.ts 3.03% 32 Missing ⚠️
packages/thirdweb/src/wallets/injected/index.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8485      +/-   ##
==========================================
- Coverage   54.73%   54.70%   -0.03%     
==========================================
  Files         920      920              
  Lines       61013    61046      +33     
  Branches     4145     4143       -2     
==========================================
+ Hits        33395    33398       +3     
- Misses      27516    27546      +30     
  Partials      102      102              
Flag Coverage Δ
packages 54.70% <7.69%> (-0.03%) ⬇️
Files with missing lines Coverage Δ
...dweb/src/wallets/eip5792/wait-for-calls-receipt.ts 92.15% <100.00%> (+0.15%) ⬆️
packages/thirdweb/src/wallets/injected/index.ts 30.95% <0.00%> (-0.23%) ⬇️
...s/thirdweb/src/react/core/hooks/useStepExecutor.ts 1.27% <3.03%> (+0.12%) ⬆️

... and 1 file 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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

size-limit report 📦

Path Size
@thirdweb-dev/nexus (esm) 104.88 KB (0%)
@thirdweb-dev/nexus (cjs) 316.6 KB (0%)

@joaquim-verges joaquim-verges force-pushed the _SDK_Add_caching_and_timeout_for_fetching_capabilities branch from 80503f5 to 36aeb50 Compare December 3, 2025 01:39
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 (1)
packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (1)

727-764: Consider logging timeout events for debugging.

The caching implementation correctly avoids caching timeout/error cases (line 761), which prevents persistent false negatives. However, when capabilities fetch times out, returning false means the wallet will fall back to non-atomic transactions even if atomic batching is actually supported.

Consider adding debug logging when timeouts occur to help diagnose slow capability checks:

  } catch (error) {
-   // Timeout or error fetching capabilities, assume not supported, but dont cache the result
+   // Timeout or error fetching capabilities, assume not supported, but dont cache the result
+   console.debug(`Failed to fetch capabilities for ${account.address} on chain ${chainId}:`, error);
    return false;
  }

This will help identify wallets with slow capability responses during development and testing.

📜 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 80503f5 and 36aeb50.

📒 Files selected for processing (4)
  • .changeset/twelve-grapes-drop.md (1 hunks)
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (2 hunks)
  • packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.ts (1 hunks)
  • packages/thirdweb/src/wallets/injected/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/thirdweb/src/wallets/eip5792/wait-for-calls-receipt.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 TypeScript 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 in TypeScript
Avoid any and unknown in TypeScript unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.) in TypeScript

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

Files:

  • packages/thirdweb/src/wallets/injected/index.ts
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
packages/thirdweb/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

packages/thirdweb/src/**/*.{ts,tsx}: Comment only ambiguous logic in SDK code; avoid restating TypeScript in prose
Load heavy dependencies inside async paths to keep initial bundle lean (e.g. const { jsPDF } = await import("jspdf");)

Lazy-load heavy dependencies inside async paths to keep the initial bundle lean (e.g., const { jsPDF } = await import('jspdf');)

Files:

  • packages/thirdweb/src/wallets/injected/index.ts
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
**/*.{js,jsx,ts,tsx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Biome governs formatting and linting; its rules live in biome.json. Run pnpm fix & pnpm lint before committing, ensure there are no linting errors

Files:

  • packages/thirdweb/src/wallets/injected/index.ts
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Lazy-import optional features; avoid top-level side-effects

Files:

  • packages/thirdweb/src/wallets/injected/index.ts
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
🧬 Code graph analysis (1)
packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (1)
packages/thirdweb/src/bridge/types/Errors.ts (1)
  • ApiError (11-36)
⏰ 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). (9)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Vercel Agent Review
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
.changeset/twelve-grapes-drop.md (1)

1-5: LGTM!

The changeset correctly documents the patch release with a clear description of the feature.

packages/thirdweb/src/wallets/injected/index.ts (1)

381-384: LGTM!

The chainId filter implementation correctly wraps the hex-encoded chainId in an array format as expected by the wallet_getCapabilities RPC method, and properly handles the optional parameter case.

packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (1)

387-394: LGTM!

The error handling correctly throws an ApiError when the transaction fails, with a user-friendly message suggesting alternative actions.

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