Commit 8c5df6e3 authored by yann300's avatar yann300

fix loading code sample

parent 33d95aa2
...@@ -443,15 +443,5 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -443,15 +443,5 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
migrateToWorkspace(fileManager) migrateToWorkspace(fileManager)
filePanel.initWorkspace() filePanel.initWorkspace()
if (params.code) {
try {
const path = 'browser/.code-sample/contract.sol'
await fileManager.writeFile(path, atob(params.code))
await fileManager.openFile(path)
} catch (e) {
console.error(e)
}
}
if (params.embed) framingService.embed() if (params.embed) framingService.embed()
} }
...@@ -5,6 +5,7 @@ import React from 'react' // eslint-disable-line ...@@ -5,6 +5,7 @@ import React from 'react' // eslint-disable-line
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import { FileExplorer } from '@remix-ui/file-explorer' // eslint-disable-line import { FileExplorer } from '@remix-ui/file-explorer' // eslint-disable-line
import './styles/file-panel-styles.css' import './styles/file-panel-styles.css'
var ethutil = require('ethereumjs-util')
var yo = require('yo-yo') var yo = require('yo-yo')
var EventManager = require('../../lib/events') var EventManager = require('../../lib/events')
var { RemixdHandle } = require('../files/remixd-handle.js') var { RemixdHandle } = require('../files/remixd-handle.js')
...@@ -104,27 +105,38 @@ module.exports = class Filepanel extends ViewPlugin { ...@@ -104,27 +105,38 @@ module.exports = class Filepanel extends ViewPlugin {
this.renderComponent() this.renderComponent()
} }
initWorkspace () { async initWorkspace () {
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath
const queryParams = new QueryParams() const queryParams = new QueryParams()
const params = queryParams.get() const params = queryParams.get()
// get the file from gist // get the file from gist
const gistHandler = new GistHandler() const gistHandler = new GistHandler()
const loadedFromGist = gistHandler.loadFromGist(params, this._deps.fileManager) const loadedFromGist = gistHandler.loadFromGist(params, this._deps.fileManager)
if (!loadedFromGist) { if (loadedFromGist) return
if (params.code) {
try {
await this._deps.fileManager.createWorkspace('code-sample')
var hash = ethutil.bufferToHex(ethutil.keccak(params.code))
const fileName = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol'
const path = 'browser/' + workspacesPath + '/code-sample/' + fileName
await this._deps.fileManager.writeFile(path, atob(params.code))
this.setWorkspace('code-sample')
await this._deps.fileManager.openFile(path)
} catch (e) {
console.error(e)
}
return
}
// insert example contracts if there are no files to show // insert example contracts if there are no files to show
this._deps.fileProviders.browser.resolveDirectory('/', async (error, filesList) => { this._deps.fileProviders.browser.resolveDirectory('/', async (error, filesList) => {
if (error) console.error(error) if (error) console.error(error)
if (Object.keys(filesList).length === 0) { if (Object.keys(filesList).length === 0) {
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath
for (const file in examples) { for (const file in examples) {
await this._deps.fileManager.writeFile('browser/' + workspacesPath + '/default_workspace/' + examples[file].name, examples[file].content) await this._deps.fileManager.writeFile('browser/' + workspacesPath + '/default_workspace/' + examples[file].name, examples[file].content)
} }
this.setWorkspace('default_workspace') this.setWorkspace('default_workspace')
} }
}) })
} else {
this.setWorkspace('gists')
}
} }
refreshWorkspacesList () { refreshWorkspacesList () {
......
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