web3-react
web3-react copied to clipboard
WalletConnect on activate returns incorrect provider.getBalance()
When connecting WalletConnect using activate method, provider.getBalance returns incorrect balance.
This is due to how defaultChainId uses whichever has the lowest chainId from the rpc options
this.defaultChainId = defaultChainId ?? Number(Object.keys(this.rpc)[0])
However, when connecting via connectEagerly method, provider.getBalance returns the correct balance with the current chain.
Is this a bug? I understand errors will be raised if RPC chain ID is not included in the rpc configuration, but what about supported chain IDs?
So my hacky workaround was to reassign eagerConnection to the walletConnect connector with the correct chainId
await walletConnect.activate();
const chainId = await walletConnect.provider?.request({ method: "eth_chainId" });
// walletConnect.rpc is a private property
if (!chainId || !Object.keys(walletConnect.rpc).includes(chainId.toString())) return;
// Reset eagerConnection
walletConnect.eagerConnection = undefined; // private property
await walletConnect.isomorphicInitialize(chainId); // private method
// update useWeb3React states
await walletConnect.connectEagerly();
When connecting WalletConnect using
activatemethod,provider.getBalancereturns incorrect balance. This is due to howdefaultChainIduses whichever has the lowest chainId from the rpc optionsthis.defaultChainId = defaultChainId ?? Number(Object.keys(this.rpc)[0])However, when connecting via
connectEagerlymethod,provider.getBalancereturns the correct balance with the current chain.Is this a bug? I understand errors will be raised if RPC chain ID is not included in the rpc configuration, but what about supported chain IDs?
So my hacky workaround was to reassign eagerConnection to the walletConnect connector with the correct chainId
await walletConnect.activate(); const chainId = await walletConnect.provider?.request({ method: "eth_chainId" }); // walletConnect.rpc is a private property if (!chainId || !Object.keys(walletConnect.rpc).includes(chainId.toString())) return; // Reset eagerConnection walletConnect.eagerConnection = undefined; // private property await walletConnect.isomorphicInitialize(chainId); // private method // update useWeb3React states await walletConnect.connectEagerly();
I have the same issue. How do we make the same supportedChain Ids functionality work in this version 8? Version is quite confusing for me.
When connecting WalletConnect using
activatemethod,provider.getBalancereturns incorrect balance. This is due to howdefaultChainIduses whichever has the lowest chainId from the rpc optionsthis.defaultChainId = defaultChainId ?? Number(Object.keys(this.rpc)[0])However, when connecting via
connectEagerlymethod,provider.getBalancereturns the correct balance with the current chain.Is this a bug? I understand errors will be raised if RPC chain ID is not included in the rpc configuration, but what about supported chain IDs?
So my hacky workaround was to reassign eagerConnection to the walletConnect connector with the correct chainId
await walletConnect.activate(); const chainId = await walletConnect.provider?.request({ method: "eth_chainId" }); // walletConnect.rpc is a private property if (!chainId || !Object.keys(walletConnect.rpc).includes(chainId.toString())) return; // Reset eagerConnection walletConnect.eagerConnection = undefined; // private property await walletConnect.isomorphicInitialize(chainId); // private method // update useWeb3React states await walletConnect.connectEagerly();
Did you figure out the solution?
I have the same issue. How do we make the same supportedChain Ids functionality work in this version 8? Version is quite confusing for me.
I have only used v8 and not previous versions. I am currently using this workaround and is good enough for me