diff --git a/src/components/Web3ReactManager/index.tsx b/src/components/Web3ReactManager/index.tsx index fecea0a448..b43c750ff4 100644 --- a/src/components/Web3ReactManager/index.tsx +++ b/src/components/Web3ReactManager/index.tsx @@ -3,7 +3,7 @@ import { useEffect } from 'react' import { useDispatch, useSelector } from 'react-redux' import LocalLoader from 'components/LocalLoader' -import { useActiveWeb3React, useInactiveListener, useWeb3React } from 'hooks' +import { useActiveWeb3React, useWeb3React } from 'hooks' import { useEagerConnect } from 'hooks/web3/useEagerConnect' import { AppState } from 'state' import { updateChainId } from 'state/user/actions' @@ -16,8 +16,6 @@ export default function Web3ReactManager({ children }: { children: JSX.Element } // try to eagerly connect to an injected provider, if it exists and has granted access already const triedEager = useEagerConnect() - // when there's no account connected, react to logins (broadly speaking) on the injected provider, if it exists - useInactiveListener(!triedEager.current) const dispatch = useDispatch() /** On user change network from wallet, update chainId in store, only work on EVM wallet */ useEffect(() => { diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 059a00291a..c499319be8 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -136,44 +136,3 @@ export const useWeb3Solana = () => { const { connection } = useKyberSwapConfig() return { connection } } - -/** - * Use for network and injected - logs user in - * and out after checking what network they're on - */ -export function useInactiveListener(suppress = false) { - const { isEVM } = useActiveWeb3React() - const { active } = useWeb3React() // specifically using useWeb3React because of what this hook does - - useEffect(() => { - const { ethereum } = window - if (isEVM && ethereum?.on && !active && !suppress) { - const handleChainChanged = () => { - // eat errors - metaMask.activate().catch(error => { - console.error('Failed to activate after chain changed', error) - }) - } - - const handleAccountsChanged = (accounts: string[]) => { - if (accounts.length > 0) { - // eat errors - metaMask.activate().catch(error => { - console.error('Failed to activate after accounts changed', error) - }) - } - } - - ethereum.on('chainChanged', handleChainChanged) - ethereum.on('accountsChanged', handleAccountsChanged) - - return () => { - if (ethereum.removeListener) { - ethereum.removeListener('chainChanged', handleChainChanged) - ethereum.removeListener('accountsChanged', handleAccountsChanged) - } - } - } - return undefined - }, [active, suppress, isEVM]) -}