simplify recorder ui

pull/3094/head
Iuri Matias 6 years ago committed by yann300
parent ef6a401b56
commit 9f78c667c2
  1. 71
      src/app/tabs/runTab/recorder.js

@ -21,13 +21,8 @@ class RecorderUI {
this.parentSelf._view.recorderCount.innerText = 0 this.parentSelf._view.recorderCount.innerText = 0
}) })
executionContext.event.register('contextChanged', () => { executionContext.event.register('contextChanged', this.recorder.clearAll.bind(this.recorder))
this.recorder.clearAll() runTabEvent.register('clearInstance', this.recorder.clearAll.bind(this.recorder))
})
runTabEvent.register('clearInstance', () => {
this.recorder.clearAll()
})
} }
render () { render () {
@ -50,29 +45,27 @@ class RecorderUI {
var currentFile = this.parentSelf._deps.config.get('currentFile') var currentFile = this.parentSelf._deps.config.get('currentFile')
this.parentSelf._deps.fileManager.fileProviderOf(currentFile).get(currentFile, (error, json) => { this.parentSelf._deps.fileManager.fileProviderOf(currentFile).get(currentFile, (error, json) => {
if (error) { if (error) {
modalDialogCustom.alert('Invalid Scenario File ' + error) return modalDialogCustom.alert('Invalid Scenario File ' + error)
} else { }
if (currentFile.match('.json$')) { if (!currentFile.match('.json$')) {
try { modalDialogCustom.alert('A scenario file is required. Please make sure a scenario file is currently displayed in the editor. The file must be of type JSON. Use the "Save Transactions" Button to generate a new Scenario File.')
var obj = JSON.parse(json) }
var txArray = obj.transactions || [] try {
var accounts = obj.accounts || [] var obj = JSON.parse(json)
var options = obj.options || {} var txArray = obj.transactions || []
var abis = obj.abis || {} var accounts = obj.accounts || []
var linkReferences = obj.linkReferences || {} var options = obj.options || {}
} catch (e) { var abis = obj.abis || {}
return modalDialogCustom.alert('Invalid Scenario File, please try again') var linkReferences = obj.linkReferences || {}
} } catch (e) {
if (txArray.length) { return modalDialogCustom.alert('Invalid Scenario File, please try again')
var noInstancesText = this.parentSelf._view.noInstancesText }
if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) } if (txArray.length) {
this.recorder.run(txArray, accounts, options, abis, linkReferences, this.parentSelf._deps.udapp, (abi, address, contractName) => { var noInstancesText = this.parentSelf._view.noInstancesText
this.parentSelf._view.instanceContainer.appendChild(this.parentSelf._deps.udappUI.renderInstanceFromABI(abi, address, contractName)) if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) }
}) this.recorder.run(txArray, accounts, options, abis, linkReferences, this.parentSelf._deps.udapp, (abi, address, contractName) => {
} this.parentSelf._view.instanceContainer.appendChild(this.parentSelf._deps.udappUI.renderInstanceFromABI(abi, address, contractName))
} else { })
modalDialogCustom.alert('A scenario file is required. Please make sure a scenario file is currently displayed in the editor. The file must be of type JSON. Use the "Save Transactions" Button to generate a new Scenario File.')
}
} }
}) })
} }
@ -83,17 +76,13 @@ class RecorderUI {
var path = fileManager.currentPath() var path = fileManager.currentPath()
modalDialogCustom.prompt(null, 'Transactions will be saved in a file under ' + path, 'scenario.json', input => { modalDialogCustom.prompt(null, 'Transactions will be saved in a file under ' + path, 'scenario.json', input => {
var fileProvider = fileManager.fileProviderOf(path) var fileProvider = fileManager.fileProviderOf(path)
if (fileProvider) { if (!fileProvider) return
var newFile = path + '/' + input var newFile = path + '/' + input
helper.createNonClashingName(newFile, fileProvider, (error, newFile) => { helper.createNonClashingName(newFile, fileProvider, (error, newFile) => {
if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
if (!fileProvider.set(newFile, txJSON)) { if (!fileProvider.set(newFile, txJSON)) return modalDialogCustom.alert('Failed to create file ' + newFile)
modalDialogCustom.alert('Failed to create file ' + newFile) fileManager.switchFile(newFile)
} else { })
fileManager.switchFile(newFile)
}
})
}
}) })
} }

Loading…
Cancel
Save