From abab464e146e383f269e95636c4dba504a726f28 Mon Sep 17 00:00:00 2001 From: Kosala Hemachandra <10602065+kvhnuke@users.noreply.github.com> Date: Tue, 8 Feb 2022 11:38:06 -0800 Subject: [PATCH 1/2] revert and add only changed files --- .../workspace/src/lib/actions/workspace.ts | 49 ++++++++++++------- .../remix-ui/workspace/src/lib/types/index.ts | 11 ++++- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 3dd6b16bbb..f2221a7e17 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -3,7 +3,7 @@ import { bufferToHex, keccakFromString } from 'ethereumjs-util' import axios, { AxiosResponse } from 'axios' import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload' import { checkSlash, checkSpecialChars } from '@remix-ui/helper' - +import { JSONStandardInput } from '../types' const examples = require('../../../../../../apps/remix-ide/src/app/editor/examples') const QueryParams = require('../../../../../../apps/remix-ide/src/lib/query-params') @@ -75,29 +75,40 @@ export const loadWorkspacePreset = async (template: 'gist-template' | 'code-temp switch (template) { case 'code-template': - // creates a new workspace code-sample and loads code from url params. - try { - let path = ''; let content = '' - - if (params.code) { - const hash = bufferToHex(keccakFromString(params.code)) + // creates a new workspace code-sample and loads code from url params. + try { + let path = ''; let content = '' - path = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol' - content = atob(params.code) - workspaceProvider.set(path, content) - } - if (params.url) { - const data = await plugin.call('contentImport', 'resolve', params.url) + if (params.code) { + const hash = bufferToHex(keccakFromString(params.code)) - path = data.cleanUrl - content = data.content + path = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol' + content = atob(params.code) + workspaceProvider.set(path, content) + } + if (params.url) { + const data = await plugin.call('contentImport', 'resolve', params.url) + + path = data.cleanUrl + content = data.content + if (typeof content === 'object') { + const standardInput = content as JSONStandardInput + if (standardInput.language && standardInput.language === "Solidity" && standardInput.sources) { + const obj = standardInput.sources as any + for (let [fname, source] of Object.entries(standardInput.sources)) { + await workspaceProvider.set(fname, source.content) + } + } + return Object.keys(standardInput.sources)[0] + } else { workspaceProvider.set(path, content) } - return path - } catch (e) { - console.error(e) } - break + return path + } catch (e) { + console.error(e) + } + break case 'gist-template': // creates a new workspace gist-sample and get the file from gist diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index bf4b24d661..d7ce409d72 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -2,7 +2,16 @@ import React from 'react' import { customAction } from '@remixproject/plugin-api/lib/file-system/file-panel' export type action = { name: string, type?: Array<'folder' | 'gist' | 'file'>, path?: string[], extension?: string[], pattern?: string[], id: string, multiselect: boolean, label: string, sticky?: boolean } - +export interface JSONStandardInput { + language: "Solidity"; + settings?: any, + sources: { + [globalName: string]: { + keccak256?: string; + content: string; + }, + }; +} export type MenuItems = action[] export interface WorkspaceProps { plugin: { From 154c84e43f77abfe7044ef9099806228764bc358 Mon Sep 17 00:00:00 2001 From: Kosala Hemachandra <10602065+kvhnuke@users.noreply.github.com> Date: Tue, 15 Feb 2022 10:47:37 -0800 Subject: [PATCH 2/2] fix: review comments --- libs/remix-ui/workspace/src/lib/actions/workspace.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index f2221a7e17..32ef1eda7c 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -91,10 +91,9 @@ export const loadWorkspacePreset = async (template: 'gist-template' | 'code-temp path = data.cleanUrl content = data.content - if (typeof content === 'object') { + if (content && typeof content === 'object') { const standardInput = content as JSONStandardInput if (standardInput.language && standardInput.language === "Solidity" && standardInput.sources) { - const obj = standardInput.sources as any for (let [fname, source] of Object.entries(standardInput.sources)) { await workspaceProvider.set(fname, source.content) }