import { useWeb3React } from "@web3-react/core" ; import { useEffect , useState } from "react" ; import { injectedConnector } from "../utils/connectors" ; import { addConnectEvent } from "../utils/analytics" ; const useEagerConnect = ( ) => { const { activate , active , account } = useWeb3React ( ) ; const [ tried , setTried ] = useState ( false ) ; useEffect ( ( ) => { if ( tried ) { return ; } injectedConnector . isAuthorized ( ) . then ( ( isAuthorized ) => { if ( isAuthorized ) { activate ( injectedConnector , undefined , true ) . catch ( ( ) => { setTried ( true ) ; } ) ; } else { setTried ( true ) ; } } ) ; } , [ activate , tried ] ) ; useEffect ( ( ) => { if ( ! tried && active ) { if ( account ) { addConnectEvent ( "background" , account ) ; } setTried ( true ) ; } } , [ tried , active , activate , account ] ) ; return tried ; } ; export default useEagerConnect ;