@@ -15,12 +15,37 @@ interface CompileDropdownProps {
15
15
compiledFileName ?: string
16
16
onNotify ?: ( msg : string ) => void
17
17
onOpen ?: ( ) => void
18
- onRequestCompileAndPublish ?: ( type : string ) => void ;
18
+ onRequestCompileAndPublish ?: ( type : string ) => void
19
+ setCompileState : ( state : 'idle' | 'compiling' | 'compiled' ) => void
19
20
}
20
21
21
- export const CompileDropdown : React . FC < CompileDropdownProps > = ( { tabPath, plugin, disabled, onNotify, onOpen, onRequestCompileAndPublish, compiledFileName } ) => {
22
+ export const CompileDropdown : React . FC < CompileDropdownProps > = ( { tabPath, plugin, disabled, onNotify, onOpen, onRequestCompileAndPublish, compiledFileName, setCompileState } ) => {
22
23
const [ scriptFiles , setScriptFiles ] = useState < string [ ] > ( [ ] )
23
24
25
+ const compileThen = async ( nextAction : ( ) => void ) => {
26
+ setCompileState ( 'compiling' )
27
+
28
+ setTimeout ( async ( ) => {
29
+ plugin . once ( 'solidity' , 'compilationFinished' , ( data ) => {
30
+ const hasErrors = data . errors && data . errors . filter ( e => e . severity === 'error' ) . length > 0
31
+ if ( hasErrors ) {
32
+ setCompileState ( 'idle' )
33
+ plugin . call ( 'notification' , 'toast' , 'Compilation failed' )
34
+ } else {
35
+ setCompileState ( 'compiled' )
36
+ nextAction ( )
37
+ }
38
+ } )
39
+
40
+ try {
41
+ await plugin . call ( 'solidity' , 'compile' , tabPath )
42
+ } catch ( e ) {
43
+ console . error ( e )
44
+ setCompileState ( 'idle' )
45
+ }
46
+ } , 0 )
47
+ }
48
+
24
49
const fetchScripts = async ( ) => {
25
50
try {
26
51
let files = { }
@@ -38,33 +63,31 @@ export const CompileDropdown: React.FC<CompileDropdownProps> = ({ tabPath, plugi
38
63
}
39
64
40
65
const runScript = async ( path : string ) => {
41
- await plugin . call ( 'solidity' , 'compile' , tabPath )
42
- const content = await plugin . call ( 'fileManager' , 'readFile' , path )
43
- await plugin . call ( 'scriptRunnerBridge' , 'execute' , content , path )
44
- onNotify ?.( `Executed script: ${ path } ` )
66
+ await compileThen ( async ( ) => {
67
+ const content = await plugin . call ( 'fileManager' , 'readFile' , path )
68
+ await plugin . call ( 'scriptRunnerBridge' , 'execute' , content , path )
69
+ onNotify ?.( `Executed script: ${ path } ` )
70
+ } )
45
71
}
46
72
47
73
const runRemixAnalysis = async ( ) => {
48
74
_paq . push ( [ 'trackEvent' , 'solidityCompiler' , 'staticAnalysis' , 'initiate' ] )
49
- await plugin . call ( 'solidity' , 'compile' , tabPath )
50
- const isStaticAnalyzersActive = await plugin . call ( 'manager' , 'isActive' , 'solidityStaticAnalysis' )
51
- if ( ! isStaticAnalyzersActive ) {
52
- await plugin . call ( 'manager' , 'activatePlugin' , 'solidityStaticAnalysis' )
53
- }
54
- plugin . call ( 'menuicons' , 'select' , 'solidityStaticAnalysis' )
55
- onNotify ?.( "Ran Remix static analysis" )
75
+ await compileThen ( async ( ) => {
76
+ const isStaticAnalyzersActive = await plugin . call ( 'manager' , 'isActive' , 'solidityStaticAnalysis' )
77
+ if ( ! isStaticAnalyzersActive ) {
78
+ await plugin . call ( 'manager' , 'activatePlugin' , 'solidityStaticAnalysis' )
79
+ }
80
+ plugin . call ( 'menuicons' , 'select' , 'solidityStaticAnalysis' )
81
+ onNotify ?.( "Ran Remix static analysis" )
82
+ } )
56
83
}
57
84
58
85
const handleScanContinue = async ( ) => {
59
- await plugin . call ( 'solidity' , 'compile' , tabPath )
60
-
61
- const firstSlashIndex = compiledFileName . indexOf ( '/' ) ;
62
-
63
- const finalPath = firstSlashIndex > 0
64
- ? compiledFileName . substring ( firstSlashIndex + 1 )
65
- : compiledFileName ;
66
-
67
- await handleSolidityScan ( plugin , finalPath )
86
+ await compileThen ( async ( ) => {
87
+ const firstSlashIndex = compiledFileName . indexOf ( '/' )
88
+ const finalPath = firstSlashIndex > 0 ? compiledFileName . substring ( firstSlashIndex + 1 ) : compiledFileName
89
+ await handleSolidityScan ( plugin , finalPath )
90
+ } )
68
91
}
69
92
70
93
const runSolidityScan = async ( ) => {
0 commit comments