From 964ac4905c20fe3c8cf1d08c6d2b845fd50199aa Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 17 Aug 2021 12:32:51 +0200 Subject: [PATCH] remove fileManager dep --- apps/remix-ide/src/app/tabs/compile-tab.js | 36 +++++++++++++++++-- .../src/lib/publish-to-storage.tsx | 6 ++-- .../src/lib/publishOnSwarm.tsx | 20 +++++------ .../src/lib/publishToIPFS.tsx | 20 +++++------ .../publish-to-storage/src/lib/types/index.ts | 1 - libs/remix-ui/renderer/src/lib/renderer.tsx | 7 ++-- .../src/lib/compiler-container.tsx | 2 +- .../src/lib/contract-selection.tsx | 4 +-- .../src/lib/logic/compileTabLogic.ts | 14 ++++---- .../src/lib/solidity-compiler.tsx | 10 +++--- .../solidity-compiler/src/lib/types/index.ts | 2 -- 11 files changed, 72 insertions(+), 50 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/compile-tab.js b/apps/remix-ide/src/app/tabs/compile-tab.js index 1efa35ffdb..5ed189813f 100644 --- a/apps/remix-ide/src/app/tabs/compile-tab.js +++ b/apps/remix-ide/src/app/tabs/compile-tab.js @@ -52,9 +52,7 @@ class CompileTab extends ViewPlugin { eventHandlers: {}, loading: false } - this.compileTabLogic = new CompileTabLogic(this, - this.fileManager, - this.contentImport) + this.compileTabLogic = new CompileTabLogic(this, this.contentImport) this.compiler = this.compileTabLogic.compiler this.compileTabLogic.init() this.contractMap = {} @@ -292,6 +290,38 @@ class CompileTab extends ViewPlugin { this.config.set(name, value) } + readFile (fileName) { + return this.call('fileManager', 'readFile', fileName) + } + + fileProviderOf (fileName) { + return this.fileManager.fileProviderOf(fileName) + } + + getFileManagerMode () { + return this.fileManager.mode + } + + fileExists (fileName) { + return this.call('fileManager', 'exists', fileName) + } + + writeFile (fileName, content) { + return this.call('fileManager', 'writeFile', fileName, content) + } + + readFile (fileName) { + return this.call('fileManager', 'readFile', fileName) + } + + saveCurrentFile () { + return this.fileManager.saveCurrentFile() + } + + open (fileName) { + return this.call('fileManager', 'open', fileName) + } + onActivation () { this.call('manager', 'activatePlugin', 'solidity-logic') this.listenToEvents() diff --git a/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx b/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx index f34ab4393b..f8f5878aa0 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx @@ -5,7 +5,7 @@ import { publishToIPFS } from './publishToIPFS' import { publishToSwarm } from './publishOnSwarm' export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { - const { api, storage, fileManager, contract, resetStorage } = props + const { api, storage, contract, resetStorage } = props const [state, setState] = useState({ modal: { title: '', @@ -25,7 +25,7 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { } else { if (storage === 'swarm') { try { - const result = await publishToSwarm(contract, fileManager) + const result = await publishToSwarm(contract, api) modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) // triggered each time there's a new verified publish (means hash correspond) @@ -39,7 +39,7 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { } } else { try { - const result = await publishToIPFS(contract, fileManager) + const result = await publishToIPFS(contract, api) modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) // triggered each time there's a new verified publish (means hash correspond) diff --git a/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx b/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx index 785d00b895..a8a39343a9 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx @@ -2,7 +2,7 @@ import swarm from 'swarmgw' const swarmgw = swarm() -export const publishToSwarm = async (contract, fileManager) => { +export const publishToSwarm = async (contract, api) => { // gather list of files to publish const sources = [] let metadata @@ -38,16 +38,14 @@ export const publishToSwarm = async (contract, fileManager) => { throw new Error('Error while extracting the hash from metadata.json') } - fileManager.fileProviderOf(fileName).get(fileName, (error, content) => { - if (error) { - console.log(error) - } else { - sources.push({ - content: content, - hash: hash, - filename: fileName - }) - } + api.readFile(fileName).then((content) => { + sources.push({ + content: content, + hash: hash, + filename: fileName + }) + }).catch((error) => { + console.log(error) }) })) // publish the list of sources in order, fail if any failed diff --git a/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx b/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx index 8b9a369565..605157c552 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx @@ -6,7 +6,7 @@ const ipfsNodes = [ new IpfsClient({ host: '127.0.0.1', port: 5001, protocol: 'http' }) ] -export const publishToIPFS = async (contract, fileManager) => { +export const publishToIPFS = async (contract, api) => { // gather list of files to publish const sources = [] let metadata @@ -42,16 +42,14 @@ export const publishToIPFS = async (contract, fileManager) => { throw new Error('Error while extracting the hash from metadata.json') } - fileManager.fileProviderOf(fileName).get(fileName, (error, content) => { - if (error) { - console.log(error) - } else { - sources.push({ - content: content, - hash: hash, - filename: fileName - }) - } + api.readFile(fileName).then((content) => { + sources.push({ + content: content, + hash: hash, + filename: fileName + }) + }).catch((error) => { + console.log(error) }) })) // publish the list of sources in order, fail if any failed diff --git a/libs/remix-ui/publish-to-storage/src/lib/types/index.ts b/libs/remix-ui/publish-to-storage/src/lib/types/index.ts index 75b29bb1ba..53a351baee 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/types/index.ts +++ b/libs/remix-ui/publish-to-storage/src/lib/types/index.ts @@ -1,7 +1,6 @@ export interface RemixUiPublishToStorageProps { api: any, storage: string, - fileManager: any, contract: any, resetStorage: () => void } diff --git a/libs/remix-ui/renderer/src/lib/renderer.tsx b/libs/remix-ui/renderer/src/lib/renderer.tsx index 4dbce52da8..8b4799a4f0 100644 --- a/libs/remix-ui/renderer/src/lib/renderer.tsx +++ b/libs/remix-ui/renderer/src/lib/renderer.tsx @@ -4,10 +4,9 @@ interface RendererProps { message: any; opt?: any, plugin: any, - fileManager: any } -export const Renderer = ({ message, opt = {}, fileManager, plugin }: RendererProps) => { +export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => { const [messageText, setMessageText] = useState(null) const [editorOptions, setEditorOptions] = useState({ useSpan: false, @@ -95,10 +94,10 @@ export const Renderer = ({ message, opt = {}, fileManager, plugin }: RendererPro const _errorClick = (errFile, errLine, errCol) => { if (errFile !== plugin.getConfiguration('currentFile')) { // TODO: refactor with this._components.contextView.jumpTo - const provider = fileManager.fileProviderOf(errFile) + const provider = plugin.fileProviderOf(errFile) if (provider) { provider.exists(errFile).then(() => { - fileManager.open(errFile) + plugin.open(errFile) plugin.call('editor', 'gotoLine', errLine, errCol) }).catch(error => { if (error) return console.log(error) diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index b63213d364..6e59535a4a 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -197,7 +197,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { // Load solc compiler version according to pragma in contract file const _setCompilerVersionFromPragma = (filename: string) => { if (!state.allversions) return - compileTabLogic.fileManager.readFile(filename).then(data => { + api.readFile(filename).then(data => { const pragmaArr = data.match(/(pragma solidity (.+?);)/g) if (pragmaArr && pragmaArr.length === 1) { const pragmaStr = pragmaArr[0].replace('pragma solidity', '').trim() 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 41ebb0ece8..7b85038aa6 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx @@ -7,7 +7,7 @@ import { CopyToClipboard } from '@remix-ui/clipboard' // eslint-disable-line import './css/style.css' export const ContractSelection = (props: ContractSelectionProps) => { - const { api, contractMap, fileManager, contractsDetails, modal } = props + const { api, contractMap, contractsDetails, modal } = props const [contractList, setContractList] = useState([]) const [selectedContract, setSelectedContract] = useState('') const [storage, setStorage] = useState(null) @@ -234,7 +234,7 @@ export const ContractSelection = (props: ContractSelectionProps) => { No Contract Compiled Yet } - + ) } diff --git a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts index 0cced8b342..4b9be01c92 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts @@ -18,7 +18,7 @@ export class CompileTab extends Plugin { public compilerImport public event - constructor (public api, public fileManager, public contentImport) { + constructor (public api, public contentImport) { super(profile) this.event = new EventEmitter() this.compiler = new Compiler((url, cb) => this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))) @@ -79,7 +79,7 @@ export class CompileTab extends Plugin { */ compileFile (target) { if (!target) throw new Error('No target provided for compiliation') - const provider = this.fileManager.fileProviderOf(target) + const provider = this.api.fileProviderOf(target) if (!provider) throw new Error(`cannot compile ${target}. Does not belong to any explorer`) return new Promise((resolve, reject) => { provider.get(target, (error, content) => { @@ -93,14 +93,14 @@ export class CompileTab extends Plugin { } async isHardhatProject () { - if (this.fileManager.mode === 'localhost') { - return await this.fileManager.exists('hardhat.config.js') + if (this.api.getFileManagerMode() === 'localhost') { + return await this.api.fileExists('hardhat.config.js') } else return false } runCompiler (hhCompilation) { try { - if (this.fileManager.mode === 'localhost' && hhCompilation) { + if (this.api.getFileManagerMode() === 'localhost' && hhCompilation) { const { currentVersion, optimize, runs } = this.compiler.state if (currentVersion) { const fileContent = `module.exports = { @@ -114,7 +114,7 @@ export class CompileTab extends Plugin { } ` const configFilePath = 'remix-compiler.config.js' - this.fileManager.setFileContent(configFilePath, fileContent) + this.api.writeFile(configFilePath, fileContent) this.call('hardhat', 'compile', configFilePath).then((result) => { this.call('terminal', 'log', { type: 'info', value: result }) }).catch((error) => { @@ -122,7 +122,7 @@ export class CompileTab extends Plugin { }) } } - this.fileManager.saveCurrentFile() + this.api.saveCurrentFile() this.event.emit('removeAnnotations') var currentFile = this.api.getConfiguration('currentFile') return this.compileFile(currentFile) 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 764a728f9f..13e0ac9352 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx @@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer' // eslint-disable-line import './css/style.css' export const SolidityCompiler = (props: SolidityCompilerProps) => { - const { plugin, plugin: { compileTabLogic, fileManager, contractsDetails, contractMap, compileErrors, isHardHatProject, setHardHatCompilation, configurationSettings } } = props + const { plugin, plugin: { compileTabLogic, contractsDetails, contractMap, compileErrors, isHardHatProject, setHardHatCompilation, configurationSettings } } = props const [state, setState] = useState({ contractsDetails: {}, eventHandlers: {}, @@ -80,18 +80,18 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { <>
- +
- { compileErrors.error && } + { compileErrors.error && } { compileErrors.error && (compileErrors.error.mode === 'panic') && modal('Error', panicMessage(compileErrors.error.formattedMessage), 'Close', null) } { compileErrors.errors && compileErrors.errors.length && compileErrors.errors.map((err, index) => { if (plugin.getConfiguration('hideWarnings')) { if (err.severity !== 'warning') { - return + return } } else { - return + return } }) }
diff --git a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts index fedaaab6e1..3987e3a0c3 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts @@ -7,7 +7,6 @@ export interface SolidityCompilerProps { isHardHatProject: boolean, compileTabLogic: any, contractsDetails: Record, - fileManager: any, contentImport: any, call: (...args) => void on: (...args) => void, @@ -35,7 +34,6 @@ export interface ContractSelectionProps { contractMap: { file: string } | Record, - fileManager: any, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, contractsDetails: Record }