Files
explore/ui/shared/solidityscanReport/SolidityscanReportDetails.tsx
tom goriunovandGitHub f0e713b877 Add support for customizing the UI color theme (#2923)
* UI customizations: new features

Fixes #2905

* colors for graphs

* introduce env variable

* colors for topbar, stats, selected state and tabs

* fix build

* fix validator

* refactor link.primary.hover color token

* refactor selected colors

* update styles for switch and fix some color tokens

* change color for selectable controls

* icon color tokens refactoring

* UI customizations: new features

Fixes #2905

* test for common components

* tweaks

* migrate from color-mode-hex cookie to color-theme cookie

* clean up

* update screenshots

* more screenshot updates

* update default color of chart line

* update envs for mega eth
2025-08-19 11:58:05 +02:00

64 lines
2.1 KiB
TypeScript

import { Box, Flex, Text, Grid, chakra } from '@chakra-ui/react';
import React from 'react';
import type { SolidityScanReportSeverityDistribution } from 'lib/solidityScan/schema';
type DistributionItem = {
id: keyof SolidityScanReportSeverityDistribution;
name: string;
color: string;
};
const DISTRIBUTION_ITEMS: Array<DistributionItem> = [
{ id: 'critical', name: 'Critical', color: '#891F11' },
{ id: 'high', name: 'High', color: '#EC672C' },
{ id: 'medium', name: 'Medium', color: '#FBE74D' },
{ id: 'low', name: 'Low', color: '#68C88E' },
{ id: 'informational', name: 'Informational', color: '#A3AEBE' },
{ id: 'gas', name: 'Gas', color: '#A47585' },
];
interface Props {
vulnerabilities: SolidityScanReportSeverityDistribution;
vulnerabilitiesCount: number;
}
type ItemProps = {
item: DistributionItem;
vulnerabilities: SolidityScanReportSeverityDistribution;
vulnerabilitiesCount: number;
};
const SolidityScanReportItem = ({ item, vulnerabilities, vulnerabilitiesCount }: ItemProps) => {
const vulnerability = vulnerabilities[item.id];
if (vulnerability === undefined) {
return null;
}
return (
<>
<Box w={ 3 } h={ 3 } bg={ item.color } borderRadius="6px" mr={ 2 }></Box>
<Flex justifyContent="space-between" mr={ 3 }>
<Text>{ item.name }</Text>
<Text color={ vulnerability > 0 ? 'text.primary' : 'text.secondary' }>{ vulnerabilities[item.id] }</Text>
</Flex>
<Box bg={{ _light: 'blackAlpha.50', _dark: 'whiteAlpha.50' }} h="10px" borderRadius="8px">
<Box bg={ item.color } w={ `${ vulnerability / vulnerabilitiesCount * 100 }%` } h="10px" borderRadius="8px"/>
</Box>
</>
);
};
const SolidityscanReportDetails = ({ vulnerabilities, vulnerabilitiesCount }: Props) => {
return (
<Grid templateColumns="20px 1fr 100px" alignItems="center" rowGap={ 2 }>
{ DISTRIBUTION_ITEMS.map(item => (
<SolidityScanReportItem item={ item } key={ item.id } vulnerabilities={ vulnerabilities } vulnerabilitiesCount={ vulnerabilitiesCount }/>
)) }
</Grid>
);
};
export default chakra(SolidityscanReportDetails);