Skip to content
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

refactor(walletconnect): migrate to WalletKit and implement multi-chain support #13515

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

abretonc7s
Copy link
Contributor

@abretonc7s abretonc7s commented Feb 14, 2025

Description

This PR completes the migration from WalletConnect SE SDK (a wrapper adding an unnecessary layer over WalletConnect) to WalletKit, improving our existing multi-chain support implementation.

Motivation

  1. WalletConnect SE SDK was an unnecessary abstraction layer over WalletConnect's core functionality
  2. Our app already has initial multi-chain support capabilities that could be leveraged directly
  3. Need for better session management and standardized error handling

Solution

  1. Removed WalletConnect SE SDK dependency in favor of WalletKit
  2. Enhanced existing multi-chain support with:
    • Proper chain permission validation
    • Standardized CAIP-2 chain ID handling
    • Improved session management using namespaced permissions
  3. Standardized error responses across WalletConnect interactions

Key implementation details:

  • Added getPermittedChains utility for better chain permission management
  • Updated session management to use proper namespacing
  • Improved error handling with consistent response formats
  • Updated test suites to cover new functionality

Related issues

Manual testing steps

  1. Connect to a WalletConnect-enabled dApp
    • Verify connection establishes successfully
    • Check chain permissions are properly handled
  2. Test multi-chain interactions
    • Switch between different networks
    • Verify proper permission handling
  3. Test session management
    • Change accounts
    • Update sessions
    • Verify proper error handling
  4. Test disconnection flow
    • Verify clean session termination
    • Check proper cleanup

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR
  • I confirm that this PR addresses all acceptance criteria and includes necessary testing evidence
  • I've verified multi-chain support works as expected
  • I've verified error handling and session management
  • I've checked all dependency updates are compatible

Copy link
Contributor

github-actions bot commented Feb 14, 2025

CLA Signature Action:

Thank you for your submission, we really appreciate it. We ask that you all read and sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just by adding a comment to this pull request with this exact sentence:

I have read the CLA Document and I hereby sign the CLA

By commenting with the above message you are agreeing to the terms of the CLA. Your account will be recorded as agreeing to our CLA so you don't need to sign it again for future contributions to this repository.

1 out of 2 committers have signed the CLA.
@abretonc7s
@chakra-guy

@metamaskbot metamaskbot added the team-sdk SDK team label Feb 14, 2025
Copy link

socket-security bot commented Feb 14, 2025

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@reown/[email protected] 🔁 npm/@reown/[email protected] None 0 3.11 MB gancho_walletconnect
npm/@walletconnect/[email protected] 🔁 npm/@walletconnect/[email protected] None 0 3.49 MB gancho_walletconnect
npm/@walletconnect/[email protected] 🔁 npm/@walletconnect/[email protected] None 0 135 kB gancho_walletconnect
npm/@walletconnect/[email protected] 🔁 npm/@walletconnect/[email protected] None 0 26.7 kB gancho_walletconnect
npm/@walletconnect/[email protected] 🔁 npm/@walletconnect/[email protected] None +3 3.61 MB gancho_walletconnect
npm/@walletconnect/[email protected] 🔁 npm/@walletconnect/[email protected] None 0 3.59 MB gancho_walletconnect
npm/@walletconnect/[email protected] 🔁 npm/@walletconnect/[email protected] None 0 328 kB gancho_walletconnect
npm/@walletconnect/[email protected] 🔁 npm/@walletconnect/[email protected] None +4 6.73 MB gancho_walletconnect

🚮 Removed packages: npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@stablelib/[email protected], npm/@walletconnect/[email protected]

View full report↗︎

@abretonc7s abretonc7s changed the title Wcmigration feat: Migrate from @walletconnect/se-sdk to @reown/walletkit Feb 14, 2025
@abretonc7s abretonc7s added the needs-qa Any New Features that needs a full manual QA prior to being added to a release. label Feb 14, 2025
@abretonc7s abretonc7s self-assigned this Feb 14, 2025
@abretonc7s abretonc7s marked this pull request as ready for review February 14, 2025 09:50
@abretonc7s abretonc7s requested review from a team as code owners February 14, 2025 09:50
@abretonc7s abretonc7s changed the title feat: Migrate from @walletconnect/se-sdk to @reown/walletkit refactor(walletconnect): migrate to WalletKit and implement multi-chain support Feb 14, 2025
chakra-guy
chakra-guy previously approved these changes Feb 14, 2025
Copy link

@chakra-guy chakra-guy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done

@chakra-guy chakra-guy self-assigned this Feb 19, 2025
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 72.72727% with 24 lines in your changes missing coverage. Please review.

Project coverage is 62.74%. Comparing base (b5ea162) to head (41e0566).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
app/core/WalletConnect/wc-utils.ts 80.85% 8 Missing and 1 partial ⚠️
app/core/Permissions/index.ts 11.11% 8 Missing ⚠️
app/core/WalletConnect/WalletConnect2Session.ts 77.77% 3 Missing and 1 partial ⚠️
app/core/WalletConnect/WalletConnectV2.ts 76.92% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13515      +/-   ##
==========================================
+ Coverage   62.53%   62.74%   +0.21%     
==========================================
  Files        2005     2014       +9     
  Lines       44261    44396     +135     
  Branches     6006     6029      +23     
==========================================
+ Hits        27679    27857     +178     
+ Misses      14748    14707      -41     
+ Partials     1834     1832       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@christopherferreira9
Copy link
Contributor

christopherferreira9 commented Feb 20, 2025

Screen.Recording.2025-02-20.at.10.59.11.AM.mov

@christopherferreira9 christopherferreira9 added QA in Progress QA has started on the feature. WalletConnect WalletConnect related issue or bug and removed needs-qa Any New Features that needs a full manual QA prior to being added to a release. labels Feb 20, 2025
Copy link

@chakra-guy chakra-guy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have read the CLA Document and I hereby sign the CLA

@christopherferreira9
Copy link
Contributor

Critical Issue ⚠️: When the connection starts from a non synced state, the wallet is not changing automatically to the proper chain to display a confirmation screen, this means users will be sending transactions for an unwanted chain.

Screen.Recording.2025-02-20.at.11.48.38.AM.mov

Note:
Having a non synced state is normal, the wallet should change for the chain on the dapp in order to start processing a request. Here's a reference video:

Screen.Recording.2025-02-20.at.11.52.04.AM.mov

@christopherferreira9
Copy link
Contributor

SendTx seems to have the wrong origin in the pill

Screenshot 2025-02-20 at 11 56 09 AM

@christopherferreira9
Copy link
Contributor

Trying to sign after switching to a chain that hasn't been approved yet fails:

Screen.Recording.2025-02-20.at.11.58.07.AM.mov

Stacktrace:

Screenshot 2025-02-20 at 11 59 16 AM

{context: 'client'} 'request() -> isValidRequest() failed')

{context: 'client'} 'Missing or invalid. request() chainId: eip155:11155111'

Uncaught (in promise) UnknownRpcError: An unknown RPC error occurred.

@chakra-guy
Copy link

Critical Issue ⚠️: When the connection starts from a non synced state, the wallet is not changing automatically to the proper chain to display a confirmation screen, this means users will be sending transactions for an unwanted chain.

Screen.Recording.2025-02-20.at.11.48.38.AM.mov
Note: Having a non synced state is normal, the wallet should change for the chain on the dapp in order to start processing a request. Here's a reference video:

Screen.Recording.2025-02-20.at.11.52.04.AM.mov

Resolved! Regarding the critical issue where the wallet doesn’t automatically switch chains from a non-synced state:

Root Cause: This was a dapp-side bug, not a mobile app issue. When reconnecting after switching to Arbitrum, the dapp sent personal_sign requests with chainId=eip155:1 (Ethereum) instead of eip155:42161 (Arbitrum). The wallet correctly processes the chain specified in the request, but the dapp failed to update its state (even though from the UI it looks like its good, the actual request is with the wrong chain id).

Verification: Testing confirmed that when the dapp switches to Ethereum, then Arbitrum, and signs, the mobile app properly switches chains.

Let me know if you need further clarification or additional test cases!

@christopherferreira9
Copy link
Contributor

Critical Issue ⚠️: When the connection starts from a non synced state, the wallet is not changing automatically to the proper chain to display a confirmation screen, this means users will be sending transactions for an unwanted chain.
Screen.Recording.2025-02-20.at.11.48.38.AM.mov
Note: Having a non synced state is normal, the wallet should change for the chain on the dapp in order to start processing a request. Here's a reference video:
Screen.Recording.2025-02-20.at.11.52.04.AM.mov

Resolved! Regarding the critical issue where the wallet doesn’t automatically switch chains from a non-synced state:

Root Cause: This was a dapp-side bug, not a mobile app issue. When reconnecting after switching to Arbitrum, the dapp sent personal_sign requests with chainId=eip155:1 (Ethereum) instead of eip155:42161 (Arbitrum). The wallet correctly processes the chain specified in the request, but the dapp failed to update its state (even though from the UI it looks like its good, the actual request is with the wrong chain id).

Verification: Testing confirmed that when the dapp switches to Ethereum, then Arbitrum, and signs, the mobile app properly switches chains.

Let me know if you need further clarification or additional test cases!

The wallet should inform the dapp the current active chain, otherwise the dapp might think they're making a request for one chain when in reality it is requesting for another. In reality, regardless of what the dapp sends, the wallet needs to act as a safeguard and switch to the chain being requested.
@ignaciosantise and @ganchoradkov , can you confirm what is the expected behavior in this situation?

@ganchoradkov
Copy link

Critical Issue ⚠️: When the connection starts from a non synced state, the wallet is not changing automatically to the proper chain to display a confirmation screen, this means users will be sending transactions for an unwanted chain.
Screen.Recording.2025-02-20.at.11.48.38.AM.mov
Note: Having a non synced state is normal, the wallet should change for the chain on the dapp in order to start processing a request. Here's a reference video:
Screen.Recording.2025-02-20.at.11.52.04.AM.mov

Resolved! Regarding the critical issue where the wallet doesn’t automatically switch chains from a non-synced state:
Root Cause: This was a dapp-side bug, not a mobile app issue. When reconnecting after switching to Arbitrum, the dapp sent personal_sign requests with chainId=eip155:1 (Ethereum) instead of eip155:42161 (Arbitrum). The wallet correctly processes the chain specified in the request, but the dapp failed to update its state (even though from the UI it looks like its good, the actual request is with the wrong chain id).
Verification: Testing confirmed that when the dapp switches to Ethereum, then Arbitrum, and signs, the mobile app properly switches chains.
Let me know if you need further clarification or additional test cases!

The wallet should inform the dapp the current active chain, otherwise the dapp might think they're making a request for one chain when in reality it is requesting for another. In reality, regardless of what the dapp sends, the wallet needs to act as a safeguard and switch to the chain being requested. @ignaciosantise and @ganchoradkov , can you confirm what is the expected behavior in this situation?

The recommended approach is for the wallet to accept requests in any of the approved chains in the session. Users can switch the chain on the dapp multiple times before sending a request and the wallet will not get notified at all of these local (dapp side) chain switches because

  • the chains are already approved by the user - asking them again to switch on the wallet is redundant
  • usually the wallet (on mobile device) is not active at the same time as the dapp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA in Progress QA has started on the feature. team-sdk SDK team WalletConnect WalletConnect related issue or bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants