Staking warn inactive (#4511)

This commit is contained in:
Jaco Greeff 2021-01-27 14:19:57 +01:00 committed by GitHub
parent 318fe2c2b7
commit 2747c7a6ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -6,7 +6,7 @@ import type { DeriveEraExposure, DeriveSessionIndexes } from '@polkadot/api-deri
import BN from 'bn.js';
import React, { useMemo } from 'react';
import { AddressMini, Expander } from '@polkadot/react-components';
import { AddressMini, Expander, MarkWarning } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { useTranslation } from '../../translate';
@ -112,6 +112,9 @@ function ListNominees ({ nominating, stashId }: Props): React.ReactElement<Props
summary={t<string>('Waiting nominations ({{count}})', { replace: { count: renWaiting[0] } })}
/>
)}
{nomsActive && nomsInactive && (nomsActive.length === 0) && (nomsInactive.length !== 0) && (
<MarkWarning content={t<string>('Your nomination has not been applied to any validator in the active set by the election algorithm. This could mean that all your validators are over-subscribed or that you have less bonded than the lowest nominator elected for each of the validators.')} />
)}
</>
);
}

View File

@ -58,6 +58,7 @@ export interface ValidatorInfo extends ValidatorInfoRank {
key: string;
knownLength: BN;
lastPayout?: BN;
minNominated: BN;
numNominators: number;
numRecentPayouts: number;
skipRewards: boolean;
@ -74,6 +75,7 @@ export interface SortedTargets {
inflation: Inflation;
lowStaked?: BN;
medianComm: number;
minNominated: BN;
nominators?: string[];
totalStaked?: BN;
totalIssuance?: BN;

View File

@ -89,6 +89,13 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
? [exposure.own.unwrap(), exposure.total.unwrap()]
: [BN_ZERO, BN_ZERO];
const skipRewards = bondTotal.isZero();
const minNominated = (exposure.others || []).reduce((min: BN, { value }): BN => {
const actual = value.unwrap();
return min.isZero() || actual.lt(min)
? actual
: min;
}, BN_ZERO);
if (bondTotal.isZero()) {
bondTotal = bondOwn = stakingLedger.total.unwrap();
@ -129,6 +136,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
key,
knownLength: activeEra.sub(stakingLedger.claimedRewards[0] || activeEra),
lastPayout,
minNominated,
numNominators: (exposure.others || []).length,
numRecentPayouts: earliestEra
? stakingLedger.claimedRewards.filter((era) => era.gte(earliestEra)).length
@ -169,6 +177,11 @@ function extractInfo (api: ApiPromise, allAccounts: string[], electedDerive: Der
});
// all validators, calc median commission
const minNominated = elected.reduce((min: BN, { minNominated }) => {
return min.isZero() || minNominated.lt(min)
? minNominated
: min;
}, BN_ZERO);
const validators = sortValidators(arrayFlatten([elected, waiting]));
const commValues = validators.map(({ commissionPer }) => commissionPer).sort((a, b) => a - b);
const midIndex = Math.floor(commValues.length / 2);
@ -188,6 +201,7 @@ function extractInfo (api: ApiPromise, allAccounts: string[], electedDerive: Der
inflation,
lowStaked: activeTotals[0] || BN_ZERO,
medianComm,
minNominated,
nominators,
totalIssuance,
totalStaked,
@ -222,5 +236,5 @@ export default function useSortedTargets (favorites: string[], withLedger: boole
[api, allAccounts, electedInfo, favorites, historyDepth, lastEraInfo, totalIssuance, waitingInfo]
);
return { inflation: { inflation: 0, stakedReturn: 0 }, medianComm: 0, ...partial };
return { inflation: { inflation: 0, stakedReturn: 0 }, medianComm: 0, minNominated: BN_ZERO, ...partial };
}