fix(@embark/whisper): ensure web3 is ready when whisper info is requested

In 1461e95c39 we've introduced a guard that ensures whisper isn't crashing
when Embark is used with the Simulator. This unfortunately also introduced
code that tries to connect to an existing websocket provider that isn't actually
ready at the time it tries to connect.

This commit ensures `web3.shh.getInfo()` is only called once `web3` is ready
and therefore the WS connection as well.
This commit is contained in:
Pascal Precht 2018-12-14 14:51:44 +01:00 committed by Iuri Matias
parent 503a79ca7a
commit fd311f9d24
1 changed files with 11 additions and 11 deletions

View File

@ -30,18 +30,18 @@ class Whisper {
this.connectToProvider();
this.events.request('processes:register', 'whisper', (cb) => {
this.web3.shh.getInfo((err) => {
if (err) {
const message = err.message || err;
if (message.indexOf('not supported') > -1) {
this.logger.error('Whisper is not supported on your node. Are you using the simulator?');
return this.logger.trace(message);
this.waitForWeb3Ready(() => {
this.web3.shh.getInfo((err) => {
if (err) {
const message = err.message || err;
if (message.indexOf('not supported') > -1) {
this.logger.error('Whisper is not supported on your node. Are you using the simulator?');
return this.logger.trace(message);
}
}
}
this.setServiceCheck();
this.addWhisperToEmbarkJS();
this.addSetProvider();
this.waitForWeb3Ready(() => {
this.setServiceCheck();
this.addWhisperToEmbarkJS();
this.addSetProvider();
this.registerAPICalls();
cb();
});