show only slither analysis

pull/1398/head
aniket-engg 4 years ago committed by Aniket
parent 2864d6bf6d
commit 1ddfd528bf
  1. 38
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -57,12 +57,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const [autoRun, setAutoRun] = useState(true) const [autoRun, setAutoRun] = useState(true)
const [slitherEnabled, setSlitherEnabled] = useState(false) const [slitherEnabled, setSlitherEnabled] = useState(false)
const [showSlither, setShowSlither] = useState('hidden') const [showSlither, setShowSlither] = useState('hidden')
// Show checkbox to select to display only Slither Analysis
const [showSlitherResult, setShowSlitherResult] = useState('hidden') const [showSlitherResult, setShowSlitherResult] = useState('hidden')
const [showSlitherResultEnabled, setShowSlitherResultEnabled] = useState(false) const [slitherResultEnabled, setSlitherResultEnabled] = useState(false)
const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules)) const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules))
const warningContainer = React.useRef(null) const warningContainer = React.useRef(null)
const [warningState, setWarningState] = useState([]) const [warningState, setWarningState] = useState({})
const [state, dispatch] = useReducer(analysisReducer, initialState) const [state, dispatch] = useReducer(analysisReducer, initialState)
useEffect(() => { useEffect(() => {
@ -70,7 +71,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
}, []) }, [])
useEffect(() => { useEffect(() => {
setWarningState([]) setWarningState({})
if (autoRun) { if (autoRun) {
if (state.data !== null) { if (state.data !== null) {
run(state.data, state.source, state.file) run(state.data, state.source, state.file)
@ -128,6 +129,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setWarningState(groupedCategory) setWarningState(groupedCategory)
} }
const showWarningsByModule = (showOnlyModule: string) => {
if(showOnlyModule && warningState[showOnlyModule]) {
const newWarningState = {}
newWarningState[showOnlyModule] = warningState[showOnlyModule]
setWarningState({[showOnlyModule]: warningState[showOnlyModule]})
}
}
const run = (lastCompilationResult, lastCompilationSource, currentFile) => { const run = (lastCompilationResult, lastCompilationSource, currentFile) => {
if (state.data !== null) { if (state.data !== null) {
if (lastCompilationResult && categoryIndex.length > 0) { if (lastCompilationResult && categoryIndex.length > 0) {
@ -237,6 +246,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: 'Slither Analysis' }) warningMessage.push({ msg, options, hasWarning: true, warningModuleName: 'Slither Analysis' })
}) })
showWarnings(warningMessage, 'warningModuleName') showWarnings(warningMessage, 'warningModuleName')
setShowSlitherResult('visible')
props.event.trigger('staticAnaysisWarning', [warningCount]) props.event.trigger('staticAnaysisWarning', [warningCount])
} }
}) })
@ -283,7 +293,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
} }
const handleShowSlitherResultEnabled = () => { const handleSlitherEnabled = () => {
if (slitherEnabled) { if (slitherEnabled) {
setSlitherEnabled(false) setSlitherEnabled(false)
} else { } else {
@ -291,11 +301,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
} }
const handleSlitherEnabled = () => { const handleShowSlitherResultEnabled = () => {
if (showSlitherResultEnabled) { if (slitherResultEnabled) {
setShowSlitherResultEnabled(false) setSlitherResultEnabled(false)
} else { } else {
setShowSlitherResultEnabled(true) setSlitherResultEnabled(true)
showWarningsByModule('Slither Analysis')
} }
} }
@ -433,12 +444,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
id="showOnlySlitherResult" id="showOnlySlitherResult"
inputType="checkbox" inputType="checkbox"
onClick={handleShowSlitherResultEnabled} onClick={handleShowSlitherResultEnabled}
checked={showSlitherResultEnabled} checked={slitherResultEnabled}
label="Show Slither result only" label="Only Show Slither Analysis"
onChange={() => {}} onChange={() => {}}
visibility = {showSlitherResult} visibility = {showSlitherResult}
/> />
</div> </div>
<br/>
{Object.entries(warningState).length > 0 && {Object.entries(warningState).length > 0 &&
<div id='staticanalysisresult' > <div id='staticanalysisresult' >
<div className="mb-4"> <div className="mb-4">
@ -446,9 +458,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
(Object.entries(warningState).map((element, index) => ( (Object.entries(warningState).map((element, index) => (
<div key={index}> <div key={index}>
<span className="text-dark h6">{element[0]}</span> <span className="text-dark h6">{element[0]}</span>
{element[1].map((x, i) => ( {element[1]['map']((x, i) => (
x.hasWarning ? ( x.hasWarning ? (
<div id={`staticAnalysisModule${element[1].warningModuleName}`} key={i}> <div id={`staticAnalysisModule${element[1]['warningModuleName']}`} key={i}>
<ErrorRenderer message={x.msg} opt={x.options} warningErrors={ x.warningErrors} editor={props.analysisModule}/> <ErrorRenderer message={x.msg} opt={x.options} warningErrors={ x.warningErrors} editor={props.analysisModule}/>
</div> </div>

Loading…
Cancel
Save