MetaMask’s current recommended way to connect to wallet (can’t paste link but it’s under get-started > setup dev environment) is supposed to handle account changes, but in practice it doesn’t appear to work. If I connect with one account, then change accounts, the new account isn’t yet connected to the site, and therefore doesn’t seem to trigger the following code (supplied by MetaMask) to call handleAccountsChanged()
window.ethereum.on(‘accountsChanged’, handleAccountsChanged);
function handleAccountsChanged(accounts) {
if (accounts.length === 0) {
console.log(‘Please connect to MetaMask.’);
} else if (accounts[0] !== currentAccount) {
currentAccount = accounts[0];
}
}