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

Two issues: walletconnect and metamask mobile #4275

Open
siosio34 opened this issue Feb 28, 2024 · 9 comments
Open

Two issues: walletconnect and metamask mobile #4275

siosio34 opened this issue Feb 28, 2024 · 9 comments
Labels
type: bug Something isn't working

Comments

@siosio34
Copy link
Contributor

Describe the bug

Hello, I am using WalletConnect and Metamask Mobile and have the following two issues.

First, Switchchain does not work properly. When you send a Switchchain request and see the chain request window on MetaMask Mobile, if you reject it, the request will not be completed, and even if you accept it, the chain change within the mobile does not work properly, so you have to change the chain within MetaMask Mobile and then process the request.

Second, when sending a sign request while connected to a chain other than Ethereum (ex polygon), there was an issue where the chain was unnecessarily requested to be changed to Ethereum.

These two issues were so critical that we had no choice but to give up on introducing WalletConnect. Is there any progress on these two issues?

Links to related issues are below.
MetaMask/metamask-mobile#8380
MetaMask/metamask-mobile#7206
MetaMask/metamask-mobile#7023

SDK Version (if relevant)

  • Client: [e.g. JS, Swift, Kotlin]
  • Version [e.g. 22]

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@siosio34 siosio34 added the type: bug Something isn't working label Feb 28, 2024
@glitch-txs
Copy link

Hi @siosio34, thanks for the report, we'll try to contact MetaMask and suggest these fixes

@siosio34
Copy link
Contributor Author

@glitch-txs

Other than that, walletconnect provides a better user experience. Thank you to the walletconnect team for creating and maintaining this product.

@glitch-txs
Copy link

Hi @siosio34 just wanted to give a heads up we've been working together with MetaMask to address the most relevant issues and a new release with a UX improvement around chain switching and else are coming eventually.

@siosio34
Copy link
Contributor Author

siosio34 commented Apr 8, 2024

@glitch-txs thank you I’m so excited for tonight that I can’t sleep 0_<

@siosio34
Copy link
Contributor Author

@glitch-txs
hello. Has this release been released yet?

@glitch-txs
Copy link

Hey @siosio34 the new MetaMask version should be released early next month with these fixed 👍

@siosio34
Copy link
Contributor Author

siosio34 commented May 7, 2024

I think what you said is included in https://github.com/MetaMask/metamask-mobile/releases/tag/v7.21.0. Is this correct?

@glitch-txs

@glitch-txs
Copy link

Mmm I think not, @ganchoradkov do you remember which one is the PR for the MetaMask update?
But should be on the next release I think

@glitch-txs glitch-txs pinned this issue Jul 6, 2024
@0xShankar
Copy link

The issue likely revolves around connection or integration problems between WalletConnect and MetaMask, such as:

WalletConnect not initializing properly with MetaMask.
Session persistence issues: MetaMask disconnects after a session, or users experience connection drops.
Multi-chain support issues: WalletConnect v2 supports multiple chains, but MetaMask

Proposed Solution:
Ensure Proper Session Persistence:

Problem: Users often experience session disconnects after some idle time.
Solution: Implement session persistence by storing the session key in local storage and reusing it when reconnecting. This avoids MetaMask having to re-establish a new session every time the page reloads.

const provider = new WalletConnectProvider({
  rpc: { 1: 'https://mainnet.infura.io/v3/INFURA_PROJECT_ID' }
});

// Check if there is an existing session
if (provider.connector.connected) {
  await provider.enable();
}
  1. Improve Error Handling and User Messaging:

Problem: When MetaMask fails to connect, users see a generic error message like "Connection failed."
Solution: Modify the error-handling logic to display user-friendly messages specific to MetaMask errors. Here’s an example for handling MetaMask-specific errors:

provider.on("error", (error) => {
  if (error.message.includes("MetaMask")) {
    alert("MetaMask connection failed. Please try reconnecting.");
  } else {
    alert("Connection failed. Check your network or wallet.");
  }
});
  1. Multi-chain Support for MetaMask:

Problem: WalletConnect supports multi-chain connections, but MetaMask might not handle chain switching smoothly.
Solution: Handle chain switching explicitly when using MetaMask with WalletConnect. If MetaMask fails to switch chains, display a prompt for the user to manually switch networks:

async function switchChain(chainId) {
  try {
    await provider.request({
      method: "wallet_switchEthereumChain",
      params: [{ chainId }],
    });
  } catch (error) {
    if (error.code === 4902) {
      // If the chain is not added, add it to MetaMask
      await provider.request({
        method: "wallet_addEthereumChain",
        params: [{ chainId }],
      });
    } else {
      alert("Please switch the network manually in MetaMask.");
    }
  }
}

4.Testing & Debugging MetaMask + WalletConnect Interactions:

Test the interactions by attempting the following:
Switch chains on MetaMask and see if WalletConnect properly updates.
Disconnect and reconnect sessions to check if sessions persist across reloads.
Ensure proper error messages appear when connections fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants