From 5028bd90e0d355052e6744aff62f99dc91d3f91d Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Wed, 23 May 2018 10:24:53 -0500 Subject: [PATCH] flesh out the index for ENS a bit further Signed-off-by: VoR0220 --- lib/modules/ens/index.js | 49 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 0bc0df4e9..ec63b5e82 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -1,4 +1,5 @@ const fs = require('../../core/fs.js'); +const utils = require('../../utils/utils.js'); class ENS { constructor(embark, options) { @@ -6,5 +7,51 @@ class ENS { this.events = embark.events; this.web3 = options.web3; this.embark = embark; + + this.addENSToEmbarkJS(); + this.addSetProvider(); } -} \ No newline at end of file + + addENSToEmbarkJS() { + const self = this; + // TODO: make this a shouldAdd condition + if (this.namesConfig === {}) { + return; + } + + if ((this.namesConfig.available_providers.indexOf('ens') < 0) && (this.namesConfig.provider !== 'ens' || this.namesConfig.enabled !== true)) { + return; + } + + self.events.request("version:get:eth-ens-namehash", function(namehashVersion) { + let currentEnsNamehashVersion = require('../../../package.json').dependencies["eth-ens-namehash"]; + if (EnsNamehashVersion !== currentEnsNamehashVersion) { + self.events.request("version:getPackageLocation", "eth-ens-namehash", EnsNamehashVersion, function(err, location) { + self.embark.registerImportFile("eth-ens-namehash", fs.dappPath(location)); + }); + } + }); + + let code = ""; + code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString(); + code += "\nEmbarkJS.Names.registerProvider('ens', __embarkENS);"; + + this.embark.addCodeToEmbarkJS(code); + } + + addSetProvider() { + let config = JSON.stringify({ + web3: this.nameConfig.web3, + }); + + let code = "\nEmbarkJS.Names.setProvider('ens'," + config + ");"; + + let shouldInit = (storageConfig) => { + return (namesConfig.provider === 'ens' && storageConfig.enabled === true); + }; + + this.embark.addProviderInit('names', code, shouldInit); + } +} + +module.exports = ENS; \ No newline at end of file