I am trying to listen to the 'chainChanged' event for Metamask, but the event never fires. When running the following snippet, the I get a console.log of the chainId once, but the chainChanged event never runs. What could be the issue? Thanks!
if (window.ethereum) {
window.ethereum.send('eth_chainId')
.then(handleChainChanged)
.catch((err: any) => console.error(err));
window.ethereum.on('chainChanged', handleChainChanged);
window.ethereum.autoRefreshOnNetworkChange = false;
...
}
function handleChainChanged(chainId: number) {
console.log(chainId);
}