diff --git a/src/app.js b/src/app.js index 3ab3c50a8c..eb33928917 100644 --- a/src/app.js +++ b/src/app.js @@ -360,7 +360,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org filePanel, registry.get('compilersartefacts').api, networkModule, - mainview + mainview, + registry.get('fileproviders/browser').api, ) const analysis = new AnalysisTab(registry) const debug = new DebuggerTab(blockchain) diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 31e431c530..86a458e7f2 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -9,8 +9,6 @@ const modalDialog = require('../ui/modaldialog') const copyToClipboard = require('../ui/copy-to-clipboard') const modalDialogCustom = require('../ui/modal-dialog-custom') const parseContracts = require('./compileTab/contractParser') -const publishOnSwarm = require('../../lib/publishOnSwarm') -const publishOnIpfs = require('../../lib/publishOnIpfs') const addTooltip = require('../ui/tooltip') const globalRegistry = require('../../global/registry') @@ -21,6 +19,7 @@ const CompilerContainer = require('./compileTab/compilerContainer.js') import { ViewPlugin } from '@remixproject/engine' import * as packageJson from '../../../package.json' +import publishToStorage from '../../publishToStorage' const profile = { name: 'solidity', @@ -255,12 +254,12 @@ class CompileTab extends ViewPlugin { ${selectEl} -
- - diff --git a/src/app/tabs/runTab/contractDropdown.js b/src/app/tabs/runTab/contractDropdown.js index 17d4a9b0d6..49d18bd492 100644 --- a/src/app/tabs/runTab/contractDropdown.js +++ b/src/app/tabs/runTab/contractDropdown.js @@ -7,6 +7,8 @@ var confirmDialog = require('../../ui/confirmDialog') var modalDialog = require('../../ui/modaldialog') var MultiParamManager = require('../../ui/multiParamManager') +import publishToStorage from '../../../publishToStorage' + class ContractDropdownUI { constructor (blockchain, dropdownLogic, logCallback, runView) { this.blockchain = blockchain @@ -16,6 +18,7 @@ class ContractDropdownUI { this.event = new EventManager() this.listenToEvents() + this.ipfsCheckedState = false } listenToEvents () { @@ -43,16 +46,28 @@ class ContractDropdownUI { }) } + updateCheckedState () { + this.ipfsCheckedState = !this.ipfsCheckedState + console.log('this.ipfsCheckedState: ', this.ipfsCheckedState) + } + render () { this.compFails = yo`` var info = yo`` - this.atAddress = yo`` this.atAddressButtonInput = yo`` this.selectContractNames = yo`` this.createPanel = yo`
` this.orLabel = yo`
or
` + const ipfsCheckbox = this.ipfsCheckedState ? + yo`` + : + yo` { + this.updateCheckedState() + publishToStorage('ipfs', this.runView.fileProvider, this.runView.fileManager, this.getSelectedContract.call(this)) + }}>` + let el = yo`
@@ -67,6 +82,11 @@ class ContractDropdownUI { ${this.atAddressButtonInput}
+
+ ${ipfsCheckbox} + + +
` this.selectContractNames.addEventListener('change', this.setInputParamsPlaceHolder.bind(this)) diff --git a/src/app/tabs/runTab/model/dropdownlogic.js b/src/app/tabs/runTab/model/dropdownlogic.js index 4ce649d177..c2dc932aa1 100644 --- a/src/app/tabs/runTab/model/dropdownlogic.js +++ b/src/app/tabs/runTab/model/dropdownlogic.js @@ -93,7 +93,8 @@ class DropdownLogic { isOverSizeLimit: () => { var deployedBytecode = contract.object.evm.deployedBytecode return (deployedBytecode && deployedBytecode.object.length / 2 > 24576) - } + }, + metadata: contract.object.metadata } } diff --git a/src/app/udapp/run-tab.js b/src/app/udapp/run-tab.js index 49ed6537d6..7834364176 100644 --- a/src/app/udapp/run-tab.js +++ b/src/app/udapp/run-tab.js @@ -33,7 +33,7 @@ const profile = { export class RunTab extends LibraryPlugin { - constructor (blockchain, pluginUDapp, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, mainView) { + constructor (blockchain, pluginUDapp, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, mainView, fileProvider) { super(pluginUDapp, profile) this.event = new EventManager() this.config = config @@ -44,6 +44,7 @@ export class RunTab extends LibraryPlugin { this.filePanel = filePanel this.compilersArtefacts = compilersArtefacts this.networkModule = networkModule + this.fileProvider = fileProvider } renderContainer () { diff --git a/src/publishToStorage.js b/src/publishToStorage.js new file mode 100644 index 0000000000..b8997f48d8 --- /dev/null +++ b/src/publishToStorage.js @@ -0,0 +1,48 @@ +const yo = require('yo-yo') +const publishOnSwarm = require('./lib/publishOnSwarm') +const publishOnIpfs = require('./lib/publishOnIpfs') +const modalDialogCustom = require('./app/ui/modal-dialog-custom') + +export default function publish (storage, fileProvider, fileManager, contract) { + if (contract) { + if (contract.metadata === undefined || contract.metadata.length === 0) { + modalDialogCustom.alert('This contract may be abstract, may not implement an abstract parent\'s methods completely or not invoke an inherited contract\'s constructor correctly.') + } else { + if (storage === 'swarm') { + publishOnSwarm(contract, fileManager, function (err, uploaded) { + 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 { + var result = yo`
${uploaded.map((value) => { + return yo`
${value.filename} :
${value.output.url}
` + })}
` + modalDialogCustom.alert(`Published ${contract.name}'s Metadata`, yo`Metadata of "${contract.name.toLowerCase()}" was published successfully.
${result}
`) + } + }, (item) => { // triggered each time there's a new verified publish (means hash correspond) + fileProvider.addExternal('swarm/' + item.hash, item.content) + }) + } else { + publishOnIpfs(contract, fileManager, function (err, uploaded) { + if (err) { + try { + err = JSON.stringify(err) + } catch (e) {} + modalDialogCustom.alert(yo`Failed to publish metadata file to ${storage}, please check the ${storage} gateways is available.
+ ${err}
`) + } else { + var result = yo`
${uploaded.map((value) => { + return yo`
${value.filename} :
${value.output.url}
` + })}
` + modalDialogCustom.alert(`Published ${contract.name}'s Metadata`, yo`Metadata of "${contract.name.toLowerCase()}" was published successfully.
${result}
`) + } + }, (item) => { // triggered each time there's a new verified publish (means hash correspond) + fileProvider.addExternal('ipfs/' + item.hash, item.content) + }) + } + } + } + } \ No newline at end of file