From aeda1db5e4015eb7216e5655e64d0a2f1f308983 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 19 Jun 2017 12:48:08 +0200 Subject: [PATCH] reset value field to 0 after each transaction --- src/app.js | 167 +++++++++++++++++++---------------- src/app/contract-tab.js | 14 +++ src/app/execution-context.js | 17 +--- src/app/righthand-panel.js | 7 +- src/universal-dapp.js | 3 +- 5 files changed, 109 insertions(+), 99 deletions(-) diff --git a/src/app.js b/src/app.js index 14e3dbd02f..adfc825cab 100644 --- a/src/app.js +++ b/src/app.js @@ -479,20 +479,106 @@ var run = function () { } var renderer = new Renderer(rendererAPI, compiler.event) + // ------------------------------------------------------------ + var executionContext = new ExecutionContext() + + // ----------------- UniversalDApp ----------------- + var udapp = new UniversalDApp(executionContext, { + removable: false, + removable_instances: true + }) + + udapp.event.register('debugRequested', this, function (txResult) { + startdebugging(txResult.transactionHash) + }) + + function swarmVerifiedPublish (content, expectedHash, cb) { + swarmgw.put(content, function (err, ret) { + if (err) { + cb(err) + } else if (ret !== expectedHash) { + cb('Hash mismatch') + } else { + cb() + } + }) + } + + function publishOnSwarm (contract, cb) { + // gather list of files to publish + var sources = [] + + sources.push({ + content: contract.metadata, + hash: contract.metadataHash + }) + + var metadata + try { + metadata = JSON.parse(contract.metadata) + } catch (e) { + return cb(e) + } + + if (metadata === undefined) { + return cb('No metadata') + } + + Object.keys(metadata.sources).forEach(function (fileName) { + // find hash + var hash + try { + hash = metadata.sources[fileName].urls[0].match('bzzr://(.+)')[1] + } catch (e) { + return cb('Metadata inconsistency') + } + + sources.push({ + content: files.get(fileName), + hash: hash + }) + }) + + // publish the list of sources in order, fail if any failed + async.eachSeries(sources, function (item, cb) { + swarmVerifiedPublish(item.content, item.hash, cb) + }, cb) + } + + udapp.event.register('publishContract', this, function (contract) { + publishOnSwarm(contract, function (err) { + if (err) { + alert('Failed to publish metadata: ' + err) + } else { + alert('Metadata published successfully') + } + }) + }) + // ---------------- Righthand-panel -------------------- var rhpAPI = { config: config, onResize: onResize, reAdjust: reAdjust, - renderer: renderer + warnCompilerLoading: (msg) => { + renderer.clear() + if (msg) { + renderer.error(msg, $('#output'), {type: 'warning'}) + } + }, + executionContextChange: (context) => { + return executionContext.executionContextChange(context) + }, + executionContextProvider: () => { + return executionContext.getProvider() + } } var rhpEvents = { compiler: compiler.event, - app: self.event + app: self.event, + udapp: udapp.event } var righthandPanel = new RighthandPanel(document.body, rhpAPI, rhpEvents, {}) // eslint-disable-line -// ------------------------------------------------------------ - var executionContext = new ExecutionContext() // ----------------- editor resize --------------- function onResize () { @@ -635,79 +721,6 @@ var run = function () { transactionDebugger.addProvider('web3', executionContext.web3()) transactionDebugger.switchProvider(executionContext.getProvider()) - // ----------------- UniversalDApp ----------------- - var udapp = new UniversalDApp(executionContext, { - removable: false, - removable_instances: true - }) - - udapp.event.register('debugRequested', this, function (txResult) { - startdebugging(txResult.transactionHash) - }) - - function swarmVerifiedPublish (content, expectedHash, cb) { - swarmgw.put(content, function (err, ret) { - if (err) { - cb(err) - } else if (ret !== expectedHash) { - cb('Hash mismatch') - } else { - cb() - } - }) - } - - function publishOnSwarm (contract, cb) { - // gather list of files to publish - var sources = [] - - sources.push({ - content: contract.metadata, - hash: contract.metadataHash - }) - - var metadata - try { - metadata = JSON.parse(contract.metadata) - } catch (e) { - return cb(e) - } - - if (metadata === undefined) { - return cb('No metadata') - } - - Object.keys(metadata.sources).forEach(function (fileName) { - // find hash - var hash - try { - hash = metadata.sources[fileName].urls[0].match('bzzr://(.+)')[1] - } catch (e) { - return cb('Metadata inconsistency') - } - - sources.push({ - content: files.get(fileName), - hash: hash - }) - }) - - // publish the list of sources in order, fail if any failed - async.eachSeries(sources, function (item, cb) { - swarmVerifiedPublish(item.content, item.hash, cb) - }, cb) - } - - udapp.event.register('publishContract', this, function (contract) { - publishOnSwarm(contract, function (err) { - if (err) { - alert('Failed to publish metadata: ' + err) - } else { - alert('Metadata published successfully') - } - }) - }) - // ----------------- StaticAnalysis ----------------- var staticAnalysisAPI = { renderWarning: (label, warningContainer, type) => { diff --git a/src/app/contract-tab.js b/src/app/contract-tab.js index cd93230d7c..06fb3a83a2 100644 --- a/src/app/contract-tab.js +++ b/src/app/contract-tab.js @@ -107,5 +107,19 @@ function contractTab (container, appAPI, appEvents, opts) {
` + appEvents.udapp.register('transactionExecuted', (to, data, lookupOnly, txResult) => { + if (!lookupOnly) el.querySelector('#value').value = '0' + }) + + /* --------------------------------------------------------------------------- + DROPDOWN + --------------------------------------------------------------------------- */ + var selectExEnv = el.querySelector('#selectExEnvOptions') + selectExEnv.addEventListener('change', function (event) { + if (!appAPI.executionContextChange(selectExEnv.options[selectExEnv.selectedIndex].value)) { + selectExEnv.value = appAPI.executionContextProvider() + } + }) + selectExEnv.value = appAPI.executionContextProvider() container.appendChild(el) } diff --git a/src/app/execution-context.js b/src/app/execution-context.js index 6ff87406f8..ccba55f739 100644 --- a/src/app/execution-context.js +++ b/src/app/execution-context.js @@ -91,10 +91,10 @@ function ExecutionContext () { this.setContext = function (context, endPointUrl) { executionContext = context - executionContextChange(context, endPointUrl) + this.executionContextChange(context, endPointUrl) } - function executionContextChange (context, endPointUrl) { + this.executionContextChange = function (context, endPointUrl) { if (context === 'web3' && !confirm('Are you sure you want to connect to an ethereum node?')) { return false } else if (context === 'injected' && injectedProvider === undefined) { @@ -131,19 +131,6 @@ function ExecutionContext () { } self.event.trigger('web3EndpointChanged') } - - /* --------------------------------------------------------------------------- - DROPDOWN - --------------------------------------------------------------------------- */ - - var selectExEnv = document.querySelector('#selectExEnvOptions') - selectExEnv.addEventListener('change', function (event) { - if (!executionContextChange(selectExEnv.options[selectExEnv.selectedIndex].value)) { - selectExEnv.value = executionContext - } - }) - - selectExEnv.value = executionContext } module.exports = ExecutionContext diff --git a/src/app/righthand-panel.js b/src/app/righthand-panel.js index afd1120407..35abfdac60 100644 --- a/src/app/righthand-panel.js +++ b/src/app/righthand-panel.js @@ -67,12 +67,7 @@ function RighthandPanel (container, appAPI, events, opts) { // ----------------- tabbed menu ----------------- var tabbedMenuAPI = { - warnCompilerLoading: function (msg) { - appAPI.renderer.clear() - if (msg) { - appAPI.renderer.error(msg, $('#output'), {type: 'warning'}) - } - } + warnCompilerLoading: appAPI.warnCompilerLoading } // load tabbed menu component var tabContainer // @TODO diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 6b0b3c7fbb..215853678d 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -686,6 +686,7 @@ UniversalDApp.prototype.getCallButton = function (args) { var decoded self.runTx({ to: args.address, data: data, useCall: lookupOnly }, function (err, txResult) { + self.event.trigger('transactionExecuted', [args.address, data, lookupOnly, txResult]) if (!txResult) { replaceOutput($result, $('').text('callback contain no result ' + err).addClass('error')) return @@ -865,7 +866,7 @@ UniversalDApp.prototype.runTx = function (args, cb) { // query value function (callback) { tx.value = 0 - + if (tx.useCall) return callback() if (self.transactionContextAPI.getValue) { self.transactionContextAPI.getValue(function (err, ret) { if (err) {