From: Ardis Lu Date: Thu, 15 Feb 2024 07:42:14 +0000 (-0800) Subject: Use the found wallet provider directly instead of overwriting window.ethereum X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=680d4035447ac395b709802fe12d05a8e15d8a81;p=alu.bz Use the found wallet provider directly instead of overwriting window.ethereum Some wallets hijack window.ethereum and prevent overwrite, e.g. Rainbow Wallet --- 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); });