From 8c271cbe0e028d577abe953720ae7df013042948 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 14 Feb 2024 21:36:16 -0800 Subject: [PATCH] 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 --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', () => { -- 2.47.3