From 680d4035447ac395b709802fe12d05a8e15d8a81 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 14 Feb 2024 23:42:14 -0800 Subject: [PATCH] Use the found wallet provider directly instead of overwriting window.ethereum Some wallets hijack window.ethereum and prevent overwrite, e.g. Rainbow Wallet --- script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 7a33a57..b9f6397 100644 --- a/script.js +++ b/script.js @@ -149,7 +149,7 @@ walletPicker.addEventListener('click', e => { if (e.target.dataset?.uuid === undefined) { return; } - globalThis.ethereum = wallets.find(wallet => wallet.info.uuid === e.target.dataset.uuid)?.provider ?? globalThis.ethereum; - ethereum?.addListener?.('accountsChanged', setAccount) ?? ethereum.on('accountsChanged', setAccount); - ethereum.request({ method: 'eth_requestAccounts' }).then(setAccount); + const provider = wallets.find(wallet => wallet.info.uuid === e.target.dataset.uuid)?.provider ?? globalThis.ethereum; + provider?.addListener?.('accountsChanged', setAccount) ?? provider.on('accountsChanged', setAccount); + provider.request({ method: 'eth_requestAccounts' }).then(setAccount); }); -- 2.47.3