Skip to content

Commit 317a4dc

Browse files
authored
Merge pull request #49 from lidofinance/feat/add-color-utils
refactor: update health and utilization thresholds; implement color c…
2 parents 9e77c7f + 3446a61 commit 317a4dc

File tree

8 files changed

+60
-41
lines changed

8 files changed

+60
-41
lines changed

consts/threshold.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
export const VAULT_GREEN_HEATH_PERCENT = 100;
2-
export const VAULT_YELLOW_HEATH_PERCENT = 91;
3-
export const VAULT_RED_HEATH_PERCENT = 90;
1+
export const VAULT_HEALTH_PERCENT_GREEN = 125;
2+
export const VAULT_HEALTH_PERCENT_YELLOW = 105;
3+
export const VAULT_HEALTH_PERCENT_RED = 100;
4+
5+
export const VAULT_UTILIZATION_RATIO_GREEN = 90;
6+
export const VAULT_UTILIZATION_RATIO_RED = 100;

features/home/components/vault-table/cells/percent-cell.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import { Percent } from './styles';
55
import { formatPercent } from 'utils/format-number';
66
import { BaseCellProps } from '../types';
77

8-
export const PercentCell: FC<BaseCellProps<number>> = ({ value }) => {
8+
interface PercentCellProps extends BaseCellProps<number> {
9+
color: string;
10+
}
11+
12+
export const PercentCell: FC<PercentCellProps> = ({ value, color }) => {
913
const percent = formatPercent.format(value / 100);
1014

11-
return <Percent value={value}>{percent}</Percent>;
15+
return <Percent color={color}>{percent}</Percent>;
1216
};

features/home/components/vault-table/cells/styles.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
import styled, { DefaultTheme } from 'styled-components';
2-
import {
3-
VAULT_GREEN_HEATH_PERCENT,
4-
VAULT_YELLOW_HEATH_PERCENT,
5-
VAULT_RED_HEATH_PERCENT,
6-
} from 'consts/threshold';
7-
8-
const getColorByValue = (theme: DefaultTheme, value: number) => {
9-
const percent = value * 100;
10-
if (percent >= VAULT_GREEN_HEATH_PERCENT) return theme.colors.success;
11-
if (percent >= VAULT_YELLOW_HEATH_PERCENT) return theme.colors.warning;
12-
if (percent <= VAULT_RED_HEATH_PERCENT) return theme.colors.error;
13-
return theme.colors.text;
14-
};
1+
import styled from 'styled-components';
152

163
export const Mintable = styled.span`
174
color: ${({ theme }) => theme.colors.textSecondary};
185
`;
196

20-
export const Percent = styled.span<{ value: number }>`
21-
color: ${({ theme, value }) => getColorByValue(theme, value)};
7+
export const Percent = styled.span<{ color: string }>`
8+
color: ${({ color }) => color};
229
font-weight: 700;
2310
`;
2411

features/home/components/vault-table/vault-table.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
HeaderCell,
1111
} from 'features/home/components/vault-table/cells';
1212
import { VaultTableInfo } from 'modules/vaults';
13+
import { getHealthFactorColor } from 'utils';
1314

1415
import {
1516
TableTitle,
@@ -77,6 +78,8 @@ export const VaultTable: FC<VaultTableProps> = (props) => {
7778
</TableHead>
7879
<Tbody>
7980
{vaults?.map((vault) => {
81+
const healthColor = getHealthFactorColor(vault.healthScore);
82+
8083
return (
8184
<TableRow key={vault.address}>
8285
<TableCell>
@@ -89,7 +92,10 @@ export const VaultTable: FC<VaultTableProps> = (props) => {
8992
<MintCell value={vault.liabilityStETH} />
9093
</TableCell>
9194
<TableCell>
92-
<PercentCell value={vault.healthScore} />
95+
<PercentCell
96+
value={vault.healthScore}
97+
color={healthColor}
98+
/>
9399
</TableCell>
94100
</TableRow>
95101
);

features/overview/components/capacity/capacity.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { OverviewItem, OverviewSection } from 'features/overview/shared';
22
import { SectionPayload, useVaultOverview } from 'features/overview/contexts';
3+
import { getUtilizationRatioColor } from 'utils';
34

45
const sectionPayloadList: SectionPayload[] = [
56
{
@@ -16,16 +17,6 @@ const sectionPayloadList: SectionPayload[] = [
1617
},
1718
];
1819

19-
const getUtilizationRatioColor = (utilizationRatio: string) => {
20-
if (!utilizationRatio) return '';
21-
const utilizationRatioNumber = Number(utilizationRatio.split('%')[0]);
22-
23-
if (utilizationRatioNumber < 90) return '#53BA95';
24-
if (utilizationRatioNumber < 100) return '#ffbf00';
25-
if (utilizationRatioNumber === 100) return '#E14D4D';
26-
if (utilizationRatioNumber > 100) return 'darkRed';
27-
};
28-
2920
export const Capacity = () => {
3021
const { getVaultDataToRender } = useVaultOverview();
3122
const renderData = getVaultDataToRender(sectionPayloadList);

features/overview/components/health/heath.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { OverviewItem, OverviewSection } from 'features/overview/shared';
22
import { SectionPayload, useVaultOverview } from 'features/overview/contexts';
3+
import { getHealthFactorColor } from 'utils';
34

45
const sectionPayloadList: SectionPayload[] = [
56
{
@@ -20,15 +21,6 @@ const sectionPayloadList: SectionPayload[] = [
2021
},
2122
];
2223

23-
const getHealthFactorColor = (healthFactor: string) => {
24-
if (!healthFactor) return '';
25-
const healthFactorNumber = Number(healthFactor.split('%')[0]);
26-
if (healthFactorNumber >= 125) return '#53BA95 ';
27-
if (healthFactorNumber >= 105) return '#ffbf00';
28-
if (healthFactorNumber >= 100) return '#E14D4D';
29-
return 'darkRed';
30-
};
31-
3224
export const Health = () => {
3325
const { getVaultDataToRender } = useVaultOverview();
3426
const renderData = getVaultDataToRender(sectionPayloadList);

utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from './extractErrorMessage';
77
export * from './shortenTokenValue';
88
export * from './format-number';
99
export * from './sleep';
10+
export * from './overview-colors';

utils/overview-colors.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
VAULT_HEALTH_PERCENT_GREEN,
3+
VAULT_HEALTH_PERCENT_YELLOW,
4+
VAULT_HEALTH_PERCENT_RED,
5+
VAULT_UTILIZATION_RATIO_GREEN,
6+
VAULT_UTILIZATION_RATIO_RED,
7+
} from 'consts/threshold';
8+
9+
export const getHealthFactorColor = (healthFactor: string | number) => {
10+
if (!healthFactor) return '';
11+
let healthFactorNumber = 0;
12+
13+
if (typeof healthFactor === 'string')
14+
healthFactorNumber = Number(healthFactor.split('%')[0]);
15+
else healthFactorNumber = healthFactor;
16+
17+
if (healthFactorNumber >= VAULT_HEALTH_PERCENT_GREEN) return '#53BA95';
18+
if (healthFactorNumber >= VAULT_HEALTH_PERCENT_YELLOW) return '#ffbf00';
19+
if (healthFactorNumber >= VAULT_HEALTH_PERCENT_RED) return '#E14D4D';
20+
return 'darkRed';
21+
};
22+
23+
export const getUtilizationRatioColor = (utilizationRatio: string) => {
24+
if (!utilizationRatio) return '';
25+
let utilizationRatioNumber = 0;
26+
27+
if (typeof utilizationRatio === 'string')
28+
utilizationRatioNumber = Number(utilizationRatio.split('%')[0]);
29+
else utilizationRatioNumber = utilizationRatio;
30+
31+
if (utilizationRatioNumber < VAULT_UTILIZATION_RATIO_GREEN) return '#53BA95';
32+
if (utilizationRatioNumber < VAULT_UTILIZATION_RATIO_RED) return '#ffbf00';
33+
if (utilizationRatioNumber === VAULT_UTILIZATION_RATIO_RED) return '#E14D4D';
34+
if (utilizationRatioNumber > VAULT_UTILIZATION_RATIO_RED) return 'darkRed';
35+
};

0 commit comments

Comments
 (0)