diff --git a/apps/remix-ide/src/app/tabs/compile-tab.js b/apps/remix-ide/src/app/tabs/compile-tab.js index 262d64f6e5..9e7094317e 100644 --- a/apps/remix-ide/src/app/tabs/compile-tab.js +++ b/apps/remix-ide/src/app/tabs/compile-tab.js @@ -86,6 +86,7 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA } getFileManagerMode () { + this.emit() return this.fileManager.mode } diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index b3d46a4712..a4fe434ef1 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -22,6 +22,7 @@ export const CompilerApiMixin = (Base) => class extends Base { onSessionSwitched: () => void onContentChanged: () => void onFileClosed: (name: string) => void + statusChanged: (data: { key: string, title?: string, type?: string }) => void initCompilerApi () { this.configurationSettings = null @@ -190,31 +191,31 @@ export const CompilerApiMixin = (Base) => class extends Base { resetResults () { this.currentFile = '' this.contractsDetails = {} - this.emit('statusChanged', { key: 'none' }) + this.statusChanged({ key: 'none' }) if (this.onResetResults) this.onResetResults() } listenToEvents () { this.on('editor', 'contentChanged', () => { - this.emit('statusChanged', { key: 'edited', title: 'the content has changed, needs recompilation', type: 'info' }) + this.statusChanged({ key: 'edited', title: 'the content has changed, needs recompilation', type: 'info' }) if (this.onContentChanged) this.onContentChanged() }) this.data.eventHandlers.onLoadingCompiler = (url) => { this.data.loading = true this.data.loadingUrl = url - this.emit('statusChanged', { key: 'loading', title: 'loading compiler...', type: 'info' }) + this.statusChanged({ key: 'loading', title: 'loading compiler...', type: 'info' }) } this.compiler.event.register('loadingCompiler', this.data.eventHandlers.onLoadingCompiler) this.data.eventHandlers.onCompilerLoaded = () => { this.data.loading = false - this.emit('statusChanged', { key: 'none' }) + this.statusChanged({ key: 'none' }) } this.compiler.event.register('compilerLoaded', this.data.eventHandlers.onCompilerLoaded) this.data.eventHandlers.onStartingCompilation = () => { - this.emit('statusChanged', { key: 'loading', title: 'compiling...', type: 'info' }) + this.statusChanged({ key: 'loading', title: 'compiling...', type: 'info' }) } this.data.eventHandlers.onRemoveAnnotations = () => { @@ -262,12 +263,12 @@ export const CompilerApiMixin = (Base) => class extends Base { // forwarding the event to the appManager infra this.emit('compilationFinished', source.target, source, 'soljson', data) if (data.errors && data.errors.length > 0) { - this.emit('statusChanged', { + this.statusChanged({ key: data.errors.length, title: `compilation finished successful with warning${data.errors.length > 1 ? 's' : ''}`, type: 'warning' }) - } else this.emit('statusChanged', { key: 'succeed', title: 'compilation successful', type: 'success' }) + } else this.statusChanged({ key: 'succeed', title: 'compilation successful', type: 'success' }) // Store the contracts this.contractsDetails = {} this.compiler.visitContracts((contract) => { @@ -279,7 +280,7 @@ export const CompilerApiMixin = (Base) => class extends Base { }) } else { const count = (data.errors ? data.errors.filter(error => error.severity === 'error').length : 0 + (data.error ? 1 : 0)) - this.emit('statusChanged', { key: count, title: `compilation failed with ${count} error${count > 1 ? 's' : ''}`, type: 'error' }) + this.statusChanged({ key: count, title: `compilation failed with ${count} error${count > 1 ? 's' : ''}`, type: 'error' }) } // Update contract Selection this.contractMap = {} diff --git a/libs/remix-lib/src/types/ICompilerApi.ts b/libs/remix-lib/src/types/ICompilerApi.ts index 4cdea95799..7daa74e7cf 100644 --- a/libs/remix-lib/src/types/ICompilerApi.ts +++ b/libs/remix-lib/src/types/ICompilerApi.ts @@ -38,6 +38,8 @@ export interface ICompilerApi { logToTerminal: (log: terminalLog) => void compileWithHardhat: (configPath: string) => Promise + statusChanged: (data: { key: string, title?: string, type?: string }) => void, + emit: (key: string, ...payload: any) => void } export type terminalLog = { diff --git a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx index a478b592cd..d60ce9c0d9 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx @@ -33,6 +33,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { const [currentVersion, setCurrentVersion] = useState('') const [hideWarnings, setHideWarnings] = useState(false) const [compileErrors, setCompileErrors] = useState>({ [currentFile]: api.compileErrors }) + const [badgeStatus, setBadgeStatus] = useState>({}) useEffect(() => { (async () => { @@ -41,6 +42,14 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { })() }, []) + useEffect(() => { + if (badgeStatus[currentFile]) { + api.emit('statusChanged', badgeStatus[currentFile]) + } else { + api.emit('statusChanged', { key: 'none' }) + } + }, [badgeStatus[currentFile], currentFile]) + api.onCurrentFileChanged = (currentFile: string) => { setState(prevState => { return { ...prevState, currentFile } @@ -75,7 +84,14 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { } api.onFileClosed = (name) => { - if (name === currentFile) setCompileErrors({ ...compileErrors, [currentFile]: {} as CompileErrors }) + if (name === currentFile) { + setCompileErrors({ ...compileErrors, [currentFile]: {} as CompileErrors }) + setBadgeStatus({ ...badgeStatus, [currentFile]: { key: 'none' } }) + } + } + + api.statusChanged = (data: { key: string, title?: string, type?: string }) => { + setBadgeStatus({ ...badgeStatus, [currentFile]: data }) } const toast = (message: string) => {