]> git.ardis.lu - alu.bz/commitdiff
Fallback to ethereum.on if ethereum.addListener is not implemented
authorArdis Lu <ardisglu@gmail.com>
Thu, 15 Feb 2024 05:36:16 +0000 (21:36 -0800)
committerArdis Lu <ardisglu@gmail.com>
Thu, 15 Feb 2024 05:36:16 +0000 (21:36 -0800)
Supports older wallets (e.g. Brave Wallet) which use the deprecated .on method from EIP-1193

script.js

index a1d9a79fb4993ead4707702ebc9b1cea16ae725e..69eba57d109038bc19139e17a40f7e60b087c5ca 100644 (file)
--- 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', () => {
This page took 0.036867 seconds and 4 git commands to generate.