Skip to content

[SDK] Handle smart account detection for inApp and ecosystem wallets #7241

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

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented May 31, 2025

Fixes TOOL-4652


PR-Codex overview

This PR focuses on improving the handling of smart wallet detection and sponsored transactions in the thirdweb package. It introduces a new implementation for identifying smart wallets and updates tests accordingly.

Detailed summary

  • Removed several test files related to smart wallets.
  • Updated createConnectionManager to use isSmartWallet instead of hasSmartAccount.
  • Replaced hasSponsoredTransactionsEnabled import path.
  • Consolidated smart wallet checks in is-smart-wallet.ts.
  • Enhanced hasSponsoredTransactionsEnabled logic for smart and in-app wallets.
  • Updated usages of hasSmartAccount to isSmartWallet across various components.
  • Added new tests for isSmartWallet and hasSponsoredTransactionsEnabled.

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

Summary by CodeRabbit

  • New Features

    • Improved detection of smart wallets, now supporting additional execution modes ("EIP4337" and "EIP7702").
    • Enhanced support for identifying wallets with sponsored transactions enabled.
  • Bug Fixes

    • More accurate handling of smart account detection for inApp and ecosystem wallets.
  • Tests

    • Added new test cases for smart wallet detection with expanded execution mode coverage.
    • Removed outdated tests related to previous smart wallet utilities.
  • Refactor

    • Streamlined logic for smart wallet and sponsored transaction detection.
    • Updated code to use new utility functions for wallet identification.

Copy link

vercel bot commented May 31, 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 May 31, 2025 9:44am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2025 9:44am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2025 9:44am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2025 9:44am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2025 9:44am

Copy link
Contributor

coderabbitai bot commented May 31, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change consolidates smart wallet detection and sponsored transaction logic into a single module, updates imports across the codebase to use the new implementations, and removes obsolete utilities and tests. The isSmartWallet and hasSponsoredTransactionsEnabled logic is centralized, with extended detection for new execution modes. Associated test coverage is updated accordingly.

Changes

File(s) Change Summary
.changeset/two-bugs-rescue.md Added a patch changeset for the "thirdweb" package, documenting improved smart account detection.
packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts Updated import of hasSponsoredTransactionsEnabled to new module location.
packages/thirdweb/src/react/core/utils/isSmartWallet.test.ts,
packages/thirdweb/src/react/core/utils/isSmartWallet.ts
Deleted old smart wallet utility and its test.
packages/thirdweb/src/react/core/utils/wallet.ts Removed hasSponsoredTransactionsEnabled and related imports.
packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx Switched from hasSmartAccount to new isSmartWallet import and updated usage.
packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx Replaced hasSmartAccount with new isSmartWallet import and refactored variable usage.
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx,
packages/thirdweb/src/react/web/ui/TransactionButton/DepositScreen.tsx
Updated import path for hasSponsoredTransactionsEnabled.
packages/thirdweb/src/wallets/manager/index.ts Replaced hasSmartAccount with isSmartWallet in connection logic.
packages/thirdweb/src/wallets/smart/get-smart-wallet-config.test.ts,
packages/thirdweb/src/wallets/smart/get-smart-wallet-config.ts
Deleted smart wallet config extraction utility and its tests.
packages/thirdweb/src/wallets/smart/is-smart-wallet.test.ts Added tests for isSmartWallet covering new execution modes and for hasSponsoredTransactionsEnabled.
packages/thirdweb/src/wallets/smart/is-smart-wallet.ts Enhanced isSmartWallet logic, added hasSponsoredTransactionsEnabled, and exported both functions.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Wallet
    participant SmartWalletUtils

    App->>SmartWalletUtils: isSmartWallet(wallet)
    SmartWalletUtils->>Wallet: getConfig()
    SmartWalletUtils-->>App: true/false (based on id, smartAccount, executionMode)

    App->>SmartWalletUtils: hasSponsoredTransactionsEnabled(wallet)
    SmartWalletUtils->>Wallet: getConfig()
    SmartWalletUtils-->>App: true/false (based on sponsorGas/gasless in config)
Loading

Assessment against linked issues

Objective Addressed Explanation
Investigate executionMode 4337 affecting active wallet in SDK (TOOL-4652)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Possibly related PRs


📜 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 88c8923 and 8eb45b7.

📒 Files selected for processing (15)
  • .changeset/two-bugs-rescue.md (1 hunks)
  • packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts (1 hunks)
  • packages/thirdweb/src/react/core/utils/isSmartWallet.test.ts (0 hunks)
  • packages/thirdweb/src/react/core/utils/isSmartWallet.ts (0 hunks)
  • packages/thirdweb/src/react/core/utils/wallet.test.ts (0 hunks)
  • packages/thirdweb/src/react/core/utils/wallet.ts (1 hunks)
  • packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx (4 hunks)
  • packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx (6 hunks)
  • packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx (1 hunks)
  • packages/thirdweb/src/react/web/ui/TransactionButton/DepositScreen.tsx (1 hunks)
  • packages/thirdweb/src/wallets/manager/index.ts (1 hunks)
  • packages/thirdweb/src/wallets/smart/get-smart-wallet-config.test.ts (0 hunks)
  • packages/thirdweb/src/wallets/smart/get-smart-wallet-config.ts (0 hunks)
  • packages/thirdweb/src/wallets/smart/is-smart-wallet.test.ts (3 hunks)
  • packages/thirdweb/src/wallets/smart/is-smart-wallet.ts (2 hunks)
✨ 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 May 31, 2025
@joaquim-verges joaquim-verges changed the title Handle smart account detection for inApp and ecosystem wallets [SDK] Handle smart account detection for inApp and ecosystem wallets May 31, 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 marked this pull request as ready for review May 31, 2025 09:24
@joaquim-verges joaquim-verges requested review from a team as code owners May 31, 2025 09:24
Copy link

linear bot commented May 31, 2025

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

🔭 Outside diff range comments (1)
packages/thirdweb/src/wallets/smart/is-smart-wallet.ts (1)

36-79: 🛠️ Refactor suggestion

hasSponsoredTransactionsEnabled may override a true value with false

let sponsoredTransactionsEnabled = false; is mutated multiple times:

if ("sponsorGas" in options) {
  sponsoredTransactionsEnabled = options.sponsorGas;   // ← true?
}
if ("gasless" in options) {
  sponsoredTransactionsEnabled = options.gasless;       // ← could overwrite to false
}

If sponsorGas = true and gasless = false, the final value becomes false, even though one flag enabled sponsorship.
The same pattern repeats for nested smartOptions.

A safer approach is to treat the flags as boolean ORs:

- sponsoredTransactionsEnabled = options.sponsorGas;
+ sponsoredTransactionsEnabled ||= options.sponsorGas;

and likewise for every subsequent assignment.

Alternatively, compute once and early-return as soon as a true is found to simplify control-flow and remove the mutable variable.

🧹 Nitpick comments (1)
packages/thirdweb/src/wallets/smart/is-smart-wallet.ts (1)

61-75: Nullish access of execMode.smartAccount

For the EIP-4337 branch you read execMode.smartAccount without guarding that it exists:

const smartOptions = execMode.smartAccount;

smartAccount is optional for 4337 wallets that rely exclusively on executionMode.
A subsequent check (smartOptions && ...) mitigates runtime errors, but you can avoid creating the extra variable when it is undefined.

Minor, but tightening the guard improves readability:

-if (execMode.mode === "EIP4337") {
-  const smartOptions = execMode.smartAccount;
-  if (smartOptions && "sponsorGas" in smartOptions) {
-    ...
-  }
-}
+if (execMode.mode === "EIP4337" && execMode.smartAccount) {
+  const smartOptions = execMode.smartAccount;
+  if ("sponsorGas" in smartOptions) {
+    ...
+  }
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e93539 and 88c8923.

📒 Files selected for processing (14)
  • .changeset/two-bugs-rescue.md (1 hunks)
  • packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts (1 hunks)
  • packages/thirdweb/src/react/core/utils/isSmartWallet.test.ts (0 hunks)
  • packages/thirdweb/src/react/core/utils/isSmartWallet.ts (0 hunks)
  • packages/thirdweb/src/react/core/utils/wallet.ts (1 hunks)
  • packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx (4 hunks)
  • packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx (6 hunks)
  • packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx (1 hunks)
  • packages/thirdweb/src/react/web/ui/TransactionButton/DepositScreen.tsx (1 hunks)
  • packages/thirdweb/src/wallets/manager/index.ts (1 hunks)
  • packages/thirdweb/src/wallets/smart/get-smart-wallet-config.test.ts (0 hunks)
  • packages/thirdweb/src/wallets/smart/get-smart-wallet-config.ts (0 hunks)
  • packages/thirdweb/src/wallets/smart/is-smart-wallet.test.ts (1 hunks)
  • packages/thirdweb/src/wallets/smart/is-smart-wallet.ts (2 hunks)
💤 Files with no reviewable changes (4)
  • packages/thirdweb/src/react/core/utils/isSmartWallet.test.ts
  • packages/thirdweb/src/wallets/smart/get-smart-wallet-config.ts
  • packages/thirdweb/src/react/core/utils/isSmartWallet.ts
  • packages/thirdweb/src/wallets/smart/get-smart-wallet-config.test.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/thirdweb/src/wallets/smart/is-smart-wallet.test.ts (1)
packages/thirdweb/src/wallets/smart/is-smart-wallet.ts (1)
  • isSmartWallet (11-31)
packages/thirdweb/src/wallets/manager/index.ts (1)
packages/thirdweb/src/wallets/smart/is-smart-wallet.ts (1)
  • isSmartWallet (11-31)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Unit Tests
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Size
  • GitHub Check: Build Packages
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (12)
packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts (1)

16-16: LGTM: Import update aligns with smart wallet logic centralization.

The import path update correctly reflects the refactor to centralize smart wallet detection logic in the wallets/smart module. The new implementation extends support for additional execution modes while maintaining backwards compatibility.

packages/thirdweb/src/react/web/ui/TransactionButton/DepositScreen.tsx (1)

7-7: LGTM: Consistent import update for centralized smart wallet logic.

The import path update is consistent with the refactor to centralize smart wallet detection logic. The function usage remains unchanged at line 104.

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx (1)

8-8: LGTM: Import update maintains consistency across UI components.

The import path update follows the same pattern as other files in this refactor, correctly moving to the centralized smart wallet module. The function usage at line 85 for determining sponsored transaction display remains intact.

.changeset/two-bugs-rescue.md (1)

1-6: LGTM: Changeset properly documents the smart wallet detection improvements.

The changeset correctly:

  • Uses a patch version bump (appropriate for non-breaking enhancements)
  • Targets the correct package ("thirdweb")
  • Provides a clear description that aligns with the PR objectives for improving smart account detection for inApp and ecosystem wallets
packages/thirdweb/src/wallets/smart/is-smart-wallet.test.ts (1)

25-51: Excellent test coverage for new execution modes.

The new test cases effectively validate the enhanced isSmartWallet function's ability to detect smart wallets based on EIP7702 and EIP4337 execution modes. The test structure is consistent with existing tests and properly mocks the wallet configuration.

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

137-137: Clean function replacement maintains existing logic.

The replacement of hasSmartAccount(wallet) with isSmartWallet(wallet) maintains the same boolean logic while providing enhanced smart wallet detection capabilities for inApp and ecosystem wallets.

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx (2)

33-33: Good import update for enhanced smart wallet detection.

The import change from hasSmartAccount to isSmartWallet brings in the enhanced detection logic for inApp and ecosystem wallets with support for EIP4337 and EIP7702 execution modes.


189-189: Excellent variable renaming to avoid naming conflicts.

Renaming the local variable from isSmartWallet to isSW effectively prevents shadowing of the imported function name while maintaining readability. All references are consistently updated throughout the component.

Also applies to: 196-196, 209-209, 219-219, 254-254, 320-320

packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx (2)

8-8: Consistent import update across platforms.

The import change aligns with the web component changes, ensuring consistent smart wallet detection logic across both web and native platforms.


329-329: Proper variable renaming maintains consistency.

The variable renaming from isSmartWallet to isSW follows the same pattern as the web component, avoiding naming conflicts while keeping all conditional logic and effect dependencies properly updated.

Also applies to: 336-336, 349-349, 380-380

packages/thirdweb/src/react/core/utils/wallet.ts (1)

10-10: Confirm that the Account type import is still required

The only change in this file is the retention of the Account type import after moving the smart-wallet utilities elsewhere.
A quick search shows Account is still referenced in useConnectedWalletDetails, so the import is indeed necessary.
No action needed, just pointing this out in case further refactors remove the last usage and the import becomes dead code.

packages/thirdweb/src/wallets/smart/is-smart-wallet.ts (1)

11-14: Good early-exit for undefined wallets

Returning false immediately for undefined input avoids downstream null checks and keeps the API predictable.
Nicely done.

Copy link
Contributor

github-actions bot commented May 31, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 62.24 KB (0%) 1.3 s (0%) 161 ms (+87.97% 🔺) 1.5 s
thirdweb (cjs) 345.34 KB (0%) 7 s (0%) 584 ms (-2.17% 🔽) 7.5 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 66 ms (+686.55% 🔺) 180 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 10 ms (+475.32% 🔺) 20 ms
thirdweb/react (minimal + tree-shaking) 19.54 KB (+0.1% 🔺) 391 ms (+0.1% 🔺) 85 ms (+697.79% 🔺) 475 ms

@joaquim-verges joaquim-verges force-pushed the Handle_smart_account_detection_for_inApp_and_ecosystem_wallets branch from 88c8923 to 8eb45b7 Compare May 31, 2025 09:32
Copy link

changeset-bot bot commented May 31, 2025

🦋 Changeset detected

Latest commit: 8eb45b7

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

This PR includes changesets to release 2 packages
Name Type
thirdweb 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

codecov bot commented May 31, 2025

Codecov Report

Attention: Patch coverage is 91.30435% with 6 lines in your changes missing coverage. Please review.

Project coverage is 55.62%. Comparing base (4e93539) to head (8eb45b7).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...hirdweb/src/react/web/ui/ConnectWallet/Details.tsx 57.14% 3 Missing ⚠️
...ages/thirdweb/src/wallets/smart/is-smart-wallet.ts 94.82% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7241   +/-   ##
=======================================
  Coverage   55.61%   55.62%           
=======================================
  Files         908      908           
  Lines       58583    58586    +3     
  Branches     4133     4138    +5     
=======================================
+ Hits        32583    32589    +6     
+ Misses      25894    25891    -3     
  Partials      106      106           
Flag Coverage Δ
packages 55.62% <91.30%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
...react/core/hooks/transaction/useSendTransaction.ts 10.59% <100.00%> (ø)
packages/thirdweb/src/react/core/utils/wallet.ts 28.57% <ø> (-9.29%) ⬇️
...onnectWallet/screens/Buy/TransactionModeScreen.tsx 8.90% <100.00%> (ø)
...c/react/web/ui/TransactionButton/DepositScreen.tsx 13.08% <100.00%> (ø)
packages/thirdweb/src/wallets/manager/index.ts 90.52% <100.00%> (-0.04%) ⬇️
...hirdweb/src/react/web/ui/ConnectWallet/Details.tsx 59.69% <57.14%> (ø)
...ages/thirdweb/src/wallets/smart/is-smart-wallet.ts 95.23% <94.82%> (-4.77%) ⬇️

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

@joaquim-verges joaquim-verges merged commit 38627d3 into main May 31, 2025
21 of 24 checks passed
@joaquim-verges joaquim-verges deleted the Handle_smart_account_detection_for_inApp_and_ecosystem_wallets branch May 31, 2025 09:39
@joaquim-verges joaquim-verges mentioned this pull request May 31, 2025
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