mirror of https://github.com/embarklabs/embark.git
register api calls when web3 ready
This commit is contained in:
parent
289ed2bda8
commit
2d1e081c15
|
@ -15,6 +15,7 @@ class Whisper {
|
|||
this.communicationConfig = embark.config.communicationConfig;
|
||||
this.web3 = new Web3();
|
||||
this.embark = embark;
|
||||
this.web3Ready = false;
|
||||
|
||||
if (!this.communicationConfig.enabled) {
|
||||
return;
|
||||
|
@ -24,6 +25,9 @@ class Whisper {
|
|||
this.setServiceCheck();
|
||||
this.addWhisperToEmbarkJS();
|
||||
this.addSetProvider();
|
||||
this.waitForWeb3Ready(() => {
|
||||
this.registerAPICalls();
|
||||
});
|
||||
}
|
||||
|
||||
connectToProvider() {
|
||||
|
@ -37,6 +41,17 @@ class Whisper {
|
|||
this.web3.setProvider(new Web3.providers.WebsocketProvider(web3Endpoint, {headers: {Origin: "http://embark"}}));
|
||||
}
|
||||
|
||||
waitForWeb3Ready(cb) {
|
||||
if (this.web3Ready) {
|
||||
return cb();
|
||||
}
|
||||
if (this.web3.currentProvider.connection.readyState !== 1) {
|
||||
return setTimeout(this.waitForWeb3Ready.bind(this, cb), 50);
|
||||
}
|
||||
this.web3Ready = true;
|
||||
cb();
|
||||
}
|
||||
|
||||
setServiceCheck() {
|
||||
const self = this;
|
||||
self.events.request("services:register", 'Whisper', function(cb) {
|
||||
|
|
Loading…
Reference in New Issue