Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(misti): persist user-selected options #300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions src/components/MistiStaticAnalyzer/MistiStaticAnalyzer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { createVirtualFileSystem } from '@nowarp/misti/dist/vfs/createVirtualFil
import stdLibFiles from '@tact-lang/compiler/dist/imports/stdlib';
import { Button, Form, Select, Switch, TreeSelect } from 'antd';
import { useForm } from 'antd/lib/form/Form';
import { FC, useState } from 'react';
import { FC, useEffect, useState } from 'react';
import s from './MistiStaticAnalyzer.module.scss';

const severityOptions = Object.keys(Severity)
Expand All @@ -26,15 +26,15 @@ const severityOptions = Object.keys(Severity)
}));

interface FormValues {
contractFile: string;
severity: Severity;
selectedPath: string;
minSeverity: Severity;
allDetectors: boolean;
detectors?: string[];
}

const MistiStaticAnalyzer: FC = () => {
const [isAnalyzing, setIsAnalyzing] = useState(false);
const { projectFiles, activeProject } = useProject();
const { projectFiles, activeProject, updateProjectSetting } = useProject();
const { createLog } = useLogActivity();

const [form] = useForm();
Expand All @@ -43,9 +43,20 @@ const MistiStaticAnalyzer: FC = () => {
return f?.path.endsWith('.tact');
});

const onFormValuesChange = (_: unknown, formValues: FormValues) => {
const {
allDetectors: _allDetectors,
detectors = [],
...finalFormValues
} = formValues;

updateProjectSetting({ misti: { ...finalFormValues, detectors } });
};

const run = async (formValues: FormValues) => {
if (!activeProject?.path) return;
const { contractFile, severity, allDetectors, detectors } = formValues;
const { selectedPath, minSeverity, allDetectors, detectors } = formValues;

try {
const vfs = createVirtualFileSystem('/', {}, false);
setIsAnalyzing(true);
Expand All @@ -70,12 +81,12 @@ const MistiStaticAnalyzer: FC = () => {
}

const driver = await Driver.create(
[normalizeRelativePath(contractFile, activeProject.path)],
[normalizeRelativePath(selectedPath, activeProject.path)],
{
allDetectors,
fs: vfs,
enabledDetectors: detectors,
minSeverity: severity,
minSeverity: minSeverity,
listDetectors: false,
souffleEnabled: false,
tactStdlibPath: Path.resolve(...DEFAULT_STDLIB_PATH_ELEMENTS),
Expand All @@ -100,6 +111,15 @@ const MistiStaticAnalyzer: FC = () => {
}
};

useEffect(() => {
if (!activeProject?.misti) return;

const { misti } = activeProject;

form.setFieldsValue(misti);
form.setFieldValue('allDetectors', misti.detectors.length === 0);
}, [activeProject?.path]);

return (
<div className={s.root}>
<h3 className={`section-heading`}>Misti - Static Analyzer</h3>
Expand All @@ -124,11 +144,12 @@ const MistiStaticAnalyzer: FC = () => {
severity: Severity.INFO,
allDetectors: true,
}}
onValuesChange={onFormValuesChange}
>
<Form.Item
name="contractFile"
name="selectedPath"
className={s.formItem}
rules={[{ required: true }]}
rules={[{ required: true, message: 'Please select contract file' }]}
label="Contract File"
>
<Select
Expand All @@ -154,8 +175,11 @@ const MistiStaticAnalyzer: FC = () => {

<Form.Item
className={s.formItem}
name="severity"
name="minSeverity"
label="Minimum Severity Level"
rules={[
{ required: true, message: 'Please select minimum severity level' },
]}
>
<Select
placeholder="Select Minimum Severity Level"
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/workspace.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IFileTab } from '@/state/IDE.context';
import { Severity } from '@nowarp/misti/dist';
import { ABITypeRef } from '@ton/core';
import { Maybe } from '@ton/core/dist/utils/maybe';
import { RcFile } from 'antd/es/upload';
Expand Down Expand Up @@ -83,6 +84,11 @@ export interface ProjectSetting {
tab?: IFileTab;
cellABI?: CellABI;
abiFormInputValues?: ABIFormInputValues[];
misti?: {
selectedPath?: string;
minSeverity: Severity;
detectors: string[];
};
}

export interface ABIParameter {
Expand Down