Show over nominators in staking overview (#3574)

* Show over nominators in staking overview

* Only summary red

* Non badge on exactly 64
This commit is contained in:
Jaco Greeff 2020-08-30 15:17:26 +02:00 committed by GitHub
parent bad2cc63d9
commit 1525ce71dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 7 deletions

View File

@ -17,7 +17,7 @@ function MaxBadge ({ numNominators }: Props): React.ReactElement<Props> | null {
const max = (api.consts.staking?.maxNominatorRewardedPerValidator || MAX_NOM_PAYOUTS);
if (!numNominators || max.gtn(numNominators)) {
if (!numNominators || max.gten(numNominators)) {
return null;
}

View File

@ -5,27 +5,46 @@
import { Balance } from '@polkadot/types/interfaces';
import BN from 'bn.js';
import React from 'react';
import React, { useMemo } from 'react';
import { AddressMini, Expander } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import { MAX_NOM_PAYOUTS } from '../../constants';
interface Props {
stakeOther?: BN;
nominators: [string, Balance][];
}
function StakeOther ({ nominators, stakeOther }: Props): React.ReactElement<Props> {
function StakeOther ({ nominators }: Props): React.ReactElement<Props> {
const { api } = useApi();
const [rewarded, rewardedTotal, unrewarded, unrewardedTotal] = useMemo(
(): [[string, Balance][], BN, [string, Balance][], BN] => {
const sorted = nominators.sort((a, b) => b[1].cmp(a[1]));
const max = (api.consts.staking?.maxNominatorRewardedPerValidator || MAX_NOM_PAYOUTS).toNumber();
const rewarded = sorted.slice(0, max);
const rewardedTotal = rewarded.reduce((total, [, value]) => total.iadd(value), new BN(0));
const unrewarded = sorted.slice(max);
const unrewardedTotal = unrewarded.reduce((total, [, value]) => total.iadd(value), new BN(0));
return [rewarded, rewardedTotal, unrewarded, unrewardedTotal];
},
[api, nominators]
);
return (
<td className='number all'>
{stakeOther?.gtn(0) && (
{rewarded.length > 0 && (
<>
<Expander summary={
<FormatBalance
labelPost={` (${nominators.length})`}
value={stakeOther}
labelPost={` (${rewarded.length})`}
value={rewardedTotal}
/>
}>
{nominators.map(([who, bonded]): React.ReactNode =>
{rewarded.map(([who, bonded]): React.ReactNode =>
<AddressMini
bonded={bonded}
key={who}
@ -34,6 +53,26 @@ function StakeOther ({ nominators, stakeOther }: Props): React.ReactElement<Prop
/>
)}
</Expander>
{unrewarded.length > 0 && (
<Expander
className='stakeOver'
summary={
<FormatBalance
labelPost={` (${unrewarded.length})`}
value={unrewardedTotal}
/>
}
>
{unrewarded.map(([who, bonded]): React.ReactNode =>
<AddressMini
bonded={bonded}
key={who}
value={who}
withBonded
/>
)}
</Expander>
)}
</>
)}
</td>

View File

@ -203,4 +203,10 @@ export default React.memo(styled(StakingApp)`
margin-top: 0.5rem;
}
}
.ui--Expander.stakeOver {
.ui--Expander-summary {
color: darkred;
}
}
`);