Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
fix: add filter for contracts on UI side (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
varex83 authored Jul 9, 2024
1 parent 0b6d8e4 commit d160410
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions plugin/src/utils/remix_storage.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import { ContractFile } from '@/types/contracts'
import { RemixClient } from '@/PluginClient'
import {ContractFile} from '@/types/contracts'
import {RemixClient} from '@/PluginClient'

export const getAllContractFiles = async (
remixClient: RemixClient,
workspacePath: string,
dirPath = ''
remixClient: RemixClient,
workspacePath: string,
dirPath = ''
): Promise<ContractFile[]> => {
const files = [] as ContractFile[]
const pathFiles = await remixClient.fileManager.readdir(`${workspacePath}/${dirPath}`)
for (const [path, entry] of Object.entries<any>(pathFiles)) {
if (entry.isDirectory) {
const deps = await getAllContractFiles(remixClient, workspacePath, path)
for (const dep of deps) files.push(dep)
continue
}
const files = [] as ContractFile[]
const pathFiles = await remixClient.fileManager.readdir(`${workspacePath}/${dirPath}`)
for (const [path, entry] of Object.entries<any>(pathFiles)) {
if (entry.isDirectory) {
const deps = await getAllContractFiles(remixClient, workspacePath, path)
for (const dep of deps) files.push(dep)
continue
}

const content = await remixClient.fileManager.readFile(path)

if (!path.endsWith('.sol')) continue

const content = await remixClient.fileManager.readFile(path)
files.push({
file_name: path,
file_content: content,
is_contract: path.endsWith('.sol')
})
}
return files
files.push({
file_name: path,
file_content: content,
// we need to keep it, to persist the json file format
is_contract: true
})
}
return files
}

export const getContractTargetPath = (contractFilePath: string) => {
const parts = contractFilePath.split('/')
if (parts.length === 1) {
return './'
} else {
parts.pop()
return './' + parts.join('/')
}
const parts = contractFilePath.split('/')
if (parts.length === 1) {
return './'
} else {
parts.pop()
return './' + parts.join('/')
}
}

export const findFilesNotInContracts = (allContracts: ContractFile[]) => {
return allContracts
.filter(({ file_name, is_contract }) => is_contract && !file_name.startsWith('contracts/'))
.map(({ file_name }) => file_name.split('/').pop())
return allContracts
.filter(({file_name, is_contract}) => is_contract && !file_name.startsWith('contracts/'))
.map(({file_name}) => file_name.split('/').pop())
}

0 comments on commit d160410

Please sign in to comment.