Skip to content

Commit

Permalink
CSUB-1019 Change the staking dashboard "waiting" label on the Validat…
Browse files Browse the repository at this point in the history
…or page to Active + number (#72)

* fix: Zero era status

* fix: Not in this branch

* fix: Remove waiting on era status

* fix: Show validators even they don't have nominators

* fix: Update component on total stake change

* fix: Clear filter

---------

Co-authored-by: Frank Li <[email protected]>
  • Loading branch information
2 people authored and Juan Gallicchio committed Feb 16, 2024
1 parent 71983fc commit f6b53c2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 68 deletions.
10 changes: 4 additions & 6 deletions src/library/ListItem/Labels/EraStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { capitalizeFirstLetter, planckToUnit } from '@polkadot-cloud/utils';
import { planckToUnit } from '@polkadot-cloud/utils';
import { useTranslation } from 'react-i18next';
import { useStaking } from 'contexts/Staking';
import { useUi } from 'contexts/UI';
Expand All @@ -23,11 +23,9 @@ export const EraStatus = ({ noMargin, status, totalStake }: EraStatusProps) => {
<h5>
{isSyncing || erasStakersSyncing
? t('syncing')
: validatorStatus !== 'waiting'
? `${t('listItemActive')} / ${planckToUnit(totalStake, units)
.integerValue()
.toFormat()} ${unit}`
: capitalizeFirstLetter(t(`${validatorStatus}`) ?? '')}
: `${t('listItemActive')} / ${planckToUnit(totalStake, units)
.integerValue()
.toFormat()} ${unit}`}
</h5>
</ValidatorStatusWrapper>
);
Expand Down
5 changes: 4 additions & 1 deletion src/library/ValidatorList/ValidatorItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export const ValidatorItemInner = (props: ValidatorItemProps) => {

export class ValidatorItem extends React.Component<ValidatorItemProps> {
shouldComponentUpdate(nextProps: ValidatorItemProps) {
return this.props.validator.address !== nextProps.validator.address;
return (
this.props.validator.address !== nextProps.validator.address ||
this.props.validator.totalStake !== nextProps.validator.totalStake
);
}

render() {
Expand Down
10 changes: 8 additions & 2 deletions src/library/ValidatorList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { ValidatorListProps } from './types';
import { FilterHeaders } from './Filters/FilterHeaders';
import { FilterBadges } from './Filters/FilterBadges';
import type { NominationStatus } from './ValidatorItem/types';
import { useStaking } from 'contexts/Staking';

export const ValidatorListInner = ({
nominator: initialNominator,
Expand Down Expand Up @@ -79,10 +80,11 @@ export const ValidatorListInner = ({
const { activeEra } = useNetworkMetrics();
const { activeAccount } = useActiveAccounts();
const { setModalResize } = useOverlay().modal;
const { injectValidatorListData } = useValidators();
const { injectValidatorListData, sessionValidators } = useValidators();
const { getNomineesStatus } = useNominationStatus();
const { getPoolNominationStatus } = useBondedPools();
const { applyFilter, applyOrder, applySearch } = useValidatorFilters();
const { eraStakers } = useStaking();

const { selected, listFormat, setListFormat } = listProvider;
const includes = getFilters('include', 'validators');
Expand Down Expand Up @@ -164,6 +166,10 @@ export const ValidatorListInner = ({
setRenderIterationState(iter);
};

useEffect(() => {
setupValidatorList();
}, [eraStakers]);

// Pagination.
const totalPages = Math.ceil(validators.length / ListItemsPerPage);
const pageEnd = page * ListItemsPerPage - 1;
Expand Down Expand Up @@ -303,7 +309,7 @@ export const ValidatorListInner = ({
// List ui changes / validator changes trigger re-render of list.
useEffect(() => {
if (allowFilters && fetched) handleValidatorsFilterUpdate();
}, [order, isSyncing, includes?.length, excludes?.length]);
}, [order, isSyncing, includes?.length, excludes?.length, sessionValidators]);

// Handle modal resize on list format change.
useEffect(() => {
Expand Down
118 changes: 59 additions & 59 deletions src/workers/stakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,69 +126,69 @@ const processExposures = (data: DataInitialiseExposures) => {
})) ?? [];

// Accumulate active nominators and min active stake threshold.
if (others.length) {
// Sort `others` by value bonded, largest first.
others = others.sort((a, b) => {
const r = new BigNumber(rmCommas(b.value)).minus(rmCommas(a.value));
return r.isZero() ? 0 : r.isLessThan(0) ? -1 : 1;
});

const lowestRewardIndex = Math.min(
maxNominatorRewardedPerValidator - 1,
others.length
);

const lowestReward =
others.length > 0
? planckToUnit(
new BigNumber(others[lowestRewardIndex]?.value || 0),
units
).toString()
: '0';

const oversubscribed = others.length > maxNominatorRewardedPerValidator;

stakers.push({
address,
lowestReward,
oversubscribed,
others,
own: rmCommas(val.own),
total: rmCommas(val.total),
});

// Accumulate active stake for all nominators.
for (const o of others) {
const value = new BigNumber(rmCommas(o.value));

// Check nominator already exists.
const index = nominators.findIndex(({ who }) => who === o.who);

// Add value to nominator, otherwise add new entry.
if (index === -1) {
nominators.push({
who: o.who,
value: value.toString(),
});
} else {
nominators[index].value = new BigNumber(nominators[index].value)
.plus(value)
.toFixed();
}
}

// get own stake if present
const own = others.find(({ who }) => who === activeAccount);
if (own !== undefined) {
activeAccountOwnStake.push({
address,
value: planckToUnit(
new BigNumber(rmCommas(own.value)),
// if (others.length) {
// Sort `others` by value bonded, largest first.
others = others.sort((a, b) => {
const r = new BigNumber(rmCommas(b.value)).minus(rmCommas(a.value));
return r.isZero() ? 0 : r.isLessThan(0) ? -1 : 1;
});

const lowestRewardIndex = Math.min(
maxNominatorRewardedPerValidator - 1,
others.length
);

const lowestReward =
others.length > 0
? planckToUnit(
new BigNumber(others[lowestRewardIndex]?.value || 0),
units
).toFixed(),
).toString()
: '0';

const oversubscribed = others.length > maxNominatorRewardedPerValidator;

stakers.push({
address,
lowestReward,
oversubscribed,
others,
own: rmCommas(val.own),
total: rmCommas(val.total),
});

// Accumulate active stake for all nominators.
for (const o of others) {
const value = new BigNumber(rmCommas(o.value));

// Check nominator already exists.
const index = nominators.findIndex(({ who }) => who === o.who);

// Add value to nominator, otherwise add new entry.
if (index === -1) {
nominators.push({
who: o.who,
value: value.toString(),
});
} else {
nominators[index].value = new BigNumber(nominators[index].value)
.plus(value)
.toFixed();
}
}

// get own stake if present
const own = others.find(({ who }) => who === activeAccount);
if (own !== undefined) {
activeAccountOwnStake.push({
address,
value: planckToUnit(
new BigNumber(rmCommas(own.value)),
units
).toFixed(),
});
}
// }
});

return {
Expand Down

0 comments on commit f6b53c2

Please sign in to comment.