Check if MetaMask is Locked

If you are building a DApp and need to create a display to let users know the status of MetaMask, here is some quick code to get you started

function checkMetaMask() {
  // Metamask is not installed
  if (typeof web3 === 'undefined') {
   this.notInstalled = true;
  // Metamask is locked
  const account = web3.eth.accounts[0];
  if (!account) { 
   // locked

Per the offical docs, it looks like you should set an interval to keep checking:

And that’s it!