- make recorderUI an internal plugin

- refactor so it accept a "file" parameter instead of only the current file (the dep config has been removed from the recorder)
fix#476
yann300 4 years ago
parent be9ab955c1
commit edbc6f3de7
  1. 16
      apps/remix-ide/src/app/tabs/runTab/model/recorder.js
  2. 19
      apps/remix-ide/src/app/tabs/runTab/recorder.js
  3. 2
      apps/remix-ide/src/app/udapp/run-tab.js

@ -12,13 +12,12 @@ var helper = require('../../../../lib/helper.js')
*
*/
class Recorder {
constructor (blockchain, fileManager, config) {
constructor (blockchain, fileManager) {
var self = this
self.event = new EventManager()
self.blockchain = blockchain
self.data = { _listen: true, _replay: false, journal: [], _createdContracts: {}, _createdContractsReverse: {}, _usedAccounts: {}, _abis: {}, _contractABIReferences: {}, _linkReferences: {} }
this.fileManager = fileManager
this.config = config
this.blockchain.event.register('initiatingTransaction', (timestamp, tx, payLoad) => {
if (tx.useCall) return
@ -279,15 +278,14 @@ class Recorder {
return address
}
runScenario (continueCb, promptCb, alertCb, confirmationCb, logCallBack, cb) {
var currentFile = this.config.get('currentFile')
this.fileManager.fileProviderOf(currentFile).get(currentFile, (error, json) => {
if (error) {
return cb('Invalid Scenario File ' + error)
runScenario (file, continueCb, promptCb, alertCb, confirmationCb, logCallBack, cb) {
if (!file) {
return cb('file must be defined')
}
if (!currentFile.match('.json$')) {
if (!file.match('.json$')) {
return cb('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.')
}
this.fileManager.readFile(file).then((json) => {
try {
var obj = JSON.parse(json)
var txArray = obj.transactions || []
@ -306,7 +304,7 @@ class Recorder {
this.run(txArray, accounts, options, abis, linkReferences, confirmationCb, continueCb, promptCb, alertCb, logCallBack, (abi, address, contractName) => {
cb(null, abi, address, contractName)
})
})
}).catch((error) => cb(error))
}
saveScenario (promptCb, cb) {

@ -1,21 +1,28 @@
var yo = require('yo-yo')
var remixLib = require('@remix-project/remix-lib')
var EventManager = remixLib.EventManager
import { Plugin } from '@remixproject/engine'
var csjs = require('csjs-inject')
var css = require('../styles/run-tab-styles')
import * as packageJson from '../../../../../package.json'
var modalDialogCustom = require('../../ui/modal-dialog-custom')
var modalDialog = require('../../ui/modaldialog')
var confirmDialog = require('../../ui/confirmDialog')
class RecorderUI {
const profile = {
name: 'recorder',
methods: ['runScenario'],
version: packageJson.version
}
class RecorderUI extends Plugin {
constructor (blockchain, recorder, logCallBack, config) {
this.blockchain = blockchain
this.recorder = recorder
this.logCallBack = logCallBack
this.config = config
this.event = new EventManager()
}
render () {
@ -34,7 +41,9 @@ class RecorderUI {
this.runButton.onclick = this.runScenario.bind(this)
}
runScenario () {
runScenario (file) {
file = file || this.config.get('currentFile')
var continueCb = (error, continueTxExecution, cancelCb) => {
if (error) {
var msg = typeof error !== 'string' ? error.message : error
@ -68,7 +77,7 @@ class RecorderUI {
const confirmationCb = this.getConfirmationCb(modalDialog, confirmDialog)
// TODO: there is still a UI dependency to remove here, it's still too coupled at this point to remove easily
this.recorder.runScenario(continueCb, promptCb, alertCb, confirmationCb, this.logCallBack, (error, abi, address, contractName) => {
this.recorder.runScenario(file, continueCb, promptCb, alertCb, confirmationCb, this.logCallBack, (error, abi, address, contractName) => {
if (error) {
return modalDialogCustom.alert(error)
}

@ -118,7 +118,7 @@ export class RunTab extends LibraryPlugin {
renderRecorder (udappUI, fileManager, config, logCallback) {
this.recorderCount = yo`<span>0</span>`
const recorder = new Recorder(this.blockchain, fileManager, config)
const recorder = new Recorder(this.blockchain, fileManager)
recorder.event.register('recorderCountChange', (count) => {
this.recorderCount.innerText = count
})

Loading…
Cancel
Save