Fix for embark run crashing after console connects to it

The providerUrl being provided to the console VM was looking for a WebsocketProvider-specific property which did not exist on the HttpProvider.

Type checking was added to provide the necessary type-dependent property.
This commit is contained in:
emizzle 2018-09-17 13:03:55 +10:00
parent a43627de5b
commit 31d3125baf
1 changed files with 10 additions and 1 deletions

View File

@ -29,7 +29,16 @@ class RunCode {
}
getWeb3Config() {
return {defaultAccount: this.context.web3.eth.defaultAccount, providerUrl: this.context.web3.currentProvider.connection._url};
const Web3 = require('web3');
const provider = this.context.web3.currentProvider;
let providerUrl;
if(provider instanceof Web3.providers.HttpProvider){
providerUrl = provider.host;
}
else if(provider instanceof Web3.provider.WebsocketProvider){
providerUrl = provider.connection._url;
}
return {defaultAccount: this.context.web3.eth.defaultAccount, providerUrl: providerUrl};
}
}