From 76f26f3ad925cdad474dd98b8f700ce557ddaa87 Mon Sep 17 00:00:00 2001 From: lianahus Date: Thu, 5 May 2022 14:13:13 +0200 Subject: [PATCH] new file on workspace change. --- apps/remix-ide/src/remixAppManager.js | 5 ++-- .../solidity-compiler/src/app/compiler-api.ts | 6 ++--- libs/remix-lib/src/types/ICompilerApi.ts | 2 +- .../src/lib/compiler-container.tsx | 23 +++++++++++++++---- .../src/lib/solidity-compiler.tsx | 11 ++++++++- .../solidity-compiler/src/lib/types/index.ts | 4 ++++ 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index 96d79aba39..0868ef8689 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -7,7 +7,7 @@ const _paq = window._paq = window._paq || [] const requiredModules = [ // services + layout views + system views 'manager', 'config', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'fileManager', 'contentImport', 'blockchain', 'web3Provider', 'scriptRunner', 'fetchAndCompile', 'mainPanel', 'hiddenPanel', 'sidePanel', 'menuicons', - 'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity-logic', 'gistHandler', 'layout', + 'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity', 'solidity-logic', 'gistHandler', 'layout', 'notification', 'permissionhandler', 'walkthrough', 'storage', 'restorebackupzip', 'link-libraries', 'deploy-libraries', 'openzeppelin-proxy', 'hardhat-provider', 'compileAndRun', 'search'] const dependentModules = ['git', 'hardhat', 'truffle', 'slither'] // module which shouldn't be manually activated (e.g git is activated by remixd) @@ -19,7 +19,8 @@ const sensitiveCalls = { } export function isNative(name) { - const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity', 'hardhat-provider', 'solidityStaticAnalysis', 'solidityUnitTesting', 'layout', 'notification', 'hardhat-provider', 'ganache-provider'] + const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity', 'solidity-logic', + 'hardhat-provider', 'solidityStaticAnalysis', 'solidityUnitTesting', 'layout', 'notification', 'hardhat-provider', 'ganache-provider'] return nativePlugins.includes(name) || requiredModules.includes(name) } diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index ade46d3223..8a5437359c 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -18,7 +18,7 @@ export const CompilerApiMixin = (Base) => class extends Base { onCurrentFileChanged: (fileName: string) => void // onResetResults: () => void - onSetWorkspace: (workspace: any) => void + onSetWorkspace: (isLocalhost: boolean, workspaceName: string) => void onNoFileSelected: () => void onCompilationFinished: (compilationDetails: { contractMap: { file: string } | Record, contractsDetails: Record }) => void onSessionSwitched: () => void @@ -237,12 +237,12 @@ export const CompilerApiMixin = (Base) => class extends Base { this.on('filePanel', 'setWorkspace', (workspace) => { this.resetResults() - if (this.onSetWorkspace) this.onSetWorkspace(workspace.isLocalhost) + if (this.onSetWorkspace) this.onSetWorkspace(workspace.isLocalhost, workspace.name) }) this.on('remixd', 'rootFolderChanged', () => { this.resetResults() - if (this.onSetWorkspace) this.onSetWorkspace(true) + if (this.onSetWorkspace) this.onSetWorkspace(true, 'localhost') }) this.on('editor', 'sessionSwitched', () => { diff --git a/libs/remix-lib/src/types/ICompilerApi.ts b/libs/remix-lib/src/types/ICompilerApi.ts index 8e43892fa0..f34d20f420 100644 --- a/libs/remix-lib/src/types/ICompilerApi.ts +++ b/libs/remix-lib/src/types/ICompilerApi.ts @@ -24,7 +24,7 @@ export interface ICompilerApi { onCurrentFileChanged: (fileName: string) => void // onResetResults: () => void, - onSetWorkspace: (workspace: any) => void + onSetWorkspace: (isLocalhost: boolean, workspaceName: string) => void onNoFileSelected: () => void onCompilationFinished: (contractsDetails: any, contractMap: any) => void onSessionSwitched: () => void diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 15f9bb8a9f..efe9e7e61e 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -9,6 +9,8 @@ import { resetEditorMode, listenToEvents } from './actions/compiler' import { OverlayTrigger, Tooltip } from 'react-bootstrap' // eslint-disable-line import { getValidLanguage } from '@remix-project/remix-solidity' import { CopyToClipboard } from '@remix-ui/clipboard' +// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries +import * as json_config from '../../../../../apps/remix-ide/contracts/solidity_compiler_config.json' import './css/style.css' @@ -21,7 +23,7 @@ declare global { const _paq = window._paq = window._paq || [] //eslint-disable-line export const CompilerContainer = (props: CompilerContainerProps) => { - const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject, isTruffleProject } = props // eslint-disable-line + const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject, isTruffleProject, workspaceName } = props // eslint-disable-line const [state, setState] = useState({ hideWarnings: false, autoCompile: false, @@ -51,6 +53,19 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const [truffleCompilation, setTruffleCompilation] = useState(false) const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState) + useEffect(() => { + setConfigFilePath("/compiler_config.json") + api.fileExists("/compiler_config.json").then((exists) => { + if (!exists) createNewConfigFile() + else { + // what to do? discuss + } + }) + setConfigFilePath("/compiler_config.json") + setManualConfig(false) + setShowFilePathInput(false) + }, [workspaceName]) + useEffect(() => { fetchAllVersion((allversions, selectedVersion, isURL) => { setState(prevState => { @@ -156,8 +171,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => { } const createNewConfigFile = async () => { - const configFileContent = - await api.writeFile(configFilePathInput.current.value, "") + const configFileContent = JSON.stringify(json_config, null, '\t') + await api.writeFile(configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : configFilePath, configFileContent) setConfigFilePath(configFilePathInput.current.value) } const handleConfigPathChange = async () => { @@ -165,7 +180,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { setConfigFilePath(configFilePathInput.current.value) else { modal( - 'New configuration file', 'The file you entered does not exist. Do you want to create a new one?', + 'New configuration file', `The file "${configFilePathInput.current.value}"" you entered does not exist. Do you want to create a new one?`, 'Create', async () => await createNewConfigFile(), 'Cancel', diff --git a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx index 328e830113..e6d8c964d5 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx @@ -13,6 +13,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { const [state, setState] = useState({ isHardhatProject: false, isTruffleProject: false, + workspaceName: '', currentFile, loading: false, compileTabLogic: null, @@ -63,11 +64,15 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { }) } - api.onSetWorkspace = async (isLocalhost: boolean) => { + api.onSetWorkspace = async (isLocalhost: boolean, workspaceName: string) => { const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject() const isTruffle = await compileTabLogic.isTruffleProject() setState(prevState => { +<<<<<<< HEAD return { ...prevState, currentFile, isHardhatProject: isHardhat, isTruffleProject: isTruffle } +======= + return { ...prevState, currentFile, isHardhatProject: isHardhat, workspaceName: workspaceName } +>>>>>>> bc1405382... new file on workspace change. }) } @@ -150,7 +155,11 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { return ( <>
+<<<<<<< HEAD +======= + +>>>>>>> bc1405382... new file on workspace change. { contractsFile[currentFile] && contractsFile[currentFile].contractsDetails && } { compileErrors[currentFile] &&
diff --git a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts index d9c5635ba9..8a08386cb9 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts @@ -10,7 +10,11 @@ export interface CompilerContainerProps { api: ICompilerApi, compileTabLogic: CompileTabLogic, isHardhatProject: boolean, +<<<<<<< HEAD isTruffleProject: boolean, +======= + workspaceName: string, +>>>>>>> bc1405382... new file on workspace change. tooltip: (message: string | JSX.Element) => void, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, compiledFileName: string,