mirror of https://github.com/embarklabs/embark.git
flesh out the index for ENS a bit further
Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
parent
4de830ca29
commit
5028bd90e0
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
Loading…
Reference in New Issue