Skip to content

Commit

Permalink
feat: update validator status
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Feb 29, 2024
1 parent 8e9ce5b commit 7fbb204
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const formatValidators = (data: ValidatorsQuery): Partial<ValidatorsState> => {
votingPowerPercent,
commission: (x?.validatorCommissions?.[0]?.commission ?? 0) * 100,
condition,
status: x?.validatorStatuses?.[0]?.status ?? 0,
status: x?.validatorStatuses?.[0]?.status ?? 3,
jailed: x?.validatorStatuses?.[0]?.jailed ?? false,
tombstoned: false,
};
Expand All @@ -59,7 +59,7 @@ const formatValidators = (data: ValidatorsQuery): Partial<ValidatorsState> => {
let cumulativeVotingPower = Big(0);
let reached = false;
formattedItems.forEach((x) => {
if (x.status === 3) {
if (x.status === 0) {
const totalVp = cumulativeVotingPower.add(x.votingPowerPercent || 0);
if (totalVp.lte(34) && !reached) {
x.topVotingPower = true;
Expand Down Expand Up @@ -159,11 +159,11 @@ export const useValidators = () => {
let sorted: ItemType[] = R.clone(items);

if (state.tab === 0) {
sorted = sorted.filter((x) => x.status === 3);
sorted = sorted.filter((x) => x.status === 0);
}

if (state.tab === 1) {
sorted = sorted.filter((x) => x.status !== 3);
sorted = sorted.filter((x) => x.status !== 0);
}

if (search) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const GridRow: FC<GridRowProps> = ({
const condition = item.status === 3 ? getValidatorConditionClass(item.condition) : undefined;
const percentDisplay =
// eslint-disable-next-line no-nested-ternary
item.status === 3
item.status === 0
? chainName === 'wormhole'
? `${numeral(item.votingPower.toFixed(6)).format('0.[00]')}%`
: `${numeral(item.votingPowerPercent.toFixed(6)).format('0.[00]')}%`
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/screens/validators/components/list/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const formatValidators = (data: ValidatorsQuery): Partial<ValidatorsState> => {
votingPowerPercent: votingPowerPercent ?? 0,
commission: (x?.validatorCommissions?.[0]?.commission ?? 0) * 100,
condition,
status: x?.validatorStatuses?.[0]?.status ?? 0,
status: x?.validatorStatuses?.[0]?.status ?? 3,
jailed: x?.validatorStatuses?.[0]?.jailed ?? false,
tombstoned: x?.validatorSigningInfos?.[0]?.tombstoned ?? false,
};
Expand All @@ -58,7 +58,7 @@ const formatValidators = (data: ValidatorsQuery): Partial<ValidatorsState> => {
let cumulativeVotingPower = Big(0);
let reached = false;
formattedItems.forEach((x) => {
if (x.status === 3) {
if (x.status === 0) {
const totalVp = cumulativeVotingPower.add(x.votingPowerPercent);
if (totalVp.lte(34) && !reached) {
x.topVotingPower = true;
Expand Down Expand Up @@ -158,11 +158,11 @@ export const useValidators = () => {
let sorted: ItemType[] = R.clone(items);

if (state.tab === 0) {
sorted = sorted.filter((x) => x.status === 3);
sorted = sorted.filter((x) => x.status === 0);
}

if (state.tab === 1) {
sorted = sorted.filter((x) => x.status !== 3);
sorted = sorted.filter((x) => x.status !== 0);
}

if (search) {
Expand Down
12 changes: 9 additions & 3 deletions packages/ui/src/utils/get_validator_status/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ export const getValidatorStatus = (status: number, jailed: boolean, tombstoned:
return results;
}

if (status === 3) {
if (status === 0) {
results.status = 'active';
results.theme = 'one';
} else if (status === 2) {
results.status = 'unbonding';
results.status = 'below-threshold';
results.theme = 'three';
} else if (status === 1) {
results.status = 'unbonded';
results.status = 'below-capacity';
results.theme = 'zero';
} else if (status === 3) {
results.status = 'inactive';
results.theme = 'zero';
} else if (status === 4) {
results.status = 'jailed';
results.theme = 'zero';
} else {
results.status = 'unknown';
Expand Down

0 comments on commit 7fbb204

Please sign in to comment.