Skip to content

Commit

Permalink
fix: fix an issue when desire chain is not added to metamask yet
Browse files Browse the repository at this point in the history
  • Loading branch information
TienPQ149 committed Aug 3, 2022
1 parent 9697356 commit 539e30a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/hooks/useActiveNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ export function useActiveNetwork() {
if (switchError?.code === 4902 || switchError?.code === -32603 || isSwitchError) {
try {
await activeProvider.request({ method: 'wallet_addEthereumChain', params: [addNetworkParams] })
if (chainId !== desiredChainId) {
addPopup({
simple: {
title: t`Failed to switch network`,
success: false,
summary: t`In order to use KyberSwap on ${NETWORKS_INFO[desiredChainId].name}, you must change the network in your wallet.`,
},
})
}
successCallback && successCallback()
} catch (addError) {
console.error(addError)
Expand All @@ -98,7 +107,7 @@ export function useActiveNetwork() {
}
}
},
[dispatch, history, library, locationWithoutNetworkId, error, addPopup],
[dispatch, history, library, locationWithoutNetworkId, error, addPopup, chainId],
)

useEffect(() => {
Expand Down

0 comments on commit 539e30a

Please sign in to comment.