fix possibility where clicking Analyse button might attempt to run slither also

pull/3779/head
Joseph Izang 1 year ago
parent fe3ab20ef3
commit 61d2cb17b6
  1. 14
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  2. 8
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -1,10 +1,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api'
import React from 'react' //eslint-disable-line
import { AnalysisTab, RemixUiStaticAnalyserReducerActionType, RemixUiStaticAnalyserState, SolHintReport, SlitherAnalysisResults } from '../../staticanalyser'
import { RemixUiStaticAnalyserProps } from '@remix-ui/static-analyser'
/**
*
*
* @param analysisModule { AnalysisTab } AnalysisTab ViewPlugin
* @param dispatch { React.Dispatch<any> } analysisReducer function's dispatch method
*/
@ -24,8 +25,8 @@ export const compilation = (analysisModule: AnalysisTab,
/**
* Run the analysis on the currently compiled contract
* @param lastCompilationResult
* @param lastCompilationSource
* @param lastCompilationResult
* @param lastCompilationSource
* @param currentFile {string} current file path
* @param state { RemixUiStaticAnalyserState}
* @param props {RemixUiStaticAnalyserProps}
@ -42,7 +43,8 @@ export const compilation = (analysisModule: AnalysisTab,
* @returns {Promise<void>}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function run (lastCompilationResult, lastCompilationSource, currentFile: string, state: RemixUiStaticAnalyserState, props: RemixUiStaticAnalyserProps, isSupportedVersion, showSlither, categoryIndex: number[], groupedModules, runner, _paq, message, showWarnings, allWarnings: React.RefObject<any>, warningContainer: React.RefObject<any>, calculateWarningStateEntries: (e:[string, any][]) => {length: number, errors: any[] }, warningState, setHints: React.Dispatch<React.SetStateAction<SolHintReport[]>>, hints: SolHintReport[], setSlitherWarnings: React.Dispatch<React.SetStateAction<any[]>>, setSsaWarnings: React.Dispatch<React.SetStateAction<any[]>>) {
export async function run (lastCompilationResult, lastCompilationSource, currentFile: string, state: RemixUiStaticAnalyserState, props: RemixUiStaticAnalyserProps, isSupportedVersion, showSlither, categoryIndex: number[], groupedModules, runner, _paq, message, showWarnings, allWarnings: React.RefObject<any>, warningContainer: React.RefObject<any>, calculateWarningStateEntries: (e:[string, any][]) => {length: number, errors: any[] }, warningState, setHints: React.Dispatch<React.SetStateAction<SolHintReport[]>>, hints: SolHintReport[], setSlitherWarnings: React.Dispatch<React.SetStateAction<any[]>>, setSsaWarnings: React.Dispatch<React.SetStateAction<any[]>>,
slitherEnabled: boolean) {
if (!isSupportedVersion) return
if (state.data !== null) {
@ -54,7 +56,7 @@ export async function run (lastCompilationResult, lastCompilationSource, current
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
setHints(hintsResult)
const warningResult = calculateWarningStateEntries(Object.entries(warningState))
props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length,
props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length,
title: `${hints.length+warningResult.length} warning${hints.length+warningResult.length === 1 ? '' : 's'}`, type: 'warning'})
// Remix Analysis
@ -121,7 +123,7 @@ export async function run (lastCompilationResult, lastCompilationSource, current
}
}
// Slither Analysis
if (showSlither) {
if (showSlither && slitherEnabled) {
try {
const compilerState = await props.analysisModule.call('solidity', 'getCompilerState')
const { currentVersion, optimize, evmVersion } = compilerState

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useEffect, useState, useReducer, useRef, Fragment } from 'react' // eslint-disable-line
import Button from './Button/StaticAnalyserButton' // eslint-disable-line
import { util } from '@remix-project/remix-lib'
@ -110,7 +112,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
useEffect(() => {
setWarningState({})
const runAnalysis = async () => {
await run(state.data, state.source, state.file, state, props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, message, showWarnings, allWarnings, warningContainer,calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings)
await run(state.data, state.source, state.file, state, props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, message, showWarnings, allWarnings, warningContainer,calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled)
}
props.event.trigger('staticAnaysisWarning', [])
// if (basicEnabled) {
@ -664,14 +666,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
buttonText={`Analyse ${state.file}`}
classList="btn btn-sm btn-primary btn-block"
onClick={async () => await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings)}
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled)}
disabled={(state.data === null || !isSupportedVersion) || (!solhintEnabled && !basicEnabled) }
/> : <Button
buttonText={`Analyse ${state.file}`}
title={`${runButtonTitle}`}
classList="btn btn-sm btn-primary btn-block"
onClick={async () => await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings)}
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled)}
disabled={(state.data === null || !isSupportedVersion) || (!solhintEnabled && !basicEnabled) }
/>}
{state && state.data !== null && state.source !== null && state.file.length > 0 ? (<div className="d-flex border-top flex-column">

Loading…
Cancel
Save