split out logic to check for web3 into browser entrypoint
This commit is contained in:
parent
ccc043f359
commit
2d41668f2f
|
@ -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;
|
|
@ -15,6 +15,8 @@ EmbarkJS.isNewWeb3 = function (web3Obj) {
|
||||||
return parseInt(_web3.version.api.split('.')[0], 10) >= 1;
|
return parseInt(_web3.version.api.split('.')[0], 10) >= 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EmbarkJS.checkWeb3 = function () {};
|
||||||
|
|
||||||
EmbarkJS.Contract = function (options) {
|
EmbarkJS.Contract = function (options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var i, abiElement;
|
var i, abiElement;
|
||||||
|
@ -24,13 +26,16 @@ EmbarkJS.Contract = function (options) {
|
||||||
this.address = options.address;
|
this.address = options.address;
|
||||||
this.gas = options.gas;
|
this.gas = options.gas;
|
||||||
this.code = '0x' + options.code;
|
this.code = '0x' + options.code;
|
||||||
|
|
||||||
//this.web3 = options.web3 || web3;
|
//this.web3 = options.web3 || web3;
|
||||||
this.web3 = options.web3;
|
this.web3 = options.web3;
|
||||||
if (!this.web3 && typeof (web3) !== 'undefined') {
|
|
||||||
this.web3 = web3;
|
//if (!this.web3 && typeof (web3) !== 'undefined') {
|
||||||
} else if (!this.web3) {
|
// this.web3 = web3;
|
||||||
this.web3 = window.web3;
|
//} else if (!this.web3) {
|
||||||
}
|
// this.web3 = window.web3;
|
||||||
|
//}
|
||||||
|
EmbarkJS.checkWeb3.call(this);
|
||||||
|
|
||||||
if (EmbarkJS.isNewWeb3(this.web3)) {
|
if (EmbarkJS.isNewWeb3(this.web3)) {
|
||||||
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
||||||
|
|
Loading…
Reference in New Issue