embark-area-51/lib/contracts/code_templates/web3-connector.js.ejs

32 lines
1013 B
Plaintext
Raw Normal View History

2017-10-14 00:01:35 +00:00
__mainContext.web3 = undefined;
__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);
2017-10-14 00:01:35 +00:00
} else if (value !== '$WEB3' && (typeof Web3 !== 'undefined' && ((typeof web3 === 'undefined') || (typeof web3 !== 'undefined' && (!web3.isConnected || (web3.isConnected && !web3.isConnected())))))) {
2018-02-08 00:41:11 +00:00
if (value.indexOf('ws://') >= 0) {
web3.setProvider(new Web3.providers.WebsocketProvider(value));
} else {
web3.setProvider(new Web3.providers.HttpProvider(value));
}
2017-10-14 00:01:35 +00:00
} else if (value === '$WEB3') {
return next(null, '');
}
__getAccounts(function(err, account) {
2017-10-14 00:01:35 +00:00
if (err) {
next(null, true)
} else {
next(null, false)
}
});
}, function(err, _result) {
__getAccounts(function(err, accounts) {
2017-10-14 00:01:35 +00:00
web3.eth.defaultAccount = accounts[0];
<%- done %>
});
});