Skip to content

[SDK] Improve WalletConnect connection and auto-connection flow #7746

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 29, 2025


PR-Codex overview

This PR focuses on improving the walletConnect connection and auto-connection flow, enhancing mobile support, and cleaning up the code for better readability and maintainability.

Detailed summary

  • Updated isAndroid and isIOS functions to remove export.
  • Enhanced autoConnectWC to handle session disconnection.
  • Improved onDisplayUri to support mobile app links.
  • Cleaned up QR overlay creation logic.
  • Removed redundant platform URI checks in WalletConnectStandaloneConnection.

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

Summary by CodeRabbit

  • New Features

    • Improved WalletConnect connection process with enhanced auto-connection flow.
    • Mobile devices now open wallet apps directly via deep links, while desktop users continue to see a QR code for connection.
  • Bug Fixes

    • Simplified and unified connection logic across platforms, reducing inconsistencies and potential errors.
  • Chores

    • Enhanced error logging during connection attempts for better troubleshooting.

Copy link

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

Copy link

changeset-bot bot commented Jul 29, 2025

🦋 Changeset detected

Latest commit: a3384ca

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

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

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

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

Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Walkthrough

This update refactors the WalletConnect connection and auto-connection flows within the "thirdweb" package. The changes simplify platform-specific logic, unify mobile deep-link handling, improve error logging, and adjust the session management for WalletConnect providers. No public API signatures are altered.

Changes

Cohort / File(s) Change Summary
WalletConnect React Connection Logic
packages/thirdweb/src/react/web/wallets/shared/WalletConnectConnection.tsx
Simplifies platform-specific logic by removing explicit Android/iOS checks and unifying URI/deep-link handling for WalletConnect connections. Adds error logging in the connection callback. Removes window-opening logic in standalone connection.
WalletConnect Connection Flow Core
packages/thirdweb/src/wallets/create-wallet.ts
Refactors WalletConnect URI display logic to support mobile deep linking using wallet metadata and formatted URLs, preserves desktop QR code modal, and enables custom onDisplayUri overrides. Adds imports for wallet info retrieval and URL formatting.
WalletConnect Provider Session Management
packages/thirdweb/src/wallets/wallet-connect/controller.ts
Removes conditional session check before calling provider.connect(). Adds session existence check and disconnect logic in auto-connect flow. Changes account retrieval from provider.enable() to extracting from provider.session.namespaces. Maintains error handling for missing accounts.
Mobile Platform Detection Utilities
packages/thirdweb/src/utils/web/isMobile.ts
Removes export keywords from isAndroid and isIOS functions, making them internal to the module. The isMobile function continues to use these internally.
Release Notes
.changeset/fifty-bars-rest.md
Documents the patch update, summarizing improvements to WalletConnect connection and auto-connection flows. No code changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant WalletConnectProvider
    participant Wallet App
    participant QRModal

    User->>App: Initiates WalletConnect connection
    App->>WalletConnectProvider: Request connection
    alt Mobile device
        App->>Wallet App: Open deep link (native/universal) with WC URI
    else Desktop
        App->>QRModal: Display QR code overlay with WC URI
        User->>Wallet App: Scan QR code
    end
    Wallet App->>WalletConnectProvider: Establish session
    WalletConnectProvider->>App: Connection established
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–25 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 33b713c and a3384ca.

📒 Files selected for processing (5)
  • .changeset/fifty-bars-rest.md (1 hunks)
  • packages/thirdweb/src/react/web/wallets/shared/WalletConnectConnection.tsx (2 hunks)
  • packages/thirdweb/src/utils/web/isMobile.ts (2 hunks)
  • packages/thirdweb/src/wallets/create-wallet.ts (2 hunks)
  • packages/thirdweb/src/wallets/wallet-connect/controller.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/fifty-bars-rest.md
  • packages/thirdweb/src/wallets/create-wallet.ts
  • packages/thirdweb/src/react/web/wallets/shared/WalletConnectConnection.tsx
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

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

Files:

  • packages/thirdweb/src/utils/web/isMobile.ts
  • packages/thirdweb/src/wallets/wallet-connect/controller.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

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

Files:

  • packages/thirdweb/src/utils/web/isMobile.ts
  • packages/thirdweb/src/wallets/wallet-connect/controller.ts
packages/thirdweb/src/wallets/**

📄 CodeRabbit Inference Engine (CLAUDE.md)

packages/thirdweb/src/wallets/**: Unified Wallet and Account interfaces in wallet architecture
Support for in-app wallets (social/email login)
Smart wallets with account abstraction
EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules

Files:

  • packages/thirdweb/src/wallets/wallet-connect/controller.ts
🧠 Learnings (3)
📓 Common learnings
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/** : Support for in-app wallets (social/email login)
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/** : Unified `Wallet` and `Account` interfaces in wallet architecture
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
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/** : Smart wallets with account abstraction
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.
Learnt from: jnsdls
PR: thirdweb-dev/js#7364
File: apps/dashboard/src/app/(app)/account/components/AccountHeader.tsx:36-41
Timestamp: 2025-06-18T02:13:34.500Z
Learning: In the logout flow in apps/dashboard/src/app/(app)/account/components/AccountHeader.tsx, when `doLogout()` fails, the cleanup steps (resetAnalytics(), wallet disconnect, router refresh) should NOT execute. This is intentional to maintain consistency - if server-side logout fails, client-side cleanup should not occur.
Learnt from: MananTank
PR: thirdweb-dev/js#7227
File: apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/OpenEditionMetadata.tsx:26-26
Timestamp: 2025-05-30T17:14:25.332Z
Learning: The ModuleCardUIProps interface already includes a client prop of type ThirdwebClient, so when components use `Omit<ModuleCardUIProps, "children" | "updateButton">`, they inherit the client prop without needing to add it explicitly.
packages/thirdweb/src/utils/web/isMobile.ts (6)

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to src/exports/react.native.ts : React Native specific exports are in src/exports/react.native.ts

Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*.{ts,tsx} : Export default async functions without 'use client'; – they run on the Node edge.

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/exports/** : Export everything via exports/ directory, grouped by feature in the SDK public API

Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard//api//*.{ts,tsx} : Prefix files with import "server-only"; so they never end up in the client bundle.

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{ts,tsx} : Server Components (Node edge): Start files with import "server-only";

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/react-native-adapter/** : Mobile platform shims are in packages/react-native-adapter/

packages/thirdweb/src/wallets/wallet-connect/controller.ts (7)

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/** : Unified Wallet and Account interfaces in wallet architecture

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/** : Smart wallets with account abstraction

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

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to test/src/test-wallets.ts : Predefined test accounts are in test/src/test-wallets.ts

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/** : Support for in-app wallets (social/email login)

Learnt from: joaquim-verges
PR: #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.

Learnt from: jnsdls
PR: #7364
File: apps/dashboard/src/app/(app)/account/components/AccountHeader.tsx:36-41
Timestamp: 2025-06-18T02:13:34.500Z
Learning: In the logout flow in apps/dashboard/src/app/(app)/account/components/AccountHeader.tsx, when doLogout() fails, the cleanup steps (resetAnalytics(), wallet disconnect, router refresh) should NOT execute. This is intentional to maintain consistency - if server-side logout fails, client-side cleanup should not occur.

⏰ 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: Size
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
packages/thirdweb/src/utils/web/isMobile.ts (3)

6-13: LGTM! Good API design improvement.

Internalizing the isAndroid function supports the unified approach to mobile detection. The function logic correctly handles edge cases and uses consistent platform detection.


18-28: LGTM! Comprehensive iOS detection with good API design.

The function correctly handles both iPhone/iPod and iPad detection using the standard maxTouchPoints approach. Internalizing this function promotes the use of the unified isMobile() API.


33-35: LGTM! Clean public API for mobile detection.

The isMobile function provides a clean, unified interface for mobile platform detection. This approach aligns perfectly with the PR objective of simplifying platform-specific logic across the codebase.

packages/thirdweb/src/wallets/wallet-connect/controller.ts (3)

126-147: LGTM! Connection flow simplification looks good.

Removing the conditional session check and calling provider.connect() unconditionally is the correct approach. The WalletConnect Universal Provider is designed to handle existing sessions internally, which simplifies the connection logic while maintaining proper namespace configuration.


224-227: Excellent session validation improvement.

Adding explicit session validation with cleanup is a great improvement. This ensures we fail fast during auto-connect when no valid session exists, and calling provider.disconnect() properly cleans up any stale provider state.


230-231: Improved account retrieval method.

The new approach of extracting the account address directly from provider.session.namespaces[NAMESPACE].accounts is more efficient than the previous provider.enable() method, as it avoids an additional RPC call and works directly with the session data.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Improve_WalletConnect_connection_and_auto-connection_flow

🪧 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 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 Jul 29, 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 Improve WalletConnect connection and auto-connection flow [SDK] Improve WalletConnect connection and auto-connection flow Jul 29, 2025
@joaquim-verges joaquim-verges marked this pull request as ready for review July 29, 2025 03:12
@joaquim-verges joaquim-verges requested review from a team as code owners July 29, 2025 03:12
Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.16 KB (0%) 1.3 s (0%) 233 ms (+48.44% 🔺) 1.5 s
thirdweb (cjs) 352.91 KB (0%) 7.1 s (0%) 1.3 s (-4.65% 🔽) 8.3 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 94 ms (+1036.1% 🔺) 208 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 14 ms (+356.82% 🔺) 24 ms
thirdweb/react (minimal + tree-shaking) 19.24 KB (0%) 385 ms (0%) 65 ms (+230.2% 🔺) 450 ms

Copy link

codecov bot commented Jul 29, 2025

Codecov Report

❌ Patch coverage is 6.02410% with 78 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.22%. Comparing base (b371bf9) to head (a3384ca).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/thirdweb/src/wallets/create-wallet.ts 4.44% 43 Missing ⚠️
.../thirdweb/src/wallets/wallet-connect/controller.ts 0.00% 26 Missing ⚠️
...act/web/wallets/shared/WalletConnectConnection.tsx 10.00% 9 Missing ⚠️

❌ Your patch status has failed because the patch coverage (6.02%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7746   +/-   ##
=======================================
  Coverage   56.22%   56.22%           
=======================================
  Files         905      905           
  Lines       58880    58864   -16     
  Branches     4134     4131    -3     
=======================================
- Hits        33106    33098    -8     
+ Misses      25669    25663    -6     
+ Partials      105      103    -2     
Flag Coverage Δ
packages 56.22% <6.02%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
packages/thirdweb/src/utils/web/isMobile.ts 85.71% <100.00%> (ø)
...act/web/wallets/shared/WalletConnectConnection.tsx 5.28% <10.00%> (+0.76%) ⬆️
.../thirdweb/src/wallets/wallet-connect/controller.ts 9.63% <0.00%> (-0.05%) ⬇️
packages/thirdweb/src/wallets/create-wallet.ts 23.22% <4.44%> (-0.67%) ⬇️

... and 5 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 4f38198 into main Jul 29, 2025
24 of 25 checks passed
@joaquim-verges joaquim-verges deleted the Improve_WalletConnect_connection_and_auto-connection_flow branch July 29, 2025 03:31
@joaquim-verges joaquim-verges mentioned this pull request Jul 29, 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