diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index ef9fb6514..dc8354301 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -135,9 +135,9 @@ class CodeGenerator { } else { let connectionList = "[" + this.contractsConfig.dappConnection.map((x) => '"' + x + '"').join(',') + "]"; 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 { - web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true}); + web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done(err);', warnAboutMetamask: true}); } } diff --git a/lib/contracts/code_templates/load-manager.js.ejs b/lib/contracts/code_templates/load-manager.js.ejs index ff9b82590..0dd7f5617 100644 --- a/lib/contracts/code_templates/load-manager.js.ejs +++ b/lib/contracts/code_templates/load-manager.js.ejs @@ -1,4 +1,4 @@ -__mainContext.__LoadManager = function() { this.list = []; this.done = false; } -__mainContext.__LoadManager.prototype.execWhenReady = function(cb) { if (this.done) { cb(); } 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 = function() { this.list = []; this.done = false; this.err = null; } +__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(err) { self.done = true; self.err = err; self.list.map((x) => x.apply(x, [self.err])) }) } __mainContext.__loadManagerInstance = new __mainContext.__LoadManager(); diff --git a/lib/contracts/code_templates/web3-connector.js.ejs b/lib/contracts/code_templates/web3-connector.js.ejs index f44368db3..2cf5f9b52 100644 --- a/lib/contracts/code_templates/web3-connector.js.ejs +++ b/lib/contracts/code_templates/web3-connector.js.ejs @@ -25,12 +25,14 @@ __reduce(<%- connectionList %>,function(prev, value, next) { }); }, function(err, _result) { __getAccounts(function(err, accounts) { - web3.eth.defaultAccount = accounts[0]; <% if (warnAboutMetamask) { %> - if (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"); + if (web3.eth.currentProvider && web3.eth.currentProvider.isMetaMask) { + 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 %> }); });