refactor ICompilerAPI

pull/5370/head
yann300 3 years ago
parent 63ee352ec4
commit c1bdf45d27
  1. 2
      apps/remix-ide/src/app.js
  2. 2
      apps/remix-ide/src/app/files/fileManager.js
  3. 39
      apps/remix-ide/src/app/tabs/compile-tab.js
  4. 2
      apps/solidity-compiler/src/app/app.tsx
  5. 55
      apps/solidity-compiler/src/app/compiler-api.ts
  6. 71
      apps/solidity-compiler/src/app/compiler.ts
  7. 23
      libs/remix-lib/src/types/ICompilerApi.ts
  8. 4
      libs/remix-ui/renderer/src/lib/renderer.tsx
  9. 4
      libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts
  10. 52
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  11. 27
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  12. 26
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  13. 9
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts

@ -425,7 +425,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
} }
// CONTENT VIEWS & DEFAULT PLUGINS // CONTENT VIEWS & DEFAULT PLUGINS
const compileTab = new CompileTab() const compileTab = new CompileTab(registry.get('config').api)
const run = new RunTab( const run = new RunTab(
blockchain, blockchain,
registry.get('config').api, registry.get('config').api,

@ -398,7 +398,7 @@ class FileManager extends Plugin {
} }
fileChangedEvent (path) { fileChangedEvent (path) {
this.emit('currentFileChanged', path) this.emit('fileChanged', path)
} }
fileRenamedEvent (oldName, newName, isFolder) { fileRenamedEvent (oldName, newName, isFolder) {

@ -1,9 +1,11 @@
/* global */ /* global */
import React from 'react' // eslint-disable-line import React from 'react' // eslint-disable-line
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import { SolidityCompiler, CompileTab as CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line import { SolidityCompiler } from '@remix-ui/solidity-compiler' // eslint-disable-line
import { CompileTabLogic } from '@remix-ui/solidity-compiler' // eslint-disable-line
import { CompilerApiMixin } from '@remixproject/solidity-compiler-plugin' import { CompilerApiMixin } from '@remixproject/solidity-compiler-plugin'
import { ViewPlugin } from '@remixproject/engine-web' import { ViewPlugin } from '@remixproject/engine-web'
import QueryParams from '../../lib/query-params'
// import { ICompilerApi } from '@remix-project/remix-lib-ts' // import { ICompilerApi } from '@remix-project/remix-lib-ts'
import * as packageJson from '../../../../../package.json' import * as packageJson from '../../../../../package.json'
@ -30,14 +32,19 @@ const profile = {
// - methods: ['getCompilationResult'] // - methods: ['getCompilationResult']
class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerApi class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerApi
constructor () { constructor (config) {
super(profile) super(profile)
this.config = config
this.queryParams = new QueryParams()
this.compileTabLogic = new CompileTabLogic(this, this.contentImport)
this.compiler = this.compileTabLogic.compiler
this.compileTabLogic.init()
this.initCompilerApi() this.initCompilerApi()
} }
renderComponent () { renderComponent () {
ReactDOM.render( ReactDOM.render(
<SolidityCompiler plugin={this}/> <SolidityCompiler api={this}/>
, this.el) , this.el)
} }
@ -49,10 +56,6 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA
this.renderComponent() this.renderComponent()
} }
setHardHatCompilation (value) {
this.hhCompilation = value
}
setSelectedVersion (version) { setSelectedVersion (version) {
this.selectedVersion = version this.selectedVersion = version
} }
@ -121,6 +124,28 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA
pattern: [] pattern: []
}) })
} }
getCompilerParameters () {
const params = this.queryParams.get()
params.optimize = (params.optimize === 'false' || params.optimize === null || params.optimize === undefined) ? false : params.optimize
params.optimize = params.optimize === 'true' ? true : params.optimize
return params
}
setCompilerParameters (params) {
this.queryParams.update(params)
}
getAppParameter (name) {
const param = this.config.get(name)
if (param === 'true') return true
if (param === 'false') return false
return param
}
setAppParameter (name, value) {
this.config.set(name, value)
}
} }
module.exports = CompileTab module.exports = CompileTab

@ -9,7 +9,7 @@ const remix = new CompilerClientApi()
export const App = () => { export const App = () => {
return ( return (
<div className="debugger"> <div className="debugger">
<SolidityCompiler plugin={remix} /> <SolidityCompiler api={remix} />
</div> </div>
); );
}; };

@ -1,7 +1,26 @@
import { compile } from '@remix-project/remix-solidity' import { compile } from '@remix-project/remix-solidity'
import { CompileTab as CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line import { CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line
import { ConfigurationSettings } from '@remix-project/remix-lib-ts'
export const CompilerApiMixin = (Base) => class extends Base { export const CompilerApiMixin = (Base) => class extends Base {
currentFile: string
contractMap: {
file: string
} | Record<string, any>
compileErrors: any
compileTabLogic: CompileTabLogic
contractsDetails: Record<string, any>
configurationSettings: ConfigurationSettings
onCurrentFileChanged: (fileName: string) => void
onResetResults: () => void
onSetWorkspace: (workspace: any) => void
onNoFileSelected: () => void
onCompilationFinished: (contractsDetails: any, contractMap: any) => void
onSessionSwitched: () => void
onContentChanged: () => void
initCompilerApi () { initCompilerApi () {
this.configurationSettings = null this.configurationSettings = null
@ -16,9 +35,6 @@ export const CompilerApiMixin = (Base) => class extends Base {
eventHandlers: {}, eventHandlers: {},
loading: false loading: false
} }
this.compileTabLogic = new CompileTabLogic(this, this.contentImport)
this.compiler = this.compileTabLogic.compiler
this.compileTabLogic.init()
this.contractMap = {} this.contractMap = {}
this.contractsDetails = {} this.contractsDetails = {}
@ -46,11 +62,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
logToTerminal (content) { logToTerminal (content) {
return this.call('terminal', 'log', content) return this.call('terminal', 'log', content)
} }
setHardHatCompilation (value) {
this.hhCompilation = value
}
setSelectedVersion (version) { setSelectedVersion (version) {
this.selectedVersion = version this.selectedVersion = version
} }
@ -102,7 +114,6 @@ export const CompilerApiMixin = (Base) => class extends Base {
} }
} }
/** /**
* set the compiler configuration * set the compiler configuration
* This function is used by remix-plugin compiler API. * This function is used by remix-plugin compiler API.
@ -110,25 +121,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
*/ */
setCompilerConfig (settings) { setCompilerConfig (settings) {
this.configurationSettings = settings this.configurationSettings = settings
} }
getParameters () {
return {}
}
setParameters (params) {}
getConfiguration (name) {
const conf = {
'currentFile': () => this.currentFile,
'hideWarnings': () => false,
'autoCompile': () => false,
'includeNightlies': () => false
}
return conf[name]()
}
setConfiguration (name, value) {}
getFileManagerMode () { getFileManagerMode () {
return 'browser' return 'browser'
@ -154,7 +147,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
this.currentFile = '' this.currentFile = ''
this.contractsDetails = {} this.contractsDetails = {}
this.emit('statusChanged', { key: 'none' }) this.emit('statusChanged', { key: 'none' })
if (this.onResetResults()) this.onResetResults() if (this.onResetResults) this.onResetResults()
} }
listenToEvents () { listenToEvents () {
@ -258,7 +251,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
// ctrl+s or command+s // ctrl+s or command+s
if ((e.metaKey || e.ctrlKey) && e.keyCode === 83) { if ((e.metaKey || e.ctrlKey) && e.keyCode === 83) {
e.preventDefault() e.preventDefault()
this.compileTabLogic.runCompiler(this.hhCompilation) this.compileTabLogic.runCompiler(this.getAppParameter('hardhat-compilation'))
} }
}) })
} }

@ -16,53 +16,38 @@ const profile = {
methods: ['getCompilationResult', 'compile', 'compileWithParameters', 'setCompilerConfig', 'compileFile' ,'getCompilerState'] methods: ['getCompilationResult', 'compile', 'compileWithParameters', 'setCompilerConfig', 'compileFile' ,'getCompilerState']
} }
export interface ConfigurationSettings {
version: string,
evmVersion: string,
language: string,
optimize: boolean,
runs: string
}
export class CompilerClientApi extends CompilerApiMixin(PluginClient) implements ICompilerApi { export class CompilerClientApi extends CompilerApiMixin(PluginClient) implements ICompilerApi {
// interface matches libs/remix-ui/solidity-compiler/types/index.ts : ICompilerApi
currentFile: string
contractMap: {
file: string
} | Record<string, any>
compileErrors: any
compileTabLogic: any
contractsDetails: Record<string, any>
configurationSettings: ConfigurationSettings
setHardHatCompilation: (value: boolean) => void
getParameters: () => ConfigurationSettings
setParameters: (params: Partial<ConfigurationSettings>) => void
setCompilerConfig: (settings: ConfigurationSettings) => void
getConfiguration: (value: string) => string
setConfiguration: (name: string, value: string) => void
getFileManagerMode: () => string
getCompilationResult: () => any
onCurrentFileChanged: (fileName: string) => void
onResetResults: () => void
onSetWorkspace: (isLocalhost: boolean) => void
onNoFileSelected: () => void
onCompilationFinished: (contractsDetails: any, contractMap: any) => void
onSessionSwitched: () => void
onContentChanged: () => void
fileExists: (file: string) => Promise<boolean>
writeFile: (file: string, content: string) => Promise<void>
readFile: (file: string) => Promise<string>
open: (file: string) => void
constructor () { constructor () {
super() super()
createClient(this as any) createClient(this as any)
this.compileTabLogic = new CompileTabLogic(this, this.contentImport)
this.compiler = this.compileTabLogic.compiler
this.compileTabLogic.init()
this.initCompilerApi() this.initCompilerApi()
} }
getCompilerParameters () {
return {
runs: '200',
optimize: false,
version: '0.8.7+commit.e28d00a7',
evmVersion: null, // default
language: 'Solidity'
}
}
setCompilerParameters (params) {}
getAppParameter (name) {
const conf = {
'currentFile': () => this.currentFile,
'hideWarnings': () => false,
'autoCompile': () => false,
'includeNightlies': () => false
}
return conf[name]()
}
setAppParameter (name, value) {}
} }

@ -8,11 +8,12 @@ export interface ICompilerApi {
contractsDetails: Record<string, any> contractsDetails: Record<string, any>
configurationSettings: ConfigurationSettings configurationSettings: ConfigurationSettings
setHardHatCompilation: (value: boolean) => void getCompilerParameters: () => ConfigurationSettings
getParameters: () => any setCompilerParameters: (ConfigurationSettings?) => void
setParameters: (params) => void
getConfiguration: (value: string) => string getAppParameter: (value: string) => string | boolean
setConfiguration: (name: string, value: string) => void setAppParameter: (name: string, value: string | boolean) => void
getFileManagerMode: () => string getFileManagerMode: () => string
setCompilerConfig: (settings: any) => void setCompilerConfig: (settings: any) => void
@ -26,11 +27,21 @@ export interface ICompilerApi {
onSessionSwitched: () => void onSessionSwitched: () => void
onContentChanged: () => void onContentChanged: () => void
resolveContentAndSave: (url: string) => Promise<string>
fileExists: (file: string) => Promise<boolean> fileExists: (file: string) => Promise<boolean>
writeFile: (file: string, content: string) => Promise<void> writeFile: (file: string, content: string) => Promise<void>
readFile: (file: string) => Promise<string> readFile: (file: string) => Promise<string>
open: (file: string) => void open: (file: string) => void
}
logToTerminal: (log: terminalLog) => {}
compileWithHardhat: (configPath: string) => Promise<string>
}
export type terminalLog = {
type: 'info' | 'error' | 'warning'
value: string
}
export interface ConfigurationSettings { export interface ConfigurationSettings {
version: string, version: string,

@ -69,7 +69,7 @@ export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => {
} }
const addAnnotation = (file, error) => { const addAnnotation = (file, error) => {
if (file === plugin.getConfiguration('currentFile')) { if (file === plugin.getAppParameter('currentFile')) {
plugin.call('editor', 'addAnnotation', error, file) plugin.call('editor', 'addAnnotation', error, file)
} }
} }
@ -87,7 +87,7 @@ export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => {
} }
const _errorClick = (errFile, errLine, errCol) => { const _errorClick = (errFile, errLine, errCol) => {
if (errFile !== plugin.getConfiguration('currentFile')) { if (errFile !== plugin.getAppParameter('currentFile')) {
// TODO: refactor with this._components.contextView.jumpTo // TODO: refactor with this._components.contextView.jumpTo
const provider = plugin.fileProviderOf(errFile) const provider = plugin.fileProviderOf(errFile)
if (provider) { if (provider) {

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import { CompileTabLogic } from '../logic/compileTabLogic'
export const setEditorMode = (mode: string) => { export const setEditorMode = (mode: string) => {
return { return {
type: 'SET_EDITOR_MODE', type: 'SET_EDITOR_MODE',
@ -26,7 +26,7 @@ export const resetCompilerMode = () => (dispatch: React.Dispatch<any>) => {
}) })
} }
export const listenToEvents = (compileTabLogic, api) => (dispatch: React.Dispatch<any>) => { export const listenToEvents = (compileTabLogic: CompileTabLogic, api) => (dispatch: React.Dispatch<any>) => {
api.onSessionSwitched = () => { api.onSessionSwitched = () => {
dispatch(setEditorMode('sessionSwitched')) dispatch(setEditorMode('sessionSwitched'))
} }

@ -19,11 +19,11 @@ declare global {
const _paq = window._paq = window._paq || [] //eslint-disable-line const _paq = window._paq = window._paq || [] //eslint-disable-line
export const CompilerContainer = (props: CompilerContainerProps) => { export const CompilerContainer = (props: CompilerContainerProps) => {
const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings } = props // eslint-disable-line const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject } = props // eslint-disable-line
const [state, setState] = useState({ const [state, setState] = useState({
hideWarnings: false, hideWarnings: false,
autoCompile: false, autoCompile: false,
optimise: false, optimize: false,
compileTimeout: null, compileTimeout: null,
timeout: 300, timeout: 300,
allversions: [], allversions: [],
@ -57,7 +57,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
_updateVersionSelector(selectedVersion) _updateVersionSelector(selectedVersion)
} }
}) })
const currentFileName = api.getConfiguration('currentFile') const currentFileName = api.getAppParameter('currentFile') as string
currentFile(currentFileName) currentFile(currentFileName)
listenToEvents(compileTabLogic, api)(dispatch) listenToEvents(compileTabLogic, api)(dispatch)
@ -66,19 +66,19 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
useEffect(() => { useEffect(() => {
if (compileTabLogic && compileTabLogic.compiler) { if (compileTabLogic && compileTabLogic.compiler) {
setState(prevState => { setState(prevState => {
const params = api.getParameters() const params = api.getCompilerParameters()
const optimize = params.optimize === 'false' ? false : params.optimize === 'true' ? true : null const optimize = params.optimize
const runs = params.runs const runs = params.runs as string
const evmVersion = params.evmVersion const evmVersion = params.evmVersion
const autoCompile = params.autoCompile === 'false' ? false : params.autoCompile === 'true' ? true : null const autoCompile = params.autoCompile === 'false' ? false : params.autoCompile === 'true' ? true : null
return { return {
...prevState, ...prevState,
hideWarnings: api.getConfiguration('hideWarnings') || false, hideWarnings: api.getAppParameter('hideWarnings') as boolean || false,
autoCompile: typeof autoCompile === 'boolean' ? autoCompile : api.getConfiguration('autoCompile') || false, autoCompile: api.getAppParameter('autoCompile') as boolean || false,
includeNightlies: api.getConfiguration('includeNightlies') || false, includeNightlies: api.getAppParameter('includeNightlies') as boolean || false,
optimize: (optimize !== null) && (optimize !== undefined) ? optimize : false, optimize: optimize,
runs: (runs !== null) && (runs !== 'null') && (runs !== undefined) && (runs !== 'undefined') ? runs : 200, runs: runs,
evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default' evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default'
} }
}) })
@ -154,7 +154,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
allVersions = [...allVersions, ...versions] allVersions = [...allVersions, ...versions]
selectedVersion = state.defaultVersion selectedVersion = state.defaultVersion
if (api.getParameters().version) selectedVersion = api.getParameters().version if (api.getCompilerParameters().version) selectedVersion = api.getCompilerParameters().version
// Check if version is a URL and corresponding filename starts with 'soljson' // Check if version is a URL and corresponding filename starts with 'soljson'
if (selectedVersion.startsWith('https://')) { if (selectedVersion.startsWith('https://')) {
const urlArr = selectedVersion.split('/') const urlArr = selectedVersion.split('/')
@ -229,8 +229,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}) })
} }
const isSolFileSelected = (currentFile = '') => { const isSolFileSelected = (currentFile: string = '') => {
if (!currentFile) currentFile = api.getConfiguration('currentFile') if (!currentFile) currentFile = api.getAppParameter('currentFile') as string
if (!currentFile) return false if (!currentFile) return false
const extention = currentFile.substr(currentFile.length - 3, currentFile.length) const extention = currentFile.substr(currentFile.length - 3, currentFile.length)
return extention.toLowerCase() === 'sol' || extention.toLowerCase() === 'yul' return extention.toLowerCase() === 'sol' || extention.toLowerCase() === 'yul'
@ -299,7 +299,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
} }
const compile = () => { const compile = () => {
const currentFile = api.getConfiguration('currentFile') const currentFile = api.getAppParameter('currentFile') as string
if (!isSolFileSelected()) return if (!isSolFileSelected()) return
@ -323,7 +323,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}) })
} }
updateCurrentVersion(selectedVersion) updateCurrentVersion(selectedVersion)
api.setParameters({ version: selectedVersion }) api.setCompilerParameters({ version: selectedVersion })
let url let url
if (customUrl !== '') { if (customUrl !== '') {
@ -333,7 +333,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}) })
updateCurrentVersion(selectedVersion) updateCurrentVersion(selectedVersion)
url = customUrl url = customUrl
api.setParameters({ version: selectedVersion }) api.setCompilerParameters({ version: selectedVersion })
} else { } else {
if (helper.checkSpecialChars(selectedVersion)) { if (helper.checkSpecialChars(selectedVersion)) {
return console.log('loading ' + selectedVersion + ' not allowed, special chars not allowed.') return console.log('loading ' + selectedVersion + ' not allowed, special chars not allowed.')
@ -404,7 +404,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const handleAutoCompile = (e) => { const handleAutoCompile = (e) => {
const checked = e.target.checked const checked = e.target.checked
api.setConfiguration('autoCompile', checked) api.setAppParameter('autoCompile', checked)
checked && compile() checked && compile()
setState(prevState => { setState(prevState => {
return { ...prevState, autoCompile: checked } return { ...prevState, autoCompile: checked }
@ -414,7 +414,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const handleOptimizeChange = (value) => { const handleOptimizeChange = (value) => {
const checked = !!value const checked = !!value
api.setConfiguration('optimise', checked) api.setAppParameter('optimize', checked)
compileTabLogic.setOptimize(checked) compileTabLogic.setOptimize(checked)
if (compileTabLogic.optimize) { if (compileTabLogic.optimize) {
compileTabLogic.setRuns(parseInt(state.runs)) compileTabLogic.setRuns(parseInt(state.runs))
@ -423,7 +423,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
} }
state.autoCompile && compile() state.autoCompile && compile()
setState(prevState => { setState(prevState => {
return { ...prevState, optimise: checked } return { ...prevState, optimize: checked }
}) })
} }
@ -440,7 +440,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const handleHideWarningsChange = (e) => { const handleHideWarningsChange = (e) => {
const checked = e.target.checked const checked = e.target.checked
api.setConfiguration('hideWarnings', checked) api.setAppParameter('hideWarnings', checked)
state.autoCompile && compile() state.autoCompile && compile()
setState(prevState => { setState(prevState => {
return { ...prevState, hideWarnings: checked } return { ...prevState, hideWarnings: checked }
@ -451,7 +451,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const checked = e.target.checked const checked = e.target.checked
if (!checked) handleLoadVersion(state.defaultVersion) if (!checked) handleLoadVersion(state.defaultVersion)
api.setConfiguration('includeNightlies', checked) api.setAppParameter('includeNightlies', checked)
setState(prevState => { setState(prevState => {
return { ...prevState, includeNightlies: checked } return { ...prevState, includeNightlies: checked }
}) })
@ -482,7 +482,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const checked = event.target.checked const checked = event.target.checked
sethhCompilation(checked) sethhCompilation(checked)
api.setHardHatCompilation(checked) api.setAppParameter('hardhat-compilation', checked)
} }
/* /*
@ -553,7 +553,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
</div> </div>
<div className="mt-2 remixui_compilerConfig custom-control custom-checkbox"> <div className="mt-2 remixui_compilerConfig custom-control custom-checkbox">
<div className="justify-content-between align-items-center d-flex"> <div className="justify-content-between align-items-center d-flex">
<input onChange={(e) => { handleOptimizeChange(e.target.checked) }} className="custom-control-input" id="optimize" type="checkbox" checked={state.optimise} /> <input onChange={(e) => { handleOptimizeChange(e.target.checked) }} className="custom-control-input" id="optimize" type="checkbox" checked={state.optimize} />
<label className="form-check-label custom-control-label" htmlFor="optimize">Enable optimization</label> <label className="form-check-label custom-control-label" htmlFor="optimize">Enable optimization</label>
<input <input
min="1" min="1"
@ -564,7 +564,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
type="number" type="number"
title="Estimated number of times each opcode of the deployed code will be executed across the life-time of the contract." title="Estimated number of times each opcode of the deployed code will be executed across the life-time of the contract."
onChange={(e) => onChangeRuns(e.target.value)} onChange={(e) => onChangeRuns(e.target.value)}
disabled={!state.optimise} disabled={!state.optimize}
/> />
</div> </div>
</div> </div>
@ -574,7 +574,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
</div> </div>
</div> </div>
{ {
api.isHardHatProject && isHardhatProject &&
<div className="mt-3 remixui_compilerConfig custom-control custom-checkbox"> <div className="mt-3 remixui_compilerConfig custom-control custom-checkbox">
<input className="remixui_autocompile custom-control-input" onChange={updatehhCompilation} id="enableHardhat" type="checkbox" title="Enable Hardhat Compilation" checked={hhCompilation} /> <input className="remixui_autocompile custom-control-input" onChange={updatehhCompilation} id="enableHardhat" type="checkbox" title="Enable Hardhat Compilation" checked={hhCompilation} />
<label className="form-check-label custom-control-label" htmlFor="enableHardhat">Enable Hardhat Compilation</label> <label className="form-check-label custom-control-label" htmlFor="enableHardhat">Enable Hardhat Compilation</label>

@ -1,3 +1,5 @@
import { ICompilerApi } from '@remix-project/remix-lib-ts'
const Compiler = require('@remix-project/remix-solidity').Compiler const Compiler = require('@remix-project/remix-solidity').Compiler
const EventEmitter = require('events') const EventEmitter = require('events')
@ -8,7 +10,7 @@ declare global {
} }
const _paq = window._paq = window._paq || [] //eslint-disable-line const _paq = window._paq = window._paq || [] //eslint-disable-line
export class CompileTab { export class CompileTabLogic {
public compiler public compiler
public optimize public optimize
public runs public runs
@ -16,45 +18,44 @@ export class CompileTab {
public compilerImport public compilerImport
public event public event
constructor (public api, public contentImport) { constructor (public api: ICompilerApi, public contentImport) {
this.event = new EventEmitter() this.event = new EventEmitter()
this.compiler = new Compiler((url, cb) => api.resolveContentAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message))) this.compiler = new Compiler((url, cb) => api.resolveContentAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message)))
} }
init () { init () {
this.optimize = this.api.getParameters().optimize this.optimize = this.api.getCompilerParameters().optimize
this.optimize = this.optimize === 'true' this.api.setCompilerParameters({ optimize: this.optimize })
this.api.setParameters({ optimize: this.optimize })
this.compiler.set('optimize', this.optimize) this.compiler.set('optimize', this.optimize)
this.runs = this.api.getParameters().runs this.runs = this.api.getCompilerParameters().runs
this.runs = this.runs && this.runs !== 'undefined' ? this.runs : 200 this.runs = this.runs && this.runs !== 'undefined' ? this.runs : 200
this.api.setParameters({ runs: this.runs }) this.api.setCompilerParameters({ runs: this.runs })
this.compiler.set('runs', this.runs) this.compiler.set('runs', this.runs)
this.evmVersion = this.api.getParameters().evmVersion this.evmVersion = this.api.getCompilerParameters().evmVersion
if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) { if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) {
this.evmVersion = null this.evmVersion = null
} }
this.api.setParameters({ evmVersion: this.evmVersion }) this.api.setCompilerParameters({ evmVersion: this.evmVersion })
this.compiler.set('evmVersion', this.evmVersion) this.compiler.set('evmVersion', this.evmVersion)
} }
setOptimize (newOptimizeValue) { setOptimize (newOptimizeValue) {
this.optimize = newOptimizeValue this.optimize = newOptimizeValue
this.api.setParameters({ optimize: this.optimize }) this.api.setCompilerParameters({ optimize: this.optimize })
this.compiler.set('optimize', this.optimize) this.compiler.set('optimize', this.optimize)
} }
setRuns (runs) { setRuns (runs) {
this.runs = runs this.runs = runs
this.api.setParameters({ runs: this.runs }) this.api.setCompilerParameters({ runs: this.runs })
this.compiler.set('runs', this.runs) this.compiler.set('runs', this.runs)
} }
setEvmVersion (newEvmVersion) { setEvmVersion (newEvmVersion) {
this.evmVersion = newEvmVersion this.evmVersion = newEvmVersion
this.api.setParameters({ evmVersion: this.evmVersion }) this.api.setCompilerParameters({ evmVersion: this.evmVersion })
this.compiler.set('evmVersion', this.evmVersion) this.compiler.set('evmVersion', this.evmVersion)
} }
@ -122,7 +123,7 @@ export class CompileTab {
// TODO readd saving current file // TODO readd saving current file
// this.api.saveCurrentFile() // this.api.saveCurrentFile()
this.event.emit('removeAnnotations') this.event.emit('removeAnnotations')
var currentFile = this.api.getConfiguration('currentFile') var currentFile = this.api.getAppParameter('currentFile')
return this.compileFile(currentFile) return this.compileFile(currentFile)
} catch (err) { } catch (err) {
console.error(err) console.error(err)

@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer' // eslint-disable-line
import './css/style.css' import './css/style.css'
export const SolidityCompiler = (props: SolidityCompilerProps) => { export const SolidityCompiler = (props: SolidityCompilerProps) => {
const { plugin, plugin: { currentFile, compileTabLogic, contractsDetails, contractMap, compileErrors, configurationSettings } } = props const { api, api: { currentFile, compileTabLogic, contractsDetails, contractMap, compileErrors, configurationSettings } } = props
const [state, setState] = useState({ const [state, setState] = useState({
isHardhatProject: false, isHardhatProject: false,
currentFile, currentFile,
@ -32,32 +32,32 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
}) })
const [currentVersion, setCurrentVersion] = useState('') const [currentVersion, setCurrentVersion] = useState('')
plugin.onCurrentFileChanged = (currentFile: string) => { api.onCurrentFileChanged = (currentFile: string) => {
setState(prevState => { setState(prevState => {
return { ...prevState, currentFile } return { ...prevState, currentFile }
}) })
} }
plugin.onResetResults = () => { api.onResetResults = () => {
setState(prevState => { setState(prevState => {
return { ...prevState, currentFile: '', contractsDetails: {}, contractMap: {} } return { ...prevState, currentFile: '', contractsDetails: {}, contractMap: {} }
}) })
} }
plugin.onSetWorkspace = async (isLocalhost: boolean) => { api.onSetWorkspace = async (isLocalhost: boolean) => {
const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject() const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject()
setState(prevState => { setState(prevState => {
return { ...prevState, currentFile, isHardhatProject: isHardhat } return { ...prevState, currentFile, isHardhatProject: isHardhat }
}) })
} }
plugin.onNoFileSelected = () => { api.onNoFileSelected = () => {
setState(prevState => { setState(prevState => {
return { ...prevState, currentFile: '' } return { ...prevState, currentFile: '' }
}) })
} }
plugin.onCompilationFinished = (contractsDetails: any, contractMap: any) => { api.onCompilationFinished = (contractsDetails: any, contractMap: any) => {
setState(prevState => { setState(prevState => {
return { ...prevState, contractsDetails, contractMap } return { ...prevState, contractsDetails, contractMap }
}) })
@ -71,7 +71,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const updateCurrentVersion = (value) => { const updateCurrentVersion = (value) => {
setCurrentVersion(value) setCurrentVersion(value)
plugin.setParameters({ version: value }) api.setCompilerParameters({ version: value })
} }
const modal = async (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => { const modal = async (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => {
@ -111,19 +111,19 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
return ( return (
<> <>
<div id="compileTabView"> <div id="compileTabView">
<CompilerContainer api={plugin} isHardhatProject={state.isHardhatProject} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} updateCurrentVersion={updateCurrentVersion} configurationSettings={configurationSettings} /> <CompilerContainer api={api} isHardhatProject={state.isHardhatProject} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} updateCurrentVersion={updateCurrentVersion} configurationSettings={configurationSettings} />
<ContractSelection api={plugin} contractMap={contractMap} contractsDetails={contractsDetails} modal={modal} /> <ContractSelection api={api} contractMap={contractMap} 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 }} /> } { compileErrors.error && <Renderer message={compileErrors.error.formattedMessage || compileErrors.error} plugin={api} opt={{ type: compileErrors.error.severity || 'error', errorType: compileErrors.error.type }} /> }
{ 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, index) => { { compileErrors.errors && compileErrors.errors.length && compileErrors.errors.map((err, index) => {
if (plugin.getConfiguration('hideWarnings')) { if (api.getAppParameter('hideWarnings')) {
if (err.severity !== 'warning') { if (err.severity !== 'warning') {
return <Renderer key={index} message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} /> return <Renderer key={index} message={err.formattedMessage} plugin={api} opt={{ type: err.severity, errorType: err.type }} />
} }
} else { } else {
return <Renderer key={index} message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} /> return <Renderer key={index} message={err.formattedMessage} plugin={api} opt={{ type: err.severity, errorType: err.type }} />
} }
}) } }) }
</div> </div>

@ -1,13 +1,14 @@
import { ICompilerApi, ConfigurationSettings } from '@remix-project/remix-lib-ts' import { ICompilerApi, ConfigurationSettings } from '@remix-project/remix-lib-ts'
import { CompileTabLogic } from '../logic/compileTabLogic'
export type onCurrentFileChanged = (fileName: string) => void export type onCurrentFileChanged = (fileName: string) => void
export interface SolidityCompilerProps { export interface SolidityCompilerProps {
plugin: ICompilerApi api: ICompilerApi
} }
export interface CompilerContainerProps { export interface CompilerContainerProps {
api: any, api: ICompilerApi,
compileTabLogic: any, compileTabLogic: CompileTabLogic,
isHardhatProject: boolean, isHardhatProject: boolean,
tooltip: (message: string | JSX.Element) => void, tooltip: (message: string | JSX.Element) => void,
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,
@ -16,7 +17,7 @@ export interface CompilerContainerProps {
configurationSettings: ConfigurationSettings configurationSettings: ConfigurationSettings
} }
export interface ContractSelectionProps { export interface ContractSelectionProps {
api: any, api: ICompilerApi,
contractMap: { contractMap: {
file: string file: string
} | Record<string, any>, } | Record<string, any>,

Loading…
Cancel
Save