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

WalletConnect v1 session collision when connecting multiple wallets #274

Closed
drichar opened this issue Sep 27, 2024 · 0 comments · Fixed by #275
Closed

WalletConnect v1 session collision when connecting multiple wallets #274

drichar opened this issue Sep 27, 2024 · 0 comments · Fixed by #275

Comments

@drichar
Copy link
Collaborator

drichar commented Sep 27, 2024

Bug Description

The library fails to properly manage WalletConnect sessions when connecting a second WalletConnect v1-based wallet (e.g., Defly) while another (e.g., Pera) is already connected. This issue stems from WalletConnect v1's use of a non-unique local storage key (walletconnect), causing a collision when attempting to connect multiple wallets.

Expected Behavior

Users should be able to connect multiple wallet providers simultaneously, including multiple WalletConnect-based wallets (e.g., Pera and Defly), without errors or inconsistent states.

Current Behavior

Attempting to connect a second WalletConnect-based wallet while another is connected results in:

  1. An error in the console: DeflyWalletConnectError: Session currently connected
  2. The second wallet failing to connect on the first attempt
  3. Inconsistent wallet states even if the connection succeeds on a second attempt
  4. Possible failure of transaction signing due to invalid wallet states

Reproduction

  1. Connect to Pera wallet
  2. Without disconnecting Pera, attempt to connect to Defly
  3. Observe the error in the console and the failure to connect
  4. Attempt to connect with Defly again
  5. Connection may succeed, but the wallets will be in an invalid state and transaction signing may fail

Environment

  • @txnlab/use-wallet version: 3.6.0

Suggested Solution

Implement a new method in the Pera (v1) and Defly provider classes to be called at the beginning of the connect process:

  1. Check if another WalletConnect-based wallet is currently active
  2. If so, backup its session data in a unique local storage key
  3. Clear the existing walletconnect key
  4. Proceed with connecting the new wallet

When setting Pera (v1) or Defly as active:

  1. Check if another WalletConnect-based wallet is currently active
  2. If so, backup its session data in a unique local storage key
  3. Restore the backup session data for the new active wallet
  4. Proceed with setting the wallet as active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant