Skip to content

Commit

Permalink
fix(@embark/whisper): ensure web3 is ready when whisper info is reque…
Browse files Browse the repository at this point in the history
…sted

In 1461e95 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.
  • Loading branch information
0x-r4bbit authored and iurimatias committed Dec 14, 2018
1 parent 503a79c commit fd311f9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/lib/modules/whisper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit fd311f9

Please sign in to comment.