Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Fix web3 race (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
piazzatron authored Oct 22, 2020
1 parent 71f8420 commit 10b2db2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<script
defer
onLoad="window.dispatchEvent(new CustomEvent('WEB3_LOADED'))"
onLoad="window.web3Loaded = true; window.dispatchEvent(new CustomEvent('WEB3_LOADED'))"
src="%PUBLIC_URL%/scripts/web3.min.js"
></script>

Expand Down
8 changes: 6 additions & 2 deletions src/services/AudiusBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down

0 comments on commit 10b2db2

Please sign in to comment.