From 93c62d9e92a8b0ccdb1d42aedba7fe991ddd6046 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 09:03:49 -0500 Subject: [PATCH 01/14] initial logical separation between the UI and the logic of the universal-dapp --- src/app.js | 5 + src/universal-dapp-ui.js | 336 ++++++++++++++++++++++++++++++++++++++ src/universal-dapp.js | 338 ++------------------------------------- 3 files changed, 355 insertions(+), 324 deletions(-) create mode 100644 src/universal-dapp-ui.js diff --git a/src/app.js b/src/app.js index 5e49e305cd..7a709392ac 100644 --- a/src/app.js +++ b/src/app.js @@ -7,6 +7,7 @@ var remixLib = require('remix-lib') var EventManager = remixLib.EventManager var UniversalDApp = require('./universal-dapp.js') +var UniversalDAppUI = require('./universal-dapp-ui.js') var Remixd = require('./lib/remixd') var OffsetToLineColumnConverter = require('./lib/offsetToLineColumnConverter') @@ -262,6 +263,10 @@ function run () { }, opt: { removable: false, removable_instances: true } }) + + var udappUI = new UniversalDAppUI(udapp) + console.dir(udappUI) + udapp.reset({}, transactionContextAPI) udapp.event.register('debugRequested', this, function (txResult) { startdebugging(txResult.transactionHash) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js new file mode 100644 index 0000000000..b2f1e769a8 --- /dev/null +++ b/src/universal-dapp-ui.js @@ -0,0 +1,336 @@ +/* global */ +'use strict' + +var $ = require('jquery') +var ethJSUtil = require('ethereumjs-util') +var remixLib = require('remix-lib') +var yo = require('yo-yo') +var txFormat = require('./app/execution/txFormat') +var txHelper = require('./app/execution/txHelper') +var txExecution = require('./app/execution/txExecution') +var helper = require('./lib/helper') +var executionContext = require('./execution-context') +var copyToClipboard = require('./app/ui/copy-to-clipboard') + +// -------------- styling ---------------------- +var csjs = require('csjs-inject') +var styleGuide = remixLib.ui.themeChooser +var styles = styleGuide.chooser() + +var css = csjs` + .instanceTitleContainer { + display: flex; + align-items: center; + } + .title { + ${styles.rightPanel.runTab.titlebox_RunTab} + display: flex; + justify-content: end; + align-items: center; + font-size: 11px; + height: 30px; + width: 97%; + overflow: hidden; + word-break: break-word; + line-height: initial; + overflow: visible; + } + .titleLine { + display: flex; + align-items: baseline; + } + .titleText { + margin-right: 1em; + word-break: break-word; + min-width: 230px; + } + + .title .copy { + color: ${styles.rightPanel.runTab.icon_AltColor_Instance_CopyToClipboard}; + } + .instance { + ${styles.rightPanel.runTab.box_Instance}; + margin-bottom: 10px; + padding: 10px 15px 15px 15px; + } + .instance .title:before { + content: "\\25BE"; + margin-right: 5%; + } + .instance.hidesub .title:before { + content: "\\25B8"; + margin-right: 5%; + } + .instance.hidesub > * { + display: none; + } + .instance.hidesub .title { + display: flex; + } + .instance.hidesub .udappClose { + display: flex; + } + .buttonsContainer { + margin-top: 2%; + display: flex; + overflow: hidden; + } + .contractActions { + display: flex; + } + .instanceButton {} + .closeIcon { + font-size: 12px; + cursor: pointer; + } + .udappClose { + display: flex; + justify-content: flex-end; + } + .contractProperty { + overflow: auto; + margin-bottom: 0.4em; + } + .contractProperty.hasArgs input { + width: 75%; + padding: .36em; + } + .contractProperty button { + ${styles.rightPanel.runTab.button_Create} + min-width: 100px; + width: 100px; + font-size: 10px; + margin:0; + word-break: inherit; + } + .contractProperty button:disabled { + cursor: not-allowed; + background-color: white; + border-color: lightgray; + } + .contractProperty.constant button { + ${styles.rightPanel.runTab.button_Constant} + min-width: 100px; + width: 100px; + font-size: 10px; + margin:0; + word-break: inherit; + outline: none; + width: inherit; + } + .contractProperty input { + display: none; + } + .contractProperty > .value { + box-sizing: border-box; + float: left; + align-self: center; + color: ${styles.appProperties.mainText_Color}; + margin-left: 4px; + } + .hasArgs input { + display: block; + border: 1px solid #dddddd; + padding: .36em; + border-left: none; + padding: 8px 8px 8px 10px; + font-size: 10px; + height: 25px; + } + .hasArgs button { + border-top-right-radius: 0; + border-bottom-right-radius: 0; + border-right: 0; + } +` + +/* + trigger debugRequested +*/ +function UniversalDAppUI (udapp, opts = {}) { + var self = this + this.udapp = udapp + + self.el = yo`
` +} + +UniversalDAppUI.prototype.reset = function (contracts, transactionContextAPI) { + this.el.innerHTML = '' +} + +// TODO: has both UI and Model +UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName) { + var abi = txHelper.sortAbiFunction(contract.abi) + return this.renderInstanceFromABI(abi, address, contractName) +} + +// TODO this function was named before "appendChild". +// this will render an instance: contract name, contract address, and all the public functions +// basically this has to be called for the "atAddress" (line 393) and when a contract creation succeed +// this returns a DOM element +UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address, contractName) { + var self = this + + function remove () { instance.remove() } + + address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex') + var instance = yo`
` + var context = executionContext.isVM() ? 'memory' : 'blockchain' + + var shortAddress = helper.shortenAddress(address) + var title = yo`
+
${contractName} at ${shortAddress} (${context})
+ ${copyToClipboard(() => address)} +
` + + if (self.removable_instances) { + var close = yo`
` + instance.append(close) + } + + function toggleClass () { + $(instance).toggleClass(`${css.hidesub}`) + } + + instance.appendChild(title) + + // Add the fallback function + var fallback = txHelper.getFallbackInterface(contractABI) + if (fallback) { + instance.appendChild(this.getCallButton({ + funABI: fallback, + address: address, + contractAbi: contractABI, + contractName: contractName + })) + } + + $.each(contractABI, (i, funABI) => { + if (funABI.type !== 'function') { + return + } + // @todo getData cannot be used with overloaded functions + instance.appendChild(this.getCallButton({ + funABI: funABI, + address: address, + contractAbi: contractABI, + contractName: contractName + })) + }) + + return instance +} + +// TODO this is used by renderInstance when a new instance is displayed. +// this returns a DOM element. +UniversalDAppUI.prototype.getCallButton = function (args) { + var self = this + // args.funABI, args.address [fun only] + // args.contractName [constr only] + var lookupOnly = args.funABI.constant + + var inputs = '' + if (args.funABI.inputs) { + inputs = txHelper.inputParametersDeclarationToString(args.funABI.inputs) + } + var inputField = yo`` + inputField.setAttribute('placeholder', inputs) + inputField.setAttribute('title', inputs) + + var outputOverride = yo`
` + + var title + if (args.funABI.name) { + title = args.funABI.name + } else { + title = '(fallback)' + } + + var button = yo`` + button.classList.add(css.call) + button.setAttribute('title', title) + button.innerHTML = title + + function clickButton () { + call(true) + } + + function call (isUserAction) { + var logMsg + if (isUserAction) { + if (!args.funABI.constant) { + logMsg = `transact to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` + } else { + logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` + } + } + txFormat.buildData(args.contractName, args.contractAbi, self.contracts, false, args.funABI, inputField.value, self, (error, data) => { + if (!error) { + if (isUserAction) { + if (!args.funABI.constant) { + self._api.logMessage(`${logMsg} pending ... `) + } else { + self._api.logMessage(`${logMsg}`) + } + } + txExecution.callFunction(args.address, data, args.funABI, self, (error, txResult) => { + if (!error) { + var isVM = executionContext.isVM() + if (isVM) { + var vmError = txExecution.checkVMError(txResult) + if (vmError.error) { + self._api.logMessage(`${logMsg} errored: ${vmError.message} `) + return + } + } + if (lookupOnly) { + var decoded = txFormat.decodeResponseToTreeView(executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI) + outputOverride.innerHTML = '' + outputOverride.appendChild(decoded) + } + } else { + self._api.logMessage(`${logMsg} errored: ${error} `) + } + }) + } else { + self._api.logMessage(`${logMsg} errored: ${error} `) + } + }, (msg) => { + self._api.logMessage(msg) + }) + } + + var contractProperty = yo`
` + var contractActions = yo`
` + + contractProperty.appendChild(contractActions) + contractActions.appendChild(button) + if (inputs.length) { + contractActions.appendChild(inputField) + } + if (lookupOnly) { + contractProperty.appendChild(outputOverride) + } + + if (lookupOnly) { + contractProperty.classList.add(css.constant) + button.setAttribute('title', (title + ' - call')) + } + + if (args.funABI.inputs && args.funABI.inputs.length > 0) { + contractProperty.classList.add(css.hasArgs) + } + + if (args.funABI.payable === true) { + contractProperty.classList.add(css.payable) + button.setAttribute('title', (title + ' - transact (payable)')) + } + + if (!lookupOnly && args.funABI.payable === false) { + button.setAttribute('title', (title + ' - transact (not payable)')) + } + + return contractProperty +} + +module.exports = UniversalDAppUI diff --git a/src/universal-dapp.js b/src/universal-dapp.js index bf28945711..0ae6552f00 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -1,165 +1,30 @@ /* global */ 'use strict' -var $ = require('jquery') var ethJSUtil = require('ethereumjs-util') var BN = ethJSUtil.BN var remixLib = require('remix-lib') var EventManager = remixLib.EventManager var crypto = require('crypto') var TxRunner = require('./app/execution/txRunner') -var yo = require('yo-yo') -var txFormat = require('./app/execution/txFormat') -var txHelper = require('./app/execution/txHelper') -var txExecution = require('./app/execution/txExecution') -var helper = require('./lib/helper') +// var txFormat = require('./app/execution/txFormat') +// var txHelper = require('./app/execution/txHelper') +// var txExecution = require('./app/execution/txExecution') +// var helper = require('./lib/helper') var executionContext = require('./execution-context') -var copyToClipboard = require('./app/ui/copy-to-clipboard') var modalCustom = require('./app/ui/modal-dialog-custom') -// -------------- styling ---------------------- -var csjs = require('csjs-inject') -var styleGuide = remixLib.ui.themeChooser -var styles = styleGuide.chooser() - -var css = csjs` - .instanceTitleContainer { - display: flex; - align-items: center; - } - .title { - ${styles.rightPanel.runTab.titlebox_RunTab} - display: flex; - justify-content: end; - align-items: center; - font-size: 11px; - height: 30px; - width: 97%; - overflow: hidden; - word-break: break-word; - line-height: initial; - overflow: visible; - } - .titleLine { - display: flex; - align-items: baseline; - } - .titleText { - margin-right: 1em; - word-break: break-word; - min-width: 230px; - } - - .title .copy { - color: ${styles.rightPanel.runTab.icon_AltColor_Instance_CopyToClipboard}; - } - .instance { - ${styles.rightPanel.runTab.box_Instance}; - margin-bottom: 10px; - padding: 10px 15px 15px 15px; - } - .instance .title:before { - content: "\\25BE"; - margin-right: 5%; - } - .instance.hidesub .title:before { - content: "\\25B8"; - margin-right: 5%; - } - .instance.hidesub > * { - display: none; - } - .instance.hidesub .title { - display: flex; - } - .instance.hidesub .udappClose { - display: flex; - } - .buttonsContainer { - margin-top: 2%; - display: flex; - overflow: hidden; - } - .contractActions { - display: flex; - } - .instanceButton {} - .closeIcon { - font-size: 12px; - cursor: pointer; - } - .udappClose { - display: flex; - justify-content: flex-end; - } - .contractProperty { - overflow: auto; - margin-bottom: 0.4em; - } - .contractProperty.hasArgs input { - width: 75%; - padding: .36em; - } - .contractProperty button { - ${styles.rightPanel.runTab.button_Create} - min-width: 100px; - width: 100px; - font-size: 10px; - margin:0; - word-break: inherit; - } - .contractProperty button:disabled { - cursor: not-allowed; - background-color: white; - border-color: lightgray; - } - .contractProperty.constant button { - ${styles.rightPanel.runTab.button_Constant} - min-width: 100px; - width: 100px; - font-size: 10px; - margin:0; - word-break: inherit; - outline: none; - width: inherit; - } - .contractProperty input { - display: none; - } - .contractProperty > .value { - box-sizing: border-box; - float: left; - align-self: center; - color: ${styles.appProperties.mainText_Color}; - margin-left: 4px; - } - .hasArgs input { - display: block; - border: 1px solid #dddddd; - padding: .36em; - border-left: none; - padding: 8px 8px 8px 10px; - font-size: 10px; - height: 25px; - } - .hasArgs button { - border-top-right-radius: 0; - border-bottom-right-radius: 0; - border-right: 0; - } -` - /* trigger debugRequested */ -function UniversalDApp (opts = {}) { +function UniversalDAppModel (opts = {}) { this.event = new EventManager() var self = this self._api = opts.api self.removable = opts.opt.removable self.removable_instances = opts.opt.removable_instances - self.el = yo`
` + self.personalMode = opts.opt.personalMode || false self.contracts self.transactionContextAPI executionContext.event.register('contextChanged', this, function (context) { @@ -168,8 +33,7 @@ function UniversalDApp (opts = {}) { self.txRunner = new TxRunner({}, opts.api) } -UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) { - this.el.innerHTML = '' +UniversalDAppModel.prototype.reset = function (contracts, transactionContextAPI) { this.contracts = contracts if (transactionContextAPI) { this.transactionContextAPI = transactionContextAPI @@ -186,7 +50,7 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) { this.txRunner = new TxRunner(this.accounts, this._api) } -UniversalDApp.prototype.newAccount = function (password, cb) { +UniversalDAppModel.prototype.newAccount = function (password, cb) { if (!executionContext.isVM()) { if (!this._api.personalMode()) { return cb('Not running in personal mode') @@ -208,7 +72,7 @@ UniversalDApp.prototype.newAccount = function (password, cb) { } } -UniversalDApp.prototype._addAccount = function (privateKey, balance) { +UniversalDAppModel.prototype._addAccount = function (privateKey, balance) { var self = this if (!executionContext.isVM()) { @@ -225,7 +89,7 @@ UniversalDApp.prototype._addAccount = function (privateKey, balance) { } } -UniversalDApp.prototype.getAccounts = function (cb) { +UniversalDAppModel.prototype.getAccounts = function (cb) { var self = this if (!executionContext.isVM()) { @@ -245,7 +109,7 @@ UniversalDApp.prototype.getAccounts = function (cb) { } } -UniversalDApp.prototype.getBalance = function (address, cb) { +UniversalDAppModel.prototype.getBalance = function (address, cb) { var self = this address = ethJSUtil.stripHexPrefix(address) @@ -273,181 +137,7 @@ UniversalDApp.prototype.getBalance = function (address, cb) { } } -UniversalDApp.prototype.renderInstance = function (contract, address, contractName) { - var abi = txHelper.sortAbiFunction(contract.abi) - return this.renderInstanceFromABI(abi, address, contractName) -} - -// TODO this function was named before "appendChild". -// this will render an instance: contract name, contract address, and all the public functions -// basically this has to be called for the "atAddress" (line 393) and when a contract creation succeed -// this returns a DOM element -UniversalDApp.prototype.renderInstanceFromABI = function (contractABI, address, contractName) { - var self = this - - function remove () { instance.remove() } - - address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex') - var instance = yo`
` - var context = executionContext.isVM() ? 'memory' : 'blockchain' - - var shortAddress = helper.shortenAddress(address) - var title = yo`
-
${contractName} at ${shortAddress} (${context})
- ${copyToClipboard(() => address)} -
` - - if (self.removable_instances) { - var close = yo`
` - instance.append(close) - } - - function toggleClass () { - $(instance).toggleClass(`${css.hidesub}`) - } - - instance.appendChild(title) - - // Add the fallback function - var fallback = txHelper.getFallbackInterface(contractABI) - if (fallback) { - instance.appendChild(this.getCallButton({ - funABI: fallback, - address: address, - contractAbi: contractABI, - contractName: contractName - })) - } - - $.each(contractABI, (i, funABI) => { - if (funABI.type !== 'function') { - return - } - // @todo getData cannot be used with overloaded functions - instance.appendChild(this.getCallButton({ - funABI: funABI, - address: address, - contractAbi: contractABI, - contractName: contractName - })) - }) - - return instance -} - -// TODO this is used by renderInstance when a new instance is displayed. -// this returns a DOM element. -UniversalDApp.prototype.getCallButton = function (args) { - var self = this - // args.funABI, args.address [fun only] - // args.contractName [constr only] - var lookupOnly = args.funABI.constant - - var inputs = '' - if (args.funABI.inputs) { - inputs = txHelper.inputParametersDeclarationToString(args.funABI.inputs) - } - var inputField = yo`` - inputField.setAttribute('placeholder', inputs) - inputField.setAttribute('title', inputs) - - var outputOverride = yo`
` - - var title - if (args.funABI.name) { - title = args.funABI.name - } else { - title = '(fallback)' - } - - var button = yo`` - button.classList.add(css.call) - button.setAttribute('title', title) - button.innerHTML = title - - function clickButton () { - call(true) - } - - function call (isUserAction) { - var logMsg - if (isUserAction) { - if (!args.funABI.constant) { - logMsg = `transact to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` - } else { - logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` - } - } - txFormat.buildData(args.contractName, args.contractAbi, self.contracts, false, args.funABI, inputField.value, self, (error, data) => { - if (!error) { - if (isUserAction) { - if (!args.funABI.constant) { - self._api.logMessage(`${logMsg} pending ... `) - } else { - self._api.logMessage(`${logMsg}`) - } - } - txExecution.callFunction(args.address, data, args.funABI, self, (error, txResult) => { - if (!error) { - var isVM = executionContext.isVM() - if (isVM) { - var vmError = txExecution.checkVMError(txResult) - if (vmError.error) { - self._api.logMessage(`${logMsg} errored: ${vmError.message} `) - return - } - } - if (lookupOnly) { - var decoded = txFormat.decodeResponseToTreeView(executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI) - outputOverride.innerHTML = '' - outputOverride.appendChild(decoded) - } - } else { - self._api.logMessage(`${logMsg} errored: ${error} `) - } - }) - } else { - self._api.logMessage(`${logMsg} errored: ${error} `) - } - }, (msg) => { - self._api.logMessage(msg) - }) - } - - var contractProperty = yo`
` - var contractActions = yo`
` - - contractProperty.appendChild(contractActions) - contractActions.appendChild(button) - if (inputs.length) { - contractActions.appendChild(inputField) - } - if (lookupOnly) { - contractProperty.appendChild(outputOverride) - } - - if (lookupOnly) { - contractProperty.classList.add(css.constant) - button.setAttribute('title', (title + ' - call')) - } - - if (args.funABI.inputs && args.funABI.inputs.length > 0) { - contractProperty.classList.add(css.hasArgs) - } - - if (args.funABI.payable === true) { - contractProperty.classList.add(css.payable) - button.setAttribute('title', (title + ' - transact (payable)')) - } - - if (!lookupOnly && args.funABI.payable === false) { - button.setAttribute('title', (title + ' - transact (not payable)')) - } - - return contractProperty -} - -UniversalDApp.prototype.pendingTransactions = function () { +UniversalDAppModel.prototype.pendingTransactions = function () { return this.txRunner.pendingTxs } @@ -461,7 +151,7 @@ function execute (pipeline, env, callback) { next(null, env) } -UniversalDApp.prototype.runTx = function (args, cb) { +UniversalDAppModel.prototype.runTx = function (args, cb) { var self = this var tx = { to: args.to, data: args.data.dataHex, useCall: args.useCall, from: args.from, value: args.value } var payLoad = { funAbi: args.data.funAbi, funArgs: args.data.funArgs, contractBytecode: args.data.contractBytecode, contractName: args.data.contractName } // contains decoded parameters @@ -546,4 +236,4 @@ function runTransaction (env, next) { }) } -module.exports = UniversalDApp +module.exports = UniversalDAppModel From 976c21152670624a9957752cd30b18e2ad55d5b4 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 11:23:27 -0500 Subject: [PATCH 02/14] add udappUI to app object and update references --- src/app.js | 4 +++- src/app/tabs/run-tab.js | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/app.js b/src/app.js index 7a709392ac..cd7206afa7 100644 --- a/src/app.js +++ b/src/app.js @@ -265,7 +265,6 @@ function run () { }) var udappUI = new UniversalDAppUI(udapp) - console.dir(udappUI) udapp.reset({}, transactionContextAPI) udapp.event.register('debugRequested', this, function (txResult) { @@ -582,6 +581,9 @@ function run () { udapp: () => { return udapp }, + udappUI: () => { + return udappUI + }, switchFile: function (path) { fileManager.switchFile(path) }, diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index c0d62140ae..f7b2385671 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -379,7 +379,7 @@ function makeRecorder (events, appAPI, appEvents) { if (txArray.length) { noInstancesText.style.display = 'none' recorder.run(txArray, accounts, options, abis, linkReferences, (abi, address, contractName) => { - instanceContainer.appendChild(appAPI.udapp().renderInstanceFromABI(abi, address, contractName)) + instanceContainer.appendChild(appAPI.udappUI().renderInstanceFromABI(abi, address, contractName)) }) } } else { @@ -484,7 +484,7 @@ function contractDropdown (events, appAPI, appEvents, instanceContainer) { } noInstancesText.style.display = 'none' var address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress - instanceContainer.appendChild(appAPI.udapp().renderInstance(selectedContract.contract.object, address, selectContractNames.value)) + instanceContainer.appendChild(appAPI.udappUI().renderInstance(selectedContract.contract.object, address, selectContractNames.value)) } else { appAPI.logMessage(`creation of ${selectedContract.name} errored: ` + error) } @@ -509,11 +509,11 @@ function contractDropdown (events, appAPI, appEvents, instanceContainer) { } catch (e) { return modalDialogCustom.alert('Failed to parse the current file as JSON ABI.') } - instanceContainer.appendChild(appAPI.udapp().renderInstanceFromABI(abi, address, address)) + instanceContainer.appendChild(appAPI.udappUI().renderInstanceFromABI(abi, address, address)) }) } else { var contract = appAPI.getContract(contractNames.children[contractNames.selectedIndex].innerHTML) - instanceContainer.appendChild(appAPI.udapp().renderInstance(contract.object, address, selectContractNames.value)) + instanceContainer.appendChild(appAPI.udappUI().renderInstance(contract.object, address, selectContractNames.value)) } } From 2bbc3b9c2aa40f1da4cd86bd952f6847e478c54c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 11:37:07 -0500 Subject: [PATCH 03/14] fix references to udapp variables --- src/universal-dapp-ui.js | 14 +++++++------- src/universal-dapp.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index b2f1e769a8..7f31668a02 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -183,7 +183,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address ${copyToClipboard(() => address)} ` - if (self.removable_instances) { + if (self.udapp.removable_instances) { var close = yo`
` instance.append(close) } @@ -268,9 +268,9 @@ UniversalDAppUI.prototype.getCallButton = function (args) { if (!error) { if (isUserAction) { if (!args.funABI.constant) { - self._api.logMessage(`${logMsg} pending ... `) + self.udapp._api.logMessage(`${logMsg} pending ... `) } else { - self._api.logMessage(`${logMsg}`) + self.udapp._api.logMessage(`${logMsg}`) } } txExecution.callFunction(args.address, data, args.funABI, self, (error, txResult) => { @@ -279,7 +279,7 @@ UniversalDAppUI.prototype.getCallButton = function (args) { if (isVM) { var vmError = txExecution.checkVMError(txResult) if (vmError.error) { - self._api.logMessage(`${logMsg} errored: ${vmError.message} `) + self.udapp._api.logMessage(`${logMsg} errored: ${vmError.message} `) return } } @@ -289,14 +289,14 @@ UniversalDAppUI.prototype.getCallButton = function (args) { outputOverride.appendChild(decoded) } } else { - self._api.logMessage(`${logMsg} errored: ${error} `) + self.udapp._api.logMessage(`${logMsg} errored: ${error} `) } }) } else { - self._api.logMessage(`${logMsg} errored: ${error} `) + self.udapp._api.logMessage(`${logMsg} errored: ${error} `) } }, (msg) => { - self._api.logMessage(msg) + self.udapp._api.logMessage(msg) }) } diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 0ae6552f00..4d5b5792f0 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -25,8 +25,8 @@ function UniversalDAppModel (opts = {}) { self.removable = opts.opt.removable self.removable_instances = opts.opt.removable_instances self.personalMode = opts.opt.personalMode || false - self.contracts - self.transactionContextAPI + // self.contracts + // self.transactionContextAPI executionContext.event.register('contextChanged', this, function (context) { self.reset(self.contracts) }) From 82874cefaf9a04e9cb0900a6a5dfd22a83ecdb93 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 11:43:42 -0500 Subject: [PATCH 04/14] remove todo --- src/universal-dapp-ui.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index 7f31668a02..cafb2a1cea 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -158,7 +158,6 @@ UniversalDAppUI.prototype.reset = function (contracts, transactionContextAPI) { this.el.innerHTML = '' } -// TODO: has both UI and Model UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName) { var abi = txHelper.sortAbiFunction(contract.abi) return this.renderInstanceFromABI(abi, address, contractName) From 52769263e9e71151cabdb3ef7939202ddd35703f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 11:53:35 -0500 Subject: [PATCH 05/14] fix reference to contracts --- src/universal-dapp-ui.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index cafb2a1cea..c65b0ee1a0 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -263,7 +263,7 @@ UniversalDAppUI.prototype.getCallButton = function (args) { logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` } } - txFormat.buildData(args.contractName, args.contractAbi, self.contracts, false, args.funABI, inputField.value, self, (error, data) => { + txFormat.buildData(args.contractName, args.contractAbi, self.udapp.contracts, false, args.funABI, inputField.value, self, (error, data) => { if (!error) { if (isUserAction) { if (!args.funABI.constant) { From 43e08c38c78da8cb0ba70eda3e212e1dcd5d111f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 12:37:27 -0500 Subject: [PATCH 06/14] move tx action logic from udapp-ui to udapp --- src/universal-dapp-ui.js | 51 +++------------------------------------- src/universal-dapp.js | 51 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index c65b0ee1a0..6d71d05392 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -2,12 +2,9 @@ 'use strict' var $ = require('jquery') -var ethJSUtil = require('ethereumjs-util') var remixLib = require('remix-lib') var yo = require('yo-yo') -var txFormat = require('./app/execution/txFormat') var txHelper = require('./app/execution/txHelper') -var txExecution = require('./app/execution/txExecution') var helper = require('./lib/helper') var executionContext = require('./execution-context') var copyToClipboard = require('./app/ui/copy-to-clipboard') @@ -251,51 +248,9 @@ UniversalDAppUI.prototype.getCallButton = function (args) { button.innerHTML = title function clickButton () { - call(true) - } - - function call (isUserAction) { - var logMsg - if (isUserAction) { - if (!args.funABI.constant) { - logMsg = `transact to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` - } else { - logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` - } - } - txFormat.buildData(args.contractName, args.contractAbi, self.udapp.contracts, false, args.funABI, inputField.value, self, (error, data) => { - if (!error) { - if (isUserAction) { - if (!args.funABI.constant) { - self.udapp._api.logMessage(`${logMsg} pending ... `) - } else { - self.udapp._api.logMessage(`${logMsg}`) - } - } - txExecution.callFunction(args.address, data, args.funABI, self, (error, txResult) => { - if (!error) { - var isVM = executionContext.isVM() - if (isVM) { - var vmError = txExecution.checkVMError(txResult) - if (vmError.error) { - self.udapp._api.logMessage(`${logMsg} errored: ${vmError.message} `) - return - } - } - if (lookupOnly) { - var decoded = txFormat.decodeResponseToTreeView(executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI) - outputOverride.innerHTML = '' - outputOverride.appendChild(decoded) - } - } else { - self.udapp._api.logMessage(`${logMsg} errored: ${error} `) - } - }) - } else { - self.udapp._api.logMessage(`${logMsg} errored: ${error} `) - } - }, (msg) => { - self.udapp._api.logMessage(msg) + self.udapp.call(true, args, inputField.value, (decoded) => { + outputOverride.innerHTML = '' + outputOverride.appendChild(decoded) }) } diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 4d5b5792f0..ad9262bf4a 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -7,9 +7,9 @@ var remixLib = require('remix-lib') var EventManager = remixLib.EventManager var crypto = require('crypto') var TxRunner = require('./app/execution/txRunner') -// var txFormat = require('./app/execution/txFormat') +var txFormat = require('./app/execution/txFormat') // var txHelper = require('./app/execution/txHelper') -// var txExecution = require('./app/execution/txExecution') +var txExecution = require('./app/execution/txExecution') // var helper = require('./lib/helper') var executionContext = require('./execution-context') var modalCustom = require('./app/ui/modal-dialog-custom') @@ -25,8 +25,6 @@ function UniversalDAppModel (opts = {}) { self.removable = opts.opt.removable self.removable_instances = opts.opt.removable_instances self.personalMode = opts.opt.personalMode || false - // self.contracts - // self.transactionContextAPI executionContext.event.register('contextChanged', this, function (context) { self.reset(self.contracts) }) @@ -141,6 +139,51 @@ UniversalDAppModel.prototype.pendingTransactions = function () { return this.txRunner.pendingTxs } +UniversalDAppModel.prototype.call = function (isUserAction, args, value, outputCb) { + const self = this + var logMsg + if (isUserAction) { + if (!args.funABI.constant) { + logMsg = `transact to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` + } else { + logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` + } + } + txFormat.buildData(args.contractName, args.contractAbi, self.contracts, false, args.funABI, value, self, (error, data) => { + if (!error) { + if (isUserAction) { + if (!args.funABI.constant) { + self._api.logMessage(`${logMsg} pending ... `) + } else { + self._api.logMessage(`${logMsg}`) + } + } + txExecution.callFunction(args.address, data, args.funABI, self, (error, txResult) => { + if (!error) { + var isVM = executionContext.isVM() + if (isVM) { + var vmError = txExecution.checkVMError(txResult) + if (vmError.error) { + self._api.logMessage(`${logMsg} errored: ${vmError.message} `) + return + } + } + if (lookupOnly) { + var decoded = txFormat.decodeResponseToTreeView(executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI) + outputCb(decoded) + } + } else { + self._api.logMessage(`${logMsg} errored: ${error} `) + } + }) + } else { + self._api.logMessage(`${logMsg} errored: ${error} `) + } + }, (msg) => { + self._api.logMessage(msg) + }) +} + function execute (pipeline, env, callback) { function next (err, env) { if (err) return callback(err) From 4324d003c44a17c128e0e1b2afb49c3bdc7206a2 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 12:41:34 -0500 Subject: [PATCH 07/14] add missing parameter to button call --- src/universal-dapp-ui.js | 2 +- src/universal-dapp.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index 6d71d05392..f9f50a062b 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -248,7 +248,7 @@ UniversalDAppUI.prototype.getCallButton = function (args) { button.innerHTML = title function clickButton () { - self.udapp.call(true, args, inputField.value, (decoded) => { + self.udapp.call(true, args, inputField.value, lookupOnly, (decoded) => { outputOverride.innerHTML = '' outputOverride.appendChild(decoded) }) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index ad9262bf4a..78d2706240 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -139,7 +139,7 @@ UniversalDAppModel.prototype.pendingTransactions = function () { return this.txRunner.pendingTxs } -UniversalDAppModel.prototype.call = function (isUserAction, args, value, outputCb) { +UniversalDAppModel.prototype.call = function (isUserAction, args, value, lookupOnly, outputCb) { const self = this var logMsg if (isUserAction) { From d28f760705989aa4b3f0c118a5f6a9db370cbdde Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 12:49:44 -0500 Subject: [PATCH 08/14] move execution context dependency from udapp-ui to udapp --- src/universal-dapp-ui.js | 3 +-- src/universal-dapp.js | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index f9f50a062b..1bf53d1e64 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -6,7 +6,6 @@ var remixLib = require('remix-lib') var yo = require('yo-yo') var txHelper = require('./app/execution/txHelper') var helper = require('./lib/helper') -var executionContext = require('./execution-context') var copyToClipboard = require('./app/ui/copy-to-clipboard') // -------------- styling ---------------------- @@ -171,7 +170,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex') var instance = yo`
` - var context = executionContext.isVM() ? 'memory' : 'blockchain' + var context = self.udapp.context() var shortAddress = helper.shortenAddress(address) var title = yo`
diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 78d2706240..59e077063a 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -184,6 +184,10 @@ UniversalDAppModel.prototype.call = function (isUserAction, args, value, lookupO }) } +UniversalDAppModel.prototype.context = function () { + return (executionContext.isVM() ? 'memory' : 'blockchain') +} + function execute (pipeline, env, callback) { function next (err, env) { if (err) return callback(err) From 8f49c8fbd730abdc308736770fb991ec5df1a44a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 12:57:00 -0500 Subject: [PATCH 09/14] remove unneded require --- src/universal-dapp.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 59e077063a..1dcfac4698 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -10,7 +10,6 @@ var TxRunner = require('./app/execution/txRunner') var txFormat = require('./app/execution/txFormat') // var txHelper = require('./app/execution/txHelper') var txExecution = require('./app/execution/txExecution') -// var helper = require('./lib/helper') var executionContext = require('./execution-context') var modalCustom = require('./app/ui/modal-dialog-custom') From e5b1df07441ac7b896fd1c02657b7a279d672e3d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 13:17:39 -0500 Subject: [PATCH 10/14] remove execution tx-helper from UI --- src/universal-dapp-ui.js | 12 ++++-------- src/universal-dapp.js | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index 1bf53d1e64..698d12b479 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -2,14 +2,13 @@ 'use strict' var $ = require('jquery') -var remixLib = require('remix-lib') var yo = require('yo-yo') -var txHelper = require('./app/execution/txHelper') var helper = require('./lib/helper') var copyToClipboard = require('./app/ui/copy-to-clipboard') // -------------- styling ---------------------- var csjs = require('csjs-inject') +var remixLib = require('remix-lib') var styleGuide = remixLib.ui.themeChooser var styles = styleGuide.chooser() @@ -155,7 +154,7 @@ UniversalDAppUI.prototype.reset = function (contracts, transactionContextAPI) { } UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName) { - var abi = txHelper.sortAbiFunction(contract.abi) + var abi = this.udapp.getABI(contract) return this.renderInstanceFromABI(abi, address, contractName) } @@ -190,7 +189,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address instance.appendChild(title) // Add the fallback function - var fallback = txHelper.getFallbackInterface(contractABI) + var fallback = self.udapp.getFallbackInterface(contractABI) if (fallback) { instance.appendChild(this.getCallButton({ funABI: fallback, @@ -224,10 +223,7 @@ UniversalDAppUI.prototype.getCallButton = function (args) { // args.contractName [constr only] var lookupOnly = args.funABI.constant - var inputs = '' - if (args.funABI.inputs) { - inputs = txHelper.inputParametersDeclarationToString(args.funABI.inputs) - } + var inputs = self.udapp.getInputs(args.funABI) var inputField = yo`` inputField.setAttribute('placeholder', inputs) inputField.setAttribute('title', inputs) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 1dcfac4698..c314259f62 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -8,7 +8,7 @@ var EventManager = remixLib.EventManager var crypto = require('crypto') var TxRunner = require('./app/execution/txRunner') var txFormat = require('./app/execution/txFormat') -// var txHelper = require('./app/execution/txHelper') +var txHelper = require('./app/execution/txHelper') var txExecution = require('./app/execution/txExecution') var executionContext = require('./execution-context') var modalCustom = require('./app/ui/modal-dialog-custom') @@ -187,6 +187,21 @@ UniversalDAppModel.prototype.context = function () { return (executionContext.isVM() ? 'memory' : 'blockchain') } +UniversalDAppModel.prototype.getABI = function (contract) { + return txHelper.sortAbiFunction(contract.abi) +} + +UniversalDAppModel.prototype.getFallbackInterface = function (contractABI) { + return txHelper.getFallbackInterface(contractABI) +} + +UniversalDAppModel.prototype.getInputs = function (funABI) { + if (!funABI.inputs) { + return '' + } + return txHelper.inputParametersDeclarationToString(funABI.inputs) +} + function execute (pipeline, env, callback) { function next (err, env) { if (err) return callback(err) From f2a9a6e19827669040fbac7ba3f32bcadeed16ee Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 13:40:17 -0500 Subject: [PATCH 11/14] move style to its own file --- src/universal-dapp-styles.js | 133 ++++++++++++++++++++++++++++++++++ src/universal-dapp-ui.js | 134 +---------------------------------- 2 files changed, 134 insertions(+), 133 deletions(-) create mode 100644 src/universal-dapp-styles.js diff --git a/src/universal-dapp-styles.js b/src/universal-dapp-styles.js new file mode 100644 index 0000000000..25a84b585d --- /dev/null +++ b/src/universal-dapp-styles.js @@ -0,0 +1,133 @@ +var csjs = require('csjs-inject') +var remixLib = require('remix-lib') +var styleGuide = remixLib.ui.themeChooser +var styles = styleGuide.chooser() + +var css = csjs` + .instanceTitleContainer { + display: flex; + align-items: center; + } + .title { + ${styles.rightPanel.runTab.titlebox_RunTab} + display: flex; + justify-content: end; + align-items: center; + font-size: 11px; + height: 30px; + width: 97%; + overflow: hidden; + word-break: break-word; + line-height: initial; + overflow: visible; + } + .titleLine { + display: flex; + align-items: baseline; + } + .titleText { + margin-right: 1em; + word-break: break-word; + min-width: 230px; + } + + .title .copy { + color: ${styles.rightPanel.runTab.icon_AltColor_Instance_CopyToClipboard}; + } + .instance { + ${styles.rightPanel.runTab.box_Instance}; + margin-bottom: 10px; + padding: 10px 15px 15px 15px; + } + .instance .title:before { + content: "\\25BE"; + margin-right: 5%; + } + .instance.hidesub .title:before { + content: "\\25B8"; + margin-right: 5%; + } + .instance.hidesub > * { + display: none; + } + .instance.hidesub .title { + display: flex; + } + .instance.hidesub .udappClose { + display: flex; + } + .buttonsContainer { + margin-top: 2%; + display: flex; + overflow: hidden; + } + .contractActions { + display: flex; + } + .instanceButton {} + .closeIcon { + font-size: 12px; + cursor: pointer; + } + .udappClose { + display: flex; + justify-content: flex-end; + } + .contractProperty { + overflow: auto; + margin-bottom: 0.4em; + } + .contractProperty.hasArgs input { + width: 75%; + padding: .36em; + } + .contractProperty button { + ${styles.rightPanel.runTab.button_Create} + min-width: 100px; + width: 100px; + font-size: 10px; + margin:0; + word-break: inherit; + } + .contractProperty button:disabled { + cursor: not-allowed; + background-color: white; + border-color: lightgray; + } + .contractProperty.constant button { + ${styles.rightPanel.runTab.button_Constant} + min-width: 100px; + width: 100px; + font-size: 10px; + margin:0; + word-break: inherit; + outline: none; + width: inherit; + } + .contractProperty input { + display: none; + } + .contractProperty > .value { + box-sizing: border-box; + float: left; + align-self: center; + color: ${styles.appProperties.mainText_Color}; + margin-left: 4px; + } + .hasArgs input { + display: block; + border: 1px solid #dddddd; + padding: .36em; + border-left: none; + padding: 8px 8px 8px 10px; + font-size: 10px; + height: 25px; + } + .hasArgs button { + border-top-right-radius: 0; + border-bottom-right-radius: 0; + border-right: 0; + } +` + +module.exports = css diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index 698d12b479..db59745069 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -5,139 +5,7 @@ var $ = require('jquery') var yo = require('yo-yo') var helper = require('./lib/helper') var copyToClipboard = require('./app/ui/copy-to-clipboard') - -// -------------- styling ---------------------- -var csjs = require('csjs-inject') -var remixLib = require('remix-lib') -var styleGuide = remixLib.ui.themeChooser -var styles = styleGuide.chooser() - -var css = csjs` - .instanceTitleContainer { - display: flex; - align-items: center; - } - .title { - ${styles.rightPanel.runTab.titlebox_RunTab} - display: flex; - justify-content: end; - align-items: center; - font-size: 11px; - height: 30px; - width: 97%; - overflow: hidden; - word-break: break-word; - line-height: initial; - overflow: visible; - } - .titleLine { - display: flex; - align-items: baseline; - } - .titleText { - margin-right: 1em; - word-break: break-word; - min-width: 230px; - } - - .title .copy { - color: ${styles.rightPanel.runTab.icon_AltColor_Instance_CopyToClipboard}; - } - .instance { - ${styles.rightPanel.runTab.box_Instance}; - margin-bottom: 10px; - padding: 10px 15px 15px 15px; - } - .instance .title:before { - content: "\\25BE"; - margin-right: 5%; - } - .instance.hidesub .title:before { - content: "\\25B8"; - margin-right: 5%; - } - .instance.hidesub > * { - display: none; - } - .instance.hidesub .title { - display: flex; - } - .instance.hidesub .udappClose { - display: flex; - } - .buttonsContainer { - margin-top: 2%; - display: flex; - overflow: hidden; - } - .contractActions { - display: flex; - } - .instanceButton {} - .closeIcon { - font-size: 12px; - cursor: pointer; - } - .udappClose { - display: flex; - justify-content: flex-end; - } - .contractProperty { - overflow: auto; - margin-bottom: 0.4em; - } - .contractProperty.hasArgs input { - width: 75%; - padding: .36em; - } - .contractProperty button { - ${styles.rightPanel.runTab.button_Create} - min-width: 100px; - width: 100px; - font-size: 10px; - margin:0; - word-break: inherit; - } - .contractProperty button:disabled { - cursor: not-allowed; - background-color: white; - border-color: lightgray; - } - .contractProperty.constant button { - ${styles.rightPanel.runTab.button_Constant} - min-width: 100px; - width: 100px; - font-size: 10px; - margin:0; - word-break: inherit; - outline: none; - width: inherit; - } - .contractProperty input { - display: none; - } - .contractProperty > .value { - box-sizing: border-box; - float: left; - align-self: center; - color: ${styles.appProperties.mainText_Color}; - margin-left: 4px; - } - .hasArgs input { - display: block; - border: 1px solid #dddddd; - padding: .36em; - border-left: none; - padding: 8px 8px 8px 10px; - font-size: 10px; - height: 25px; - } - .hasArgs button { - border-top-right-radius: 0; - border-bottom-right-radius: 0; - border-right: 0; - } -` +var css = require('./universal-dapp-styles') /* trigger debugRequested From 1d4097c5346ce657c2911c8c307fe56a69a8d88d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 13:45:08 -0500 Subject: [PATCH 12/14] rename UniversalDAppModel back to UniversalDApp --- src/universal-dapp.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index c314259f62..e034f1dc23 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -16,7 +16,7 @@ var modalCustom = require('./app/ui/modal-dialog-custom') /* trigger debugRequested */ -function UniversalDAppModel (opts = {}) { +function UniversalDApp (opts = {}) { this.event = new EventManager() var self = this @@ -30,7 +30,7 @@ function UniversalDAppModel (opts = {}) { self.txRunner = new TxRunner({}, opts.api) } -UniversalDAppModel.prototype.reset = function (contracts, transactionContextAPI) { +UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) { this.contracts = contracts if (transactionContextAPI) { this.transactionContextAPI = transactionContextAPI @@ -47,7 +47,7 @@ UniversalDAppModel.prototype.reset = function (contracts, transactionContextAPI) this.txRunner = new TxRunner(this.accounts, this._api) } -UniversalDAppModel.prototype.newAccount = function (password, cb) { +UniversalDApp.prototype.newAccount = function (password, cb) { if (!executionContext.isVM()) { if (!this._api.personalMode()) { return cb('Not running in personal mode') @@ -69,7 +69,7 @@ UniversalDAppModel.prototype.newAccount = function (password, cb) { } } -UniversalDAppModel.prototype._addAccount = function (privateKey, balance) { +UniversalDApp.prototype._addAccount = function (privateKey, balance) { var self = this if (!executionContext.isVM()) { @@ -86,7 +86,7 @@ UniversalDAppModel.prototype._addAccount = function (privateKey, balance) { } } -UniversalDAppModel.prototype.getAccounts = function (cb) { +UniversalDApp.prototype.getAccounts = function (cb) { var self = this if (!executionContext.isVM()) { @@ -106,7 +106,7 @@ UniversalDAppModel.prototype.getAccounts = function (cb) { } } -UniversalDAppModel.prototype.getBalance = function (address, cb) { +UniversalDApp.prototype.getBalance = function (address, cb) { var self = this address = ethJSUtil.stripHexPrefix(address) @@ -134,11 +134,11 @@ UniversalDAppModel.prototype.getBalance = function (address, cb) { } } -UniversalDAppModel.prototype.pendingTransactions = function () { +UniversalDApp.prototype.pendingTransactions = function () { return this.txRunner.pendingTxs } -UniversalDAppModel.prototype.call = function (isUserAction, args, value, lookupOnly, outputCb) { +UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly, outputCb) { const self = this var logMsg if (isUserAction) { @@ -183,19 +183,19 @@ UniversalDAppModel.prototype.call = function (isUserAction, args, value, lookupO }) } -UniversalDAppModel.prototype.context = function () { +UniversalDApp.prototype.context = function () { return (executionContext.isVM() ? 'memory' : 'blockchain') } -UniversalDAppModel.prototype.getABI = function (contract) { +UniversalDApp.prototype.getABI = function (contract) { return txHelper.sortAbiFunction(contract.abi) } -UniversalDAppModel.prototype.getFallbackInterface = function (contractABI) { +UniversalDApp.prototype.getFallbackInterface = function (contractABI) { return txHelper.getFallbackInterface(contractABI) } -UniversalDAppModel.prototype.getInputs = function (funABI) { +UniversalDApp.prototype.getInputs = function (funABI) { if (!funABI.inputs) { return '' } @@ -212,7 +212,7 @@ function execute (pipeline, env, callback) { next(null, env) } -UniversalDAppModel.prototype.runTx = function (args, cb) { +UniversalDApp.prototype.runTx = function (args, cb) { var self = this var tx = { to: args.to, data: args.data.dataHex, useCall: args.useCall, from: args.from, value: args.value } var payLoad = { funAbi: args.data.funAbi, funArgs: args.data.funArgs, contractBytecode: args.data.contractBytecode, contractName: args.data.contractName } // contains decoded parameters @@ -297,4 +297,4 @@ function runTransaction (env, next) { }) } -module.exports = UniversalDAppModel +module.exports = UniversalDApp From f90dc0b9463dcd7c8ff45e37887301728702826a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 6 Feb 2018 13:47:58 -0500 Subject: [PATCH 13/14] also reset UI when reseting udapp --- src/app.js | 2 ++ src/universal-dapp-ui.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index cd7206afa7..359c547d0c 100644 --- a/src/app.js +++ b/src/app.js @@ -267,6 +267,7 @@ function run () { var udappUI = new UniversalDAppUI(udapp) udapp.reset({}, transactionContextAPI) + udappUI.reset() udapp.event.register('debugRequested', this, function (txResult) { startdebugging(txResult.transactionHash) }) @@ -617,6 +618,7 @@ function run () { }, resetDapp: (contracts) => { udapp.reset(contracts, transactionContextAPI) + udappUI.reset() }, setOptimize: (optimize, runCompilation) => { compiler.setOptimize(optimize) diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index db59745069..9a84c2e393 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -17,7 +17,7 @@ function UniversalDAppUI (udapp, opts = {}) { self.el = yo`
` } -UniversalDAppUI.prototype.reset = function (contracts, transactionContextAPI) { +UniversalDAppUI.prototype.reset = function () { this.el.innerHTML = '' } From d005431ecfe61b27b5e102f2ad329f49e117221f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 7 Feb 2018 09:21:13 -0500 Subject: [PATCH 14/14] more unneded personal mode assigment --- src/universal-dapp.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index e034f1dc23..9e14263018 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -23,7 +23,6 @@ function UniversalDApp (opts = {}) { self._api = opts.api self.removable = opts.opt.removable self.removable_instances = opts.opt.removable_instances - self.personalMode = opts.opt.personalMode || false executionContext.event.register('contextChanged', this, function (context) { self.reset(self.contracts) })