Skip to content

Commit db3356c

Browse files
committed
detect if there is a connection error and pass it down to the ready function
1 parent 8800da6 commit db3356c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

lib/contracts/code_generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ class CodeGenerator {
135135
} else {
136136
let connectionList = "[" + this.contractsConfig.dappConnection.map((x) => '"' + x + '"').join(',') + "]";
137137
if (self.env === 'development') {
138-
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true});
138+
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done(err);', warnAboutMetamask: true});
139139
} else {
140-
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true});
140+
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done(err);', warnAboutMetamask: true});
141141
}
142142
}
143143

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__mainContext.__LoadManager = function() { this.list = []; this.done = false; }
2-
__mainContext.__LoadManager.prototype.execWhenReady = function(cb) { if (this.done) { cb(); } else { this.list.push(cb) } }
3-
__mainContext.__LoadManager.prototype.doFirst = function(todo) { var self = this; todo(function() { self.done = true; self.list.map((x) => x.apply()) }) }
1+
__mainContext.__LoadManager = function() { this.list = []; this.done = false; this.err = null; }
2+
__mainContext.__LoadManager.prototype.execWhenReady = function(cb) { if (this.done) { cb(this.err); } else { this.list.push(cb) } }
3+
__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])) }) }
44
__mainContext.__loadManagerInstance = new __mainContext.__LoadManager();

lib/contracts/code_templates/web3-connector.js.ejs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ __reduce(<%- connectionList %>,function(prev, value, next) {
2525
});
2626
}, function(err, _result) {
2727
__getAccounts(function(err, accounts) {
28-
web3.eth.defaultAccount = accounts[0];
2928
<% if (warnAboutMetamask) { %>
30-
if (web3.eth.currentProvider.isMetaMask) {
31-
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");
29+
if (web3.eth.currentProvider && web3.eth.currentProvider.isMetaMask) {
30+
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");
3231
}
3332
<% } %>
33+
if (accounts) {
34+
web3.eth.defaultAccount = accounts[0];
35+
}
3436
<%- done %>
3537
});
3638
});

0 commit comments

Comments
 (0)