detect web3 version and get accounts correctly

This commit is contained in:
Iuri Matias 2018-05-11 08:20:03 -04:00
parent 6824c17ed3
commit 81e0c9ce77
2 changed files with 19 additions and 2 deletions

View File

@ -34,3 +34,20 @@ function __reduce(arr, memo, iteratee, cb) {
});
})(0, memo);
};
function __isNewWeb3_1() {
return (typeof(web3.version) === "string");
};
function __getAccounts(cb) {
if (__isNewWeb3_1()) {
web3.eth.getAccounts().then(function(accounts) {
cb(null, accounts);
}).catch(function(err) {
cb(err);
});
return;
}
web3.eth.getAccounts(cb);
};

View File

@ -16,7 +16,7 @@ __reduce(<%- connectionList %>,function(prev, value, next) {
return next(null, '');
}
web3.eth.getAccounts(function(err, account) {
__getAccounts(function(err, account) {
if (err) {
next(null, true)
} else {
@ -24,7 +24,7 @@ __reduce(<%- connectionList %>,function(prev, value, next) {
}
});
}, function(err, _result) {
web3.eth.getAccounts(function(err, accounts) {
__getAccounts(function(err, accounts) {
web3.eth.defaultAccount = accounts[0];
<%- done %>
});