Switched chain is not reflected in the address and balance
If the wallet uses different addresses for different chains, switching the cryptocurrency for exchange does not update the address and balance.
Page reload updates the address and balance to the correct values.
WalletConnect approved session namespace:
{
"eip155": {
"chains": [
"eip155:1",
"eip155:42161",
"eip155:56"
],
"methods": [
"eth_accounts",
"eth_requestAccounts",
"eth_sendRawTransaction",
"eth_sign",
"eth_signTransaction",
"eth_signTypedData",
"eth_signTypedData_v3",
"eth_signTypedData_v4",
"eth_sendTransaction",
"personal_sign",
"wallet_switchEthereumChain",
"wallet_addEthereumChain",
"wallet_getPermissions",
"wallet_requestPermissions",
"wallet_registerOnboarding",
"wallet_watchAsset",
"wallet_scanQRCode",
"wallet_sendCalls",
"wallet_getCapabilities",
"wallet_getCallsStatus",
"wallet_showCallsStatus"
],
"events": [
"chainChanged",
"accountsChanged",
"message",
"disconnect",
"connect"
],
"accounts": [
"eip155:1:0xB6bB59b3aC844e8e4A98A281D57E3E0628bcb471",
"eip155:42161:0xAd8eDE8697aF92AF31Fe66EDAD9A52A74F74464E",
"eip155:56:0x9B0d038121EB94CeA52FD08B416056B2824524dd"
]
}
}
Thanks for the report, what wallet was used for wallet connect?
Wallet https://coin.space/wallet/
@plondon Most likely, all wallets that use different addresses for different chains are affected.
Switching the chain on the wallet side correctly switches the chain on the app side:
await web3wallet.emitSessionEvent({
topic: session.topic,
event: {
name: 'chainChanged',
data: chain,
},
chainId: `${prefix}:${chain}`,
});
await await web3wallet.emitSessionEvent({
topic: session.topic,
event: {
name: 'accountsChanged',
data: [address],
},
chainId: `${prefix}:${chain}`,
});
hey @plondon can i take this issue?
@ktarun1419 @plondon for your information, this issue is a bug in the underlying library: https://github.com/WalletConnect/walletconnect-monorepo/issues/5706 and PR https://github.com/WalletConnect/walletconnect-monorepo/pull/5713
The following issue is a bit related https://github.com/Uniswap/interface/issues/7864
Similar issue has been fixed in PancakeSwap https://github.com/pancakeswap/pancake-frontend/issues/11325 PR: https://github.com/pancakeswap/pancake-frontend/pull/11338
Thanks for following up @mahnunchik we'll update the necessary packages
Hi @mahnunchik , a couple of things, the interface delays the switchChain request until its required for the transaction. I tried updating the wagmi library to include the shared fix, and added a checkSwitchReloadNeeded (shared below). If reload is needed we can refresh and switchChain, however I noticed that on refresh the dapp reverts back to mainnet (video attached)
export const checkSwitchReloadNeeded = async (
chainId: number,
connector?: Connector,
address?: string,
): Promise<boolean> => {
if (!connector || !address) {
return false
}
try {
const provider = await (connector as WalletConnectConnector).getProvider()
const accounts = provider?.session?.namespaces?.eip155?.accounts
const isSwitchNeeded =
Array.isArray(accounts) && !accounts.some((account: string) => account?.includes(`${chainId}:${address}`))
return isSwitchNeeded
} catch (error) {
logger.debug('Web3Provider', 'checkSwitchReloadNeeded', 'Error checking if reload needed:', error)
return false
}
}
https://github.com/user-attachments/assets/0735d2d9-05f4-4a93-9f82-64f113b8e317
Connected to coin space wallet above, 0xd5 is my mainnet account, 0x89 is my base address
Closing this due to inactivity
@mahnunchik can you provide more information here
@plondon everything remains as it was before.
- Connect the wallet https://coin.space/wallet/settings/walletconnect
- Switch the blockchain (token to exchange in Uniswap interface)
- Address AND balance does not change