how can i know my metamask wallet locked?

Issue

This Content is from Stack Overflow. Question asked by Jerry

I developed metamask auto-login function after refresh browser.

However, there is a problem when metamask is locked because It’s been a long time since user visited.

I don’t want show metamask popup when it is locked.

Is there anyway I can check metamask is locked ?

web3.eth.getAccounts is not a solution because it returns empty array when refresh browser. so it is not reliable.

useEffect(() => {
    const walletCompany = getWalletFromLocalStorage('wallet');
    const metamaskWalletAutoLogin = async () => {
      const res = await connectWithMetamask();
      res.address && saveWalletAddress(res.address);
      setIsLoading(false);
    };
    const coinbaseWalletAutoLogin = async () => {
      const res = await connectWithCoinbase();
      res.address && saveWalletAddress(res.address);
      setIsLoading(false);
    };
    if (walletCompany) {
      walletCompany === 'metamask' ? metamaskWalletAutoLogin() : coinbaseWalletAutoLogin();
    } else setIsLoading(false);
  }, []);



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?