Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
c4013fd0
Commit
c4013fd0
authored
Sep 07, 2021
by
yann300
Committed by
davidzagi93@gmail.com
Sep 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor ICompilerAPI
parent
e804389d
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
166 additions
and
150 deletions
+166
-150
app.js
apps/remix-ide/src/app.js
+1
-1
fileManager.js
apps/remix-ide/src/app/files/fileManager.js
+1
-1
compile-tab.js
apps/remix-ide/src/app/tabs/compile-tab.js
+32
-7
app.tsx
apps/solidity-compiler/src/app/app.tsx
+1
-1
compiler-api.ts
apps/solidity-compiler/src/app/compiler-api.ts
+24
-31
compiler.ts
apps/solidity-compiler/src/app/compiler.ts
+28
-43
ICompilerApi.ts
libs/remix-lib/src/types/ICompilerApi.ts
+17
-6
renderer.tsx
libs/remix-ui/renderer/src/lib/renderer.tsx
+2
-2
compiler.ts
libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts
+2
-2
compiler-container.tsx
...remix-ui/solidity-compiler/src/lib/compiler-container.tsx
+26
-26
compileTabLogic.ts
...mix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
+14
-13
solidity-compiler.tsx
.../remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
+13
-13
index.ts
libs/remix-ui/solidity-compiler/src/lib/types/index.ts
+5
-4
No files found.
apps/remix-ide/src/app.js
View file @
c4013fd0
...
...
@@ -429,7 +429,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}
// CONTENT VIEWS & DEFAULT PLUGINS
const
compileTab
=
new
CompileTab
()
const
compileTab
=
new
CompileTab
(
registry
.
get
(
'config'
).
api
)
const
run
=
new
RunTab
(
blockchain
,
registry
.
get
(
'config'
).
api
,
...
...
apps/remix-ide/src/app/files/fileManager.js
View file @
c4013fd0
...
...
@@ -398,7 +398,7 @@ class FileManager extends Plugin {
}
fileChangedEvent
(
path
)
{
this
.
emit
(
'
currentF
ileChanged'
,
path
)
this
.
emit
(
'
f
ileChanged'
,
path
)
}
fileRenamedEvent
(
oldName
,
newName
,
isFolder
)
{
...
...
apps/remix-ide/src/app/tabs/compile-tab.js
View file @
c4013fd0
/* global */
import
React
from
'react'
// eslint-disable-line
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
{
ViewPlugin
}
from
'@remixproject/engine-web'
import
QueryParams
from
'../../lib/query-params'
// import { ICompilerApi } from '@remix-project/remix-lib-ts'
import
*
as
packageJson
from
'../../../../../package.json'
...
...
@@ -30,14 +32,19 @@ const profile = {
// - methods: ['getCompilationResult']
class
CompileTab
extends
CompilerApiMixin
(
ViewPlugin
)
{
// implements ICompilerApi
constructor
()
{
constructor
(
config
)
{
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
()
}
renderComponent
()
{
ReactDOM
.
render
(
<
SolidityCompiler
plugin
=
{
this
}
/
>
<
SolidityCompiler
api
=
{
this
}
/
>
,
this
.
el
)
}
...
...
@@ -49,10 +56,6 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA
this
.
renderComponent
()
}
setHardHatCompilation
(
value
)
{
this
.
hhCompilation
=
value
}
setSelectedVersion
(
version
)
{
this
.
selectedVersion
=
version
}
...
...
@@ -121,6 +124,28 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA
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
apps/solidity-compiler/src/app/app.tsx
View file @
c4013fd0
...
...
@@ -9,7 +9,7 @@ const remix = new CompilerClientApi()
export
const
App
=
()
=>
{
return
(
<
div
className=
"debugger"
>
<
SolidityCompiler
plugin
=
{
remix
}
/>
<
SolidityCompiler
api
=
{
remix
}
/>
</
div
>
);
};
...
...
apps/solidity-compiler/src/app/compiler-api.ts
View file @
c4013fd0
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
{
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
()
{
this
.
configurationSettings
=
null
...
...
@@ -16,9 +35,6 @@ export const CompilerApiMixin = (Base) => class extends Base {
eventHandlers
:
{},
loading
:
false
}
this
.
compileTabLogic
=
new
CompileTabLogic
(
this
,
this
.
contentImport
)
this
.
compiler
=
this
.
compileTabLogic
.
compiler
this
.
compileTabLogic
.
init
()
this
.
contractMap
=
{}
this
.
contractsDetails
=
{}
...
...
@@ -46,11 +62,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
logToTerminal
(
content
)
{
return
this
.
call
(
'terminal'
,
'log'
,
content
)
}
setHardHatCompilation
(
value
)
{
this
.
hhCompilation
=
value
}
setSelectedVersion
(
version
)
{
this
.
selectedVersion
=
version
}
...
...
@@ -102,7 +114,6 @@ export const CompilerApiMixin = (Base) => class extends Base {
}
}
/**
* set the compiler configuration
* This function is used by remix-plugin compiler API.
...
...
@@ -110,25 +121,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
*/
setCompilerConfig
(
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
()
{
return
'browser'
...
...
@@ -154,7 +147,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
this
.
currentFile
=
''
this
.
contractsDetails
=
{}
this
.
emit
(
'statusChanged'
,
{
key
:
'none'
})
if
(
this
.
onResetResults
()
)
this
.
onResetResults
()
if
(
this
.
onResetResults
)
this
.
onResetResults
()
}
listenToEvents
()
{
...
...
@@ -258,7 +251,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
// ctrl+s or command+s
if
((
e
.
metaKey
||
e
.
ctrlKey
)
&&
e
.
keyCode
===
83
)
{
e
.
preventDefault
()
this
.
compileTabLogic
.
runCompiler
(
this
.
hhCompilation
)
this
.
compileTabLogic
.
runCompiler
(
this
.
getAppParameter
(
'hardhat-compilation'
)
)
}
})
}
...
...
apps/solidity-compiler/src/app/compiler.ts
View file @
c4013fd0
...
...
@@ -16,53 +16,38 @@ const profile = {
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
{
// 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
()
{
super
()
createClient
(
this
as
any
)
this
.
compileTabLogic
=
new
CompileTabLogic
(
this
,
this
.
contentImport
)
this
.
compiler
=
this
.
compileTabLogic
.
compiler
this
.
compileTabLogic
.
init
()
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
)
{}
}
libs/remix-lib/src/types/ICompilerApi.ts
View file @
c4013fd0
...
...
@@ -8,11 +8,12 @@ export interface ICompilerApi {
contractsDetails
:
Record
<
string
,
any
>
configurationSettings
:
ConfigurationSettings
setHardHatCompilation
:
(
value
:
boolean
)
=>
void
getParameters
:
()
=>
any
setParameters
:
(
params
)
=>
void
getConfiguration
:
(
value
:
string
)
=>
string
setConfiguration
:
(
name
:
string
,
value
:
string
)
=>
void
getCompilerParameters
:
()
=>
ConfigurationSettings
setCompilerParameters
:
(
ConfigurationSettings
?)
=>
void
getAppParameter
:
(
value
:
string
)
=>
string
|
boolean
setAppParameter
:
(
name
:
string
,
value
:
string
|
boolean
)
=>
void
getFileManagerMode
:
()
=>
string
setCompilerConfig
:
(
settings
:
any
)
=>
void
...
...
@@ -26,11 +27,21 @@ export interface ICompilerApi {
onSessionSwitched
:
()
=>
void
onContentChanged
:
()
=>
void
resolveContentAndSave
:
(
url
:
string
)
=>
Promise
<
string
>
fileExists
:
(
file
:
string
)
=>
Promise
<
boolean
>
writeFile
:
(
file
:
string
,
content
:
string
)
=>
Promise
<
void
>
readFile
:
(
file
:
string
)
=>
Promise
<
string
>
open
:
(
file
:
string
)
=>
void
}
logToTerminal
:
(
log
:
terminalLog
)
=>
{}
compileWithHardhat
:
(
configPath
:
string
)
=>
Promise
<
string
>
}
export
type
terminalLog
=
{
type
:
'info'
|
'error'
|
'warning'
value
:
string
}
export
interface
ConfigurationSettings
{
version
:
string
,
...
...
libs/remix-ui/renderer/src/lib/renderer.tsx
View file @
c4013fd0
...
...
@@ -69,7 +69,7 @@ export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => {
}
const
addAnnotation
=
(
file
,
error
)
=>
{
if
(
file
===
plugin
.
get
Configuration
(
'currentFile'
))
{
if
(
file
===
plugin
.
get
AppParameter
(
'currentFile'
))
{
plugin
.
call
(
'editor'
,
'addAnnotation'
,
error
,
file
)
}
}
...
...
@@ -87,7 +87,7 @@ export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => {
}
const
_errorClick
=
(
errFile
,
errLine
,
errCol
)
=>
{
if
(
errFile
!==
plugin
.
get
Configuration
(
'currentFile'
))
{
if
(
errFile
!==
plugin
.
get
AppParameter
(
'currentFile'
))
{
// TODO: refactor with this._components.contextView.jumpTo
const
provider
=
plugin
.
fileProviderOf
(
errFile
)
if
(
provider
)
{
...
...
libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts
View file @
c4013fd0
import
React
from
'react'
import
{
CompileTabLogic
}
from
'../logic/compileTabLogic'
export
const
setEditorMode
=
(
mode
:
string
)
=>
{
return
{
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
=
()
=>
{
dispatch
(
setEditorMode
(
'sessionSwitched'
))
}
...
...
libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
View file @
c4013fd0
...
...
@@ -19,11 +19,11 @@ declare global {
const
_paq
=
window
.
_paq
=
window
.
_paq
||
[]
//eslint-disable-line
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
({
hideWarnings
:
false
,
autoCompile
:
false
,
optimi
s
e
:
false
,
optimi
z
e
:
false
,
compileTimeout
:
null
,
timeout
:
300
,
allversions
:
[],
...
...
@@ -57,7 +57,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
_updateVersionSelector
(
selectedVersion
)
}
})
const
currentFileName
=
api
.
get
Configuration
(
'currentFile'
)
const
currentFileName
=
api
.
get
AppParameter
(
'currentFile'
)
as
string
currentFile
(
currentFileName
)
listenToEvents
(
compileTabLogic
,
api
)(
dispatch
)
...
...
@@ -66,19 +66,19 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
useEffect
(()
=>
{
if
(
compileTabLogic
&&
compileTabLogic
.
compiler
)
{
setState
(
prevState
=>
{
const
params
=
api
.
getParameters
()
const
optimize
=
params
.
optimize
===
'false'
?
false
:
params
.
optimize
===
'true'
?
true
:
null
const
runs
=
params
.
runs
const
params
=
api
.
get
Compiler
Parameters
()
const
optimize
=
params
.
optimize
const
runs
=
params
.
runs
as
string
const
evmVersion
=
params
.
evmVersion
const
autoCompile
=
params
.
autoCompile
===
'false'
?
false
:
params
.
autoCompile
===
'true'
?
true
:
null
return
{
...
prevState
,
hideWarnings
:
api
.
get
Configuration
(
'hideWarnings'
)
||
false
,
autoCompile
:
typeof
autoCompile
===
'boolean'
?
autoCompile
:
api
.
getConfiguration
(
'autoCompile'
)
||
false
,
includeNightlies
:
api
.
get
Configuration
(
'includeNightlies'
)
||
false
,
optimize
:
(
optimize
!==
null
)
&&
(
optimize
!==
undefined
)
?
optimize
:
fals
e
,
runs
:
(
runs
!==
null
)
&&
(
runs
!==
'null'
)
&&
(
runs
!==
undefined
)
&&
(
runs
!==
'undefined'
)
?
runs
:
200
,
hideWarnings
:
api
.
get
AppParameter
(
'hideWarnings'
)
as
boolean
||
false
,
autoCompile
:
api
.
getAppParameter
(
'autoCompile'
)
as
boolean
||
false
,
includeNightlies
:
api
.
get
AppParameter
(
'includeNightlies'
)
as
boolean
||
false
,
optimize
:
optimiz
e
,
runs
:
runs
,
evmVersion
:
(
evmVersion
!==
null
)
&&
(
evmVersion
!==
'null'
)
&&
(
evmVersion
!==
undefined
)
&&
(
evmVersion
!==
'undefined'
)
?
evmVersion
:
'default'
}
})
...
...
@@ -154,7 +154,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
allVersions
=
[...
allVersions
,
...
versions
]
selectedVersion
=
state
.
defaultVersion
if
(
api
.
get
Parameters
().
version
)
selectedVersion
=
api
.
get
Parameters
().
version
if
(
api
.
get
CompilerParameters
().
version
)
selectedVersion
=
api
.
getCompiler
Parameters
().
version
// Check if version is a URL and corresponding filename starts with 'soljson'
if
(
selectedVersion
.
startsWith
(
'https://'
))
{
const
urlArr
=
selectedVersion
.
split
(
'/'
)
...
...
@@ -229,8 +229,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
})
}
const
isSolFileSelected
=
(
currentFile
=
''
)
=>
{
if
(
!
currentFile
)
currentFile
=
api
.
get
Configuration
(
'currentFile'
)
const
isSolFileSelected
=
(
currentFile
:
string
=
''
)
=>
{
if
(
!
currentFile
)
currentFile
=
api
.
get
AppParameter
(
'currentFile'
)
as
string
if
(
!
currentFile
)
return
false
const
extention
=
currentFile
.
substr
(
currentFile
.
length
-
3
,
currentFile
.
length
)
return
extention
.
toLowerCase
()
===
'sol'
||
extention
.
toLowerCase
()
===
'yul'
...
...
@@ -299,7 +299,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}
const
compile
=
()
=>
{
const
currentFile
=
api
.
get
Configuration
(
'currentFile'
)
const
currentFile
=
api
.
get
AppParameter
(
'currentFile'
)
as
string
if
(
!
isSolFileSelected
())
return
...
...
@@ -323,7 +323,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
})
}
updateCurrentVersion
(
selectedVersion
)
api
.
setParameters
({
version
:
selectedVersion
})
api
.
set
Compiler
Parameters
({
version
:
selectedVersion
})
let
url
if
(
customUrl
!==
''
)
{
...
...
@@ -333,7 +333,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
})
updateCurrentVersion
(
selectedVersion
)
url
=
customUrl
api
.
setParameters
({
version
:
selectedVersion
})
api
.
set
Compiler
Parameters
({
version
:
selectedVersion
})
}
else
{
if
(
helper
.
checkSpecialChars
(
selectedVersion
))
{
return
console
.
log
(
'loading '
+
selectedVersion
+
' not allowed, special chars not allowed.'
)
...
...
@@ -404,7 +404,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const
handleAutoCompile
=
(
e
)
=>
{
const
checked
=
e
.
target
.
checked
api
.
set
Configuration
(
'autoCompile'
,
checked
)
api
.
set
AppParameter
(
'autoCompile'
,
checked
)
checked
&&
compile
()
setState
(
prevState
=>
{
return
{
...
prevState
,
autoCompile
:
checked
}
...
...
@@ -414,7 +414,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const
handleOptimizeChange
=
(
value
)
=>
{
const
checked
=
!!
value
api
.
set
Configuration
(
'optimis
e'
,
checked
)
api
.
set
AppParameter
(
'optimiz
e'
,
checked
)
compileTabLogic
.
setOptimize
(
checked
)
if
(
compileTabLogic
.
optimize
)
{
compileTabLogic
.
setRuns
(
parseInt
(
state
.
runs
))
...
...
@@ -423,7 +423,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}
state
.
autoCompile
&&
compile
()
setState
(
prevState
=>
{
return
{
...
prevState
,
optimi
s
e
:
checked
}
return
{
...
prevState
,
optimi
z
e
:
checked
}
})
}
...
...
@@ -440,7 +440,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const
handleHideWarningsChange
=
(
e
)
=>
{
const
checked
=
e
.
target
.
checked
api
.
set
Configuration
(
'hideWarnings'
,
checked
)
api
.
set
AppParameter
(
'hideWarnings'
,
checked
)
state
.
autoCompile
&&
compile
()
setState
(
prevState
=>
{
return
{
...
prevState
,
hideWarnings
:
checked
}
...
...
@@ -451,7 +451,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const
checked
=
e
.
target
.
checked
if
(
!
checked
)
handleLoadVersion
(
state
.
defaultVersion
)
api
.
set
Configuration
(
'includeNightlies'
,
checked
)
api
.
set
AppParameter
(
'includeNightlies'
,
checked
)
setState
(
prevState
=>
{
return
{
...
prevState
,
includeNightlies
:
checked
}
})
...
...
@@ -482,7 +482,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const
checked
=
event
.
target
.
checked
sethhCompilation
(
checked
)
api
.
set
HardHatCompilation
(
checked
)
api
.
set
AppParameter
(
'hardhat-compilation'
,
checked
)
}
/*
...
...
@@ -553,7 +553,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
</
div
>
<
div
className=
"mt-2 remixui_compilerConfig custom-control custom-checkbox"
>
<
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
.
optimi
s
e
}
/>
<
input
onChange=
{
(
e
)
=>
{
handleOptimizeChange
(
e
.
target
.
checked
)
}
}
className=
"custom-control-input"
id=
"optimize"
type=
"checkbox"
checked=
{
state
.
optimi
z
e
}
/>
<
label
className=
"form-check-label custom-control-label"
htmlFor=
"optimize"
>
Enable optimization
</
label
>
<
input
min=
"1"
...
...
@@ -564,7 +564,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
type=
"number"
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
)
}
disabled=
{
!
state
.
optimi
s
e
}
disabled=
{
!
state
.
optimi
z
e
}
/>
</
div
>
</
div
>
...
...
@@ -574,7 +574,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
</
div
>
</
div
>
{
api
.
isHardH
atProject
&&
isHardh
atProject
&&
<
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
}
/>
<
label
className=
"form-check-label custom-control-label"
htmlFor=
"enableHardhat"
>
Enable Hardhat Compilation
</
label
>
...
...
libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
View file @
c4013fd0
import
{
ICompilerApi
}
from
'@remix-project/remix-lib-ts'
const
Compiler
=
require
(
'@remix-project/remix-solidity'
).
Compiler
const
EventEmitter
=
require
(
'events'
)
...
...
@@ -8,7 +10,7 @@ declare global {
}
const
_paq
=
window
.
_paq
=
window
.
_paq
||
[]
//eslint-disable-line
export
class
CompileTab
{
export
class
CompileTab
Logic
{
public
compiler
public
optimize
public
runs
...
...
@@ -16,45 +18,44 @@ export class CompileTab {
public
compilerImport
public
event
constructor
(
public
api
,
public
contentImport
)
{
constructor
(
public
api
:
ICompilerApi
,
public
contentImport
)
{
this
.
event
=
new
EventEmitter
()
this
.
compiler
=
new
Compiler
((
url
,
cb
)
=>
api
.
resolveContentAndSave
(
url
).
then
((
result
)
=>
cb
(
null
,
result
)).
catch
((
error
)
=>
cb
(
error
.
message
)))
}
init
()
{
this
.
optimize
=
this
.
api
.
getParameters
().
optimize
this
.
optimize
=
this
.
optimize
===
'true'
this
.
api
.
setParameters
({
optimize
:
this
.
optimize
})
this
.
optimize
=
this
.
api
.
getCompilerParameters
().
optimize
this
.
api
.
setCompilerParameters
({
optimize
:
this
.
optimize
})
this
.
compiler
.
set
(
'optimize'
,
this
.
optimize
)
this
.
runs
=
this
.
api
.
getParameters
().
runs
this
.
runs
=
this
.
api
.
get
Compiler
Parameters
().
runs
this
.
runs
=
this
.
runs
&&
this
.
runs
!==
'undefined'
?
this
.
runs
:
200
this
.
api
.
setParameters
({
runs
:
this
.
runs
})
this
.
api
.
set
Compiler
Parameters
({
runs
:
this
.
runs
})
this
.
compiler
.
set
(
'runs'
,
this
.
runs
)
this
.
evmVersion
=
this
.
api
.
getParameters
().
evmVersion
this
.
evmVersion
=
this
.
api
.
get
Compiler
Parameters
().
evmVersion
if
(
this
.
evmVersion
===
'undefined'
||
this
.
evmVersion
===
'null'
||
!
this
.
evmVersion
)
{
this
.
evmVersion
=
null
}
this
.
api
.
setParameters
({
evmVersion
:
this
.
evmVersion
})
this
.
api
.
set
Compiler
Parameters
({
evmVersion
:
this
.
evmVersion
})
this
.
compiler
.
set
(
'evmVersion'
,
this
.
evmVersion
)
}
setOptimize
(
newOptimizeValue
)
{
this
.
optimize
=
newOptimizeValue
this
.
api
.
setParameters
({
optimize
:
this
.
optimize
})
this
.
api
.
set
Compiler
Parameters
({
optimize
:
this
.
optimize
})
this
.
compiler
.
set
(
'optimize'
,
this
.
optimize
)
}
setRuns
(
runs
)
{
this
.
runs
=
runs
this
.
api
.
setParameters
({
runs
:
this
.
runs
})
this
.
api
.
set
Compiler
Parameters
({
runs
:
this
.
runs
})
this
.
compiler
.
set
(
'runs'
,
this
.
runs
)
}
setEvmVersion
(
newEvmVersion
)
{
this
.
evmVersion
=
newEvmVersion
this
.
api
.
setParameters
({
evmVersion
:
this
.
evmVersion
})
this
.
api
.
set
Compiler
Parameters
({
evmVersion
:
this
.
evmVersion
})
this
.
compiler
.
set
(
'evmVersion'
,
this
.
evmVersion
)
}
...
...
@@ -122,7 +123,7 @@ export class CompileTab {
// TODO readd saving current file
// this.api.saveCurrentFile()
this
.
event
.
emit
(
'removeAnnotations'
)
var
currentFile
=
this
.
api
.
get
Configuration
(
'currentFile'
)
var
currentFile
=
this
.
api
.
get
AppParameter
(
'currentFile'
)
return
this
.
compileFile
(
currentFile
)
}
catch
(
err
)
{
console
.
error
(
err
)
...
...
libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
View file @
c4013fd0
...
...
@@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer' // eslint-disable-line
import
'./css/style.css'
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
({
isHardhatProject
:
false
,
currentFile
,
...
...
@@ -32,32 +32,32 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
})
const
[
currentVersion
,
setCurrentVersion
]
=
useState
(
''
)
plugin
.
onCurrentFileChanged
=
(
currentFile
:
string
)
=>
{
api
.
onCurrentFileChanged
=
(
currentFile
:
string
)
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
currentFile
}
})
}
plugin
.
onResetResults
=
()
=>
{
api
.
onResetResults
=
()
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
currentFile
:
''
,
contractsDetails
:
{},
contractMap
:
{}
}
})
}
plugin
.
onSetWorkspace
=
async
(
isLocalhost
:
boolean
)
=>
{
api
.
onSetWorkspace
=
async
(
isLocalhost
:
boolean
)
=>
{
const
isHardhat
=
isLocalhost
&&
await
compileTabLogic
.
isHardhatProject
()
setState
(
prevState
=>
{
return
{
...
prevState
,
currentFile
,
isHardhatProject
:
isHardhat
}
})
}
plugin
.
onNoFileSelected
=
()
=>
{
api
.
onNoFileSelected
=
()
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
currentFile
:
''
}
})
}
plugin
.
onCompilationFinished
=
(
contractsDetails
:
any
,
contractMap
:
any
)
=>
{
api
.
onCompilationFinished
=
(
contractsDetails
:
any
,
contractMap
:
any
)
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
contractsDetails
,
contractMap
}
})
...
...
@@ -71,7 +71,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const
updateCurrentVersion
=
(
value
)
=>
{
setCurrentVersion
(
value
)
plugin
.
set
Parameters
({
version
:
value
})
api
.
setCompiler
Parameters
({
version
:
value
})
}
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
(
<>
<
div
id=
"compileTabView"
>
<
CompilerContainer
api=
{
plugin
}
isHardhatProject=
{
state
.
isHardhatProject
}
compileTabLogic=
{
compileTabLogic
}
tooltip=
{
toast
}
modal=
{
modal
}
compiledFileName=
{
currentFile
}
updateCurrentVersion=
{
updateCurrentVersion
}
configurationSettings=
{
configurationSettings
}
/>
<
ContractSelection
api=
{
plugin
}
contractMap=
{
contractMap
}
contractsDetails=
{
contractsDetails
}
modal=
{
modal
}
/>
<
CompilerContainer
api=
{
api
}
isHardhatProject=
{
state
.
isHardhatProject
}
compileTabLogic=
{
compileTabLogic
}
tooltip=
{
toast
}
modal=
{
modal
}
compiledFileName=
{
currentFile
}
updateCurrentVersion=
{
updateCurrentVersion
}
configurationSettings=
{
configurationSettings
}
/>
<
ContractSelection
api=
{
api
}
contractMap=
{
contractMap
}
contractsDetails=
{
contractsDetails
}
modal=
{
modal
}
/>
<
div
className=
"remixui_errorBlobs p-4"
data
-
id=
"compiledErrors"
>
<
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
.
errors
&&
compileErrors
.
errors
.
length
&&
compileErrors
.
errors
.
map
((
err
,
index
)
=>
{
if
(
plugin
.
getConfiguration
(
'hideWarnings'
))
{
if
(
api
.
getAppParameter
(
'hideWarnings'
))
{
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
{
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
>
...
...
libs/remix-ui/solidity-compiler/src/lib/types/index.ts
View file @
c4013fd0
import
{
ICompilerApi
,
ConfigurationSettings
}
from
'@remix-project/remix-lib-ts'
import
{
CompileTabLogic
}
from
'../logic/compileTabLogic'
export
type
onCurrentFileChanged
=
(
fileName
:
string
)
=>
void
export
interface
SolidityCompilerProps
{
plugin
:
ICompilerApi
api
:
ICompilerApi
}
export
interface
CompilerContainerProps
{
api
:
any
,
compileTabLogic
:
any
,
api
:
ICompilerApi
,
compileTabLogic
:
CompileTabLogic
,
isHardhatProject
:
boolean
,
tooltip
:
(
message
:
string
|
JSX
.
Element
)
=>
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
}
export
interface
ContractSelectionProps
{
api
:
any
,
api
:
ICompilerApi
,
contractMap
:
{
file
:
string
}
|
Record
<
string
,
any
>
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment