Skip to content

MetaMask does not show signature request if open when 'eth_signTypedData' request is sent #4821

@alex-ppg

Description

@alex-ppg

This is quite a crucial issue with user interaction as we cannot reasonably expect a user, after unlocking his account, to close and re-open the MetaMask plugin screen.

  • Expected Behavior: Whilst the MetaMask plugin screen is open, either the page itself transitions to the signature request or the signature request pop-up shows.
  • Actual Behavior: If MetaMask is open when the request is sent, the request does not show unless I close and re-open the MetaMask screen.
  • Browser Used: Google Chrome although I believe this is irrelevant.
  • Operating System Used: Windows 10 but likewise irrelevant.

Code Example (Ensure your account is locked):

const msgParams = [
    {
        type: 'string',
        name: 'Authorization Request',
        value: 'test'
    }
];
if (typeof window.web3 !== 'undefined' && typeof window.web3.currentProvider !== 'undefined') {
    let localWeb3 = new Web3(window.web3.currentProvider);
    window.web3.eth.getAccounts((err, accounts) => {
        if (!accounts[0]) {
            watchAccountUnlock();
        } else {
            localWeb3.eth.defaultAccount = accounts[0];
            requestSignature();
        }
    });
}

function watchAccountUnlock() {
    const toClear = setInterval(() => {
       window.web3.eth.getAccounts((err, accounts) => {
            if (accounts[0] !== localWeb3.eth.defaultAccount) {
                localWeb3.eth.defaultAccount = accounts[0];
                requestSignature();
                clearInterval(toClear);
            }
        });
    },500);
}

function requestSignature() {
    localWeb3.currentProvider.sendAsync({
      method: 'eth_signTypedData',
      params: [msgParams, localWeb3.eth.defaultAccount],
      from: localWeb3.eth.defaultAccount,
    }, (err, result) => {
      if (err) return console.error(err)
      if (result.error) {
        // User denied signature
      }
      const signature = result.result;
      alert(signature);
    });
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions