- ${self._view.createPanel}
- ${self._view.orLabel}
-
- `
+ `
+ this.selectContractNames.addEventListener('change', this.setInputParamsPlaceHolder.bind(this))
+
+ return el
+ }
- function setInputParamsPlaceHolder () {
- self._view.createPanel.innerHTML = ''
- if (selectContractNames.selectedIndex >= 0 && selectContractNames.children.length > 0) {
- var selectedContract = getSelectedContract()
+ setInputParamsPlaceHolder () {
+ this.parentSelf._view.createPanel.innerHTML = ''
+ if (this.selectContractNames.selectedIndex >= 0 && this.selectContractNames.children.length > 0) {
+ var selectedContract = this.getSelectedContract()
var ctrabi = txHelper.getConstructorInterface(selectedContract.contract.object.abi)
var ctrEVMbc = selectedContract.contract.object.evm.bytecode.object
var createConstructorInstance = new MultiParamManager(0, ctrabi, (valArray, inputsValues) => {
- createInstance(inputsValues, selectedContract.compiler)
+ this.createInstance(inputsValues, selectedContract.compiler)
}, txHelper.inputParametersDeclarationToString(ctrabi.inputs), 'Deploy', ctrEVMbc)
- self._view.createPanel.appendChild(createConstructorInstance.render())
+ this.parentSelf._view.createPanel.appendChild(createConstructorInstance.render())
return
} else {
- self._view.createPanel.innerHTML = 'No compiled contracts'
+ this.parentSelf._view.createPanel.innerHTML = 'No compiled contracts'
}
}
- selectContractNames.addEventListener('change', setInputParamsPlaceHolder)
+ getSelectedContract () {
+ var contract = this.selectContractNames.children[this.selectContractNames.selectedIndex]
+ var contractName = contract.innerHTML
+ var compiler = this.parentSelf._deps.compilersArtefacts[contract.getAttribute('compiler')]
+ if (!compiler) return null
+
+ if (contractName) {
+ return {
+ name: contractName,
+ contract: compiler.getContract(contractName),
+ compiler
+ }
+ }
+ return null
+ }
- function createInstanceCallback (selectedContract, data) {
- self._deps.logCallback(`creation of ${selectedContract.name} pending...`)
+ createInstanceCallback (selectedContract, data) {
+ this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} pending...`)
if (data) {
data.contractName = selectedContract.name
data.linkReferences = selectedContract.contract.object.evm.bytecode.linkReferences
data.contractABI = selectedContract.contract.object.abi
}
- self._deps.udapp.createContract(data,
+ this.parentSelf._deps.udapp.createContract(data,
(network, tx, gasEstimation, continueTxExecution, cancelCb) => {
if (network.name !== 'Main') {
return continueTxExecution(null)
}
var amount = executionContext.web3().fromWei(typeConversion.toInt(tx.value), 'ether')
- var content = confirmDialog(tx, amount, gasEstimation, self,
+ var content = confirmDialog(tx, amount, gasEstimation, this.parentSelf,
(gasPrice, cb) => {
let txFeeText, priceStatus
// TODO: this try catch feels like an anti pattern, can/should be
@@ -170,7 +177,7 @@ function contractDropdown (events, self) {
modalDialog('Confirm transaction', content,
{ label: 'Confirm',
fn: () => {
- self._deps.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
+ this.parentSelf._deps.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
// TODO: check if this is check is still valid given the refactor
if (!content.gasPriceStatus) {
cancelCb('Given gas price is not correct')
@@ -215,28 +222,28 @@ function contractDropdown (events, self) {
if (isVM) {
var vmError = txExecution.checkVMError(txResult)
if (vmError.error) {
- self._deps.logCallback(vmError.message)
+ this.parentSelf._deps.logCallback(vmError.message)
return
}
}
if (txResult.result.status && txResult.result.status === '0x0') {
- self._deps.logCallback(`creation of ${selectedContract.name} errored: transaction execution failed`)
+ this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: transaction execution failed`)
return
}
- var noInstancesText = self._view.noInstancesText
+ var noInstancesText = this.parentSelf._view.noInstancesText
if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) }
var address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress
- instanceContainer.appendChild(self._deps.udappUI.renderInstance(selectedContract.contract.object, address, selectContractNames.value))
+ this.instanceContainer.appendChild(this.parentSelf._deps.udappUI.renderInstance(selectedContract.contract.object, address, this.selectContractNames.value))
} else {
- self._deps.logCallback(`creation of ${selectedContract.name} errored: ${error}`)
+ this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ${error}`)
}
}
)
}
// DEPLOY INSTANCE
- function createInstance (args, compiler) {
- var selectedContract = getSelectedContract()
+ createInstance (args, compiler) {
+ var selectedContract = this.getSelectedContract()
if (selectedContract.contract.object.evm.bytecode.object.length === 0) {
modalDialogCustom.alert('This contract may be abstract, not implement an abstract parent\'s methods completely or not invoke an inherited contract\'s constructor correctly.')
@@ -245,23 +252,23 @@ function contractDropdown (events, self) {
var forceSend = () => {
var constructor = txHelper.getConstructorInterface(selectedContract.contract.object.abi)
- self._deps.filePanel.compilerMetadata().deployMetadataOf(selectedContract.name, (error, contractMetadata) => {
- if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
+ this.parentSelf._deps.filePanel.compilerMetadata().deployMetadataOf(selectedContract.name, (error, contractMetadata) => {
+ if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) {
txFormat.buildData(selectedContract.name, selectedContract.contract.object, compiler.getContracts(), true, constructor, args, (error, data) => {
- if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
- createInstanceCallback(selectedContract, data)
+ if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
+ this.createInstanceCallback(selectedContract, data)
}, (msg) => {
- self._deps.logCallback(msg)
+ this.parentSelf._deps.logCallback(msg)
}, (data, runTxCallback) => {
// called for libraries deployment
- self._deps.udapp.runTx(data,
+ this.parentSelf._deps.udapp.runTx(data,
(network, tx, gasEstimation, continueTxExecution, cancelCb) => {
if (network.name !== 'Main') {
return continueTxExecution(null)
}
var amount = executionContext.web3().fromWei(typeConversion.toInt(tx.value), 'ether')
- var content = confirmDialog(tx, amount, gasEstimation, self,
+ var content = confirmDialog(tx, amount, gasEstimation, this.parentSelf,
(gasPrice, cb) => {
let txFeeText, priceStatus
// TODO: this try catch feels like an anti pattern, can/should be
@@ -294,7 +301,7 @@ function contractDropdown (events, self) {
modalDialog('Confirm transaction', content,
{ label: 'Confirm',
fn: () => {
- self._deps.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
+ this.parentSelf._deps.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
// TODO: check if this is check is still valid given the refactor
if (!content.gasPriceStatus) {
cancelCb('Given gas price is not correct')
@@ -315,10 +322,10 @@ function contractDropdown (events, self) {
runTxCallback)
})
} else {
- if (Object.keys(selectedContract.contract.object.evm.bytecode.linkReferences).length) self._deps.logCallback(`linking ${JSON.stringify(selectedContract.contract.object.evm.bytecode.linkReferences, null, '\t')} using ${JSON.stringify(contractMetadata.linkReferences, null, '\t')}`)
+ if (Object.keys(selectedContract.contract.object.evm.bytecode.linkReferences).length) this.parentSelf._deps.logCallback(`linking ${JSON.stringify(selectedContract.contract.object.evm.bytecode.linkReferences, null, '\t')} using ${JSON.stringify(contractMetadata.linkReferences, null, '\t')}`)
txFormat.encodeConstructorCallAndLinkLibraries(selectedContract.contract.object, args, constructor, contractMetadata.linkReferences, selectedContract.contract.object.evm.bytecode.linkReferences, (error, data) => {
- if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
- createInstanceCallback(selectedContract, data)
+ if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
+ this.createInstanceCallback(selectedContract, data)
})
}
})
@@ -335,7 +342,7 @@ function contractDropdown (events, self) {
}}, {
label: 'Cancel',
fn: () => {
- self._deps.logCallback(`creation of ${selectedContract.name} canceled by user.`)
+ this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} canceled by user.`)
}
})
} else {
@@ -344,48 +351,47 @@ function contractDropdown (events, self) {
}
// ACCESS DEPLOYED INSTANCE
- function loadFromAddress () {
- var noInstancesText = self._view.noInstancesText
+ loadFromAddress () {
+ var noInstancesText = this.parentSelf._view.noInstancesText
if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) }
- var address = atAddressButtonInput.value
+ var address = this.atAddressButtonInput.value
if (!ethJSUtil.isValidAddress(address)) {
return modalDialogCustom.alert('Invalid address.')
}
if (/[a-f]/.test(address) && /[A-F]/.test(address) && !ethJSUtil.isValidChecksumAddress(address)) {
return modalDialogCustom.alert('Invalid checksum address.')
}
- if (/.(.abi)$/.exec(self._deps.config.get('currentFile'))) {
+ if (/.(.abi)$/.exec(this.parentSelf._deps.config.get('currentFile'))) {
modalDialogCustom.confirm(null, 'Do you really want to interact with ' + address + ' using the current ABI definition ?', () => {
var abi
try {
- abi = JSON.parse(self._deps.editor.currentContent())
+ abi = JSON.parse(this.parentSelf._deps.editor.currentContent())
} catch (e) {
return modalDialogCustom.alert('Failed to parse the current file as JSON ABI.')
}
- instanceContainer.appendChild(self._deps.udappUI.renderInstanceFromABI(abi, address, address))
+ this.instanceContainer.appendChild(this.parentSelf._deps.udappUI.renderInstanceFromABI(abi, address, address))
})
} else {
- var selectedContract = getSelectedContract()
- instanceContainer.appendChild(self._deps.udappUI.renderInstance(selectedContract.contract.object, address, selectContractNames.value))
+ var selectedContract = this.getSelectedContract()
+ this.instanceContainer.appendChild(this.parentSelf._deps.udappUI.renderInstance(selectedContract.contract.object, address, this.selectContractNames.value))
}
}
// GET NAMES OF ALL THE CONTRACTS
- function getContractNames (success, data, compiler, compilerFullName) {
+ getContractNames (success, data, compiler, compilerFullName) {
var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`)
contractNames.innerHTML = ''
if (success) {
- selectContractNames.removeAttribute('disabled')
+ this.selectContractNames.removeAttribute('disabled')
compiler.visitContracts((contract) => {
contractNames.appendChild(yo`
${contract.name} `)
})
} else {
- selectContractNames.setAttribute('disabled', true)
+ this.selectContractNames.setAttribute('disabled', true)
}
- setInputParamsPlaceHolder()
+ this.setInputParamsPlaceHolder()
}
- return el
}
-module.exports = contractDropdown
+module.exports = ContractDropdownUI