Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
fix(network switch): do not show failed to switch networks for succes…
Browse files Browse the repository at this point in the history
…sful network switches
  • Loading branch information
moodysalem committed Dec 23, 2021
1 parent 458e04f commit 13c42a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/Popups/FailedNetworkSwitchPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default function FailedNetworkSwitchPopup({ chainId }: { chainId: Support
<AutoColumn gap="8px">
<ThemedText.Body fontWeight={500}>
<Trans>
Your wallet does not support switching networks from the Uniswap Interface. In order to use Uniswap on{' '}
{chainInfo.label}, you must change the network in your wallet.
Failed to switch networks from the Uniswap Interface. In order to use Uniswap on {chainInfo.label}, you must
change the network in your wallet.
</Trans>
</ThemedText.Body>
</AutoColumn>
Expand Down
11 changes: 6 additions & 5 deletions src/utils/switchToNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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 (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
// metamask's behavior when switching to the current network is just to return null (a no-op)
try {
await library.provider.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: formattedChainId }],
})
} catch (error) {
console.debug('Added network but could not switch chains', error)
}
} else {
throw error
Expand Down

0 comments on commit 13c42a3

Please sign in to comment.