From 633461321559be4530d7ae42a52ceaad4f912290 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Jul 2018 16:29:35 +0200 Subject: [PATCH] move transactionContextAPI to runTab and reset udapp from there --- src/app.js | 41 +++++-------------------------------- src/app/tabs/compile-tab.js | 8 -------- src/app/tabs/run-tab.js | 33 ++++++++++++++++++++++++++++- src/universal-dapp-ui.js | 3 --- src/universal-dapp.js | 29 ++++++++++++++++---------- 5 files changed, 55 insertions(+), 59 deletions(-) diff --git a/src/app.js b/src/app.js index ba8da8d78f..1d046edbfc 100644 --- a/src/app.js +++ b/src/app.js @@ -395,48 +395,17 @@ Please make a backup of your contracts and start using http://remix.ethereum.org var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event) registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'}) - // ----------------- UniversalDApp ----------------- - var transactionContextAPI = { - getAddress: (cb) => { - cb(null, $('#txorigin').val()) - }, - getValue: (cb) => { - try { - var number = document.querySelector('#value').value - var select = document.getElementById('unit') - var index = select.selectedIndex - var selectedUnit = select.querySelectorAll('option')[index].dataset.unit - var unit = 'ether' // default - if (selectedUnit === 'ether') { - unit = 'ether' - } else if (selectedUnit === 'finney') { - unit = 'finney' - } else if (selectedUnit === 'gwei') { - unit = 'gwei' - } else if (selectedUnit === 'wei') { - unit = 'wei' - } - cb(null, executionContext.web3().toWei(number, unit)) - } catch (e) { - cb(e) - } - }, - getGasLimit: (cb) => { - cb(null, $('#gasLimit').val()) - } - } - // @TODO should put this in runtab - registry.put({api: transactionContextAPI, name: 'transactionContextAPI'}) - var udapp = new UniversalDApp({ removable: false, removable_instances: true }) + // ----------------- UniversalDApp ----------------- + var udapp = new UniversalDApp({ + removable: false, + removable_instances: true + }) registry.put({api: udapp, name: 'udapp'}) var udappUI = new UniversalDAppUI(udapp) registry.put({api: udappUI, name: 'udappUI'}) - udapp.reset({}) - udappUI.reset() - // ----------------- Tx listener ----------------- var transactionReceiptResolver = new TransactionReceiptResolver() diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index d86e8b4680..cf81c4baa4 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -33,15 +33,11 @@ module.exports = class CompileTab { // dependencies self._deps = { app: self._components.registry.get('app').api, - udapp: self._components.registry.get('udapp').api, - udappUI: self._components.registry.get('udappUI').api, editor: self._components.registry.get('editor').api, config: self._components.registry.get('config').api, compiler: self._components.registry.get('compiler').api, staticAnalysis: self._components.registry.get('staticanalysis').api, renderer: self._components.registry.get('renderer').api, - fileManager: self._components.registry.get('filemanager').api, - transactionContextAPI: self._components.registry.get('transactionContextAPI').api, rightHandPanel: self._components.registry.get('righthandpanel').api } self.data = { @@ -113,12 +109,8 @@ module.exports = class CompileTab { var contractName = yo`` self._view.contractNames.appendChild(contractName) }) - self._deps.udapp.reset(self.data.contractsDetails, self._deps.transactionContextAPI) - self._deps.udappUI.reset() } else { self._view.contractNames.setAttribute('disabled', true) - self._deps.udapp.reset({}, self._deps.transactionContextAPI) - self._deps.udappUI.reset() } // hightlight the tab if error if (success) document.querySelector('.compileView').style.color = '' // @TODO: compileView tab diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 8c6ec40eee..a99f326907 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -19,7 +19,7 @@ var addTooltip = require('../ui/tooltip') var css = require('./styles/run-tab-styles') var MultiParamManager = require('../../multiParamManager') -function runTab (localRegistry) { +function runTab (opts, localRegistry) { /* ------------------------- VARIABLES --------------------------- */ @@ -35,6 +35,35 @@ function runTab (localRegistry) { } self._components = {} self._components.registry = localRegistry || globlalRegistry + self._components.transactionContextAPI = { + getAddress: (cb) => { + cb(null, $('#txorigin').val()) + }, + getValue: (cb) => { + try { + var number = document.querySelector('#value').value + var select = document.getElementById('unit') + var index = select.selectedIndex + var selectedUnit = select.querySelectorAll('option')[index].dataset.unit + var unit = 'ether' // default + if (selectedUnit === 'ether') { + unit = 'ether' + } else if (selectedUnit === 'finney') { + unit = 'finney' + } else if (selectedUnit === 'gwei') { + unit = 'gwei' + } else if (selectedUnit === 'wei') { + unit = 'wei' + } + cb(null, executionContext.web3().toWei(number, unit)) + } catch (e) { + cb(e) + } + }, + getGasLimit: (cb) => { + cb(null, $('#gasLimit').val()) + } + } // dependencies self._deps = { compiler: self._components.registry.get('compiler').api, @@ -42,8 +71,10 @@ function runTab (localRegistry) { udappUI: self._components.registry.get('udappUI').api, config: self._components.registry.get('config').api, fileManager: self._components.registry.get('filemanager').api, + editor: self._components.registry.get('editor').api, logCallback: self._components.registry.get('logCallback').api } + self._deps.udapp.resetAPI(self._components.transactionContextAPI) self._view.recorderCount = yo`0` self._view.instanceContainer = yo`
` self._view.clearInstanceElement = yo` diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index 674d28d631..a900ff2cd9 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -12,9 +12,6 @@ function UniversalDAppUI (udapp, opts = {}) { this.udapp = udapp } -UniversalDAppUI.prototype.reset = function () { -} - UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName) { var noInstances = document.querySelector('[class^="noInstancesText"]') if (noInstances) { diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 4725c98f8f..7008cbb47e 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -24,15 +24,18 @@ var confirmDialog = require('./app/execution/confirmDialog') function UniversalDApp (opts, localRegistry) { this.event = new EventManager() var self = this + self.data = {} 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, + compiler: self._components.registry.get('compiler').api, logCallback: self._components.registry.get('logCallback').api } executionContext.event.register('contextChanged', this, function (context) { - self.reset(self.contracts) + self.resetEnvironment() }) self._txRunnerAPI = { config: self._deps.config, @@ -44,16 +47,15 @@ function UniversalDApp (opts, localRegistry) { } } self.txRunner = new TxRunner({}, self._txRunnerAPI) + self.data.contractsDetails = {} + self._deps.compiler.event.register('compilationFinished', (success, data, source) => { + self.data.contractsDetails = success && data ? data.contracts : {} + }) + self.accounts = {} + self.resetEnvironment() } -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 - } +UniversalDApp.prototype.resetEnvironment = function () { this.accounts = {} if (executionContext.isVM()) { this._addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511', '0x56BC75E2D63100000') @@ -68,12 +70,16 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) { executionContext.detectNetwork((error, network) => { if (!error && network) { var txLink = executionContext.txDetailsLink(network.name, txhash) - if (txLink) this._deps.editorpanel.logHtmlMessage(yo`${txLink}`) + if (txLink) this._deps.logCallback(yo`${txLink}`) } }) }) } +UniversalDApp.prototype.resetAPI = function (transactionContextAPI) { + this.transactionContextAPI = transactionContextAPI +} + UniversalDApp.prototype.newAccount = function (password, cb) { if (!executionContext.isVM()) { if (!this._deps.config.get('settings/personal-mode')) { @@ -186,7 +192,8 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly, logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` } } - txFormat.buildData(args.contractName, args.contractAbi, self.contracts, false, args.funABI, value, (error, data) => { + // contractsDetails is used to resolve libraries + txFormat.buildData(args.contractName, args.contractAbi, self.data.contractsDetails, false, args.funABI, value, (error, data) => { if (!error) { if (isUserAction) { if (!args.funABI.constant) {