From 10b2db2071b6721a1cbd8fb362506f8ba8be6cf5 Mon Sep 17 00:00:00 2001 From: Michael Piazza Date: Thu, 22 Oct 2020 15:14:39 -0700 Subject: [PATCH] Fix web3 race (#76) --- public/index.html | 2 +- src/services/AudiusBackend.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/public/index.html b/public/index.html index 198d0473b0..29b3ba4814 100644 --- a/public/index.html +++ b/public/index.html @@ -34,7 +34,7 @@ diff --git a/src/services/AudiusBackend.js b/src/services/AudiusBackend.js index 7f3525c84a..5cc78eb2d3 100644 --- a/src/services/AudiusBackend.js +++ b/src/services/AudiusBackend.js @@ -388,9 +388,13 @@ class AudiusBackend { static async setup() { // Wait for web3 to load if necessary - if (!window.Web3) { + if (!window.web3Loaded) { await new Promise(resolve => { - window.addEventListener('WEB3_LOADED', resolve) + const onLoad = () => { + window.removeEventListener('WEB3_LOADED', onLoad) + resolve() + } + window.addEventListener('WEB3_LOADED', onLoad) }) }