Skip to content

Commit

Permalink
feature: improvement-add failed to switch network message
Browse files Browse the repository at this point in the history
  • Loading branch information
TienPQ149 committed Aug 2, 2022
1 parent 3cdeb9b commit 9697356
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/hooks/useActiveNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ChainId } from '@kyberswap/ks-sdk-core'
import { useAppDispatch } from 'state/hooks'
import { updateChainIdWhenNotConnected } from 'state/application/actions'
import { UnsupportedChainIdError } from '@web3-react/core'
import { useAddPopup } from 'state/application/hooks'
import { t } from '@lingui/macro'

const getAddNetworkParams = (chainId: ChainId) => ({
chainId: '0x' + chainId.toString(16),
Expand Down Expand Up @@ -36,6 +38,7 @@ export function useActiveNetwork() {
const location = useLocation()
const qs = useParsedQueryString()
const dispatch = useAppDispatch()
const addPopup = useAddPopup()

const locationWithoutNetworkId = useMemo(() => {
// Delete networkId from qs object
Expand Down Expand Up @@ -84,11 +87,18 @@ export function useActiveNetwork() {
// handle other "switch" errors
console.error(switchError)
failureCallback && failureCallback()
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.`,
},
})
}
}
}
},
[dispatch, history, library, locationWithoutNetworkId, error],
[dispatch, history, library, locationWithoutNetworkId, error, addPopup],
)

useEffect(() => {
Expand Down

0 comments on commit 9697356

Please sign in to comment.