Getline-Network / getline

Distributed P2P Lending System
https://getline.in
Apache License 2.0
9 stars 6 forks source link

Fix web3/API page loading race conditions #43

Closed q3k closed 6 years ago

q3k commented 6 years ago

setTimeout() wasn't enough to guarantee consistent loading. In this commit, we make the API.instance() method asynchronous and only return an instance when it's confirmed to be loaded. We also initialize the API instance only on window.load, as per Metamask documentation [1].

[1] - https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md

ritave commented 6 years ago

This shouldn't be in the library probably. I never had to use a timeout or polling when using any kind of web3, either injected or my own. I'd prefer explicit crash with a suggestion that maybe user should wait on window load, and that should be enough

q3k commented 6 years ago

It's not in the library, it's in the frontend code :)