remove need for self in dropdown logic

pull/1/head
Iuri Matias 6 years ago committed by yann300
parent 85b8863c66
commit 825ca33c2d
  1. 1
      src/app/execution/confirmDialog.js
  2. 1
      src/app/files/compiler-metadata.js
  3. 11
      src/app/tabs/run-tab.js
  4. 8
      src/app/tabs/runTab/contractDropdown.js
  5. 73
      src/app/tabs/runTab/model/dropdownlogic.js

@ -16,6 +16,7 @@ var css = csjs`
} }
` `
// TODO: self is not actually used and can be removed
function confirmDialog (tx, amount, gasEstimation, self, newGasPriceCb, initialParamsCb) { function confirmDialog (tx, amount, gasEstimation, self, newGasPriceCb, initialParamsCb) {
var onGasPriceChange = function () { var onGasPriceChange = function () {
var gasPrice = el.querySelector('#gasprice').value var gasPrice = el.querySelector('#gasprice').value

@ -74,6 +74,7 @@ class CompilerMetadata {
return metadata return metadata
} }
// TODO: is only called by dropdownLogic and can be moved there
deployMetadataOf (contractName, callback) { deployMetadataOf (contractName, callback) {
var self = this var self = this
var provider = self._opts.fileManager.currentFileProvider() var provider = self._opts.fileManager.currentFileProvider()

@ -142,7 +142,16 @@ function runTab (opts, localRegistry) {
this.event.trigger('clearInstance', []) this.event.trigger('clearInstance', [])
}) })
var dropdownLogic = new DropdownLogic(self) var dropdownLogic = new DropdownLogic(
this.parentSelf._deps.fileManager,
this.parentSelf._deps.pluginManager,
this.parentSelf._deps.compilersArtefacts,
this.parentSelf._deps.compiler,
this.parentSelf._deps.config,
this.parentSelf._deps.editor,
this.parentSelf._deps.udapp,
this.parentSelf._deps.filePanel
)
var contractDropdownUI = new ContractDropdownUI(dropdownLogic, self) var contractDropdownUI = new ContractDropdownUI(dropdownLogic, self)
contractDropdownUI.event.register('clearInstance', () => { contractDropdownUI.event.register('clearInstance', () => {

@ -142,6 +142,10 @@ class ContractDropdownUI {
modalDialogCustom.promptPassphrase(null, 'Personal mode is enabled. Please provide passphrase of account', '', okCb, cancelCb) modalDialogCustom.promptPassphrase(null, 'Personal mode is enabled. Please provide passphrase of account', '', okCb, cancelCb)
} }
var statusCb = (msg) => {
return this.parentSelf._deps.logCallback(msg)
}
var finalCb = (error, contractObject, address) => { var finalCb = (error, contractObject, address) => {
this.event.trigger('clearInstance') this.event.trigger('clearInstance')
@ -159,7 +163,7 @@ class ContractDropdownUI {
{ {
label: 'Force Send', label: 'Force Send',
fn: () => { fn: () => {
this.dropdownLogic.forceSend(selectedContract, args, continueCb, promptCb, modalDialogCustom, confirmDialog, finalCb) this.dropdownLogic.forceSend(selectedContract, args, continueCb, promptCb, modalDialogCustom, confirmDialog, statusCb, finalCb)
}}, { }}, {
label: 'Cancel', label: 'Cancel',
fn: () => { fn: () => {
@ -167,7 +171,7 @@ class ContractDropdownUI {
} }
}) })
} }
this.dropdownLogic.forceSend(selectedContract, args, continueCb, promptCb, modalDialogCustom, confirmDialog, finalCb) this.dropdownLogic.forceSend(selectedContract, args, continueCb, promptCb, modalDialogCustom, confirmDialog, statusCb, finalCb)
} }
loadFromAddress () { loadFromAddress () {

@ -9,32 +9,39 @@ var CompilerAbstract = require('../../../compiler/compiler-abstract')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
class DropdownLogic { class DropdownLogic {
constructor (parentSelf) { constructor (fileManager, pluginManager, compilersArtefacts, compiler, config, editor, udapp, filePanel) {
this.parentSelf = parentSelf this.pluginManager = pluginManager
this.compilersArtefacts = compilersArtefacts
this.compiler = compiler
this.config = config
this.editor = editor
this.udapp = udapp
this.filePanel = filePanel
this.event = new EventManager() this.event = new EventManager()
this.listenToCompilationEvents() this.listenToCompilationEvents()
this.parentSelf._deps.fileManager.event.register('currentFileChanged', (currentFile) => { fileManager.event.register('currentFileChanged', (currentFile) => {
this.event.trigger('currentFileChanged', [currentFile]) this.event.trigger('currentFileChanged', [currentFile])
}) })
} }
listenToCompilationEvents () { listenToCompilationEvents () {
this.parentSelf._deps.pluginManager.event.register('sendCompilationResult', (file, source, languageVersion, data) => { this.pluginManager.event.register('sendCompilationResult', (file, source, languageVersion, data) => {
// TODO check whether the tab is configured // TODO check whether the tab is configured
let compiler = new CompilerAbstract(languageVersion, data) let compiler = new CompilerAbstract(languageVersion, data)
this.parentSelf._deps.compilersArtefacts[languageVersion] = compiler this.compilersArtefacts[languageVersion] = compiler
this.parentSelf._deps.compilersArtefacts['__last'] = compiler this.compilersArtefacts['__last'] = compiler
this.event.trigger('newlyCompiled', [true, data, source, compiler, languageVersion]) this.event.trigger('newlyCompiled', [true, data, source, compiler, languageVersion])
}) })
this.parentSelf._deps.compiler.event.register('compilationFinished', (success, data, source) => { this.compiler.event.register('compilationFinished', (success, data, source) => {
var name = 'solidity' var name = 'solidity'
let compiler = new CompilerAbstract(name, data) let compiler = new CompilerAbstract(name, data)
this.parentSelf._deps.compilersArtefacts[name] = compiler this.compilersArtefacts[name] = compiler
this.parentSelf._deps.compilersArtefacts['__last'] = compiler this.compilersArtefacts['__last'] = compiler
this.event.trigger('newlyCompiled', [success, data, source, this.parentSelf._deps.compiler, name]) this.event.trigger('newlyCompiled', [success, data, source, this.compiler, name])
}) })
} }
@ -45,11 +52,11 @@ class DropdownLogic {
if (/[a-f]/.test(address) && /[A-F]/.test(address) && !ethJSUtil.isValidChecksumAddress(address)) { if (/[a-f]/.test(address) && /[A-F]/.test(address) && !ethJSUtil.isValidChecksumAddress(address)) {
return cb('Invalid checksum address.') return cb('Invalid checksum address.')
} }
if (/.(.abi)$/.exec(this.parentSelf._deps.config.get('currentFile'))) { if (/.(.abi)$/.exec(this.config.get('currentFile'))) {
confirmCb(() => { confirmCb(() => {
var abi var abi
try { try {
abi = JSON.parse(this.parentSelf._deps.editor.currentContent()) abi = JSON.parse(this.editor.currentContent())
} catch (e) { } catch (e) {
return cb('Failed to parse the current file as JSON ABI.') return cb('Failed to parse the current file as JSON ABI.')
} }
@ -70,7 +77,7 @@ class DropdownLogic {
getSelectedContract (contractName, compilerAtributeName) { getSelectedContract (contractName, compilerAtributeName) {
if (!contractName) return null if (!contractName) return null
var compiler = this.parentSelf._deps.compilersArtefacts[compilerAtributeName] var compiler = this.compilersArtefacts[compilerAtributeName]
if (!compiler) return null if (!compiler) return null
var contract = compiler.getContract(contractName) var contract = compiler.getContract(contractName)
@ -185,7 +192,7 @@ class DropdownLogic {
}) })
} }
this.parentSelf._deps.udapp.createContract(data, confirmationCb, continueCb, promptCb, this.udapp.createContract(data, confirmationCb, continueCb, promptCb,
(error, txResult) => { (error, txResult) => {
if (error) { if (error) {
return finalCb(`creation of ${selectedContract.name} errored: ${error}`) return finalCb(`creation of ${selectedContract.name} errored: ${error}`)
@ -212,7 +219,7 @@ class DropdownLogic {
return continueTxExecution(null) return continueTxExecution(null)
} }
var amount = this.fromWei(tx.value, true, 'ether') var amount = this.fromWei(tx.value, true, 'ether')
var content = confirmDialog(tx, amount, gasEstimation, this.parentSelf, var content = confirmDialog(tx, amount, gasEstimation, null,
(gasPrice, cb) => { (gasPrice, cb) => {
let txFeeText, priceStatus let txFeeText, priceStatus
// TODO: this try catch feels like an anti pattern, can/should be // TODO: this try catch feels like an anti pattern, can/should be
@ -245,7 +252,7 @@ class DropdownLogic {
modalDialog('Confirm transaction', content, modalDialog('Confirm transaction', content,
{ label: 'Confirm', { label: 'Confirm',
fn: () => { fn: () => {
this.parentSelf._deps.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked) this.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
// TODO: check if this is check is still valid given the refactor // TODO: check if this is check is still valid given the refactor
if (!content.gasPriceStatus) { if (!content.gasPriceStatus) {
cancelCb('Given gas price is not correct') cancelCb('Given gas price is not correct')
@ -262,34 +269,32 @@ class DropdownLogic {
) )
} }
this.parentSelf._deps.udapp.runTx(data, confirmationCb, promptCb, finalCb) this.udapp.runTx(data, confirmationCb, promptCb, finalCb)
} }
forceSend (selectedContract, args, continueCb, promptCb, modalDialog, confirmDialog, cb) { forceSend (selectedContract, args, continueCb, promptCb, modalDialog, confirmDialog, statusCb, cb) {
var constructor = selectedContract.getConstructorInterface() var constructor = selectedContract.getConstructorInterface()
this.parentSelf._deps.filePanel.compilerMetadata().deployMetadataOf(selectedContract.name, (error, contractMetadata) => { // TODO: deployMetadataOf can be moved here
if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) this.filePanel.compilerMetadata().deployMetadataOf(selectedContract.name, (error, contractMetadata) => {
if (error) return statusCb(`creation of ${selectedContract.name} errored: ` + error)
if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) { if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) {
txFormat.buildData(selectedContract.name, selectedContract.object, selectedContract.compiler.getContracts(), true, constructor, args, (error, data) => { return txFormat.buildData(selectedContract.name, selectedContract.object, selectedContract.compiler.getContracts(), true, constructor, args, (error, data) => {
if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) if (error) return statusCb(`creation of ${selectedContract.name} errored: ` + error)
this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} pending...`) statusCb(`creation of ${selectedContract.name} pending...`)
this.createContract(selectedContract, data, continueCb, promptCb, modalDialog, confirmDialog, cb) this.createContract(selectedContract, data, continueCb, promptCb, modalDialog, confirmDialog, cb)
}, (msg) => { }, statusCb, (data, runTxCallback) => {
this.parentSelf._deps.logCallback(msg)
}, (data, runTxCallback) => {
// called for libraries deployment // called for libraries deployment
this.runTransaction(data, promptCb, modalDialog, confirmDialog, runTxCallback) this.runTransaction(data, promptCb, modalDialog, confirmDialog, runTxCallback)
}) })
} else {
if (Object.keys(selectedContract.bytecodeLinkReferences).length) this.parentSelf._deps.logCallback(`linking ${JSON.stringify(selectedContract.bytecodeLinkReferences, null, '\t')} using ${JSON.stringify(contractMetadata.linkReferences, null, '\t')}`)
txFormat.encodeConstructorCallAndLinkLibraries(selectedContract.object, args, constructor, contractMetadata.linkReferences, selectedContract.bytecodeLinkReferences, (error, data) => {
if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} pending...`)
this.createContract(selectedContract, data, continueCb, promptCb, modalDialog, confirmDialog, cb)
})
} }
if (Object.keys(selectedContract.bytecodeLinkReferences).length) statusCb(`linking ${JSON.stringify(selectedContract.bytecodeLinkReferences, null, '\t')} using ${JSON.stringify(contractMetadata.linkReferences, null, '\t')}`)
txFormat.encodeConstructorCallAndLinkLibraries(selectedContract.object, args, constructor, contractMetadata.linkReferences, selectedContract.bytecodeLinkReferences, (error, data) => {
if (error) return statusCb(`creation of ${selectedContract.name} errored: ` + error)
statusCb(`creation of ${selectedContract.name} pending...`)
this.createContract(selectedContract, data, continueCb, promptCb, modalDialog, confirmDialog, cb)
})
}) })
} }

Loading…
Cancel
Save