Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

shouldSwitchNetwork is not provider agnostic #3579

Closed
iamacook opened this issue Feb 24, 2022 · 1 comment · Fixed by #3729
Closed

shouldSwitchNetwork is not provider agnostic #3579

iamacook opened this issue Feb 24, 2022 · 1 comment · Fixed by #3729
Assignees
Labels
Bug 🐛 Something isn't working

Comments

@iamacook
Copy link
Member

iamacook commented Feb 24, 2022

tl;dr

In MM chainId is a hex, in WC a number. Need to handle. Convert to a numberified string.

Description

shouldSwitchNetwork references the provider of Onboard's wallet instance. However, it seems as there is no universal chainId value that we can reference across all providers.

The original version of shouldSwitchNetwork checked networkVersion, which is MetaMask-specific (although likely other providers as well. As part of the desktop pairing implementation (also affecting WC), it was extended to check chainId as well.

Subsequently, it has been noticed that there is no 'standard' across these two keys (maybe there are also other keys with other providers), e.g.

WC

  const provider = {
    chainId: 4 // integer
    ...
  }

MM

  const provider = {
    chainId: "0x04", // hex
    networkVersion: "4" // string
    ...
  }

We need a way of consistently checking against a standard key that the current chainId matches that, perhaps comparing an integer, string and hex value of it.

Expected result

shouldSwitchNetwork returns a consistent boolean back across all chains when the chain needs to be switched.

Obtained result

It is not always consistent.

@iamacook iamacook added the Bug 🐛 Something isn't working label Feb 24, 2022
@katspaugh
Copy link
Member

A mind-blowing find. 🤦

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants