diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index b9819b78e..12b35c899 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -55,7 +55,6 @@ class EmbarkController { let self = this; self.context = options.context || [constants.contexts.run, constants.contexts.build]; let Dashboard = require('./dashboard/dashboard.js'); - let REPL = require('./dashboard/repl.js'); let webServerConfig = { enabled: options.runWebserver @@ -93,14 +92,6 @@ class EmbarkController { async.parallel([ function startDashboard(callback) { if (!options.useDashboard) { - new REPL({ - env: engine.env, - plugins: engine.plugins, - version: engine.version, - events: engine.events, - logger: engine.logger, - ipc: engine.ipc - }).startConsole(); return callback(); } @@ -109,8 +100,7 @@ class EmbarkController { logger: engine.logger, plugins: engine.plugins, version: self.version, - env: engine.env, - ipc: engine.ipc + env: engine.env }); dashboard.start(function () { engine.logger.info(__('dashboard start')); @@ -133,6 +123,7 @@ class EmbarkController { engine.startService("storage"); engine.startService("codeGenerator"); engine.startService("namingSystem"); + engine.startService("console"); engine.events.on('check:backOnline:Ethereum', function () { engine.logger.info(__('Ethereum node detected') + '..'); @@ -279,11 +270,14 @@ class EmbarkController { engine.startService("storage"); engine.startService("codeGenerator"); engine.startService("webServer"); + engine.startService("namingSystem"); + engine.startService("console"); return callback(); } engine.startService("codeRunner"); + engine.startService("console"); callback(); }); }, @@ -315,6 +309,7 @@ class EmbarkController { if(engine.ipc.connected && engine.ipc.isClient()) { return callback(); } + engine.config.reloadConfig(); engine.events.request('deploy:contracts', function (err) { callback(err); }); @@ -331,15 +326,7 @@ class EmbarkController { }); }, function startREPL(callback) { - let repl = new REPL({ - env: engine.env, - plugins: engine.plugins, - version: engine.version, - events: engine.events, - logger: engine.logger, - ipc: engine.ipc - }); - repl.start(callback); + new REPL({events: engine.events, env: engine.env}).start(callback); } ], function (err, _result) { if (err) { diff --git a/cmd/dashboard/dashboard.js b/cmd/dashboard/dashboard.js index 107ebb979..12715b789 100644 --- a/cmd/dashboard/dashboard.js +++ b/cmd/dashboard/dashboard.js @@ -2,7 +2,6 @@ let async = require('async'); let windowSize = require('window-size'); let Monitor = require('./monitor.js'); -let Console = require('./console.js'); class Dashboard { constructor(options) { @@ -11,7 +10,6 @@ class Dashboard { this.plugins = options.plugins; this.version = options.version; this.env = options.env; - this.ipc = options.ipc; this.events.on('firstDeploymentDone', this.checkWindowSize.bind(this)); this.events.on('outputDone', this.checkWindowSize.bind(this)); @@ -25,44 +23,23 @@ class Dashboard { } start(done) { - let console, monitor; - let self = this; + let monitor; - async.waterfall([ - function startConsole(callback) { - console = new Console({ - events: self.events, - plugins: self.plugins, - version: self.version, - ipc: self.ipc, - logger: self.logger - }); - callback(); - }, - function startMonitor(callback) { - monitor = new Monitor({env: self.env, console: console, events: self.events}); - self.logger.logFunction = monitor.logEntry; + monitor = new Monitor({env: this.env, events: this.events}); + this.logger.logFunction = monitor.logEntry; - self.events.on('contractsState', monitor.setContracts); - self.events.on('status', monitor.setStatus.bind(monitor)); - self.events.on('servicesState', monitor.availableServices.bind(monitor)); + this.events.on('contractsState', monitor.setContracts); + this.events.on('status', monitor.setStatus.bind(monitor)); + this.events.on('servicesState', monitor.availableServices.bind(monitor)); - self.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor)); + this.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor)); - self.logger.info('========================'.bold.green); - self.logger.info((__('Welcome to Embark') + ' ' + self.version).yellow.bold); - self.logger.info('========================'.bold.green); + this.logger.info('========================'.bold.green); + this.logger.info((__('Welcome to Embark') + ' ' + this.version).yellow.bold); + this.logger.info('========================'.bold.green); - // TODO: do this after monitor is rendered - callback(); - } - ], function () { - self.console = console; - self.monitor = monitor; - done(); - }); + done(); } - } module.exports = Dashboard; diff --git a/cmd/dashboard/monitor.js b/cmd/dashboard/monitor.js index f5ba4bbdf..eb2a256c7 100644 --- a/cmd/dashboard/monitor.js +++ b/cmd/dashboard/monitor.js @@ -366,11 +366,10 @@ class Monitor { } executeCmd(cmd, cb) { - const self = this; - self.logText.log('console> '.bold.green + cmd); - self.console.executeCmd(cmd, function (err, result) { + this.logText.log('console> '.bold.green + cmd); + this.events.request('console:executeCmd', cmd, (err, result) => { let message = err || result; - self.logText.log(message); + this.logText.log(message); if (cb) { cb(message); } diff --git a/cmd/dashboard/repl.js b/cmd/dashboard/repl.js index b89c20f1a..cdc724a95 100644 --- a/cmd/dashboard/repl.js +++ b/cmd/dashboard/repl.js @@ -1,30 +1,13 @@ const repl = require("repl"); const util = require("util"); - -const Console = require('./console.js'); - class REPL { constructor(options) { - this.logger = options.logger; - this.env = options.env; - this.plugins = options.plugins; this.events = options.events; - this.version = options.version; - this.ipc = options.ipc; - } - - startConsole(){ - this.console = new Console({ - events: this.events, - plugins: this.plugins, - version: this.version, - ipc: this.ipc, - logger: this.logger - }); + this.env = options.env } enhancedEval(cmd, context, filename, callback) { - this.console.executeCmd(cmd.trim(), callback); + this.events.request('console:executeCmd', cmd.trim(), callback); } enhancedWriter(output) { @@ -36,7 +19,6 @@ class REPL { } start(done) { - this.startConsole(); this.replServer = repl.start({ prompt: "Embark (" + this.env + ") > ", useGlobal: true, diff --git a/lib/core/config.js b/lib/core/config.js index eacff5268..fb95558e4 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -63,10 +63,7 @@ Config.prototype.loadConfigFiles = function(options) { this.loadStorageConfigFile(); this.loadCommunicationConfigFile(); this.loadNameSystemConfigFile(); - - this.loadContractsConfigFile(); this.loadPipelineConfigFile(); - this.loadContractsConfigFile(); this.loadExternalContractsFiles(); this.loadWebServerConfigFile(); @@ -82,7 +79,6 @@ Config.prototype.reloadConfig = function() { this.loadStorageConfigFile(); this.loadCommunicationConfigFile(); this.loadNameSystemConfigFile(); - this.loadContractsConfigFile(); this.loadPipelineConfigFile(); this.loadContractsConfigFile(); this.loadExternalContractsFiles(); diff --git a/lib/core/engine.js b/lib/core/engine.js index 132e29512..49eb645d4 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -60,6 +60,7 @@ class Engine { "fileWatcher": this.fileWatchService, "webServer": this.webServerService, "namingSystem": this.namingSystem, + "console": this.console, "web3": this.web3Service, "libraryManager": this.libraryManagerService, "processManager": this.processManagerService, @@ -129,9 +130,21 @@ class Engine { this.registerModule('ens'); } + console(_options) { + this.registerModule('console', { + events: this.events, + plugins: this.plugins, + version: this.version, + ipc: this.ipc, + logger: this.logger, + config: this.config + }); + } + codeRunnerService(_options) { const CodeRunner = require('./modules/coderunner/codeRunner.js'); this.codeRunner = new CodeRunner({ + config: this.config, plugins: this.plugins, events: this.events, logger: this.logger, diff --git a/lib/core/modules/coderunner/codeRunner.js b/lib/core/modules/coderunner/codeRunner.js index 4924c5f48..3fccdfd29 100644 --- a/lib/core/modules/coderunner/codeRunner.js +++ b/lib/core/modules/coderunner/codeRunner.js @@ -1,76 +1,91 @@ -// still needs to be run on a separate file due to the global context -var RunCode = require('./runCode.js'); +const RunCode = require('./runCode.js'); class CodeRunner { constructor(options) { + this.config = options.config; this.plugins = options.plugins; this.logger = options.logger; this.events = options.events; this.ipc = options.ipc; this.commands = []; this.runCode = new RunCode(); - let self = this; + this.registerIpcEvents(); + this.IpcClientListen(); + this.registerEvents(); + this.registerCommands(); + } - if (this.ipc.isServer()) { - this.ipc.on('runcode:getCommands', (_err, callback) => { - let result = {web3Config: self.runCode.getWeb3Config(), commands: self.commands}; - callback(null, result); - }); + registerIpcEvents() { + if (!this.ipc.isServer()) { + return; } - if (this.ipc.isClient() && this.ipc.connected) { - this.ipc.listenTo('runcode:newCommand', function (command) { - if (command.varName) { - self.events.emit("runcode:register", command.varName, command.code); - } else { - self.events.request("runcode:eval", command.code); - } - }); - } - - this.events.on("runcode:register", (varName, code) => { - if (self.ipc.isServer() && varName !== 'web3') { - self.commands.push({varName, code}); - self.ipc.broadcast("runcode:newCommand", {varName, code}); - } - self.runCode.registerVar(varName, code); - }); - - this.events.setCommandHandler('runcode:getContext', (cb) => { - cb(self.runCode.context); - }); - - this.events.setCommandHandler('runcode:eval', (code, cb, forConsoleOnly = false) => { - if (!cb) { - cb = function() {}; - } - const awaitIdx = code.indexOf('await'); - if (awaitIdx > -1) { - if (awaitIdx < 2) { - let end = code.length; - if (code[end - 1] === ';') { - end--; // Remove the `;` because we add function calls - } - code = code.substring(5, end); // remove await keyword - } else { - code = `(async function() {${code}})();`; - } - } - let result = self.runCode.doEval(code); - - if (forConsoleOnly && self.ipc.isServer()) { - self.commands.push({code}); - self.ipc.broadcast("runcode:newCommand", {code}); - } - - if (result instanceof Promise) { - return result.then((value) => cb(null, value)).catch(cb); - } - - cb(null, result); + this.ipc.on('runcode:getCommands', (_err, callback) => { + let result = {web3Config: this.runCode.getWeb3Config(), commands: this.commands}; + callback(null, result); }); } + IpcClientListen() { + if (!this.ipc.isClient() || !this.ipc.connected) { + return; + } + + this.ipc.listenTo('runcode:newCommand', (command) => { + if (command.varName) { + this.events.emit("runcode:register", command.varName, command.code); + } else { + this.events.request("runcode:eval", command.code); + } + }); + } + + registerEvents() { + this.events.on("runcode:register", this.registerVar.bind(this)); + } + + registerCommands() { + this.events.setCommandHandler('runcode:getContext', (cb) => { + cb(this.runCode.context); + }); + this.events.setCommandHandler('runcode:eval', this.evalCode.bind(this)); + } + + registerVar(varName, code, toRecord = true) { + if (this.ipc.isServer() && toRecord) { + this.commands.push({varName, code}); + this.ipc.broadcast("runcode:newCommand", {varName, code}); + } + this.runCode.registerVar(varName, code); + } + + evalCode(code, cb, forConsoleOnly = false) { + cb = cb || function() {}; + const awaitIdx = code.indexOf('await'); + if (awaitIdx > -1) { + if (awaitIdx < 2) { + let end = code.length; + if (code[end - 1] === ';') { + end--; // Remove the `;` because we add function calls + } + code = code.substring(5, end); // remove await keyword + } else { + code = `(async function() {${code}})();`; + } + } + let result = this.runCode.doEval(code); + + if (forConsoleOnly && this.ipc.isServer()) { + this.commands.push({code}); + this.ipc.broadcast("runcode:newCommand", {code}); + } + + if (result instanceof Promise) { + return result.then((value) => cb(null, value)).catch(cb); + } + + cb(null, result); + } } module.exports = CodeRunner; diff --git a/lib/core/modules/coderunner/runCode.js b/lib/core/modules/coderunner/runCode.js index 730780911..0fc2ff6cc 100644 --- a/lib/core/modules/coderunner/runCode.js +++ b/lib/core/modules/coderunner/runCode.js @@ -2,11 +2,15 @@ const vm = require('vm'); class RunCode { constructor() { - this.context = Object.assign({}, global.this); + this.context = Object.assign({}, {global, console, exports, require, module, __filename, __dirname}); } doEval(code) { - return vm.runInNewContext(code, this.context); + try { + return vm.runInNewContext(code, this.context); + } catch(e) { + console.error(e.message); + } } registerVar(varName, code) { @@ -16,6 +20,7 @@ class RunCode { if (varName === 'web3') { global.web3 = code; } + this.context["global"][varName] = code; this.context[varName] = code; } diff --git a/lib/core/plugin.js b/lib/core/plugin.js index 80e14ec05..70957ffac 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -25,6 +25,7 @@ var Plugin = function(options) { this.imports = []; this.embarkjs_code = []; this.embarkjs_init_code = {}; + this.embarkjs_init_console_code = {}; this.afterContractsDeployActions = []; this.onDeployActions = []; this.eventActions = {}; @@ -189,6 +190,12 @@ Plugin.prototype.addProviderInit = function(providerType, code, initCondition) { this.addPluginType('initCode'); }; +Plugin.prototype.addConsoleProviderInit = function(providerType, code, initCondition) { + this.embarkjs_init_console_code[providerType] = this.embarkjs_init_console_code[providerType] || []; + this.embarkjs_init_console_code[providerType].push([code, initCondition]); + this.addPluginType('initConsoleCode'); +}; + Plugin.prototype.registerImportFile = function(importName, importLocation) { this.imports.push([importName, importLocation]); this.addPluginType('imports'); diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index 6d812ef5e..ce179cce5 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -254,7 +254,7 @@ class BlockchainConnector { registerWeb3Object() { // doesn't feel quite right, should be a cmd or plugin method // can just be a command without a callback - this.events.emit("runcode:register", "web3", this.web3); + this.events.emit("runcode:register", "web3", this.web3, false); } subscribeToPendingTransactions() { diff --git a/lib/modules/code_generator/index.js b/lib/modules/code_generator/index.js index 8c13819b0..cd5dfdf81 100644 --- a/lib/modules/code_generator/index.js +++ b/lib/modules/code_generator/index.js @@ -99,6 +99,9 @@ class CodeGenerator { self.buildPlaceholderPage(cb); }); + self.events.setCommandHandler('code-generator:embarkjs:provider-code', (cb) => { + cb(self.getEmbarkJsProviderCode()); + }); } generateContext() { @@ -117,7 +120,7 @@ class CodeGenerator { result += Templates.main_context(); result += Templates.load_manager(); result += Templates.define_when_env_loaded(); - + if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) { return result; } @@ -216,7 +219,6 @@ class CodeGenerator { return result; } - generateStorageInitialization(useEmbarkJS) { if (!useEmbarkJS || this.storageConfig === {}) return ""; @@ -313,18 +315,18 @@ class CodeGenerator { web3Location = web3Location.replace(/\\/g, '/'); // Import paths must always have forward slashes code += "\nimport Web3 from '" + web3Location + "';\n"; code += "\nimport web3 from 'Embark/web3';\n"; + code += "\nimport IpfsApi from 'ipfs-api';\n"; + next(); }, function getJSCode(next) { code += "\n" + embarkjsCode + "\n"; - let pluginsWithCode = self.plugins.getPluginsFor('embarkjsCode'); - for (let plugin of pluginsWithCode) { - code += plugin.embarkjs_code.join('\n'); - } + code += self.getEmbarkJsProviderCode(); code += self.generateCommunicationInitialization(true); code += self.generateStorageInitialization(true); code += self.generateNamesInitialization(true); + next(); }, function writeFile(next) { @@ -337,6 +339,12 @@ class CodeGenerator { }); } + getEmbarkJsProviderCode() { + return this.plugins.getPluginsFor('embarkjsCode').reduce((code, plugin) => ( + code += plugin.embarkjs_code.join('\n') + ), ''); + } + buildContractJS(contractName, contractJSON, cb) { let contractCode = ""; contractCode += "import web3 from 'Embark/web3';\n"; diff --git a/cmd/dashboard/console.js b/lib/modules/console/index.js similarity index 61% rename from cmd/dashboard/console.js rename to lib/modules/console/index.js index 793993012..97fa303ba 100644 --- a/cmd/dashboard/console.js +++ b/lib/modules/console/index.js @@ -1,16 +1,22 @@ -let utils = require('../../lib/utils/utils.js'); +let utils = require('../../utils/utils'); +const EmbarkJS = require('embarkjs'); +const IpfsApi = require('ipfs-api'); +const Web3 = require('web3'); class Console { - constructor(options) { + constructor(_embark, options) { this.events = options.events; this.plugins = options.plugins; this.version = options.version; this.logger = options.logger; this.ipc = options.ipc; + this.config = options.config; if (this.ipc.isServer()) { this.ipc.on('console:executeCmd', this.executeCmd.bind(this)); } + this.events.setCommandHandler("console:executeCmd", this.executeCmd.bind(this)); + this.registerEmbarkJs(); } processEmbarkCmd (cmd) { @@ -65,6 +71,44 @@ class Console { callback(e); } } + + registerEmbarkJs() { + this.events.emit('runcode:register', 'IpfsApi', IpfsApi, false); + this.events.emit('runcode:register', 'Web3', Web3, false); + this.events.emit('runcode:register', 'EmbarkJS', EmbarkJS, false); + + this.events.on('code-generator-ready', () => { + if (this.ipc.connected) { + return; + } + + this.events.request('code-generator:embarkjs:provider-code', (code) => { + const func = () => {}; + this.events.request('runcode:eval', code, func, true); + this.events.request('runcode:eval', this.getInitProviderCode(), func, true); + }); + }); + } + + getInitProviderCode() { + const codeTypes = { + 'communication': this.config.communicationConfig || {}, + 'names': this.config.namesystemConfig || {}, + 'storage': this.config.storageConfig || {} + }; + + return this.plugins.getPluginsFor('initConsoleCode').reduce((acc, plugin) => { + Object.keys(codeTypes).forEach(codeTypeName => { + (plugin.embarkjs_init_console_code[codeTypeName] || []).forEach(initCode => { + let [block, shouldInit] = initCode; + if (shouldInit.call(plugin, codeTypes[codeTypeName])) { + acc += block; + } + }); + }); + return acc; + }, ''); + } } module.exports = Console; diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 3a8418daa..26c711476 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -156,10 +156,10 @@ __embarkENS.setProvider = function (config) { web3.eth.net.getId() .then((id) => { const registryAddress = self.registryAddresses[id] || config.registryAddress; - self.isAvailable = true; - self.ens = new EmbarkJS.Contract({abi: config.registryAbi, address: registryAddress}); - self.registrar = new EmbarkJS.Contract({abi: config.registrarAbi, address: config.registrarAddress}); - self.resolver = new EmbarkJS.Contract({abi: config.resolverAbi, address: config.resolverAddress}); + self._isAvailable = true; + self.ens = new EmbarkJS.Contract({abi: config.registryAbi, address: registryAddress, web3: web3}); + self.registrar = new EmbarkJS.Contract({abi: config.registrarAbi, address: config.registrarAddress, web3: web3}); + self.resolver = new EmbarkJS.Contract({abi: config.resolverAbi, address: config.resolverAddress, web3: web3}); }) .catch(err => { if (err.message.indexOf('Provider not set or invalid') > -1) { @@ -192,7 +192,7 @@ __embarkENS.resolve = function (name, callback) { if (resolverAddress === voidAddress) { return cb('Name not yet registered'); } - let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress}); + let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress, web3: web3}); resolverContract.methods.addr(node).call(cb); }); }; @@ -221,7 +221,7 @@ __embarkENS.lookup = function (address, callback) { if (resolverAddress === voidAddress) { return cb('Address not associated to a resolver'); } - let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress}); + let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress, web3: web3}); resolverContract.methods.name(node).call(cb); }); }; @@ -245,5 +245,5 @@ __embarkENS.registerSubDomain = function (name, address, callback) { }; __embarkENS.isAvailable = function () { - return Boolean(this.isAvailable); + return Boolean(this._isAvailable); }; diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 9455e2a73..23fa652e5 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -307,7 +307,6 @@ class ENS { } addSetProvider(config) { - let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");"; let shouldInit = (namesConfig) => { @@ -315,6 +314,7 @@ class ENS { }; this.embark.addProviderInit('names', code, shouldInit); + this.embark.addConsoleProviderInit('names', code, shouldInit); } } diff --git a/lib/modules/ipfs/embarkjs.js b/lib/modules/ipfs/embarkjs.js index 105739d49..3f4541338 100644 --- a/lib/modules/ipfs/embarkjs.js +++ b/lib/modules/ipfs/embarkjs.js @@ -1,4 +1,4 @@ -import IpfsApi from 'ipfs-api'; +/*global IpfsApi*/ let __embarkIPFS = {}; diff --git a/lib/modules/storage/index.js b/lib/modules/storage/index.js index c6bbb32f7..186434367 100644 --- a/lib/modules/storage/index.js +++ b/lib/modules/storage/index.js @@ -35,6 +35,7 @@ class Storage { }; this.embark.addProviderInit('storage', code, shouldInit); + this.embark.addConsoleProviderInit('storage', code, shouldInit); } } diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index 7b4a6dfb1..2211d5893 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -73,21 +73,22 @@ class Whisper { addSetProvider() { let connection = this.communicationConfig.connection || {}; + const shouldInit = (communicationConfig) => { + return (communicationConfig.provider === 'whisper' && communicationConfig.enabled === true); + }; // todo: make the add code a function as well - let config = { + const config = { server: canonicalHost(connection.host || defaultHost), port: connection.port || '8546', type: connection.type || 'ws' }; - - let code = `\nEmbarkJS.Messages.setProvider('whisper', ${JSON.stringify(config)});`; - - let shouldInit = (communicationConfig) => { - return (communicationConfig.provider === 'whisper' && communicationConfig.enabled === true); - }; - + const code = `\nEmbarkJS.Messages.setProvider('whisper', ${JSON.stringify(config)});`; this.embark.addProviderInit('communication', code, shouldInit); + + const consoleConfig = Object.assign({}, config, {providerOptions: {headers: {Origin: "embark"}}}); + const consoleCode = `\nEmbarkJS.Messages.setProvider('whisper', ${JSON.stringify(consoleConfig)});`; + this.embark.addConsoleProviderInit('communication', consoleCode, shouldInit); } } diff --git a/lib/modules/whisper/js/embarkjs.js b/lib/modules/whisper/js/embarkjs.js index ea72b9d0e..7796b3cc3 100644 --- a/lib/modules/whisper/js/embarkjs.js +++ b/lib/modules/whisper/js/embarkjs.js @@ -12,7 +12,7 @@ __embarkWhisperNewWeb3.setProvider = function (options) { provider = options.server + ':' + options.port; } // TODO: take into account type - self.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider)); + self.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider, options.providerOptions)); self.getWhisperVersion(function (err, version) { if (err) { console.log("whisper not available"); diff --git a/lib/modules/whisper/js/message_events.js b/lib/modules/whisper/js/message_events.js index 302d62bea..dd9319035 100644 --- a/lib/modules/whisper/js/message_events.js +++ b/lib/modules/whisper/js/message_events.js @@ -1,4 +1,3 @@ - let __MessageEvents = function() { this.cb = function() {}; }; diff --git a/templates/demo/app/components/ens.js b/templates/demo/app/components/ens.js index 64e5a4e2a..1afaf5100 100644 --- a/templates/demo/app/components/ens.js +++ b/templates/demo/app/components/ens.js @@ -146,7 +146,7 @@ class ENS extends React.Component { -

Register subdomain for embark

+

Register subdomain

this.checkEnter(e, this.registerSubDomain)}> {this.state.responseRegister && diff --git a/templates/demo/app/dapp.js b/templates/demo/app/dapp.js index 2117558b3..87f5c4a06 100644 --- a/templates/demo/app/dapp.js +++ b/templates/demo/app/dapp.js @@ -21,8 +21,7 @@ class App extends React.Component { error: null, activeKey: 1, whisperEnabled: false, - storageEnabled: false, - ensEnabled: false + storageEnabled: false }; } @@ -56,10 +55,6 @@ class App extends React.Component { }).catch(() => { this.setState({storageEnabled: false}); }); - - this.setState({ - ensEnabled: EmbarkJS.Names.isAvailable() - }); }); } @@ -76,6 +71,7 @@ class App extends React.Component { } render() { + const ensEnabled = EmbarkJS.Names.currentNameSystems && EmbarkJS.Names.isAvailable(); if (this.state.error) { return (
Something went wrong connecting to ethereum. Please make sure you have a node running or are using metamask to connect to the ethereum network:
@@ -94,8 +90,8 @@ class App extends React.Component { - - + +
); diff --git a/test/console.js b/test/console.js index 0ed7eebcc..dac075a7f 100644 --- a/test/console.js +++ b/test/console.js @@ -1,5 +1,5 @@ /*globals describe, it*/ -let Console = require('../cmd/dashboard/console.js'); +let Console = require('../lib/modules/console/'); let Plugins = require('../lib/core/plugins.js'); let IPC = require('../lib/core/ipc.js'); let assert = require('assert'); @@ -8,7 +8,8 @@ let version = require('../package.json').version; describe('embark.Console', function() { let ipc = new IPC({ipcRole: 'none'}); let plugins = new Plugins({plugins: {}}); - let console = new Console({plugins, version, ipc}); + let events = {on: () => {}, setCommandHandler: () => {}, emit: () => {}}; + let console = new Console({}, {plugins, version, ipc, events}); describe('#executeCmd', function() {