Enable hardhat compilation

pull/5370/head
ioedeveloper 3 years ago
parent 30711561ee
commit 6e388288fa
  1. 20
      apps/remix-ide/src/app/tabs/compile-tab.js
  2. 14
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  3. 3
      libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx
  4. 10
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  5. 6
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts

@ -67,6 +67,7 @@ class CompileTab extends ViewPlugin {
this.compiler = this.compileTabLogic.compiler this.compiler = this.compileTabLogic.compiler
this.compileTabLogic.init() this.compileTabLogic.init()
this.contractMap = {} this.contractMap = {}
this.isHardHatProject = false
this.el = document.createElement('div') this.el = document.createElement('div')
this.el.setAttribute('id', 'compileTabView') this.el.setAttribute('id', 'compileTabView')
@ -84,13 +85,6 @@ class CompileTab extends ViewPlugin {
*/ */
listenToEvents () { listenToEvents () {
this.on('filePanel', 'setWorkspace', (workspace) => {
this.compileTabLogic.isHardhatProject().then((result) => {
if (result && workspace.isLocalhost) this.compilerContainer.hardhatCompilation.style.display = 'flex'
else this.compilerContainer.hardhatCompilation.style.display = 'none'
})
})
this.data.eventHandlers.onContentChanged = () => { this.data.eventHandlers.onContentChanged = () => {
this.emit('statusChanged', { key: 'edited', title: 'the content has changed, needs recompilation', type: 'info' }) this.emit('statusChanged', { key: 'edited', title: 'the content has changed, needs recompilation', type: 'info' })
} }
@ -116,7 +110,14 @@ class CompileTab extends ViewPlugin {
this.call('editor', 'clearAnnotations') this.call('editor', 'clearAnnotations')
} }
this.on('filePanel', 'setWorkspace', () => this.resetResults()) this.on('filePanel', 'setWorkspace', (workspace) => {
this.compileTabLogic.isHardhatProject().then((result) => {
if (result && workspace.isLocalhost) this.isHardHatProject = true
else this.isHardHatProject = false
this.renderComponent()
})
this.resetResults()
})
this.compileTabLogic.event.on('startingCompilation', this.data.eventHandlers.onStartingCompilation) this.compileTabLogic.event.on('startingCompilation', this.data.eventHandlers.onStartingCompilation)
this.compileTabLogic.event.on('removeAnnotations', this.data.eventHandlers.onRemoveAnnotations) this.compileTabLogic.event.on('removeAnnotations', this.data.eventHandlers.onRemoveAnnotations)
@ -284,9 +285,10 @@ class CompileTab extends ViewPlugin {
compileTabLogic={this.compileTabLogic} compileTabLogic={this.compileTabLogic}
compiledFileName={this.currentFile} compiledFileName={this.currentFile}
contractsDetails={this.contractsDetails} contractsDetails={this.contractsDetails}
setHardHatCompilation={this.setHardHatCompilation} setHardHatCompilation={this.setHardHatCompilation.bind(this)}
contractMap={this.contractMap} contractMap={this.contractMap}
compileErrors={this.compileErrors || {}} compileErrors={this.compileErrors || {}}
isHardHatProject={this.isHardHatProject}
/> />
, this.el) , this.el)
} }

@ -7,7 +7,7 @@ import { canUseWorker, baseURLBin, baseURLWasm, urlFromVersion, pathToURL, promi
import './css/style.css' import './css/style.css'
export const CompilerContainer = (props: CompilerContainerProps) => { export const CompilerContainer = (props: CompilerContainerProps) => {
const { editor, config, queryParams, compileTabLogic, tooltip, modal, compiledFileName, setHardHatCompilation, updateCurrentVersion } = props // eslint-disable-line const { editor, config, queryParams, compileTabLogic, tooltip, modal, compiledFileName, setHardHatCompilation, updateCurrentVersion, isHardHatProject } = props // eslint-disable-line
const [state, setState] = useState({ const [state, setState] = useState({
hideWarnings: false, hideWarnings: false,
autoCompile: false, autoCompile: false,
@ -53,8 +53,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
useEffect(() => { useEffect(() => {
if (compileTabLogic && compileTabLogic.compiler) { if (compileTabLogic && compileTabLogic.compiler) {
compileTabLogic.compiler.event.register('compilerLoaded', compilerLoaded) compileTabLogic.compiler.event.register('compilerLoaded', compilerLoaded)
console.log(`${config.get('autoCompile') || false}`)
setState(prevState => { setState(prevState => {
return { return {
...prevState, ...prevState,
@ -513,10 +511,12 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
<label className="form-check-label custom-control-label" htmlFor="hideWarningsBox">Hide warnings</label> <label className="form-check-label custom-control-label" htmlFor="hideWarningsBox">Hide warnings</label>
</div> </div>
</div> </div>
<div className="mt-2 remixui_compilerConfig custom-control custom-checkbox" style={{ display: "none" }}> {
<input className="remixui_autocompile custom-control-input" onChange={updatehhCompilation} id="enableHardhat" type="checkbox" title="Enable Hardhat Compilation" checked={hhCompilation} /> isHardHatProject && <div className="mt-2 remixui_compilerConfig custom-control custom-checkbox">
<label className="form-check-label custom-control-label" htmlFor="enableHardhat">Enable Hardhat Compilation</label> <input className="remixui_autocompile custom-control-input" onChange={updatehhCompilation} id="enableHardhat" type="checkbox" title="Enable Hardhat Compilation" checked={hhCompilation} />
</div> <label className="form-check-label custom-control-label" htmlFor="enableHardhat">Enable Hardhat Compilation</label>
</div>
}
<button id="compileBtn" data-id="compilerContainerCompileBtn" className="btn btn-primary btn-block remixui_disabled mt-3" title="Compile" onClick={compile} disabled={!state.compiledFileName || (state.compiledFileName && !isSolFileSelected(state.compiledFileName))}> <button id="compileBtn" data-id="compilerContainerCompileBtn" className="btn btn-primary btn-block remixui_disabled mt-3" title="Compile" onClick={compile} disabled={!state.compiledFileName || (state.compiledFileName && !isSolFileSelected(state.compiledFileName))}>
<span> <span>
<i ref={warningIcon} title="Compilation Slow" style={{ visibility: 'hidden' }} className="remixui_warnCompilationSlow fas fa-exclamation-triangle" aria-hidden="true"></i> <i ref={warningIcon} title="Compilation Slow" style={{ visibility: 'hidden' }} className="remixui_warnCompilationSlow fas fa-exclamation-triangle" aria-hidden="true"></i>

@ -66,7 +66,8 @@ export const ContractSelection = (props: ContractSelectionProps) => {
if (!selectedContract) throw new Error('No contract compiled yet') if (!selectedContract) throw new Error('No contract compiled yet')
const contractProperties = contractsDetails[selectedContract] const contractProperties = contractsDetails[selectedContract]
return contractProperties[property] || null if (contractProperties && contractProperties[property]) return contractProperties[property]
return null
} }
const renderData = (item, key: string | number, keyPath: string) => { const renderData = (item, key: string | number, keyPath: string) => {

@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer'
import './css/style.css' import './css/style.css'
export const SolidityCompiler = (props: SolidityCompilerProps) => { export const SolidityCompiler = (props: SolidityCompilerProps) => {
const { editor, config, queryParams, plugin, compileTabLogic, compiledFileName, fileProvider, fileManager, contractsDetails, setHardHatCompilation, contractMap, compileErrors } = props const { editor, config, queryParams, plugin, compileTabLogic, compiledFileName, fileProvider, fileManager, contractsDetails, setHardHatCompilation, contractMap, compileErrors, isHardHatProject } = props
const [state, setState] = useState({ const [state, setState] = useState({
contractsDetails: {}, contractsDetails: {},
eventHandlers: {}, eventHandlers: {},
@ -81,19 +81,19 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
return ( return (
<> <>
<div id="compileTabView"> <div id="compileTabView">
<CompilerContainer editor={editor} config={config} queryParams={queryParams} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={compiledFileName} setHardHatCompilation={setHardHatCompilation} updateCurrentVersion={updateCurrentVersion} /> <CompilerContainer editor={editor} config={config} queryParams={queryParams} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={compiledFileName} setHardHatCompilation={setHardHatCompilation} updateCurrentVersion={updateCurrentVersion} isHardHatProject={isHardHatProject} />
<ContractSelection contractMap={contractMap} fileProvider={fileProvider} fileManager={fileManager} contractsDetails={contractsDetails} modal={modal} /> <ContractSelection contractMap={contractMap} fileProvider={fileProvider} fileManager={fileManager} contractsDetails={contractsDetails} modal={modal} />
<div className="remixui_errorBlobs p-4" data-id="compiledErrors"> <div className="remixui_errorBlobs p-4" data-id="compiledErrors">
<span data-id={`compilationFinishedWith_${currentVersion}`}></span> <span data-id={`compilationFinishedWith_${currentVersion}`}></span>
{ compileErrors.error && <Renderer message={compileErrors.error.formattedMessage || compileErrors.error} plugin={plugin} opt={{ type: compileErrors.error.severity || 'error', errorType: compileErrors.error.type }} config={config} /> } { compileErrors.error && <Renderer message={compileErrors.error.formattedMessage || compileErrors.error} plugin={plugin} opt={{ type: compileErrors.error.severity || 'error', errorType: compileErrors.error.type }} config={config} /> }
{ compileErrors.error && (compileErrors.error.mode === 'panic') && modal('Error', panicMessage(compileErrors.error.formattedMessage), 'Close', null) } { compileErrors.error && (compileErrors.error.mode === 'panic') && modal('Error', panicMessage(compileErrors.error.formattedMessage), 'Close', null) }
{ compileErrors.errors && compileErrors.errors.length && compileErrors.errors.map((err) => { { compileErrors.errors && compileErrors.errors.length && compileErrors.errors.map((err, index) => {
if (config.get('hideWarnings')) { if (config.get('hideWarnings')) {
if (err.severity !== 'warning') { if (err.severity !== 'warning') {
return <Renderer message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} config={config} /> return <Renderer key={index} message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} config={config} />
} }
} else { } else {
return <Renderer message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} config={config} /> return <Renderer key={index} message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} config={config} />
} }
}) } }) }
</div> </div>

@ -14,7 +14,8 @@ export interface SolidityCompilerProps {
contractMap: { contractMap: {
file: string file: string
} | Record<string, any> } | Record<string, any>
compileErrors: any compileErrors: any,
isHardHatProject: boolean
} }
export interface CompilerContainerProps { export interface CompilerContainerProps {
@ -26,7 +27,8 @@ export interface CompilerContainerProps {
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,
compiledFileName: string, compiledFileName: string,
setHardHatCompilation: (value: boolean) => void, setHardHatCompilation: (value: boolean) => void,
updateCurrentVersion: any updateCurrentVersion: any,
isHardHatProject: boolean
} }
export interface ContractSelectionProps { export interface ContractSelectionProps {
contractMap: { contractMap: {

Loading…
Cancel
Save