fix badge bug on contract compile

pull/3838/head
Joseph Izang 1 year ago
parent 602f267a0d
commit aa5bce6dbb
  1. 2
      libs/remix-ui/static-analyser/src/lib/components/BasicTitle.tsx
  2. 55
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -42,7 +42,7 @@ export function BasicTitle(props: BasicTitleProps) {
<span id="ssaRemixtab">Remix{props.ssaWarnings.length > 0 ? !props.hideWarnings ? !props.showLibsWarnings ? <span data-id="RemixStaticAnalysisErrorCount" className={`badge ${props.ssaWarnings.filter(x => x.hasWarning).length > 0 ? 'badge-warning' : props.ssaWarnings.filter(x => x.options.type === 'errors').length > 0 ? 'badge-danger' : 'badge-info'} badge-pill mx-1 ml-1 text-center`}> <span id="ssaRemixtab">Remix{props.ssaWarnings.length > 0 ? !props.hideWarnings ? !props.showLibsWarnings ? <span data-id="RemixStaticAnalysisErrorCount" className={`badge ${props.ssaWarnings.filter(x => x.hasWarning).length > 0 ? 'badge-warning' : props.ssaWarnings.filter(x => x.options.type === 'errors').length > 0 ? 'badge-danger' : 'badge-info'} badge-pill mx-1 ml-1 text-center`}>
{filteredTotal} {filteredTotal}
</span>: ( </span>: (
<i className="badge badge-warning badge-pill mx-1 ml-1 text-center"> <i className={`badge ${props.ssaWarnings.filter(x => x.options.type !== 'warning' && x.options.type !== 'error').length > 0 ? 'badge-info' : props.ssaWarnings.filter(x => x.options.type === 'errors').length > 0 ? 'badge-danger' : 'badge-warning'} badge-pill mx-1 ml-1 text-center`}>
{ {
props.ssaWarnings.length props.ssaWarnings.length
} }

@ -110,17 +110,19 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
compilation(props.analysisModule, dispatch) compilation(props.analysisModule, dispatch)
}, [props]) }, [props])
// useEffect(() => { useEffect(() => {
// setWarningState({}) // setWarningState({})
// const runAnalysis = async () => { // setHints([])
// 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, setStartAnalysis, solhintEnabled) // setSlitherWarnings([])
// } // setSsaWarnings([])
// props.event.trigger('staticAnaysisWarning', []) setStartAnalysis(false)
// return () => { } props.event.trigger('staticAnaysisWarning', [-1])
// }, [state]) return () => { }
}, [state])
useEffect(() => { useEffect(() => {
props.analysisModule.call('solidity', 'getCompilerState').then((compilerState) => setDisableForRun(compilerState.currentVersion)) props.analysisModule.call('solidity', 'getCompilerState').then((compilerState) => setDisableForRun(compilerState.currentVersion))
props.event.trigger('staticAnalysisWarning', [-1])
}, []) }, [])
useEffect(() => { useEffect(() => {
@ -132,6 +134,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
} }
checkRemixdActive() checkRemixdActive()
props.event.trigger('staticAnalysisWarning', [-1])
}, [props]) }, [props])
useEffect(() => { useEffect(() => {
@ -165,7 +168,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setSlitherEnabled(false) setSlitherEnabled(false)
setSsaWarnings([]) setSsaWarnings([])
// Reset badge // Reset badge
props.event.trigger('staticAnaysisWarning', []) props.event.trigger('staticAnalysisWarning', [-1])
// Reset state // Reset state
dispatch({ type: '', payload: initialState }) dispatch({ type: '', payload: initialState })
setShowSlither(false) setShowSlither(false)
@ -174,6 +177,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
props.analysisModule.on('solidity', 'compilerLoaded', async (version: string, license: string) => { props.analysisModule.on('solidity', 'compilerLoaded', async (version: string, license: string) => {
setDisableForRun(version) setDisableForRun(version)
props.event.trigger('staticAnalysisWarning', [-1])
}) })
return () => { } return () => { }
}, [props]) }, [props])
@ -337,11 +341,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
) )
} }
//#endregion //#endregion
// useEffect(() => {
// if(hints.length > 0) {
// props.event.trigger('staticAnaysisWarning', [hints.length])
// }
// },[hints.length])
useEffect(() => { useEffect(() => {
if(!hideWarnings && !showLibsWarning) { if(!hideWarnings && !showLibsWarning) {
@ -379,17 +378,17 @@ useEffect(() => {
props.event.trigger('staticAnaysisWarning', [slitherTotal + ssaTotal + hintsTotal]) props.event.trigger('staticAnaysisWarning', [slitherTotal + ssaTotal + hintsTotal])
}, [hints.length, slitherWarnings.length, ssaWarnings.length]) }, [hints.length, slitherWarnings.length, ssaWarnings.length])
// useEffect(() => { useEffect(() => {
// const slitherTotal = slitherWarnings && slitherEnabled && showSlither && state.data && state.source !== null const slitherTotal = slitherWarnings && slitherEnabled && showSlither && state.data && state.source !== null
// ? slitherWarnings.filter((x) => !x.options.isLibrary && x.hasWarning).length ? slitherWarnings.filter((x) => !x.options.isLibrary && x.hasWarning).length
// : 0 : 0
// const ssaTotal = ssaWarnings && basicEnabled && state.data && state.source !== null const ssaTotal = ssaWarnings && basicEnabled && state.data && state.source !== null
// ? ssaWarnings.filter((x) => !x.options.isLibrary && x.hasWarning).length ? ssaWarnings.filter((x) => !x.options.isLibrary && x.hasWarning).length
// : 0 : 0
// const hintsTotal = hints && solhintEnabled && state.data && state.source !== null ? hints.length : 0 const hintsTotal = hints && solhintEnabled && state.data && state.source !== null ? hints.length : 0
// console.log('hideWarnings & showLibsWarning are unchecked and tools could be checked or unchecked', { slitherTotal, ssaTotal, hintsTotal }) console.log('hideWarnings & showLibsWarning are unchecked and tools could be checked or unchecked', { slitherTotal, ssaTotal, hintsTotal })
// props.event.trigger('staticAnaysisWarning', [slitherTotal + ssaTotal + hintsTotal]) props.event.trigger('staticAnaysisWarning', [slitherTotal + ssaTotal + hintsTotal])
// }, [solhintEnabled, basicEnabled, slitherEnabled, showSlither]) }, [solhintEnabled, basicEnabled, slitherEnabled, showSlither])
const handleSlitherEnabled = async () => { const handleSlitherEnabled = async () => {
const checkRemixd = await props.analysisModule.call('manager', 'isActive', 'remixd') const checkRemixd = await props.analysisModule.call('manager', 'isActive', 'remixd')
@ -529,7 +528,7 @@ useEffect(() => {
), ),
title: ( title: (
<span> <span>
Linter Solhint
{hints.length > 0 ? ( {hints.length > 0 ? (
hideWarnings ? ( hideWarnings ? (
<i className={`badge ${hints.filter(x => x.type === 'error').length > 0 <i className={`badge ${hints.filter(x => x.type === 'error').length > 0
@ -561,10 +560,9 @@ useEffect(() => {
{Object.entries(warningState).length > 0 ? ( {Object.entries(warningState).length > 0 ? (
<div id="staticanalysisresult"> <div id="staticanalysisresult">
<div className="mb-4 pt-2"> <div className="mb-4 pt-2">
{Object.entries(warningState).map((element, index) => ( <div>
<div key={index}>
{ {
!hideWarnings && !showLibsWarning && ssaWarnings.length > 0 ? ssaWarnings.filter(x => !x.options.isLibrary).map((x, i) => ( !hideWarnings && !showLibsWarning && ssaWarnings.length > 0 ? ssaWarnings.filter(x => !x.options.isLibrary && x.hasWarning).map((x, i) => (
<div <div
data-id={`staticAnalysisModule${x.warningModuleName}${i}`} data-id={`staticAnalysisModule${x.warningModuleName}${i}`}
id={`staticAnalysisModule${x.warningModuleName}${i}`} id={`staticAnalysisModule${x.warningModuleName}${i}`}
@ -595,7 +593,6 @@ useEffect(() => {
)) : null )) : null
} }
</div> </div>
))}
</div> </div>
</div> </div>
) : state.data && state.file.length > 0 && state.source && startAnalysis && Object.entries(warningState).length > 0 ? <span className="ml-4 spinner-grow-sm d-flex justify-content-center">Loading...</span> : <span className="display-6 text-center">Nothing to report</span>} ) : state.data && state.file.length > 0 && state.source && startAnalysis && Object.entries(warningState).length > 0 ? <span className="ml-4 spinner-grow-sm d-flex justify-content-center">Loading...</span> : <span className="display-6 text-center">Nothing to report</span>}

Loading…
Cancel
Save