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

Fix web3 race #76

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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