This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add filter for contracts on UI side (#141)
- Loading branch information
Showing
1 changed file
with
35 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |