Skip to content

Commit b1684d8

Browse files
authored
Merge pull request #595 from embark-framework/bad_connection_handling_patch_fix
Bad connection handling patch fix
2 parents 098a896 + 6ee3876 commit b1684d8

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

lib/contracts/code_generator.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,15 @@ class CodeGenerator {
126126
result += plugin.generateProvider(self) + "\n";
127127
});
128128
} else {
129-
130129
let web3Load;
131130

132131
if (isDeployment) {
133132
let connection = "http://" + this.contractsConfig.deployment.host + ":" + this.contractsConfig.deployment.port;
134133
web3Load = Templates.define_web3_simple({url: connection, done: 'done();'});
135134
} else {
136135
let connectionList = "[" + this.contractsConfig.dappConnection.map((x) => '"' + x + '"').join(',') + "]";
137-
if (self.env === 'development') {
138-
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true});
139-
} else {
140-
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true});
141-
}
136+
let isDev = (self.env === 'development');
137+
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done(err);', warnAboutMetamask: isDev});
142138
}
143139

144140
result += Templates.do_when_loaded({block: web3Load});
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)