Skip to content

fix(walletconnect): improve chain switching error message with standard code 4902 #13415

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abretonc7s
Copy link
Contributor

@abretonc7s abretonc7s commented Feb 11, 2025

Description

This change improves WalletConnect chain switching error handling by implementing standard error codes and more descriptive messages when users attempt to switch to unregistered chains.

  1. Reason for change:

    • Currently, attempting to switch to an unregistered chain returns a generic error code (32603)
    • Error message lacks clarity about how to resolve the issue
  2. Improvement/solution:

    • Implements standard Ethereum error code 4902 for unrecognized chain scenarios
    • Provides clear error message suggesting the user to add the chain first
    • Updates logging for better debugging

Related issues

Fixes: #13406

Manual testing steps

  1. Connect to the WalletConnect dApp example (using provided test dApp)
  2. Attempt to switch to Arbitrum network that hasn't been added yet
  3. Verify error code 4902 is returned with descriptive message
  4. Confirm loading state behaves as expected

Screenshots/Recordings

Before

Error with code 32603:

error: { code: 32603, message: ERROR_MESSAGES.INVALID_CHAIN }

After

Improved error with code 4902:

error: { 
  code: 4902, 
  message: `Unrecognized chain ID "${_chainId}". Try adding the chain using wallet_addEthereumChain first.`
}

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed)
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-sdk SDK team label Feb 11, 2025
@abretonc7s abretonc7s added No QA Needed Apply this label when your PR does not need any QA effort. needs-qa Any New Features that needs a full manual QA prior to being added to a release. and removed No QA Needed Apply this label when your PR does not need any QA effort. labels Feb 11, 2025
@abretonc7s abretonc7s marked this pull request as ready for review February 11, 2025 04:30
@abretonc7s abretonc7s requested a review from a team as a code owner February 11, 2025 04:30
@christopherferreira9
Copy link
Contributor

This doesn't seem to fix #13406 . Also, this change might also have some implications on the WalletConnect dapp side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-qa Any New Features that needs a full manual QA prior to being added to a release. team-sdk SDK team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: WalletConnect chain switching returns an error
4 participants