diff --git a/src/app.js b/src/app.js index 50124b32df..4d76dcf029 100644 --- a/src/app.js +++ b/src/app.js @@ -553,6 +553,9 @@ function run () { fileProviderOf: (path) => { return fileManager.fileProviderOf(path) }, + fileProvider: (name) => { + return self._api.filesProviders[name] + }, getBalance: (address, callback) => { udapp.getBalance(address, (error, balance) => { if (error) { diff --git a/src/app/contract/publishOnSwarm.js b/src/app/contract/publishOnSwarm.js index d3284d5a71..1155a2fbb7 100644 --- a/src/app/contract/publishOnSwarm.js +++ b/src/app/contract/publishOnSwarm.js @@ -3,10 +3,14 @@ var async = require('async') var swarmgw = require('swarmgw') -module.exports = (contract, appAPI, cb) => { +module.exports = (contract, appAPI, cb, swarmVerifiedPublishCallBack) => { // gather list of files to publish var sources = [] + try { + contract.metadata = JSON.stringify(JSON.parse(contract.metadata), null, '\t') + } catch (e) {} + sources.push({ content: contract.metadata, hash: contract.metadataHash @@ -49,7 +53,10 @@ module.exports = (contract, appAPI, cb) => { } else { // publish the list of sources in order, fail if any failed async.eachSeries(sources, function (item, cb) { - swarmVerifiedPublish(item.content, item.hash, cb) + swarmVerifiedPublish(item.content, item.hash, (error) => { + if (!error && swarmVerifiedPublishCallBack) swarmVerifiedPublishCallBack(item) + cb(error) + }) }, cb) } }) diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index c3fc5edaee..0d32accb47 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -436,6 +436,9 @@ function compileTab (container, appAPI, appEvents, opts) { } 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) }) } }