diff --git a/lang/zh-Hant.json b/lang/zh-Hant.json index e62ccf1dba..3bf9fe6252 100644 --- a/lang/zh-Hant.json +++ b/lang/zh-Hant.json @@ -766,7 +766,7 @@ "description": "src/views/Circle/Analytics/FollowerAnalytics/index.tsx" }, "Bkx6Gk": { - "defaultMessage": "切換網絡中…" + "defaultMessage": "切換網路中…" }, "BnMru1": { "defaultMessage": "語言", diff --git a/src/components/Hook/useTargetNetwork.ts b/src/components/Hook/useTargetNetwork.ts index b920872070..028205db25 100644 --- a/src/components/Hook/useTargetNetwork.ts +++ b/src/components/Hook/useTargetNetwork.ts @@ -1,8 +1,10 @@ -import { Chain, useNetwork, useSwitchNetwork } from 'wagmi' +import { useEffect } from 'react' +import { Chain, useDisconnect, useNetwork, useSwitchNetwork } from 'wagmi' export const useTargetNetwork = (target: Chain) => { + const { disconnect } = useDisconnect() const { chain: currentChain } = useNetwork() - const { switchNetwork, isLoading } = useSwitchNetwork() + const { switchNetwork, isLoading, error } = useSwitchNetwork() const isUnsupportedNetwork = currentChain?.id !== target.id const targetChainId = target.id @@ -12,6 +14,14 @@ export const useTargetNetwork = (target: Chain) => { switchNetwork(targetChainId) } + // disconnect if failed to switch network + useEffect(() => { + if (!error) return + if (error.name === 'UserRejectedRequestError') return + + disconnect() + }, [error]) + return { isUnsupportedNetwork, isSwitchingNetwork: isLoading,