remove utils; use EmbarkJS.connect method

This commit is contained in:
Iuri Matias 2018-08-27 16:45:44 -04:00
parent 0428ff83cb
commit e42c4f94d8
3 changed files with 2 additions and 93 deletions

View File

@ -1,55 +0,0 @@
function __reduce(arr, memo, iteratee, cb) {
if (typeof cb !== 'function') {
if (typeof memo === 'function' && typeof iteratee === 'function') {
cb = iteratee;
iteratee = memo;
memo = [];
} else {
throw new TypeError('expected callback to be a function');
}
}
if (!Array.isArray(arr)) {
cb(new TypeError('expected an array'));
return;
}
if (typeof iteratee !== 'function') {
cb(new TypeError('expected iteratee to be a function'));
return;
}
(function next(i, acc) {
if (i === arr.length) {
cb(null, acc);
return;
}
iteratee(acc, arr[i], function(err, val) {
if (err) {
cb(err);
return;
}
next(i + 1, val);
});
})(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);
return null;
}).catch(function(err) {
cb(err);
return null;
});
return;
}
web3.eth.getAccounts(cb);
};

View File

@ -1,37 +1,3 @@
__reduce(<%- connectionList %>,function(prev, value, next) { EmbarkJS.connect(<%- connectionList %>, {warnAboutMetamask: <%= warnAboutMetamask %>}, function(err) {
if (prev === false) {
return next(null, false);
}
if (value === '$WEB3' && (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined')) {
web3.setProvider(web3.givenProvider);
} else if (value !== '$WEB3' && (typeof Web3 !== 'undefined' && ((typeof web3 === 'undefined') || (typeof web3 !== 'undefined' && (!web3.isConnected || (web3.isConnected && !web3.isConnected())))))) {
if (value.indexOf('ws://') >= 0) {
web3.setProvider(new Web3.providers.WebsocketProvider(value));
} else {
web3.setProvider(new Web3.providers.HttpProvider(value));
}
} else if (value === '$WEB3') {
return next(null, '');
}
__getAccounts(function(err, account) {
if (err) {
next(null, true)
} else {
next(null, false)
}
});
}, function(err, _result) {
__getAccounts(function(err, accounts) {
<% if (warnAboutMetamask) { %>
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 %> <%- done %>
});
}); });

View File

@ -4,7 +4,6 @@ const utils = require('../../utils/utils.js');
require('ejs'); require('ejs');
const Templates = { const Templates = {
utils: require('./code_templates/utils.js.ejs'),
vanilla_contract: require('./code_templates/vanilla-contract.js.ejs'), vanilla_contract: require('./code_templates/vanilla-contract.js.ejs'),
embarkjs_contract: require('./code_templates/embarkjs-contract.js.ejs'), embarkjs_contract: require('./code_templates/embarkjs-contract.js.ejs'),
exec_when_ready: require('./code_templates/exec-when-ready.js.ejs'), exec_when_ready: require('./code_templates/exec-when-ready.js.ejs'),
@ -116,7 +115,6 @@ class CodeGenerator {
let result = ""; let result = "";
let providerPlugins; let providerPlugins;
result += Templates.utils();
result += Templates.main_context(); result += Templates.main_context();
result += Templates.load_manager(); result += Templates.load_manager();
result += Templates.define_when_env_loaded(); result += Templates.define_when_env_loaded();