57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
const fs = require('../../core/fs.js');
|
|
const utils = require('../../utils/utils.js');
|
|
|
|
class ENS {
|
|
constructor(embark, options) {
|
|
this.logger = embark.logger;
|
|
this.events = embark.events;
|
|
this.web3 = options.web3;
|
|
this.namesConfig = options.namesConfig;
|
|
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(EnsNamehashVersion) {
|
|
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({});
|
|
|
|
let code = "\nEmbarkJS.Names.setProvider('ens'," + config + ");";
|
|
|
|
let shouldInit = (namesConfig) => {
|
|
return (namesConfig.provider === 'ens' && namesConfig.enabled === true);
|
|
};
|
|
|
|
this.embark.addProviderInit('names', code, shouldInit);
|
|
}
|
|
}
|
|
|
|
module.exports = ENS;
|