Commit 13c42a38 authored by Moody Salem's avatar Moody Salem

fix(network switch): do not show failed to switch networks for successful network switches

parent 458e04f9
...@@ -24,8 +24,8 @@ export default function FailedNetworkSwitchPopup({ chainId }: { chainId: Support ...@@ -24,8 +24,8 @@ export default function FailedNetworkSwitchPopup({ chainId }: { chainId: Support
<AutoColumn gap="8px"> <AutoColumn gap="8px">
<ThemedText.Body fontWeight={500}> <ThemedText.Body fontWeight={500}>
<Trans> <Trans>
Your wallet does not support switching networks from the Uniswap Interface. In order to use Uniswap on{' '} Failed to switch networks from the Uniswap Interface. In order to use Uniswap on {chainInfo.label}, you must
{chainInfo.label}, you must change the network in your wallet. change the network in your wallet.
</Trans> </Trans>
</ThemedText.Body> </ThemedText.Body>
</AutoColumn> </AutoColumn>
......
...@@ -37,15 +37,16 @@ export async function switchToNetwork({ library, chainId }: SwitchNetworkArgumen ...@@ -37,15 +37,16 @@ export async function switchToNetwork({ library, chainId }: SwitchNetworkArgumen
}, },
], ],
}) })
const { chainId: chainIdAfterSwitch } = await library.getNetwork()
if (chainIdAfterSwitch !== chainId) {
// metamask (only known implementer) automatically switches after a network is added // metamask (only known implementer) automatically switches after a network is added
// the second call is done here because that behavior is not a part of the spec and cannot be relied upon in the future // the second call is done here because that behavior is not a part of the spec and cannot be relied upon in the future
// metamask's behavior when switching to the current network is just to return null (a no-op) // metamask's behavior when switching to the current network is just to return null (a no-op)
try {
await library.provider.request({ await library.provider.request({
method: 'wallet_switchEthereumChain', method: 'wallet_switchEthereumChain',
params: [{ chainId: formattedChainId }], params: [{ chainId: formattedChainId }],
}) })
} catch (error) {
console.debug('Added network but could not switch chains', error)
} }
} else { } else {
throw error throw error
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment