|
|
|
@ -22,11 +22,23 @@ 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, workspaceName } = props // eslint-disable-line
|
|
|
|
|
const { |
|
|
|
|
api, |
|
|
|
|
compileTabLogic, |
|
|
|
|
tooltip, |
|
|
|
|
modal, |
|
|
|
|
compiledFileName, |
|
|
|
|
updateCurrentVersion, |
|
|
|
|
configurationSettings, |
|
|
|
|
isHardhatProject, |
|
|
|
|
isTruffleProject, |
|
|
|
|
workspaceName, |
|
|
|
|
configFilePath, |
|
|
|
|
setConfigFilePath, |
|
|
|
|
} = props // eslint-disable-line
|
|
|
|
|
const [state, setState] = useState({ |
|
|
|
|
hideWarnings: false, |
|
|
|
|
autoCompile: false, |
|
|
|
|
configFilePath: "compiler_config.json", |
|
|
|
|
useFileConfiguration: false, |
|
|
|
|
matomoAutocompileOnce: true, |
|
|
|
|
optimize: false, |
|
|
|
@ -40,7 +52,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
compiledFileName: '', |
|
|
|
|
includeNightlies: false, |
|
|
|
|
language: 'Solidity', |
|
|
|
|
evmVersion: '' |
|
|
|
|
evmVersion: '', |
|
|
|
|
createFileOnce: true |
|
|
|
|
}) |
|
|
|
|
const [showFilePathInput, setShowFilePathInput] = useState<boolean>(false) |
|
|
|
|
const [toggleExpander, setToggleExpander] = useState<boolean>(false) |
|
|
|
@ -53,17 +66,27 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
api.setAppParameter('configFilePath', "/compiler_config.json") |
|
|
|
|
api.fileExists("/compiler_config.json").then((exists) => { |
|
|
|
|
if (!exists) createNewConfigFile() |
|
|
|
|
else { |
|
|
|
|
// what to do? discuss
|
|
|
|
|
} |
|
|
|
|
api.setAppParameter('configFilePath', "compiler_config.json") |
|
|
|
|
|
|
|
|
|
if (state.useFileConfiguration) { |
|
|
|
|
api.fileExists("compiler_config.json").then((exists) => { |
|
|
|
|
if (!exists || state.useFileConfiguration ) createNewConfigFile() |
|
|
|
|
}) |
|
|
|
|
api.setAppParameter('configFilePath', "/compiler_config.json") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
api.setAppParameter('configFilePath', "compiler_config.json") |
|
|
|
|
setShowFilePathInput(false) |
|
|
|
|
}, [workspaceName]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
|
|
if (state.useFileConfiguration) |
|
|
|
|
api.fileExists("compiler_config.json").then((exists) => { |
|
|
|
|
if (!exists || state.useFileConfiguration ) createNewConfigFile() |
|
|
|
|
}) |
|
|
|
|
}, [state.useFileConfiguration]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const listener = (event) => { |
|
|
|
|
if (configFilePathInput.current !== event.target) { |
|
|
|
@ -106,8 +129,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
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 || false |
|
|
|
|
let configFilePath = await api.getAppParameter('configFilePath') |
|
|
|
|
if (!configFilePath || configFilePath == '') configFilePath = "/compiler_config.json" |
|
|
|
|
let configFilePathSaved = await api.getAppParameter('configFilePath') |
|
|
|
|
if (!configFilePathSaved || configFilePathSaved == '') configFilePathSaved = "compiler_config.json" |
|
|
|
|
|
|
|
|
|
setConfigFilePath(configFilePathSaved) |
|
|
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
const params = api.getCompilerParameters() |
|
|
|
@ -122,7 +147,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
autoCompile: autocompile, |
|
|
|
|
includeNightlies: includeNightlies, |
|
|
|
|
useFileConfiguration: useFileConfiguration, |
|
|
|
|
configFilePath: configFilePath, |
|
|
|
|
optimize: optimize, |
|
|
|
|
runs: runs, |
|
|
|
|
evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default', |
|
|
|
@ -181,7 +205,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
compileTabLogic.setUseFileConfiguration(state.useFileConfiguration) |
|
|
|
|
if (state.useFileConfiguration) compileTabLogic.setConfigFilePath(state.configFilePath) |
|
|
|
|
if (state.useFileConfiguration) compileTabLogic.setConfigFilePath(configFilePath) |
|
|
|
|
}, [state.useFileConfiguration]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
@ -191,6 +215,16 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
}, [configurationSettings]) |
|
|
|
|
|
|
|
|
|
const toggleConfigType = () => { |
|
|
|
|
if (state.useFileConfiguration) |
|
|
|
|
if (state.createFileOnce) { |
|
|
|
|
api.fileExists("compiler_config.json").then((exists) => { |
|
|
|
|
if (!exists || state.useFileConfiguration ) createNewConfigFile() |
|
|
|
|
}) |
|
|
|
|
setState(prevState => { |
|
|
|
|
return { ...prevState, createFileOnce: false } |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
api.setAppParameter('useFileConfiguration', !state.useFileConfiguration) |
|
|
|
|
return { ...prevState, useFileConfiguration: !state.useFileConfiguration } |
|
|
|
@ -198,18 +232,16 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const openFile = async () => { |
|
|
|
|
api.open(state.configFilePath) |
|
|
|
|
api.open(configFilePath) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const createNewConfigFile = async () => { |
|
|
|
|
let filePath = configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : state.configFilePath |
|
|
|
|
let filePath = configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : configFilePath |
|
|
|
|
if (!filePath.endsWith('.json')) filePath = filePath + '.json' |
|
|
|
|
|
|
|
|
|
await api.writeFile(filePath, configFileContent) |
|
|
|
|
api.setAppParameter('configFilePath', filePath) |
|
|
|
|
setState(prevState => { |
|
|
|
|
return { ...prevState, configFilePath: filePath } |
|
|
|
|
}) |
|
|
|
|
setConfigFilePath(filePath) |
|
|
|
|
compileTabLogic.setConfigFilePath(filePath) |
|
|
|
|
setShowFilePathInput(false) |
|
|
|
|
} |
|
|
|
@ -220,9 +252,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
|
|
|
|
|
if (await api.fileExists(configFilePathInput.current.value)) { |
|
|
|
|
api.setAppParameter('configFilePath', configFilePathInput.current.value) |
|
|
|
|
setState(prevState => { |
|
|
|
|
return { ...prevState, configFilePath: configFilePathInput.current.value } |
|
|
|
|
}) |
|
|
|
|
setConfigFilePath(configFilePathInput.current.value) |
|
|
|
|
compileTabLogic.setConfigFilePath(configFilePathInput.current.value) |
|
|
|
|
|
|
|
|
|
setShowFilePathInput(false) |
|
|
|
@ -755,10 +785,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
<div className={`pt-2 ml-4 ml-2 align-items-start justify-content-between d-flex`}> |
|
|
|
|
{ (!showFilePathInput && state.useFileConfiguration) && <span |
|
|
|
|
title="Click to open the config file." |
|
|
|
|
onClick={openFile} |
|
|
|
|
className="py-2 text-primary remixui_compilerConfigPath" |
|
|
|
|
>{state.configFilePath}</span> } |
|
|
|
|
{ (!showFilePathInput&& !state.useFileConfiguration) && <span className="py-2 text-secondary">{state.configFilePath}</span> } |
|
|
|
|
onClick={configFilePath === '' ? () => {} : openFile} |
|
|
|
|
className="py-2 remixui_compilerConfigPath" |
|
|
|
|
>{configFilePath === '' ? 'No file selected.' : configFilePath}</span> } |
|
|
|
|
{ (!showFilePathInput && !state.useFileConfiguration) && <span className="py-2 text-secondary">{configFilePath}</span> } |
|
|
|
|
<input |
|
|
|
|
ref={configFilePathInput} |
|
|
|
|
className={`py-0 my-0 form-control ${showFilePathInput ? "d-flex" : "d-none"}`} |
|
|
|
@ -775,11 +805,12 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<div className="px-4"> |
|
|
|
|
<button id="compileBtn" data-id="compilerContainerCompileBtn" className="btn btn-primary btn-block d-block w-100 text-break remixui_disabled mb-1 mt-3" onClick={compile} disabled={disableCompileButton}> |
|
|
|
|
<button id="compileBtn" data-id="compilerContainerCompileBtn" className="btn btn-primary btn-block d-block w-100 text-break remixui_disabled mb-1 mt-3" onClick={compile} disabled={(configFilePath === '' && state.useFileConfiguration) || disableCompileButton}> |
|
|
|
|
<OverlayTrigger overlay={ |
|
|
|
|
<Tooltip id="overlay-tooltip-compile"> |
|
|
|
|
<div className="text-left"> |
|
|
|
|
<div><b>Ctrl+S</b> for compiling</div> |
|
|
|
|
{ !(configFilePath === '' && state.useFileConfiguration) && <div><b>Ctrl+S</b> for compiling</div> } |
|
|
|
|
{ (configFilePath === '' && state.useFileConfiguration) && <div> No config file selected</div> } |
|
|
|
|
</div> |
|
|
|
|
</Tooltip> |
|
|
|
|
}> |
|
|
|
@ -790,11 +821,12 @@ export const CompilerContainer = (props: CompilerContainerProps) => { |
|
|
|
|
</OverlayTrigger> |
|
|
|
|
</button> |
|
|
|
|
<div className='d-flex align-items-center'>
|
|
|
|
|
<button id="compileAndRunBtn" data-id="compilerContainerCompileAndRunBtn" className="btn btn-secondary btn-block d-block w-100 text-break remixui_solidityCompileAndRunButton d-inline-block remixui_disabled mb-1 mt-3" onClick={compileAndRun} disabled={disableCompileButton}> |
|
|
|
|
<button id="compileAndRunBtn" data-id="compilerContainerCompileAndRunBtn" className="btn btn-secondary btn-block d-block w-100 text-break remixui_solidityCompileAndRunButton d-inline-block remixui_disabled mb-1 mt-3" onClick={compileAndRun} disabled={(configFilePath === '' && state.useFileConfiguration) || disableCompileButton}> |
|
|
|
|
<OverlayTrigger overlay={ |
|
|
|
|
<Tooltip id="overlay-tooltip-compile-run"> |
|
|
|
|
<div className="text-left"> |
|
|
|
|
<div><b>Ctrl+Shift+S</b> for compiling and script execution</div> |
|
|
|
|
{ !(configFilePath === '' && state.useFileConfiguration) && <div><b>Ctrl+Shift+S</b> for compiling and script execution</div> } |
|
|
|
|
{ (configFilePath === '' && state.useFileConfiguration) && <div> No config file selected</div> } |
|
|
|
|
</div> |
|
|
|
|
</Tooltip> |
|
|
|
|
}> |
|
|
|
|