From d00d0ff5927607ebe3a946f2a2e431f8c01ff050 Mon Sep 17 00:00:00 2001 From: lianahus Date: Thu, 7 Apr 2022 14:23:08 +0200 Subject: [PATCH] fixe path update --- .../contracts/solidity_compiler_config.json | 2 +- apps/solidity-compiler/src/app/compiler.ts | 2 +- libs/remix-solidity/src/compiler/compiler.ts | 2 +- .../src/lib/compiler-container.tsx | 67 +++++++++++++------ .../src/lib/logic/compileTabLogic.ts | 6 +- 5 files changed, 53 insertions(+), 26 deletions(-) diff --git a/apps/remix-ide/contracts/solidity_compiler_config.json b/apps/remix-ide/contracts/solidity_compiler_config.json index 5a0a73b786..c5f984ca34 100644 --- a/apps/remix-ide/contracts/solidity_compiler_config.json +++ b/apps/remix-ide/contracts/solidity_compiler_config.json @@ -3,7 +3,7 @@ "settings": { "optimizer": { "enabled": true, - "runs": 260 + "runs": 200 }, "outputSelection": { "*": { diff --git a/apps/solidity-compiler/src/app/compiler.ts b/apps/solidity-compiler/src/app/compiler.ts index 8b042d25df..1e38ce51a6 100644 --- a/apps/solidity-compiler/src/app/compiler.ts +++ b/apps/solidity-compiler/src/app/compiler.ts @@ -26,7 +26,7 @@ const defaultCompilerParameters = { evmVersion: null, // compiler default language: 'Solidity', useFileConfiguration: false, - configFilePath: '' + configFilePath: "/compiler_config.json" } export class CompilerClientApi extends CompilerApiMixin(PluginClient) implements ICompilerApi { constructor () { diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index b3b02ae0b8..f728748a9e 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -314,7 +314,7 @@ export class Compiler { input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) } } catch (exception) { - this.onCompilationFinished({ error: { formattedMessage: exception.messsage } }, [], source, "", this.state.currentVersion) + this.onCompilationFinished({ error: { formattedMessage: exception.message } }, [], source, "", this.state.currentVersion) return } 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 6467577377..8193c550ec 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -27,6 +27,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const [state, setState] = useState({ hideWarnings: false, autoCompile: false, + configFilePath: "/compiler_config.json", + useFileConfiguration: false, matomoAutocompileOnce: true, optimize: false, compileTimeout: null, @@ -41,8 +43,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => { language: 'Solidity', evmVersion: '' }) - const [manualConfig, setManualConfig] = useState(true) - const [configFilePath, setConfigFilePath] = useState("/compiler_config.json") const [showFilePathInput, setShowFilePathInput] = useState(false) const [disableCompileButton, setDisableCompileButton] = useState(false) @@ -54,15 +54,15 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState) useEffect(() => { - setConfigFilePath("/compiler_config.json") + api.setAppParameter('configFilePath', "/compiler_config.json") api.fileExists("/compiler_config.json").then((exists) => { if (!exists) createNewConfigFile() else { // what to do? discuss } }) - setConfigFilePath("/compiler_config.json") - setManualConfig(false) + api.setAppParameter('configFilePath', "/compiler_config.json") + api.setAppParameter('useFileConfiguration', false) setShowFilePathInput(false) }, [workspaceName]) @@ -92,6 +92,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const autocompile = await api.getAppParameter('autoCompile') as boolean || false const hideWarnings = await api.getAppParameter('hideWarnings') as boolean || false const includeNightlies = await api.getAppParameter('includeNightlies') as boolean || false + const useFileConfiguration = await api.getAppParameter('useFileConfiguration') as boolean || true + let configFilePath = await api.getAppParameter('configFilePath') + console.log("in useeff init ", configFilePath) + if (!configFilePath || configFilePath == '') configFilePath = "/compiler_config.json" setState(prevState => { const params = api.getCompilerParameters() @@ -105,6 +109,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => { hideWarnings: hideWarnings, autoCompile: autocompile, includeNightlies: includeNightlies, + useFileConfiguration: useFileConfiguration, + configFilePath: configFilePath, optimize: optimize, runs: runs, evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default', @@ -162,9 +168,9 @@ export const CompilerContainer = (props: CompilerContainerProps) => { }, [compilerContainer.editor.mode]) useEffect(() => { - compileTabLogic.setUseFileConfiguration(!manualConfig) - if (!manualConfig) compileTabLogic.setConfigFilePath(configFilePath) - }, [manualConfig]) + compileTabLogic.setUseFileConfiguration(state.useFileConfiguration) + if (state.useFileConfiguration) compileTabLogic.setConfigFilePath(state.configFilePath) + }, [state.useFileConfiguration]) useEffect(() => { if (configurationSettings) { @@ -173,31 +179,48 @@ export const CompilerContainer = (props: CompilerContainerProps) => { }, [configurationSettings]) const toggleConfigType = () => { - setManualConfig(!manualConfig) + setState(prevState => { + return { ...prevState, useFileConfiguration: !state.useFileConfiguration } + }) + api.setAppParameter('useFileConfiguration', state.useFileConfiguration) + } const createNewConfigFile = async () => { 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 filePath = configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : state.configFilePath + await api.writeFile(filePath, configFileContent) + console.log("createNewConfigFile ", filePath) + api.setAppParameter('configFilePath', filePath) + setState(prevState => { + return { ...prevState, configFilePath: filePath } + }) + compileTabLogic.setConfigFilePath(filePath) + setShowFilePathInput(false) } + const handleConfigPathChange = async () => { if (configFilePathInput.current.value !== '') { - if (await api.fileExists(configFilePathInput.current.value)) - setConfigFilePath(configFilePathInput.current.value) - else { + if (await api.fileExists(configFilePathInput.current.value)) { + api.setAppParameter('configFilePath', configFilePathInput.current.value) + setState(prevState => { + return { ...prevState, configFilePath: configFilePathInput.current.value } + }) + compileTabLogic.setConfigFilePath(configFilePathInput.current.value) + + setShowFilePathInput(false) + } else { modal( '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', - () => {} + () => { + setShowFilePathInput(false) + } ) } } - - setShowFilePathInput(false) - compileTabLogic.setConfigFilePath(configFilePath) } const _retrieveVersion = (version?) => { @@ -596,11 +619,11 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
- +
-
- { !showFilePathInput && {configFilePath} } +
+ { !showFilePathInput && {state.configFilePath} } { /> { !showFilePathInput && }
-
+
diff --git a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts index 5b24d59d3e..eb99b36490 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts @@ -48,7 +48,9 @@ export class CompileTabLogic { this.api.setCompilerParameters({ evmVersion: this.evmVersion }) this.compiler.set('evmVersion', this.evmVersion) - this.useFileConfiguration = this.api.getCompilerParameters().useFileConfiguration + //this.useFileConfiguration = this.api.getCompilerParameters().useFileConfiguration + console.log("logic this.configFilePath ", this.configFilePath) + console.log("logic this.api.getCompilerParameters().configFilePath ", this.api.getCompilerParameters().configFilePath) this.configFilePath = this.api.getCompilerParameters().configFilePath this.language = getValidLanguage(this.api.getCompilerParameters().language) if (this.language != null) { @@ -68,6 +70,7 @@ export class CompileTabLogic { } setConfigFilePath (path) { + console.log("path in logic = ", path) this.configFilePath = path } @@ -108,6 +111,7 @@ export class CompileTabLogic { const sources = { [target]: { content } } this.event.emit('removeAnnotations') this.event.emit('startingCompilation') + console.log("compile from ", this.configFilePath) this.api.readFile(this.configFilePath).then( contentConfig => { this.compiler.set('configFileContent', contentConfig) })