use an event to get web3 instead of global

This commit is contained in:
Jonathan Rainville 2018-10-05 13:15:01 -04:00
parent ec1382e838
commit 467eeeec55
2 changed files with 15 additions and 5 deletions

View File

@ -168,6 +168,10 @@ class BlockchainConnector {
registerRequests() { registerRequests() {
const self = this; const self = this;
this.events.setCommandHandler("blockchain:get", function(cb) {
cb(self.web3);
});
this.events.setCommandHandler("blockchain:defaultAccount:get", function(cb) { this.events.setCommandHandler("blockchain:defaultAccount:get", function(cb) {
cb(self.defaultAccount()); cb(self.defaultAccount());
}); });

View File

@ -274,13 +274,19 @@ class ENS {
(resolver) => { (resolver) => {
paraCb(null, resolver); paraCb(null, resolver);
}); });
},
function getWeb3(paraCb) {
self.events.request("blockchain:get",
(web3) => {
paraCb(null, web3);
});
} }
], (err, contracts) => { ], (err, result) => {
self.ensContract = contracts[0]; self.ensContract = result[0];
self.registrarContract = contracts[1]; self.registrarContract = result[1];
self.resolverContract = contracts[2]; self.resolverContract = result[2];
const web3 = result[3];
/*global web3*/
const rootNode = namehash.hash(self.registration.rootDomain); const rootNode = namehash.hash(self.registration.rootDomain);
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + reverseAddrSuffix); var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + reverseAddrSuffix);
self.ensContract.methods.setOwner(rootNode, web3.eth.defaultAccount).send({from: web3.eth.defaultAccount, gas: 700000}).then(() => { self.ensContract.methods.setOwner(rootNode, web3.eth.defaultAccount).send({from: web3.eth.defaultAccount, gas: 700000}).then(() => {