Open 0xSaga opened 1 year ago
Got the same issue - it has to do with the way web3-react expects the desiredChainId
to be included in the chains
array (which afaik is now an antipattern due to optionalChains
). The WC2 API became quite messy 🫣.
A quick fix (although dirty as you'd be touching "private" attributes) is to re-configuring the connector before attempting to activate
. Assuming you have a chain picker before the user asks to connect with WC2 (just like in the example):
connector.chains = [desiredChainId];
connector.options.chain = [desiredChainId];
connector.options.optionalChains = CHAINS.filter((c) => c !== desiredChainId);
Not sure what the fix at web3-react's level would be here but probably involved re-building the chains
parameter based on desiredChainId
(without checking for it in the initial array provided to the connector). For context, this is wagmi's implementation.
Later edit 8.5.0
: looks like optionalChains
will now crash if it doesn't contain the desiredChainId/defaultChainId due to getChainsWithDefault
?
You can update the walletconnectv2 connector to include all chains
const [mainnet] = Object.keys(MAINNET_CHAINS).map(Number)
const [...optionalChains] = Object.keys(MAINNET_CHAINS).map(Number)
const projectId = process.env.walletConnectProjectId;
export const [walletConnectV2, hooks] = initializeConnector<WalletConnectV2>(
(actions) =>
new WalletConnectV2({
actions,
options: {
projectId: projectId,
chains: [mainnet],
rpc: getInfuraUrlFor('mainnet'),
optionalChains,
showQrModal: true,
},
})
)
Have the same issue here
@RitzyDevBox doesnt solve issue.
weird bug, somehow previously there's a time it was working, now it doesnt. not even in the example's url. i guess i will just migrate everything to wagmi
WalletConnect2 shows the following error even if including the chain ID in chains and/or optionalChains
Can be reproduced as follows: