CompileTab: minor refactorings

pull/1/head
serapath 7 years ago
parent fedd7cfa8b
commit c8d6661eb0
  1. 78
      src/app/tabs/compile-tab.js

@ -90,37 +90,31 @@ module.exports = class CompileTab {
// refill the dropdown list // refill the dropdown list
getContractNames(success, data) getContractNames(success, data)
// hightlight the tab if error // hightlight the tab if error
if (success) { if (success) document.querySelector('.compileView').style.color = '' // @TODO: compileView tab
document.querySelector('.compileView').style.color = '' else document.querySelector('.compileView').style.color = styles.colors.red // @TODO: compileView tab
} else {
document.querySelector('.compileView').style.color = styles.colors.red
}
// display warning error if any // display warning error if any
var error = false var error = false
if (data['error']) { if (data['error']) {
error = true error = true
self._opts.renderer.error(data['error'].formattedMessage, self._view.errorContainer, {type: data['error'].severity}) self._opts.renderer.error(data['error'].formattedMessage, self._view.errorContainer, {type: data['error'].severity})
} }
if (data['errors']) { if (data.errors && data.errors.length) {
if (data['errors'].length) error = true error = true
data['errors'].forEach(function (err) { data.errors.forEach(function (err) {
self._opts.renderer.error(err.formattedMessage, self._view.errorContainer, {type: err.severity}) self._opts.renderer.error(err.formattedMessage, self._view.errorContainer, {type: err.severity})
}) })
} }
if (!error) { if (!error && data.contracts) {
if (data.contracts) {
self._opts.compiler.visitContracts((contract) => { self._opts.compiler.visitContracts((contract) => {
self._opts.renderer.error(contract.name, self._view.errorContainer, {type: 'success'}) self._opts.renderer.error(contract.name, self._view.errorContainer, {type: 'success'})
}) })
} }
}
}) })
self._events.staticAnalysis.register('staticAnaysisWarning', (count) => { self._events.staticAnalysis.register('staticAnaysisWarning', (count) => {
if (count) { if (count) {
self._opts.renderer.error(`Static Analysis raised ${count} warning(s) that requires your attention.`, self._view.errorContainer, { const msg = `Static Analysis raised ${count} warning(s) that requires your attention.`
type: 'warning', const settings = { type: 'warning', click: () => self._api.switchTab('staticanalysisView') }
click: () => self._api.switchTab('staticanalysisView') self._opts.renderer.error(msg, self._view.errorContainer, settings)
})
} }
}) })
@ -163,8 +157,8 @@ module.exports = class CompileTab {
self._view.contractNames.innerHTML = '' self._view.contractNames.innerHTML = ''
if (success) { if (success) {
self._view.contractNames.removeAttribute('disabled') self._view.contractNames.removeAttribute('disabled')
opts.compiler.visitContracts((contract) => { self._opts.compiler.visitContracts(contract => {
self.data.contractsDetails[contract.name] = parseContracts(contract.name, contract.object, opts.compiler.getSource(contract.file)) self.data.contractsDetails[contract.name] = parseContracts(contract.name, contract.object, self._opts.compiler.getSource(contract.file))
var contractName = yo`<option>${contract.name}</option>` var contractName = yo`<option>${contract.name}</option>`
self._view.contractNames.appendChild(contractName) self._view.contractNames.appendChild(contractName)
}) })
@ -174,28 +168,7 @@ module.exports = class CompileTab {
self._api.resetDapp({}) self._api.resetDapp({})
} }
} }
function details () { const help = {
var select = self._view.contractNames
if (select.children.length > 0 && select.selectedIndex >= 0) {
var contractName = select.children[select.selectedIndex].innerHTML
var contractProperties = self.data.contractsDetails[contractName]
var log = yo`<div class="${css.detailsJSON}"></div>`
Object.keys(contractProperties).map(propertyName => {
var copyDetails = yo`<span class="${css.copyDetails}">
${copyToClipboard(() => contractProperties[propertyName])}
</span>`
var questionMark = yo`<span class="${css.questionMark}"><i title="${detailsHelpSection()[propertyName]}" class="fa fa-question-circle" aria-hidden="true"></i></span>`
log.appendChild(yo`
<div class=${css.log}>
<div class="${css.key}">${propertyName} ${copyDetails} ${questionMark}</div>
${insertValue(contractProperties, propertyName)}
</div>`)
})
modalDialog(contractName, log, {label: ''}, {label: 'Close'})
}
}
function detailsHelpSection () {
return {
'Assembly': 'Assembly opcodes describing the contract including corresponding solidity source code', 'Assembly': 'Assembly opcodes describing the contract including corresponding solidity source code',
'Opcodes': 'Assembly opcodes describing the contract', 'Opcodes': 'Assembly opcodes describing the contract',
'Runtime Bytecode': 'Bytecode storing the state and being executed during normal contract call', 'Runtime Bytecode': 'Bytecode storing the state and being executed during normal contract call',
@ -209,6 +182,22 @@ module.exports = class CompileTab {
'swarmLocation': 'Swarm url where all metadata information can be found (contract needs to be published first)', 'swarmLocation': 'Swarm url where all metadata information can be found (contract needs to be published first)',
'web3Deploy': 'Copy/paste this code to any JavaScript/Web3 console to deploy this contract' 'web3Deploy': 'Copy/paste this code to any JavaScript/Web3 console to deploy this contract'
} }
function details () {
var select = self._view.contractNames
if (select.children.length > 0 && select.selectedIndex >= 0) {
var contractName = select.children[select.selectedIndex].innerHTML
var contractProperties = self.data.contractsDetails[contractName]
var log = yo`<div class="${css.detailsJSON}"></div>`
Object.keys(contractProperties).map(propertyName => {
var copyDetails = yo`<span class="${css.copyDetails}">${copyToClipboard(() => contractProperties[propertyName])}</span>`
var questionMark = yo`<span class="${css.questionMark}"><i title="${help[propertyName]}" class="fa fa-question-circle" aria-hidden="true"></i></span>`
log.appendChild(yo`<div class=${css.log}>
<div class="${css.key}">${propertyName} ${copyDetails} ${questionMark}</div>
${insertValue(contractProperties, propertyName)}
</div>`)
})
modalDialog(contractName, log, { label: '' }, { label: 'Close' })
}
} }
function insertValue (details, propertyName) { function insertValue (details, propertyName) {
var value = yo`<pre class="${css.value}"></pre>` var value = yo`<pre class="${css.value}"></pre>`
@ -220,14 +209,10 @@ module.exports = class CompileTab {
extractData: function (item, parent, key) { extractData: function (item, parent, key) {
var ret = {} var ret = {}
if (item instanceof Array) { if (item instanceof Array) {
ret.children = item.map((item, index) => { ret.children = item.map((item, index) => ({ key: index, value: item }))
return {key: index, value: item}
})
ret.self = '' ret.self = ''
} else if (item instanceof Object) { } else if (item instanceof Object) {
ret.children = Object.keys(item).map((key) => { ret.children = Object.keys(item).map((key) => ({key: key, value: item[key]}))
return {key: key, value: item[key]}
})
ret.self = '' ret.self = ''
} else { } else {
ret.self = item ret.self = item
@ -268,8 +253,7 @@ module.exports = class CompileTab {
} else { } else {
modalDialogCustom.alert(yo`<span>Metadata published successfully.<br />The Swarm address of the metadata file is available in the contract details.</span>`) modalDialogCustom.alert(yo`<span>Metadata published successfully.<br />The Swarm address of the metadata file is available in the contract details.</span>`)
} }
}, function (item) { }, function (item) { // triggered each time there's a new verified publish (means hash correspond)
// triggered each time there's a new verified publish (means hash correspond)
self._api.fileProvider('swarm').addReadOnly(item.hash, item.content) self._api.fileProvider('swarm').addReadOnly(item.hash, item.content)
}) })
} }

Loading…
Cancel
Save