Unverified Commit 1de5dd72 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #2008 from ethereum/fixToaster

Fix Swarm integration
parents 0aabc474 fbeebd11
......@@ -47,6 +47,11 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => {
var uploaded = []
async.eachSeries(sources, function (item, cb) {
swarmVerifiedPublish(item.content, item.hash, (error, result) => {
try {
item.hash = result.url.match('bzz-raw://(.+)')[1]
} catch (e) {
item.hash = '<Metadata inconsistency> - ' + item.fileName
}
if (!error && swarmVerifiedPublishCallBack) swarmVerifiedPublishCallBack(item)
item.output = result
uploaded.push(item)
......@@ -55,10 +60,16 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => {
cb(error)
})
}, () => {
swarmVerifiedPublish(JSON.stringify(metadata), '', (error, result) => {
const metadataContent = JSON.stringify(metadata)
swarmVerifiedPublish(metadataContent, '', (error, result) => {
try {
contract.metadataHash = result.url.match('bzz-raw://(.+)')[1]
} catch (e) {
contract.metadataHash = '<Metadata inconsistency> - metadata.json'
}
if (!error && swarmVerifiedPublishCallBack) {
swarmVerifiedPublishCallBack({
content: contract.metadata,
content: metadataContent,
hash: contract.metadataHash
})
}
......
......@@ -41,13 +41,13 @@ class BasicReadOnlyExplorer {
}
set (path, content, cb) {
var unprefixedPath = this.removePrefix(path)
this.addReadOnly(unprefixedPath, content)
this.addReadOnly(path, content)
if (cb) cb()
return true
}
addReadOnly (path, content, rawPath) {
path = this.removePrefix(path)
try { // lazy try to format JSON
content = JSON.stringify(JSON.parse(content), null, '\t')
} catch (e) {}
......@@ -67,7 +67,7 @@ class BasicReadOnlyExplorer {
this.paths[this.type][split] = { isDirectory: folder }
this.files[path] = content
this.normalizedNames[rawPath] = path
this.event.trigger('fileAdded', [path, true])
this.event.trigger('fileAdded', [this.type + '/' + path, true])
return true
}
......
......@@ -158,7 +158,8 @@ function fileExplorer (localRegistry, files, menuItems) {
return yo`
<div class="${css.items}">
<label
class=${css.label}
title="${data.path}"
class="${css.label} ${!isRoot ? css.leaf : ''}"
data-path="${data.path}"
style="${isRoot ? 'font-weight:bold;' : ''}"
onkeydown=${editModeOff}
......
......@@ -2,7 +2,13 @@ var csjs = require('csjs-inject')
var css = csjs`
.label {
margin-top : 4px
margin-top : 4px;
}
.leaf {
overflow : hidden;
text-overflow : ellipsis;
width : 90%;
margin-bottom : 0px;
}
.fileexplorer {
box-sizing : border-box;
......
......@@ -259,7 +259,7 @@ class CompileTab extends CompilerApi {
modalDialogCustom.alert(yo`<span>Metadata published successfully.<br> <pre>${result}</pre> </span>`)
}
}, (item) => { // triggered each time there's a new verified publish (means hash correspond)
this.swarmfileProvider.addReadOnly(item.hash, item.content)
this.swarmfileProvider.addReadOnly('swarm/' + item.hash, item.content)
})
}
}
......
......@@ -4,6 +4,7 @@ var async = require('async')
var remixLib = require('remix-lib')
var EventManager = require('../lib/events')
var CompilerImport = require('../app/compiler/compiler-imports')
var executionContext = require('../execution-context')
var toolTip = require('../app/ui/tooltip')
var globalRegistry = require('../global/registry')
......@@ -20,6 +21,7 @@ class CmdInterpreterAPI {
self._components.registry = localRegistry || globalRegistry
self._components.terminal = terminal
self._components.sourceHighlighter = new SourceHighlighter()
self._components.fileImport = new CompilerImport()
self._deps = {
app: self._components.registry.get('app').api,
fileManager: self._components.registry.get('filemanager').api,
......@@ -141,28 +143,40 @@ class CmdInterpreterAPI {
}
loadurl (url, cb) {
const self = this
self._deps.app.importExternal(url, (err, content) => {
if (err) {
toolTip(`Unable to load ${url}: ${err}`)
if (cb) cb(err)
} else {
try {
content = JSON.parse(content)
async.eachOfSeries(content.sources, (value, file, callbackSource) => {
var url = value.urls[0] // @TODO retrieve all other contents ?
self._deps.app.importExternal(url, (error, content) => {
if (error) {
toolTip(`Cannot retrieve the content of ${url}: ${error}`)
}
callbackSource()
self._components.fileImport.import(url,
(loadingMsg) => { toolTip(loadingMsg) },
(err, content, cleanUrl, type, url) => {
if (err) {
toolTip(`Unable to load ${url}: ${err}`)
if (cb) cb(err)
} else {
self._deps.fileManager.setFile(type + '/' + cleanUrl, content)
try {
content = JSON.parse(content)
async.eachOfSeries(content.sources, (value, file, callbackSource) => {
var url = value.urls[0] // @TODO retrieve all other contents ?
self._components.fileImport.import(url,
(loadingMsg) => { toolTip(loadingMsg) },
async (error, content, cleanUrl, type, url) => {
if (error) {
toolTip(`Cannot retrieve the content of ${url}: ${error}`)
return callbackSource(`Cannot retrieve the content of ${url}: ${error}`)
} else {
try {
await self._deps.fileManager.setFile(type + '/' + cleanUrl, content)
callbackSource()
} catch (e) {
callbackSource(e.message)
}
}
})
}, (error) => {
if (cb) cb(error)
})
}, (error) => {
if (cb) cb(error)
})
} catch (e) {}
if (cb) cb()
}
})
} catch (e) {}
if (cb) cb()
}
})
}
setproviderurl (url, cb) {
executionContext.setProviderFromEndpoint(url, 'web3', (error) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment