diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index b18798072..394b6cee7 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -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) {