Skip to content

Commit 65a5de9

Browse files
committed
fix(tabs): Update compile status based on 'compilationFinished' event
1 parent 1045130 commit 65a5de9

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,54 @@ export const TabsUI = (props: TabsUIProps) => {
317317
}
318318
}
319319

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+
320368
return (
321369
<div
322370
className={`remix-ui-tabs justify-content-between border-0 header nav-tabs ${
@@ -357,24 +405,7 @@ export const TabsUI = (props: TabsUIProps) => {
357405
borderRadius: "4px 0 0 4px"
358406
}}
359407
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}
378409
>
379410
<i className={
380411
compileState === 'compiled' ? "fas fa-check"

0 commit comments

Comments
 (0)