From 2d41668f2f346a72c66927b58e40154b7a70b58b Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 6 Jul 2018 10:10:12 -0500 Subject: [PATCH] split out logic to check for web3 into browser entrypoint --- src/browser.js | 14 ++++++++++++++ src/embark.js | 15 ++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/browser.js diff --git a/src/browser.js b/src/browser.js new file mode 100644 index 0000000..fb18030 --- /dev/null +++ b/src/browser.js @@ -0,0 +1,14 @@ +import _EmbarkJS from './embark'; + +var EmbarkJS = Object.assign({}, _EmbarkJS); + +EmbarkJS.checkWeb3 = function () { + _EmbarkJS.checkWeb3.call(this); + if (!this.web3 && typeof (web3) !== 'undefined') { + this.web3 = web3; + } else if (!this.web3) { + this.web3 = window.web3; + } +}; + +export default EmbarkJS; diff --git a/src/embark.js b/src/embark.js index 2db701e..53757ce 100644 --- a/src/embark.js +++ b/src/embark.js @@ -15,6 +15,8 @@ EmbarkJS.isNewWeb3 = function (web3Obj) { return parseInt(_web3.version.api.split('.')[0], 10) >= 1; }; +EmbarkJS.checkWeb3 = function () {}; + EmbarkJS.Contract = function (options) { var self = this; var i, abiElement; @@ -24,13 +26,16 @@ EmbarkJS.Contract = function (options) { this.address = options.address; this.gas = options.gas; this.code = '0x' + options.code; + //this.web3 = options.web3 || web3; this.web3 = options.web3; - if (!this.web3 && typeof (web3) !== 'undefined') { - this.web3 = web3; - } else if (!this.web3) { - this.web3 = window.web3; - } + + //if (!this.web3 && typeof (web3) !== 'undefined') { + // this.web3 = web3; + //} else if (!this.web3) { + // this.web3 = window.web3; + //} + EmbarkJS.checkWeb3.call(this); if (EmbarkJS.isNewWeb3(this.web3)) { ContractClass = new this.web3.eth.Contract(this.abi, this.address);