Commit e6a36a3f authored by ioedeveloper's avatar ioedeveloper

Wait for workspace creation before fetching

parent c991d4ab
This diff is collapsed.
......@@ -4,7 +4,7 @@ import * as packageJson from '../../../../../package.json'
import React from 'react' // eslint-disable-line
import ReactDOM from 'react-dom'
import { Workspace } from '@remix-ui/workspace' // eslint-disable-line
import { bufferToHex, keccakFromString } from 'ethereumjs-util'
import * as ethutil from 'ethereumjs-util'
import { checkSpecialChars, checkSlash } from '../../lib/helper'
var EventManager = require('../../lib/events')
var { RemixdHandle } = require('../files/remixd-handle.js')
......@@ -154,7 +154,7 @@ module.exports = class Filepanel extends ViewPlugin {
try {
await this.processCreateWorkspace('code-sample')
this._deps.fileProviders.workspace.setWorkspace('code-sample')
var hash = bufferToHex(keccakFromString(params.code))
var hash = ethutil.bufferToHex(ethutil.keccak(params.code))
const fileName = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol'
const path = fileName
await this._deps.fileProviders.workspace.set(path, atob(params.code))
......@@ -166,12 +166,16 @@ module.exports = class Filepanel extends ViewPlugin {
return
}
// insert example contracts if there are no files to show
return new Promise((resolve, reject) => {
this._deps.fileProviders.browser.resolveDirectory('/', async (error, filesList) => {
if (error) console.error(error)
if (Object.keys(filesList).length === 0) {
await this.createWorkspace('default_workspace')
}
this.getWorkspaces()
const workspaces = await this.getWorkspaces()
resolve(workspaces)
})
})
}
......
......@@ -182,7 +182,8 @@ export const fileRenamedSuccess = (path: string, removePath: string, files) => {
export const init = (provider, workspaceName: string, plugin, registry) => (dispatch: React.Dispatch<any>) => {
if (provider) {
provider.event.register('fileAdded', async (filePath) => {
const path = extractParentFromKey(filePath) ? extractParentFromKey(filePath) === '/.workspaces' ? workspaceName : extractParentFromKey(filePath) : workspaceName
if (extractParentFromKey(filePath) === '/.workspaces') return
const path = extractParentFromKey(filePath) || workspaceName
const data = await fetchDirectoryContent(provider, path)
dispatch(fileAddedSuccess(path, data))
......@@ -191,7 +192,8 @@ export const init = (provider, workspaceName: string, plugin, registry) => (disp
}
})
provider.event.register('folderAdded', async (folderPath) => {
const path = extractParentFromKey(folderPath) ? extractParentFromKey(folderPath) === '/.workspaces' ? workspaceName : extractParentFromKey(folderPath) : workspaceName
if (extractParentFromKey(folderPath) === '/.workspaces') return
const path = extractParentFromKey(folderPath) || workspaceName
const data = await fetchDirectoryContent(provider, path)
dispatch(folderAddedSuccess(path, data))
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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