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. 20
      libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx
  4. 20
      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: {},
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()

@ -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)

@ -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

@ -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

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

@ -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)

@ -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()

@ -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) => {
<span className="mt-2 mx-3 w-100 alert alert-warning" role="alert">No Contract Compiled Yet</span>
</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 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)

@ -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) => {
<>
<div id="compileTabView">
<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">
<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.errors && compileErrors.errors.length && compileErrors.errors.map((err, index) => {
if (plugin.getConfiguration('hideWarnings')) {
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 {
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>

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

Loading…
Cancel
Save