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' ...@@ -4,7 +4,7 @@ import * as packageJson from '../../../../../package.json'
import React from 'react' // eslint-disable-line import React from 'react' // eslint-disable-line
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import { Workspace } from '@remix-ui/workspace' // eslint-disable-line 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' import { checkSpecialChars, checkSlash } from '../../lib/helper'
var EventManager = require('../../lib/events') var EventManager = require('../../lib/events')
var { RemixdHandle } = require('../files/remixd-handle.js') var { RemixdHandle } = require('../files/remixd-handle.js')
...@@ -154,7 +154,7 @@ module.exports = class Filepanel extends ViewPlugin { ...@@ -154,7 +154,7 @@ module.exports = class Filepanel extends ViewPlugin {
try { try {
await this.processCreateWorkspace('code-sample') await this.processCreateWorkspace('code-sample')
this._deps.fileProviders.workspace.setWorkspace('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 fileName = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol'
const path = fileName const path = fileName
await this._deps.fileProviders.workspace.set(path, atob(params.code)) await this._deps.fileProviders.workspace.set(path, atob(params.code))
...@@ -166,12 +166,16 @@ module.exports = class Filepanel extends ViewPlugin { ...@@ -166,12 +166,16 @@ module.exports = class Filepanel extends ViewPlugin {
return 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) => { return new Promise((resolve, reject) => {
if (error) console.error(error) this._deps.fileProviders.browser.resolveDirectory('/', async (error, filesList) => {
if (Object.keys(filesList).length === 0) { if (error) console.error(error)
await this.createWorkspace('default_workspace') 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) => { ...@@ -182,7 +182,8 @@ export const fileRenamedSuccess = (path: string, removePath: string, files) => {
export const init = (provider, workspaceName: string, plugin, registry) => (dispatch: React.Dispatch<any>) => { export const init = (provider, workspaceName: string, plugin, registry) => (dispatch: React.Dispatch<any>) => {
if (provider) { if (provider) {
provider.event.register('fileAdded', async (filePath) => { 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) const data = await fetchDirectoryContent(provider, path)
dispatch(fileAddedSuccess(path, data)) dispatch(fileAddedSuccess(path, data))
...@@ -191,7 +192,8 @@ export const init = (provider, workspaceName: string, plugin, registry) => (disp ...@@ -191,7 +192,8 @@ export const init = (provider, workspaceName: string, plugin, registry) => (disp
} }
}) })
provider.event.register('folderAdded', async (folderPath) => { 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) const data = await fetchDirectoryContent(provider, path)
dispatch(folderAddedSuccess(path, data)) 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