update inclusion prob UI
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
/* eslint-disable no-nested-ternary */
|
||||
import React, { useContext, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { Box, Button, CircularProgress, Grid, LinearProgress, Stack, TextField, Typography } from '@mui/material';
|
||||
import { PercentOutlined } from '@mui/icons-material';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { SelectionChance } from 'src/types/rust/selectionchance';
|
||||
import { validationSchema } from './validationSchema';
|
||||
import { Fee, InfoTooltip } from '../../components';
|
||||
import { InclusionProbabilityResponse } from '../../types';
|
||||
@@ -29,6 +30,26 @@ const DataField = ({ title, info, Indicator }: { title: string; info: string; In
|
||||
</Grid>
|
||||
);
|
||||
|
||||
const colorMap: { [key in SelectionChance]: string } = {
|
||||
VeryLow: 'error.main',
|
||||
Low: 'error.main',
|
||||
Moderate: 'warning.main',
|
||||
High: 'success.main',
|
||||
VeryHigh: 'success.main',
|
||||
};
|
||||
|
||||
const textMap: { [key in SelectionChance]: string } = {
|
||||
VeryLow: 'Very low',
|
||||
Low: 'Low',
|
||||
Moderate: 'Moderate',
|
||||
High: 'High',
|
||||
VeryHigh: 'Very high',
|
||||
};
|
||||
|
||||
const InclusionProbability = ({ probability }: { probability: SelectionChance }) => (
|
||||
<Typography sx={{ color: colorMap[probability] }}>{textMap[probability]}</Typography>
|
||||
);
|
||||
|
||||
const PercentIndicator = ({ value, warning }: { value: number; warning?: boolean }) => (
|
||||
<Grid container alignItems="center">
|
||||
<Grid item xs={2}>
|
||||
@@ -115,12 +136,12 @@ export const SystemVariables = ({
|
||||
<DataField
|
||||
title="Estimated chance of being in the active set"
|
||||
info="Probability of getting selected in the reward set (active and standby nodes) in the next epoch. The more your stake, the higher the chances to be selected"
|
||||
Indicator={<PercentIndicator value={inclusionProbability.in_active} />}
|
||||
Indicator={<InclusionProbability probability={inclusionProbability.in_active} />}
|
||||
/>
|
||||
<DataField
|
||||
title="Estimated chance of being in the standby set"
|
||||
info="Probability of getting selected in the reward set (active and standby nodes) in the next epoch. The more your stake, the higher the chances to be selected"
|
||||
Indicator={<PercentIndicator value={inclusionProbability.in_reserve} />}
|
||||
Indicator={<InclusionProbability probability={inclusionProbability.in_reserve} />}
|
||||
/>
|
||||
|
||||
<DataField
|
||||
|
||||
@@ -8,8 +8,8 @@ export const useSettingsState = (shouldUpdate: boolean) => {
|
||||
const [saturation, setSaturation] = useState<number>(0);
|
||||
const [rewardEstimation, setRewardEstimation] = useState<number>(0);
|
||||
const [inclusionProbability, setInclusionProbability] = useState<InclusionProbabilityResponse>({
|
||||
in_active: 0,
|
||||
in_reserve: 0,
|
||||
in_active: 'Low',
|
||||
in_reserve: 'Low',
|
||||
});
|
||||
|
||||
const { mixnodeDetails } = useContext(ClientContext);
|
||||
@@ -31,10 +31,8 @@ export const useSettingsState = (shouldUpdate: boolean) => {
|
||||
const probability = await getInclusionProbability(mixnodeKey);
|
||||
if (probability) {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const in_active = Math.round(probability.in_active * 100);
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const in_reserve = Math.round(probability.in_reserve * 100);
|
||||
setInclusionProbability({ in_active, in_reserve });
|
||||
|
||||
setInclusionProbability({ in_active: probability.in_active, in_reserve: probability.in_reserve });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,7 +40,7 @@ export const useSettingsState = (shouldUpdate: boolean) => {
|
||||
setStatus('not_found');
|
||||
setSaturation(0);
|
||||
setRewardEstimation(0);
|
||||
setInclusionProbability({ in_active: 0, in_reserve: 0 });
|
||||
setInclusionProbability({ in_active: 'Low', in_reserve: 'Low' });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { SelectionChance } from './selectionchance';
|
||||
|
||||
export interface InclusionProbabilityResponse {
|
||||
in_active: number;
|
||||
in_reserve: number;
|
||||
in_active: SelectionChance;
|
||||
in_reserve: SelectionChance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user