- | {numNominators || ''} |
+ {numNominators || ''} |
+ {nominatedBy.length || ''} |
{
isCommission
diff --git a/packages/page-staking/src/Targets/index.tsx b/packages/page-staking/src/Targets/index.tsx
index 3f996b9c9d..df8a924d12 100644
--- a/packages/page-staking/src/Targets/index.tsx
+++ b/packages/page-staking/src/Targets/index.tsx
@@ -3,7 +3,7 @@
import type { DeriveStakingOverview, DeriveHasIdentity } from '@polkadot/api-derive/types';
import type { StakerState } from '@polkadot/react-hooks/types';
-import type { SortedTargets, TargetSortBy, ValidatorInfo } from '../types';
+import type { NominatedBy, SortedTargets, TargetSortBy, ValidatorInfo } from '../types';
import BN from 'bn.js';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
@@ -16,6 +16,7 @@ import Filtering from '../Filtering';
import Legend from '../Legend';
import { MAX_NOMINATIONS } from '../constants';
import { useTranslation } from '../translate';
+import useNominations from '../useNominations';
import Nominate from './Nominate';
import Summary from './Summary';
import Validator from './Validator';
@@ -49,16 +50,14 @@ interface SortState {
const CLASSES: Record = {
rankBondOther: 'media--1600',
- rankBondOwn: 'media--900',
- rankComm: 'media--1100',
- rankNumNominators: 'media--1200'
+ rankBondOwn: 'media--900'
};
-const MAX_CAP_PERCENT = 75;
-const MAX_COMM_PERCENT = 20; // %
+const MAX_CAP_PERCENT = 100; // 75 if only using numNominators
+const MAX_COMM_PERCENT = 20;
const MAX_DAYS = 7;
-const SORT_KEYS = ['rankNumNominators', 'rankComm', 'rankBondTotal', 'rankBondOwn', 'rankBondOther', 'rankOverall'];
+const SORT_KEYS = ['rankBondTotal', 'rankBondOwn', 'rankBondOther', 'rankOverall'];
-function filterValidators (validators: ValidatorInfo[], allIdentity: Record, { daysPayout, isBabe, maxPaid, withElected, withGroup, withIdentity, withPayout, withoutComm, withoutOver }: Flags): ValidatorInfo[] {
+function applyFilter (validators: ValidatorInfo[], allIdentity: Record, { daysPayout, isBabe, maxPaid, withElected, withGroup, withIdentity, withPayout, withoutComm, withoutOver }: Flags, nominatedBy?: Record): ValidatorInfo[] {
const parentIds: string[] = [];
return validators.filter(({ accountId, commissionPer, isElected, isFavorite, lastPayout, numNominators }): boolean => {
@@ -68,13 +67,14 @@ function filterValidators (validators: ValidatorInfo[], allIdentity: Record([]);
const [{ isQueryFiltered, nameFilter }, setNameFilter] = useState({ isQueryFiltered: false, nameFilter: '' });
const [withElected, setWithElected] = useState(false);
@@ -161,8 +162,6 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
rankBondOther: t('other stake'),
rankBondOwn: t('own stake'),
rankBondTotal: t('total stake'),
- rankComm: t('comm.'),
- rankNumNominators: t('nominators'),
rankOverall: t('return')
});
@@ -183,8 +182,8 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
);
const filtered = useMemo(
- () => allIdentity && validators && filterValidators(validators, allIdentity, flags),
- [allIdentity, flags, validators]
+ () => allIdentity && validators && nominatedBy && applyFilter(validators, allIdentity, flags, nominatedBy),
+ [allIdentity, flags, nominatedBy, validators]
);
// We are using an effect here to get this async. Sorting will have a double-render, however it allows
@@ -235,6 +234,8 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
const header = useMemo(() => [
[t('validators'), 'start', 3],
[t('payout'), 'media--1500'],
+ [t('nominators'), 'media--1200', 2],
+ [t('comm.'), 'media--1100'],
...(SORT_KEYS as (keyof typeof labelsRef.current)[]).map((header) => [
<>{labelsRef.current[header]}>,
`${sorted ? `isClickable ${sortBy === header ? 'highlight--border' : ''} number` : 'number'} ${CLASSES[header] || ''}`,
@@ -267,7 +268,11 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
/>
('no {{maxCap}}%+ capacity', { replace: { maxCap: MAX_CAP_PERCENT } })}
+ label={
+ MAX_CAP_PERCENT < 100
+ ? t('no {{maxCap}}%+ capacity', { replace: { maxCap: MAX_CAP_PERCENT } })
+ : t('no at capacity')
+ }
onChange={setWithoutOver}
value={withoutOver}
/>
@@ -322,6 +327,12 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
('No active validators to check')}
+ emptySpinner={
+ <>
+ {!(validators && allIdentity) && {t('Retrieving validators')} }
+ {!nominatedBy && {t('Retrieving nominators')} }
+ >
+ }
filter={filter}
header={header}
legend={}
@@ -335,6 +346,7 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
isNominated={myNominees.includes(info.key)}
isSelected={selected.includes(info.key)}
key={info.key}
+ nominatedBy={nominatedBy?.[info.key]}
toggleFavorite={toggleFavorite}
toggleSelected={_toggleSelected}
/>
diff --git a/packages/page-staking/src/types.ts b/packages/page-staking/src/types.ts
index 673d565d69..728e69aef0 100644
--- a/packages/page-staking/src/types.ts
+++ b/packages/page-staking/src/types.ts
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
-import type { AccountId, Balance, BlockNumber, Exposure, Hash, SessionIndex, ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
+import type { AccountId, Balance, BlockNumber, EraIndex, Exposure, Hash, SessionIndex, ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
import type { Inflation } from '@polkadot/react-hooks/types';
import BN from 'bn.js';
@@ -12,6 +12,12 @@ export type AccountFilter = 'all' | 'controller' | 'session' | 'stash' | 'unbond
export type ValidatorFilter = 'all' | 'hasNominators' | 'noNominators' | 'hasWarnings' | 'noWarnings' | 'iNominated' | 'nextSet';
+export interface NominatedBy {
+ index: number;
+ nominatorId: string;
+ submittedIn: EraIndex;
+}
+
export interface Slash {
accountId: AccountId;
amount: Balance;
diff --git a/packages/page-staking/src/useNominations.ts b/packages/page-staking/src/useNominations.ts
new file mode 100644
index 0000000000..a6573dc457
--- /dev/null
+++ b/packages/page-staking/src/useNominations.ts
@@ -0,0 +1,43 @@
+// Copyright 2017-2020 @polkadot/app-staking authors & contributors
+// SPDX-License-Identifier: Apache-2.0
+
+import type { Option, StorageKey } from '@polkadot/types';
+import type { Nominations } from '@polkadot/types/interfaces';
+import type { NominatedBy } from './types';
+
+import { useMemo } from 'react';
+import { useApi, useCall } from '@polkadot/react-hooks';
+
+type Result = Record;
+
+function extractNominators (nominations: [StorageKey, Option][]): Result {
+ return nominations.reduce((mapped: Result, [key, optNoms]) => {
+ if (optNoms.isSome && key.args.length) {
+ const nominatorId = key.args[0].toString();
+ const { submittedIn, targets } = optNoms.unwrap();
+
+ targets.forEach((_validatorId, index): void => {
+ const validatorId = _validatorId.toString();
+ const info = { index: index + 1, nominatorId, submittedIn };
+
+ if (!mapped[validatorId]) {
+ mapped[validatorId] = [info];
+ } else {
+ mapped[validatorId].push(info);
+ }
+ });
+ }
+
+ return mapped;
+ }, {});
+}
+
+export default function useNominations (isActive = true): Result | undefined {
+ const { api } = useApi();
+ const nominators = useCall<[StorageKey, Option][]>(isActive && api.query.staking.nominators.entries);
+
+ return useMemo(
+ () => nominators && extractNominators(nominators),
+ [nominators]
+ );
+}
diff --git a/packages/page-staking/src/useSortedTargets.ts b/packages/page-staking/src/useSortedTargets.ts
index e32af69702..280df67763 100644
--- a/packages/page-staking/src/useSortedTargets.ts
+++ b/packages/page-staking/src/useSortedTargets.ts
@@ -51,8 +51,9 @@ function sortValidators (list: ValidatorInfo[]): ValidatorInfo[] {
return false;
})
.filter((a) => a.bondTotal.gtn(0))
- .sort((a, b) => b.commissionPer - a.commissionPer)
- .map(mapIndex('rankComm'))
+ // ignored, not used atm
+ // .sort((a, b) => b.commissionPer - a.commissionPer)
+ // .map(mapIndex('rankComm'))
.sort((a, b) => b.bondOther.cmp(a.bondOther))
.map(mapIndex('rankBondOther'))
.sort((a, b) => b.bondOwn.cmp(a.bondOwn))
@@ -63,8 +64,9 @@ function sortValidators (list: ValidatorInfo[]): ValidatorInfo[] {
.map(mapIndex('rankPayment'))
.sort((a, b) => a.stakedReturnCmp - b.stakedReturnCmp)
.map(mapIndex('rankReward'))
- .sort((a, b) => b.numNominators - a.numNominators)
- .map(mapIndex('rankNumNominators'))
+ // ignored, not used atm
+ // .sort((a, b) => b.numNominators - a.numNominators)
+ // .map(mapIndex('rankNumNominators'))
.sort((a, b): number => {
const cmp = b.stakedReturnCmp - a.stakedReturnCmp;
diff --git a/packages/react-components/src/Spinner.tsx b/packages/react-components/src/Spinner.tsx
index 16291b1827..35c480afd7 100644
--- a/packages/react-components/src/Spinner.tsx
+++ b/packages/react-components/src/Spinner.tsx
@@ -59,5 +59,9 @@ export default React.memo(styled(Spinner)`
color: inherit !important;
margin: 0.25rem auto 1.5rem auto;
opacity: 0.6;
+
+ div+div {
+ margin-top: 0.25rem;
+ }
}
`);
diff --git a/packages/react-components/src/Table/Body.tsx b/packages/react-components/src/Table/Body.tsx
index 84d54d7867..0212100a8d 100644
--- a/packages/react-components/src/Table/Body.tsx
+++ b/packages/react-components/src/Table/Body.tsx
@@ -107,6 +107,14 @@ export default React.memo(styled(Body)(({ theme }: ThemeProps) => `
width: 0;
}
+ &.no-pad-left {
+ padding-left: 0.125rem;
+ }
+
+ &.no-pad-right {
+ padding-right: 0.125rem;
+ }
+
&.number {
text-align: right;
}
|