diff --git a/src/app.js b/src/app.js index ecce1e1980..39c5d74633 100644 --- a/src/app.js +++ b/src/app.js @@ -556,6 +556,7 @@ function run () { udapp: () => { return udapp }, + filesProviders: filesProviders, fileProviderOf: (path) => { return fileManager.fileProviderOf(path) }, diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 3cfaf86edd..374c8dfaa1 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -303,8 +303,14 @@ function makeRecorder (self, appAPI, appEvents) { ` recordButton.onclick = () => { var txJSON = JSON.stringify(recorder.getAll(), null, 2) - copy(txJSON) - modalDialogCustom.alert(txJSON) + modalDialogCustom.prompt(null, 'journal file name', 'scenario.json', input => { + var newName = appAPI.filesProvider['browser'].type + '/' + helper.createNonClashingName(input, appAPI.filesProvider['browser']) + if (!appAPI.filesProvider['browser'].set(newName, txJSON)) { + modalDialogCustom.alert('Failed to create file ' + newName) + } else { + appAPI.switchFile(newName) + } + }) } runButton.onclick = () => { var opts = { title: `Enter Transactions`, text: `Paste the array of transaction you want to replay here`, inputValue: '', multiline: true } @@ -315,7 +321,13 @@ function makeRecorder (self, appAPI, appEvents) { modalDialogCustom.alert('Invalid JSON, please try again') } if (txArray.length) { - txArray.forEach(tx => udapp.rerunTx(tx.record, CALLBACK)) + txArray.forEach(tx => { + udapp.getAccounts((err, accounts = []) => { + if (err) console.error(err) + tx.record = recorder.resolveAddress(tx.record, accounts) + udapp.rerunTx(tx.record, CALLBACK) + }) + }) } }, function cancel () { }) } diff --git a/src/recorder.js b/src/recorder.js index 07e4a24dc4..bea7de57dc 100644 --- a/src/recorder.js +++ b/src/recorder.js @@ -44,6 +44,16 @@ class Recorder { }) }) } + resolveAddress (record, accounts) { + if (record.to && record.to[0] === '<') record.to = accounts[record.to.split('>')[0].slice(11)] + if (record.from && record.from[0] === '<') record.from = accounts[record.from.split('>')[0].slice(11)] + // @TODO: change copy/paste to write and read from history file + + // @TODO: writing browser test + + // @TODO: replace addresses with custom ones (maybe address mapping file?) + return record + } append (timestamp, record) { var self = this self.data.journal.push({ timestamp, record }) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index f69bd63cf8..65359d0b7a 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -471,8 +471,6 @@ UniversalDApp.prototype.rerunTx = function (args, cb) { var self = this self.getAccounts(function (err, accounts = []) { if (err) console.error(err) - if (args.to && args.to[0] === '<') args.to = accounts[args.to.split('>')[0].slice(11)] - if (args.from && args.from[0] === '<') args.from = accounts[args.from.split('>')[0].slice(11)] var pipeline = [queryGasLimit, runTransaction] var env = { self, args, tx: { to: args.to, from: args.from, data: args.data, useCall: args.useCall } } execute(pipeline, env, cb)