fix(network switch): do not show failed to switch networks for successful network switches
This commit is contained in:
parent
458e04f94c
commit
13c42a384b
@ -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
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user