From 8279c620415ce9cfc15a41a170399a21c1cf5bb0 Mon Sep 17 00:00:00 2001 From: Micah Zoltu Date: Sun, 24 Jul 2022 09:36:03 -0700 Subject: [PATCH 1/2] Adds support for delayed injection. A privacy respecting wallet will not inject into the page until *after* the user tells it to so websites cannot fingerprint the user. Unfortunately, this script as currently written doesn't support this pattern because it only calls `handleEthereum` once and if the `timeout` is hit before `ethereum` is injected this will unsubscribe from the event listener and refuse any further attempts at connecting things up. By checking for `ethereum` in window first in `handleEthereum`, if the timeout is hit but nothing is hooked up yet then the system will continue listening for the `ethereum#initialized` event indefinitely. --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 2141c3e..859f1ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,9 @@ function detectEthereumProvider({ } function handleEthereum() { - + if (!('ethereum' in window) { + return; + } if (handled) { return; } From 043c5b5d923ce3a0ef08776985bf4d4b3e4a289c Mon Sep 17 00:00:00 2001 From: Micah Zoltu Date: Sun, 24 Jul 2022 09:36:33 -0700 Subject: [PATCH 2/2] Update index.ts --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 859f1ba..5576875 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,7 @@ function detectEthereumProvider({ } function handleEthereum() { - if (!('ethereum' in window) { + if (!('ethereum' in window)) { return; } if (handled) {