@@ -317,6 +317,54 @@ export const TabsUI = (props: TabsUIProps) => {
317
317
}
318
318
}
319
319
320
+ const handleCompileClick = async ( ) => {
321
+ setCompileState ( 'compiling' )
322
+ _paq . push ( [ 'trackEvent' , 'editor' , 'clickRunFromEditor' , tabsState . currentExt ] )
323
+
324
+ try {
325
+ const path = active ( ) . substr ( active ( ) . indexOf ( '/' ) + 1 , active ( ) . length )
326
+
327
+ if ( tabsState . currentExt === 'js' || tabsState . currentExt === 'ts' ) {
328
+ const content = await props . plugin . call ( 'fileManager' , 'readFile' , path )
329
+ await props . plugin . call ( 'scriptRunnerBridge' , 'execute' , content , path )
330
+ setCompileState ( 'compiled' )
331
+ return
332
+ }
333
+
334
+ const compilerName = {
335
+ sol : 'solidity' ,
336
+ yul : 'solidity' ,
337
+ vy : 'vyper' ,
338
+ circom : 'circuit-compiler' ,
339
+ nr : 'noir-compiler'
340
+ } [ tabsState . currentExt ]
341
+
342
+ if ( ! compilerName ) {
343
+ setCompileState ( 'idle' )
344
+ return
345
+ }
346
+
347
+ props . plugin . once ( compilerName , 'compilationFinished' , ( fileName , source , languageVersion , data ) => {
348
+ const hasErrors = data . errors && data . errors . filter ( e => e . severity === 'error' ) . length > 0
349
+
350
+ if ( hasErrors ) {
351
+ setCompileState ( 'idle' )
352
+ } else {
353
+ setCompileState ( 'compiled' )
354
+ }
355
+ } ) ;
356
+
357
+ if ( tabsState . currentExt === 'vy' ) {
358
+ await props . plugin . call ( compilerName , 'vyperCompileCustomAction' )
359
+ } else {
360
+ await props . plugin . call ( compilerName , 'compile' , path )
361
+ }
362
+ } catch ( e ) {
363
+ console . error ( e )
364
+ setCompileState ( 'idle' )
365
+ }
366
+ }
367
+
320
368
return (
321
369
< div
322
370
className = { `remix-ui-tabs justify-content-between border-0 header nav-tabs ${
@@ -357,24 +405,7 @@ export const TabsUI = (props: TabsUIProps) => {
357
405
borderRadius : "4px 0 0 4px"
358
406
} }
359
407
disabled = { ! ( PlayExtList . includes ( tabsState . currentExt ) ) || compileState === 'compiling' }
360
- onClick = { async ( ) => {
361
- setCompileState ( 'compiling' )
362
- const path = active ( ) . substr ( active ( ) . indexOf ( '/' ) + 1 , active ( ) . length )
363
- const content = await props . plugin . call ( 'fileManager' , 'readFile' , path )
364
- if ( tabsState . currentExt === 'js' || tabsState . currentExt === 'ts' ) {
365
- await props . plugin . call ( 'scriptRunnerBridge' , 'execute' , content , path )
366
- } else if ( tabsState . currentExt === 'sol' || tabsState . currentExt === 'yul' ) {
367
- await props . plugin . call ( 'solidity' , 'compile' , path )
368
- } else if ( tabsState . currentExt === 'circom' ) {
369
- await props . plugin . call ( 'circuit-compiler' , 'compile' , path )
370
- } else if ( tabsState . currentExt === 'vy' ) {
371
- await props . plugin . call ( 'vyper' , 'vyperCompileCustomAction' )
372
- } else if ( tabsState . currentExt === 'nr' ) {
373
- await props . plugin . call ( 'noir-compiler' , 'compile' , path )
374
- }
375
- setCompileState ( 'compiled' )
376
- _paq . push ( [ 'trackEvent' , 'editor' , 'clickRunFromEditor' , tabsState . currentExt ] )
377
- } }
408
+ onClick = { handleCompileClick }
378
409
>
379
410
< i className = {
380
411
compileState === 'compiled' ? "fas fa-check"
0 commit comments