diff --git a/lib/modules/code_generator/code_templates/utils.js.ejs b/lib/modules/code_generator/code_templates/utils.js.ejs deleted file mode 100644 index 1fa58f29a..000000000 --- a/lib/modules/code_generator/code_templates/utils.js.ejs +++ /dev/null @@ -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); -}; - diff --git a/lib/modules/code_generator/code_templates/web3-connector.js.ejs b/lib/modules/code_generator/code_templates/web3-connector.js.ejs index b272786e7..07b83a612 100644 --- a/lib/modules/code_generator/code_templates/web3-connector.js.ejs +++ b/lib/modules/code_generator/code_templates/web3-connector.js.ejs @@ -1,37 +1,3 @@ -__reduce(<%- connectionList %>,function(prev, value, next) { - 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 %> - }); +EmbarkJS.connect(<%- connectionList %>, {warnAboutMetamask: <%= warnAboutMetamask %>}, function(err) { + <%- done %> }); diff --git a/lib/modules/code_generator/index.js b/lib/modules/code_generator/index.js index 5c53da23c..d16fa9445 100644 --- a/lib/modules/code_generator/index.js +++ b/lib/modules/code_generator/index.js @@ -4,7 +4,6 @@ const utils = require('../../utils/utils.js'); require('ejs'); const Templates = { - utils: require('./code_templates/utils.js.ejs'), vanilla_contract: require('./code_templates/vanilla-contract.js.ejs'), embarkjs_contract: require('./code_templates/embarkjs-contract.js.ejs'), exec_when_ready: require('./code_templates/exec-when-ready.js.ejs'), @@ -116,7 +115,6 @@ class CodeGenerator { let result = ""; let providerPlugins; - result += Templates.utils(); result += Templates.main_context(); result += Templates.load_manager(); result += Templates.define_when_env_loaded();