detect if there is a connection error and pass it down to the ready function

This commit is contained in:
Iuri Matias 2018-06-29 17:49:17 -04:00
parent 8800da6b42
commit db3356cec0
3 changed files with 10 additions and 8 deletions

View File

@ -135,9 +135,9 @@ class CodeGenerator {
} else { } else {
let connectionList = "[" + this.contractsConfig.dappConnection.map((x) => '"' + x + '"').join(',') + "]"; let connectionList = "[" + this.contractsConfig.dappConnection.map((x) => '"' + x + '"').join(',') + "]";
if (self.env === 'development') { if (self.env === 'development') {
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true}); web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done(err);', warnAboutMetamask: true});
} else { } else {
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true}); web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done(err);', warnAboutMetamask: true});
} }
} }

View File

@ -1,4 +1,4 @@
__mainContext.__LoadManager = function() { this.list = []; this.done = false; } __mainContext.__LoadManager = function() { this.list = []; this.done = false; this.err = null; }
__mainContext.__LoadManager.prototype.execWhenReady = function(cb) { if (this.done) { cb(); } else { this.list.push(cb) } } __mainContext.__LoadManager.prototype.execWhenReady = function(cb) { if (this.done) { cb(this.err); } else { this.list.push(cb) } }
__mainContext.__LoadManager.prototype.doFirst = function(todo) { var self = this; todo(function() { self.done = true; self.list.map((x) => x.apply()) }) } __mainContext.__LoadManager.prototype.doFirst = function(todo) { var self = this; todo(function(err) { self.done = true; self.err = err; self.list.map((x) => x.apply(x, [self.err])) }) }
__mainContext.__loadManagerInstance = new __mainContext.__LoadManager(); __mainContext.__loadManagerInstance = new __mainContext.__LoadManager();

View File

@ -25,12 +25,14 @@ __reduce(<%- connectionList %>,function(prev, value, next) {
}); });
}, function(err, _result) { }, function(err, _result) {
__getAccounts(function(err, accounts) { __getAccounts(function(err, accounts) {
web3.eth.defaultAccount = accounts[0];
<% if (warnAboutMetamask) { %> <% if (warnAboutMetamask) { %>
if (web3.eth.currentProvider.isMetaMask) { if (web3.eth.currentProvider && web3.eth.currentProvider.isMetaMask) {
console.log("Note: Embark has detected you are in the development environment and using Metamask, please make sure Metamask is connected to your local node"); console.log("%cNote: Embark has detected you are in the development environment and using Metamask, please make sure Metamask is connected to your local node", "font-size: 2em");
} }
<% } %> <% } %>
if (accounts) {
web3.eth.defaultAccount = accounts[0];
}
<%- done %> <%- done %>
}); });
}); });