Hi! Using Ethers JS you can try to instantiate a
Web3Provider object passing it
window.ethereum and issue an
eth_requestAccounts. This according to my tests triggers the MetaMask login popup if the user is not connected, and if not, it “works silently”. Then you can try to get the signer from the instantiated provider. If it returns an account, you render the “Connected to: …” thingy. If not, the Connect button.
const provider = new Web3Provider(wallet);
await provider.send('eth_requestAccounts', );
const signer = await provider.getSigner(0);
if (signer === undefined) userIsNotConnected();
The one thing that this doesn’t solve is that issuing the
eth_requestAccounts to poke on the state of the connection will trigger the MM login popup, which might be too aggressive depending on how you’d like your app to behave.