From: Ardis Lu Date: Thu, 15 Feb 2024 05:36:16 +0000 (-0800) Subject: Fallback to ethereum.on if ethereum.addListener is not implemented X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=8c271cbe0e028d577abe953720ae7df013042948;p=alu.bz Fallback to ethereum.on if ethereum.addListener is not implemented Supports older wallets (e.g. Brave Wallet) which use the deprecated .on method from EIP-1193 --- diff --git a/script.js b/script.js index a1d9a79..69eba57 100644 --- a/script.js +++ b/script.js @@ -113,7 +113,7 @@ async function handleSubmit(event) { if (window.ethereum !== undefined) { // User switches account manually in wallet - ethereum.addListener('accountsChanged', setAccount); + ethereum?.addListener?.('accountsChanged', setAccount) ?? ethereum.on('accountsChanged', setAccount); } connectButton.addEventListener('click', () => {