refactor contract dropdown logic

pull/5370/head
Iuri Matias 5 years ago
parent fdcb10f450
commit f37bee213f
  1. 18
      src/app/tabs/runTab/contractDropdown.js
  2. 26
      src/app/tabs/runTab/model/dropdownlogic.js
  3. 6
      src/app/udapp/run-tab.js

@ -8,9 +8,10 @@ var modalDialog = require('../../ui/modaldialog')
var MultiParamManager = require('../../ui/multiParamManager')
class ContractDropdownUI {
constructor (dropdownLogic, logCallback) {
constructor (dropdownLogic, logCallback, runView) {
this.dropdownLogic = dropdownLogic
this.logCallback = logCallback
this.runView = runView
this.event = new EventManager()
this.listenToEvents()
@ -39,8 +40,6 @@ class ContractDropdownUI {
document.querySelector(`.${css.contractNames}`).classList.add(css.contractNamesError)
}
})
this.dropdownLogic.event.register('currentFileChanged', this.changeCurrentFile.bind(this))
}
render () {
@ -176,6 +175,15 @@ class ContractDropdownUI {
this.event.trigger('newContractInstanceAdded', [contractObject, address, contractObject.name])
}
let contractMetadata
try {
contractMetadata = await this.runView.call('compilerMetadata', 'deployMetadataOf', selectedContract.name)
} catch (error) {
return statusCb(`creation of ${selectedContract.name} errored: ` + error)
}
const compilerContracts = this.dropdownLogic.getCompilerContracts()
if (selectedContract.isOverSizeLimit()) {
return modalDialog('Contract code size over limit', yo`<div>Contract creation initialization returns data with length of more than 24576 bytes. The deployment will likely fails. <br>
More info: <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md" target="_blank">eip-170</a>
@ -183,7 +191,7 @@ class ContractDropdownUI {
{
label: 'Force Send',
fn: () => {
this.dropdownLogic.deployContract(selectedContract, args, {continueCb, promptCb, statusCb, finalCb}, {modalDialog, confirmDialog})
this.dropdownLogic.deployContract(selectedContract, args, contractMetadata, compilerContracts, {continueCb, promptCb, statusCb, finalCb}, {modalDialog, confirmDialog})
}}, {
label: 'Cancel',
fn: () => {
@ -191,7 +199,7 @@ class ContractDropdownUI {
}
})
}
this.dropdownLogic.deployContract(selectedContract, args, {continueCb, promptCb, statusCb, finalCb}, {modalDialog, confirmDialog})
this.dropdownLogic.deployContract(selectedContract, args, contractMetadata, compilerContracts, {continueCb, promptCb, statusCb, finalCb}, {modalDialog, confirmDialog})
}
loadFromAddress () {

@ -9,22 +9,17 @@ var EventManager = remixLib.EventManager
var Web3 = require('web3')
class DropdownLogic {
constructor (executionContext, fileManager, compilersArtefacts, config, editor, udapp, filePanel, runView) {
constructor (executionContext, compilersArtefacts, config, editor, udapp, runView) {
this.compilersArtefacts = compilersArtefacts
this.executionContext = executionContext
this.config = config
this.editor = editor
this.udapp = udapp
this.runView = runView
this.filePanel = filePanel
this.event = new EventManager()
this.listenToCompilationEvents()
fileManager.events.on('currentFileChanged', (currentFile) => {
this.event.trigger('currentFileChanged', [currentFile])
})
}
// TODO: can be moved up; the event in contractDropdown will have to refactored a method instead
@ -124,10 +119,6 @@ class DropdownLogic {
return this.executionContext.web3().eth.getGasPrice(cb)
}
isVM () {
return this.executionContext.isVM()
}
// TODO: check if selectedContract and data can be joined
createContract (selectedContract, data, continueCb, promptCb, modalDialog, confirmDialog, finalCb) {
if (data) {
@ -224,20 +215,17 @@ class DropdownLogic {
this.udapp.runTx(data, confirmationCb, continueCb, promptCb, finalCb)
}
async deploContract (selectedContract, args, callbacks, dialogs) {
getCompilerContracts() {
return this.compilersArtefacts['__last'].getData().contracts
}
async deploContract (selectedContract, args, contractMetadata, compilerContracts, callbacks, dialogs) {
const {continueCb, promptCb, statusCb, finalCb} = callbacks
const {modalDialog, confirmDialog} = dialogs
var constructor = selectedContract.getConstructorInterface()
// TODO: deployMetadataOf can be moved here
let contractMetadata
try {
contractMetadata = await this.runView.call('compilerMetadata', 'deployMetadataOf', selectedContract.name)
} catch (error) {
return statusCb(`creation of ${selectedContract.name} errored: ` + error)
}
if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) {
return txFormat.buildData(selectedContract.name, selectedContract.object, this.compilersArtefacts['__last'].getData().contracts, true, constructor, args, (error, data) => {
return txFormat.buildData(selectedContract.name, selectedContract.object, compilerContracts, true, constructor, args, (error, data) => {
if (error) return statusCb(`creation of ${selectedContract.name} errored: ` + error)
statusCb(`creation of ${selectedContract.name} pending...`)

@ -131,8 +131,10 @@ export class RunTab extends LibraryPlugin {
}
renderDropdown (udappUI, fileManager, compilersArtefacts, config, editor, udapp, filePanel, logCallback) {
const dropdownLogic = new DropdownLogic(this.executionContext, fileManager, compilersArtefacts, config, editor, udapp, filePanel, this)
this.contractDropdownUI = new ContractDropdownUI(dropdownLogic, logCallback)
const dropdownLogic = new DropdownLogic(this.executionContext, compilersArtefacts, config, editor, udapp, this)
this.contractDropdownUI = new ContractDropdownUI(dropdownLogic, logCallback, this)
fileManager.events.on('currentFileChanged', contractDropdownUI.changeCurrentFile.bind(contractDropdownUI))
this.contractDropdownUI.event.register('clearInstance', () => {
const noInstancesText = this.noInstancesText

Loading…
Cancel
Save