diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 4e90513d88..f5762149a2 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -139,172 +139,172 @@ class CompileTab { function contractNames (appAPI, appEvents, opts) { /* eslint-disable */ - var contractsDetails = {} + var contractsDetails = {} - appEvents.compiler.register('compilationFinished', function (success, data, source) { - // reset the contractMetadata list (used by the publish action) - contractsDetails = {} - // refill the dropdown list - getContractNames(success, data) - // hightlight the tab if error - if (success) { - document.querySelector('.compileView').style.color = '' - } else { - document.querySelector('.compileView').style.color = styles.colors.red - } - // display warning error if any - var error = false - if (data['error']) { - error = true - opts.renderer.error(data['error'].formattedMessage, $(errorContainer), {type: data['error'].severity}) - } - if (data['errors']) { - if (data['errors'].length) error = true - data['errors'].forEach(function (err) { - opts.renderer.error(err.formattedMessage, $(errorContainer), {type: err.severity}) + appEvents.compiler.register('compilationFinished', function (success, data, source) { + // reset the contractMetadata list (used by the publish action) + contractsDetails = {} + // refill the dropdown list + getContractNames(success, data) + // hightlight the tab if error + if (success) { + document.querySelector('.compileView').style.color = '' + } else { + document.querySelector('.compileView').style.color = styles.colors.red + } + // display warning error if any + var error = false + if (data['error']) { + error = true + opts.renderer.error(data['error'].formattedMessage, $(errorContainer), {type: data['error'].severity}) + } + if (data['errors']) { + if (data['errors'].length) error = true + data['errors'].forEach(function (err) { + opts.renderer.error(err.formattedMessage, $(errorContainer), {type: err.severity}) + }) + } + if (!error) { + if (data.contracts) { + opts.compiler.visitContracts((contract) => { + opts.renderer.error(contract.name, $(errorContainer), {type: 'success'}) }) } - if (!error) { - if (data.contracts) { - opts.compiler.visitContracts((contract) => { - opts.renderer.error(contract.name, $(errorContainer), {type: 'success'}) - }) - } - } - }) + } + }) - appEvents.staticAnalysis.register('staticAnaysisWarning', (count) => { - if (count) { - opts.renderer.error(`Static Analysis raised ${count} warning(s) that requires your attention.`, $(errorContainer), { - type: 'warning', - click: () => appAPI.switchTab('staticanalysisView') - }) - } - }) + appEvents.staticAnalysis.register('staticAnaysisWarning', (count) => { + if (count) { + opts.renderer.error(`Static Analysis raised ${count} warning(s) that requires your attention.`, $(errorContainer), { + type: 'warning', + click: () => appAPI.switchTab('staticanalysisView') + }) + } + }) - var contractEl = yo` -
- -
-
{ details() }}>Details
-
{ publish(appAPI) }}>Publish on Swarm
-
+ var contractEl = yo` +
+ +
+
{ details() }}>Details
+
{ publish(appAPI) }}>Publish on Swarm
- ` +
+ ` - // HELPERS + // HELPERS - // GET NAMES OF ALL THE CONTRACTS - function getContractNames (success, data) { - var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) - contractNames.innerHTML = '' - if (success) { - contractNames.removeAttribute('disabled') - opts.compiler.visitContracts((contract) => { - contractsDetails[contract.name] = parseContracts(contract.name, contract.object, opts.compiler.getSource(contract.file)) - var contractName = yo` - ` - contractNames.appendChild(contractName) - }) - appAPI.resetDapp(contractsDetails) - } else { - contractNames.setAttribute('disabled', true) - appAPI.resetDapp({}) - } + // GET NAMES OF ALL THE CONTRACTS + function getContractNames (success, data) { + var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) + contractNames.innerHTML = '' + if (success) { + contractNames.removeAttribute('disabled') + opts.compiler.visitContracts((contract) => { + contractsDetails[contract.name] = parseContracts(contract.name, contract.object, opts.compiler.getSource(contract.file)) + var contractName = yo` + ` + contractNames.appendChild(contractName) + }) + appAPI.resetDapp(contractsDetails) + } else { + contractNames.setAttribute('disabled', true) + appAPI.resetDapp({}) } + } - function details () { - var select = contractEl.querySelector('select') + function details () { + var select = contractEl.querySelector('select') - if (select.children.length > 0 && select.selectedIndex >= 0) { - var contractName = select.children[select.selectedIndex].innerHTML - var contractProperties = contractsDetails[contractName] - var log = yo`
` - Object.keys(contractProperties).map(propertyName => { - var copyDetails = yo` - ${copyToClipboard(() => contractProperties[propertyName])} - ` - var questionMark = yo`` - log.appendChild(yo` -
-
${propertyName} ${copyDetails} ${questionMark}
- ${insertValue(contractProperties, propertyName)} -
- `) - }) - modalDialog(contractName, log, {label: ''}, {label: 'Close'}) - } + if (select.children.length > 0 && select.selectedIndex >= 0) { + var contractName = select.children[select.selectedIndex].innerHTML + var contractProperties = contractsDetails[contractName] + var log = yo`
` + Object.keys(contractProperties).map(propertyName => { + var copyDetails = yo` + ${copyToClipboard(() => contractProperties[propertyName])} + ` + var questionMark = yo`` + log.appendChild(yo` +
+
${propertyName} ${copyDetails} ${questionMark}
+ ${insertValue(contractProperties, propertyName)} +
+ `) + }) + modalDialog(contractName, log, {label: ''}, {label: 'Close'}) } + } - function insertValue (details, propertyName) { - var value = yo`
`
-        var node
-        if (propertyName === 'web3Deploy' || propertyName === 'name' || propertyName === 'Assembly') {
-          node = yo`
${details[propertyName]}
` - } else if (propertyName === 'abi' || propertyName === 'metadata') { - var treeView = new TreeView({ - extractData: function (item, parent, key) { - var ret = {} - if (item instanceof Array) { - ret.children = item.map((item, index) => { - return {key: index, value: item} - }) - ret.self = '' - } else if (item instanceof Object) { - ret.children = Object.keys(item).map((key) => { - return {key: key, value: item[key]} - }) - ret.self = '' - } else { - ret.self = item - ret.children = [] - } - return ret + function insertValue (details, propertyName) { + var value = yo`
`
+      var node
+      if (propertyName === 'web3Deploy' || propertyName === 'name' || propertyName === 'Assembly') {
+        node = yo`
${details[propertyName]}
` + } else if (propertyName === 'abi' || propertyName === 'metadata') { + var treeView = new TreeView({ + extractData: function (item, parent, key) { + var ret = {} + if (item instanceof Array) { + ret.children = item.map((item, index) => { + return {key: index, value: item} + }) + ret.self = '' + } else if (item instanceof Object) { + ret.children = Object.keys(item).map((key) => { + return {key: key, value: item[key]} + }) + ret.self = '' + } else { + ret.self = item + ret.children = [] } - }) - if (details[propertyName] !== '') { - try { - node = yo`
${treeView.render(typeof details[propertyName] === 'object' ? details[propertyName] : JSON.parse(details[propertyName]))}
` // catch in case the parsing fails. - } catch (e) { - node = yo`
Unable to display "${propertyName}": ${e.message}
` - } - } else { - node = yo`
-
` + return ret + } + }) + if (details[propertyName] !== '') { + try { + node = yo`
${treeView.render(typeof details[propertyName] === 'object' ? details[propertyName] : JSON.parse(details[propertyName]))}
` // catch in case the parsing fails. + } catch (e) { + node = yo`
Unable to display "${propertyName}": ${e.message}
` } } else { - node = yo`
${JSON.stringify(details[propertyName], null, 4)}
` + node = yo`
-
` } - if (node) value.appendChild(node) - return value + } else { + node = yo`
${JSON.stringify(details[propertyName], null, 4)}
` } + if (node) value.appendChild(node) + return value + } - function publish (appAPI) { - var selectContractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) - if (selectContractNames.children.length > 0 && selectContractNames.selectedIndex >= 0) { - var contract = contractsDetails[selectContractNames.children[selectContractNames.selectedIndex].innerHTML] - if (contract.metadata === undefined || contract.metadata.length === 0) { - modalDialogCustom.alert('This contract does not implement all functions and thus cannot be published.') - } else { - publishOnSwarm(contract, appAPI, function (err) { - if (err) { - try { - err = JSON.stringify(err) - } catch (e) {} - modalDialogCustom.alert(yo`Failed to publish metadata file to swarm, please check the Swarm gateways is available ( swarm-gateways.net ).
- ${err}
`) - } else { - modalDialogCustom.alert(yo`Metadata published successfully.
The Swarm address of the metadata file is available in the contract details.
`) - } - }, function (item) { - // triggered each time there's a new verified publish (means hash correspond) - appAPI.fileProvider('swarm').addReadOnly(item.hash, item.content) - }) - } + function publish (appAPI) { + var selectContractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) + if (selectContractNames.children.length > 0 && selectContractNames.selectedIndex >= 0) { + var contract = contractsDetails[selectContractNames.children[selectContractNames.selectedIndex].innerHTML] + if (contract.metadata === undefined || contract.metadata.length === 0) { + modalDialogCustom.alert('This contract does not implement all functions and thus cannot be published.') + } else { + publishOnSwarm(contract, appAPI, function (err) { + if (err) { + try { + err = JSON.stringify(err) + } catch (e) {} + modalDialogCustom.alert(yo`Failed to publish metadata file to swarm, please check the Swarm gateways is available ( swarm-gateways.net ).
+ ${err}
`) + } else { + modalDialogCustom.alert(yo`Metadata published successfully.
The Swarm address of the metadata file is available in the contract details.
`) + } + }, function (item) { + // triggered each time there's a new verified publish (means hash correspond) + appAPI.fileProvider('swarm').addReadOnly(item.hash, item.content) + }) } } - return contractEl + } + return contractEl /* eslint-enable */ } return { render () { return el } }