diff --git a/apps/remix-ide/src/app/tabs/compile-tab.js b/apps/remix-ide/src/app/tabs/compile-tab.js index da85e7ea61..8e3d17e366 100644 --- a/apps/remix-ide/src/app/tabs/compile-tab.js +++ b/apps/remix-ide/src/app/tabs/compile-tab.js @@ -48,9 +48,9 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA this.renderComponent() } - onResetResults () { - this.renderComponent() - } + // onResetResults () { + // this.renderComponent() + // } onSetWorkspace () { this.renderComponent() @@ -60,6 +60,10 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA this.renderComponent() } + onFileClosed () { + this.renderComponent() + } + onCompilationFinished () { this.renderComponent() } diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 2e81d08ba1..abfe0b377b 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -4,23 +4,26 @@ import type { ConfigurationSettings } from '@remix-project/remix-lib-ts' export const CompilerApiMixin = (Base) => class extends Base { currentFile: string - contractMap: { - file: string - } | Record - + compilationDetails: { + contractMap: { + file: string + } | Record, + contractsDetails: Record, + target?: string + } compileErrors: any compileTabLogic: CompileTabLogic - contractsDetails: Record - configurationSettings: ConfigurationSettings onCurrentFileChanged: (fileName: string) => void - onResetResults: () => void + // onResetResults: () => void onSetWorkspace: (workspace: any) => void onNoFileSelected: () => void - onCompilationFinished: (contractsDetails: any, contractMap: any) => void + onCompilationFinished: (compilationDetails: { contractMap: { file: string } | Record, contractsDetails: Record }) => void onSessionSwitched: () => void onContentChanged: () => void + onFileClosed: (name: string) => void + statusChanged: (data: { key: string, title?: string, type?: string }) => void initCompilerApi () { this.configurationSettings = null @@ -31,15 +34,15 @@ export const CompilerApiMixin = (Base) => class extends Base { contractEl: null } - this.contractsDetails = {} + this.compilationDetails = { + contractsDetails:{}, + contractMap: {} + } this.data = { eventHandlers: {}, loading: false } - this.contractMap = {} - this.contractsDetails = {} - this.compileErrors = {} this.compiledFileName = '' this.currentFile = '' @@ -188,32 +191,35 @@ export const CompilerApiMixin = (Base) => class extends Base { resetResults () { this.currentFile = '' - this.contractsDetails = {} - this.emit('statusChanged', { key: 'none' }) - if (this.onResetResults) this.onResetResults() + this.compilationDetails = { + contractsDetails: {}, + contractMap: {} + } + 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 = () => { @@ -249,22 +255,28 @@ export const CompilerApiMixin = (Base) => class extends Base { } this.on('fileManager', 'noFileSelected', this.data.eventHandlers.onNoFileSelected) + this.data.eventHandlers.onFileClosed = (name: string) => { + this.onFileClosed(name) + } + + this.on('fileManager', 'fileClosed', this.data.eventHandlers.onFileClosed) + this.data.eventHandlers.onCompilationFinished = (success, data, source) => { this.compileErrors = data if (success) { // 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.compilationDetails.contractsDetails = {} this.compiler.visitContracts((contract) => { - this.contractsDetails[contract.name] = parseContracts( + this.compilationDetails.contractsDetails[contract.name] = parseContracts( contract.name, contract.object, this.compiler.getSource(contract.file) @@ -272,12 +284,13 @@ 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 = {} - if (success) this.compiler.visitContracts((contract) => { this.contractMap[contract.name] = contract }) - if (this.onCompilationFinished) this.onCompilationFinished(this.contractsDetails, this.contractMap) + this.compilationDetails.contractMap = {} + if (success) this.compiler.visitContracts((contract) => { this.compilationDetails.contractMap[contract.name] = contract }) + this.compilationDetails.target = source.target + if (this.onCompilationFinished) this.onCompilationFinished(this.compilationDetails) } this.compiler.event.register('compilationFinished', this.data.eventHandlers.onCompilationFinished) diff --git a/libs/remix-lib/src/types/ICompilerApi.ts b/libs/remix-lib/src/types/ICompilerApi.ts index 62f86b5652..4c796ee3c1 100644 --- a/libs/remix-lib/src/types/ICompilerApi.ts +++ b/libs/remix-lib/src/types/ICompilerApi.ts @@ -1,11 +1,14 @@ export interface ICompilerApi { currentFile: string - contractMap: { - file: string - } | Record + compilationDetails: { + contractMap: { + file: string + } | Record, + contractsDetails: Record, + target?: string + } compileErrors: any compileTabLogic: any - contractsDetails: Record configurationSettings: ConfigurationSettings getCompilerParameters: () => ConfigurationSettings @@ -20,12 +23,13 @@ export interface ICompilerApi { getCompilationResult: () => any onCurrentFileChanged: (fileName: string) => void - onResetResults: () => void, + // onResetResults: () => void, onSetWorkspace: (workspace: any) => void onNoFileSelected: () => void onCompilationFinished: (contractsDetails: any, contractMap: any) => void onSessionSwitched: () => void onContentChanged: () => void + onFileClosed: (name: string) => void resolveContentAndSave: (url: string) => Promise fileExists: (file: string) => Promise @@ -37,6 +41,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/modal-dialog/src/lib/remix-ui-modal-dialog.tsx b/libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx index 714255aa93..38df2fd8b8 100644 --- a/libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx +++ b/libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx @@ -37,7 +37,7 @@ export const ModalDialog = (props: ModalDialogProps) => { modal.current.addEventListener('blur', handleBlur) } return () => { - modal.current.removeEventListener('blur', handleBlur) + modal.current && modal.current.removeEventListener('blur', handleBlur) } }, [modal.current]) diff --git a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx index efac0765ec..338fe7fd7e 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx @@ -7,32 +7,18 @@ import { CopyToClipboard } from '@remix-ui/clipboard' // eslint-disable-line import './css/style.css' export const ContractSelection = (props: ContractSelectionProps) => { - const { api, contractMap, contractsDetails, modal } = props - const [contractList, setContractList] = useState([]) + const { api, contractsDetails, contractList, modal } = props const [selectedContract, setSelectedContract] = useState('') const [storage, setStorage] = useState(null) useEffect(() => { - const contractList = contractMap ? Object.keys(contractMap).map((key) => ({ - name: key, - file: getFileName(contractMap[key].file) - })) : [] - - setContractList(contractList) if (contractList.length) setSelectedContract(contractList[0].name) - }, [contractMap, contractsDetails]) + }, [contractList]) const resetStorage = () => { setStorage('') } - // Return the file name of a path: ex "browser/ballot.sol" -> "ballot.sol" - const getFileName = (path) => { - const part = path.split('/') - - return part[part.length - 1] - } - const handleContractChange = (contractName: string) => { setSelectedContract(contractName) } @@ -214,13 +200,13 @@ export const ContractSelection = (props: ContractSelectionProps) => {
- + - +