remove fileManager dep

pull/1487/head
yann300 3 years ago
parent a18bc70b85
commit 0be2e2793f
  1. 36
      apps/remix-ide/src/app/tabs/compile-tab.js
  2. 6
      libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx
  3. 10
      libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx
  4. 10
      libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx
  5. 1
      libs/remix-ui/publish-to-storage/src/lib/types/index.ts
  6. 7
      libs/remix-ui/renderer/src/lib/renderer.tsx
  7. 2
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  8. 4
      libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx
  9. 14
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  10. 10
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  11. 2
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts

@ -52,9 +52,7 @@ class CompileTab extends ViewPlugin {
eventHandlers: {}, eventHandlers: {},
loading: false loading: false
} }
this.compileTabLogic = new CompileTabLogic(this, this.compileTabLogic = new CompileTabLogic(this, this.contentImport)
this.fileManager,
this.contentImport)
this.compiler = this.compileTabLogic.compiler this.compiler = this.compileTabLogic.compiler
this.compileTabLogic.init() this.compileTabLogic.init()
this.contractMap = {} this.contractMap = {}
@ -292,6 +290,38 @@ class CompileTab extends ViewPlugin {
this.config.set(name, value) 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 () { onActivation () {
this.call('manager', 'activatePlugin', 'solidity-logic') this.call('manager', 'activatePlugin', 'solidity-logic')
this.listenToEvents() this.listenToEvents()

@ -5,7 +5,7 @@ import { publishToIPFS } from './publishToIPFS'
import { publishToSwarm } from './publishOnSwarm' import { publishToSwarm } from './publishOnSwarm'
export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { export const PublishToStorage = (props: RemixUiPublishToStorageProps) => {
const { api, storage, fileManager, contract, resetStorage } = props const { api, storage, contract, resetStorage } = props
const [state, setState] = useState({ const [state, setState] = useState({
modal: { modal: {
title: '', title: '',
@ -25,7 +25,7 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => {
} else { } else {
if (storage === 'swarm') { if (storage === 'swarm') {
try { try {
const result = await publishToSwarm(contract, fileManager) const result = await publishToSwarm(contract, api)
modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded))
// triggered each time there's a new verified publish (means hash correspond) // triggered each time there's a new verified publish (means hash correspond)
@ -39,7 +39,7 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => {
} }
} else { } else {
try { try {
const result = await publishToIPFS(contract, fileManager) const result = await publishToIPFS(contract, api)
modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded))
// triggered each time there's a new verified publish (means hash correspond) // triggered each time there's a new verified publish (means hash correspond)

@ -2,7 +2,7 @@ import swarm from 'swarmgw'
const swarmgw = swarm() const swarmgw = swarm()
export const publishToSwarm = async (contract, fileManager) => { export const publishToSwarm = async (contract, api) => {
// gather list of files to publish // gather list of files to publish
const sources = [] const sources = []
let metadata let metadata
@ -38,16 +38,14 @@ export const publishToSwarm = async (contract, fileManager) => {
throw new Error('Error while extracting the hash from metadata.json') throw new Error('Error while extracting the hash from metadata.json')
} }
fileManager.fileProviderOf(fileName).get(fileName, (error, content) => { api.readFile(fileName).then((content) => {
if (error) {
console.log(error)
} else {
sources.push({ sources.push({
content: content, content: content,
hash: hash, hash: hash,
filename: fileName filename: fileName
}) })
} }).catch((error) => {
console.log(error)
}) })
})) }))
// publish the list of sources in order, fail if any failed // publish the list of sources in order, fail if any failed

@ -6,7 +6,7 @@ const ipfsNodes = [
new IpfsClient({ host: '127.0.0.1', port: 5001, protocol: 'http' }) 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 // gather list of files to publish
const sources = [] const sources = []
let metadata let metadata
@ -42,16 +42,14 @@ export const publishToIPFS = async (contract, fileManager) => {
throw new Error('Error while extracting the hash from metadata.json') throw new Error('Error while extracting the hash from metadata.json')
} }
fileManager.fileProviderOf(fileName).get(fileName, (error, content) => { api.readFile(fileName).then((content) => {
if (error) {
console.log(error)
} else {
sources.push({ sources.push({
content: content, content: content,
hash: hash, hash: hash,
filename: fileName filename: fileName
}) })
} }).catch((error) => {
console.log(error)
}) })
})) }))
// publish the list of sources in order, fail if any failed // publish the list of sources in order, fail if any failed

@ -1,7 +1,6 @@
export interface RemixUiPublishToStorageProps { export interface RemixUiPublishToStorageProps {
api: any, api: any,
storage: string, storage: string,
fileManager: any,
contract: any, contract: any,
resetStorage: () => void resetStorage: () => void
} }

@ -4,10 +4,9 @@ interface RendererProps {
message: any; message: any;
opt?: any, opt?: any,
plugin: 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 [messageText, setMessageText] = useState(null)
const [editorOptions, setEditorOptions] = useState({ const [editorOptions, setEditorOptions] = useState({
useSpan: false, useSpan: false,
@ -95,10 +94,10 @@ export const Renderer = ({ message, opt = {}, fileManager, plugin }: RendererPro
const _errorClick = (errFile, errLine, errCol) => { const _errorClick = (errFile, errLine, errCol) => {
if (errFile !== plugin.getConfiguration('currentFile')) { if (errFile !== plugin.getConfiguration('currentFile')) {
// TODO: refactor with this._components.contextView.jumpTo // TODO: refactor with this._components.contextView.jumpTo
const provider = fileManager.fileProviderOf(errFile) const provider = plugin.fileProviderOf(errFile)
if (provider) { if (provider) {
provider.exists(errFile).then(() => { provider.exists(errFile).then(() => {
fileManager.open(errFile) plugin.open(errFile)
plugin.call('editor', 'gotoLine', errLine, errCol) plugin.call('editor', 'gotoLine', errLine, errCol)
}).catch(error => { }).catch(error => {
if (error) return console.log(error) if (error) return console.log(error)

@ -197,7 +197,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
// Load solc compiler version according to pragma in contract file // Load solc compiler version according to pragma in contract file
const _setCompilerVersionFromPragma = (filename: string) => { const _setCompilerVersionFromPragma = (filename: string) => {
if (!state.allversions) return if (!state.allversions) return
compileTabLogic.fileManager.readFile(filename).then(data => { api.readFile(filename).then(data => {
const pragmaArr = data.match(/(pragma solidity (.+?);)/g) const pragmaArr = data.match(/(pragma solidity (.+?);)/g)
if (pragmaArr && pragmaArr.length === 1) { if (pragmaArr && pragmaArr.length === 1) {
const pragmaStr = pragmaArr[0].replace('pragma solidity', '').trim() const pragmaStr = pragmaArr[0].replace('pragma solidity', '').trim()

@ -7,7 +7,7 @@ import { CopyToClipboard } from '@remix-ui/clipboard' // eslint-disable-line
import './css/style.css' import './css/style.css'
export const ContractSelection = (props: ContractSelectionProps) => { export const ContractSelection = (props: ContractSelectionProps) => {
const { api, contractMap, fileManager, contractsDetails, modal } = props const { api, contractMap, contractsDetails, modal } = props
const [contractList, setContractList] = useState([]) const [contractList, setContractList] = useState([])
const [selectedContract, setSelectedContract] = useState('') const [selectedContract, setSelectedContract] = useState('')
const [storage, setStorage] = useState(null) const [storage, setStorage] = useState(null)
@ -234,7 +234,7 @@ export const ContractSelection = (props: ContractSelectionProps) => {
<span className="mt-2 mx-3 w-100 alert alert-warning" role="alert">No Contract Compiled Yet</span> <span className="mt-2 mx-3 w-100 alert alert-warning" role="alert">No Contract Compiled Yet</span>
</article></section> </article></section>
} }
<PublishToStorage api={api} storage={storage} fileManager={fileManager} contract={contractsDetails[selectedContract]} resetStorage={resetStorage} /> <PublishToStorage api={api} storage={storage} contract={contractsDetails[selectedContract]} resetStorage={resetStorage} />
</> </>
) )
} }

@ -18,7 +18,7 @@ export class CompileTab extends Plugin {
public compilerImport public compilerImport
public event public event
constructor (public api, public fileManager, public contentImport) { constructor (public api, public contentImport) {
super(profile) super(profile)
this.event = new EventEmitter() 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))) 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) { compileFile (target) {
if (!target) throw new Error('No target provided for compiliation') 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`) if (!provider) throw new Error(`cannot compile ${target}. Does not belong to any explorer`)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
provider.get(target, (error, content) => { provider.get(target, (error, content) => {
@ -93,14 +93,14 @@ export class CompileTab extends Plugin {
} }
async isHardhatProject () { async isHardhatProject () {
if (this.fileManager.mode === 'localhost') { if (this.api.getFileManagerMode() === 'localhost') {
return await this.fileManager.exists('hardhat.config.js') return await this.api.fileExists('hardhat.config.js')
} else return false } else return false
} }
runCompiler (hhCompilation) { runCompiler (hhCompilation) {
try { try {
if (this.fileManager.mode === 'localhost' && hhCompilation) { if (this.api.getFileManagerMode() === 'localhost' && hhCompilation) {
const { currentVersion, optimize, runs } = this.compiler.state const { currentVersion, optimize, runs } = this.compiler.state
if (currentVersion) { if (currentVersion) {
const fileContent = `module.exports = { const fileContent = `module.exports = {
@ -114,7 +114,7 @@ export class CompileTab extends Plugin {
} }
` `
const configFilePath = 'remix-compiler.config.js' 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('hardhat', 'compile', configFilePath).then((result) => {
this.call('terminal', 'log', { type: 'info', value: result }) this.call('terminal', 'log', { type: 'info', value: result })
}).catch((error) => { }).catch((error) => {
@ -122,7 +122,7 @@ export class CompileTab extends Plugin {
}) })
} }
} }
this.fileManager.saveCurrentFile() this.api.saveCurrentFile()
this.event.emit('removeAnnotations') this.event.emit('removeAnnotations')
var currentFile = this.api.getConfiguration('currentFile') var currentFile = this.api.getConfiguration('currentFile')
return this.compileFile(currentFile) return this.compileFile(currentFile)

@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer' // eslint-disable-line
import './css/style.css' import './css/style.css'
export const SolidityCompiler = (props: SolidityCompilerProps) => { 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({ const [state, setState] = useState({
contractsDetails: {}, contractsDetails: {},
eventHandlers: {}, eventHandlers: {},
@ -80,18 +80,18 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
<> <>
<div id="compileTabView"> <div id="compileTabView">
<CompilerContainer api={plugin} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} setHardHatCompilation={setHardHatCompilation.bind(plugin)} updateCurrentVersion={updateCurrentVersion} isHardHatProject={isHardHatProject} configurationSettings={configurationSettings} /> <CompilerContainer api={plugin} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} setHardHatCompilation={setHardHatCompilation.bind(plugin)} updateCurrentVersion={updateCurrentVersion} isHardHatProject={isHardHatProject} configurationSettings={configurationSettings} />
<ContractSelection api={plugin} contractMap={contractMap} fileManager={fileManager} contractsDetails={contractsDetails} modal={modal} /> <ContractSelection api={plugin} contractMap={contractMap} contractsDetails={contractsDetails} modal={modal} />
<div className="remixui_errorBlobs p-4" data-id="compiledErrors"> <div className="remixui_errorBlobs p-4" data-id="compiledErrors">
<span data-id={`compilationFinishedWith_${currentVersion}`}></span> <span data-id={`compilationFinishedWith_${currentVersion}`}></span>
{ compileErrors.error && <Renderer message={compileErrors.error.formattedMessage || compileErrors.error} plugin={plugin} opt={{ type: compileErrors.error.severity || 'error', errorType: compileErrors.error.type }} fileManager={fileManager} /> } { compileErrors.error && <Renderer message={compileErrors.error.formattedMessage || compileErrors.error} plugin={plugin} opt={{ type: compileErrors.error.severity || 'error', errorType: compileErrors.error.type }} /> }
{ compileErrors.error && (compileErrors.error.mode === 'panic') && modal('Error', panicMessage(compileErrors.error.formattedMessage), 'Close', null) } { compileErrors.error && (compileErrors.error.mode === 'panic') && modal('Error', panicMessage(compileErrors.error.formattedMessage), 'Close', null) }
{ compileErrors.errors && compileErrors.errors.length && compileErrors.errors.map((err, index) => { { compileErrors.errors && compileErrors.errors.length && compileErrors.errors.map((err, index) => {
if (plugin.getConfiguration('hideWarnings')) { if (plugin.getConfiguration('hideWarnings')) {
if (err.severity !== 'warning') { if (err.severity !== 'warning') {
return <Renderer key={index} message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} fileManager={fileManager} /> return <Renderer key={index} message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} />
} }
} else { } else {
return <Renderer key={index} message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} fileManager={fileManager} /> return <Renderer key={index} message={err.formattedMessage} plugin={plugin} opt={{ type: err.severity, errorType: err.type }} />
} }
}) } }) }
</div> </div>

@ -7,7 +7,6 @@ export interface SolidityCompilerProps {
isHardHatProject: boolean, isHardHatProject: boolean,
compileTabLogic: any, compileTabLogic: any,
contractsDetails: Record<string, any>, contractsDetails: Record<string, any>,
fileManager: any,
contentImport: any, contentImport: any,
call: (...args) => void call: (...args) => void
on: (...args) => void, on: (...args) => void,
@ -35,7 +34,6 @@ export interface ContractSelectionProps {
contractMap: { contractMap: {
file: string file: string
} | Record<string, any>, } | Record<string, any>,
fileManager: any,
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,
contractsDetails: Record<string, any> contractsDetails: Record<string, any>
} }

Loading…
Cancel
Save