From ac2ebb20646e1beafb1e6d5a9d3aba28b82f87d4 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Jun 2018 18:04:52 +0200 Subject: [PATCH 1/2] UniversalDApp refactor --- src/app.js | 19 +------------ src/app/panels/editor-panel.js | 4 +++ src/universal-dapp.js | 50 ++++++++++++++++++++++------------ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/app.js b/src/app.js index 5bad821530..66144b68c2 100644 --- a/src/app.js +++ b/src/app.js @@ -374,24 +374,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org // @TODO should put this in runtab registry.put({api: transactionContextAPI, name: 'transactionContextAPI'}) - var udapp = new UniversalDApp({ - api: { - logMessage: (msg) => { - self._components.editorpanel.log({ type: 'log', value: msg }) - }, - logHtmlMessage: (msg) => { - self._components.editorpanel.log({ type: 'html', value: msg }) - }, - config: self._api.config, - detectNetwork: (cb) => { - executionContext.detectNetwork(cb) - }, - personalMode: () => { - return self._api.config.get('settings/personal-mode') - } - }, - opt: { removable: false, removable_instances: true } - }) + var udapp = new UniversalDApp({ removable: false, removable_instances: true }) registry.put({api: udapp, name: 'udapp'}) var udappUI = new UniversalDAppUI(udapp) diff --git a/src/app/panels/editor-panel.js b/src/app/panels/editor-panel.js index 6ecd460c70..370a14683a 100644 --- a/src/app/panels/editor-panel.js +++ b/src/app/panels/editor-panel.js @@ -100,6 +100,10 @@ class EditorPanel { var self = this self.log({type: 'log', value: msg}) } + logHtmlMessage (msg) { + var self = this + self.log({type: 'html', value: msg}) + } render () { var self = this if (self._view.el) return self._view.el diff --git a/src/universal-dapp.js b/src/universal-dapp.js index bf17cd2a7e..454517ad99 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -15,6 +15,7 @@ var txHelper = remixLib.execution.txHelper var executionContext = require('./execution-context') var modalCustom = require('./app/ui/modal-dialog-custom') var uiUtil = require('./app/ui/util') +var globalRegistry = require('./global/registry') var modalDialog = require('./app/ui/modaldialog') var typeConversion = remixLib.execution.typeConversion @@ -23,20 +24,35 @@ var confirmDialog = require('./app/execution/confirmDialog') /* trigger debugRequested */ -function UniversalDApp (opts = {}) { +function UniversalDApp (opts, localRegistry) { this.event = new EventManager() var self = this - - self._api = opts.api - self.removable = opts.opt.removable - self.removable_instances = opts.opt.removable_instances + self._components = {} + self._components.registry = localRegistry || globalRegistry + self.removable = opts.removable + self.removable_instances = opts.removable_instances + self._deps = { + config: self._components.registry.get('config').api + } executionContext.event.register('contextChanged', this, function (context) { self.reset(self.contracts) }) - self.txRunner = new TxRunner({}, opts.api) + self._txRunnerAPI = { + config: self._deps.config, + detectNetwork: (cb) => { + executionContext.detectNetwork(cb) + }, + personalMode: () => { + return self._deps.config.get('settings/personal-mode') + } + } + self.txRunner = new TxRunner({}, self._txRunnerAPI) } UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) { + this._deps.editorpanel = this._components.registry.get('editorpanel') + if (this._deps.editorpanel) this._deps.editorpanel = this._deps.editorpanel.api + this.contracts = contracts if (transactionContextAPI) { this.transactionContextAPI = transactionContextAPI @@ -50,12 +66,12 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) { this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce', '0x56BC75E2D63100000') executionContext.vm().stateManager.cache.flush(function () {}) } - this.txRunner = new TxRunner(this.accounts, this._api) + this.txRunner = new TxRunner(this.accounts, this._txRunnerAPI) this.txRunner.event.register('transactionBroadcasted', (txhash) => { - this._api.detectNetwork((error, network) => { + executionContext.detectNetwork((error, network) => { if (!error && network) { var txLink = executionContext.txDetailsLink(network.name, txhash) - if (txLink) this._api.logHtmlMessage(yo`${txLink}`) + if (txLink) this._deps.editorpanel.logHtmlMessage(yo`${txLink}`) } }) }) @@ -63,7 +79,7 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) { UniversalDApp.prototype.newAccount = function (password, cb) { if (!executionContext.isVM()) { - if (!this._api.personalMode()) { + if (!this._deps.config.get('settings/personal-mode')) { return cb('Not running in personal mode') } modalCustom.promptPassphraseCreation((error, passphrase) => { @@ -106,7 +122,7 @@ UniversalDApp.prototype.getAccounts = function (cb) { if (!executionContext.isVM()) { // Weirdness of web3: listAccounts() is sync, `getListAccounts()` is async // See: https://github.com/ethereum/web3.js/issues/442 - if (this._api.personalMode()) { + if (this._deps.config.get('settings/personal-mode')) { executionContext.web3().personal.getListAccounts(cb) } else { executionContext.web3().eth.getAccounts(cb) @@ -177,9 +193,9 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly, if (!error) { if (isUserAction) { if (!args.funABI.constant) { - self._api.logMessage(`${logMsg} pending ... `) + self._deps.editorpanel.logMessage(`${logMsg} pending ... `) } else { - self._api.logMessage(`${logMsg}`) + self._deps.editorpanel.logMessage(`${logMsg}`) } } self.callFunction(args.address, data, args.funABI, (error, txResult) => { @@ -188,7 +204,7 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly, if (isVM) { var vmError = txExecution.checkVMError(txResult) if (vmError.error) { - self._api.logMessage(`${logMsg} errored: ${vmError.message} `) + self._deps.editorpanel.logMessage(`${logMsg} errored: ${vmError.message} `) return } } @@ -197,14 +213,14 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly, outputCb(decoded) } } else { - self._api.logMessage(`${logMsg} errored: ${error} `) + self._deps.editorpanel.logMessage(`${logMsg} errored: ${error} `) } }) } else { - self._api.logMessage(`${logMsg} errored: ${error} `) + self._deps.editorpanel.logMessage(`${logMsg} errored: ${error} `) } }, (msg) => { - self._api.logMessage(msg) + self._deps.editorpanel.logMessage(msg) }, (data, runTxCallback) => { // called for libraries deployment self.runTx(data, runTxCallback) From 268b8de2c1cfd47c88246dca9915aa9ec4c9b72a Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Jun 2018 18:06:44 +0200 Subject: [PATCH 2/2] fix filemanager ref --- src/app/tabs/test-tab.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index 1c35be9aeb..1c4d2f95e0 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -27,6 +27,7 @@ module.exports = class TestTab { return { render () { return self._view.el } } } render () { + var self = this var container = yo`
` function append (container, txt) { @@ -85,7 +86,7 @@ module.exports = class TestTab { container.innerHTML = '' var path = this._deps.fileManager.currentPath() var tests = [] - this._deps.fileManager.filesFromPath(path, (error, files) => { + self._deps.fileManager.filesFromPath(path, (error, files) => { if (!error) { for (var file in files) { if (/.(_test.sol)$/.exec(file)) tests.push(path + file)