mirror of https://github.com/embarklabs/embark.git
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:
parent
503a79ca7a
commit
fd311f9d24
|
@ -30,18 +30,18 @@ class Whisper {
|
||||||
this.connectToProvider();
|
this.connectToProvider();
|
||||||
|
|
||||||
this.events.request('processes:register', 'whisper', (cb) => {
|
this.events.request('processes:register', 'whisper', (cb) => {
|
||||||
this.web3.shh.getInfo((err) => {
|
this.waitForWeb3Ready(() => {
|
||||||
if (err) {
|
this.web3.shh.getInfo((err) => {
|
||||||
const message = err.message || err;
|
if (err) {
|
||||||
if (message.indexOf('not supported') > -1) {
|
const message = err.message || err;
|
||||||
this.logger.error('Whisper is not supported on your node. Are you using the simulator?');
|
if (message.indexOf('not supported') > -1) {
|
||||||
return this.logger.trace(message);
|
this.logger.error('Whisper is not supported on your node. Are you using the simulator?');
|
||||||
|
return this.logger.trace(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
this.setServiceCheck();
|
||||||
this.setServiceCheck();
|
this.addWhisperToEmbarkJS();
|
||||||
this.addWhisperToEmbarkJS();
|
this.addSetProvider();
|
||||||
this.addSetProvider();
|
|
||||||
this.waitForWeb3Ready(() => {
|
|
||||||
this.registerAPICalls();
|
this.registerAPICalls();
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue