Skip to content

Commit

Permalink
L1-63: Fix other stake list missing nominators from pages other than 1
Browse files Browse the repository at this point in the history
  • Loading branch information
youPickItUp committed Oct 29, 2024
1 parent 447d9f1 commit 4ade054
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tmp/
.yarn/*
!.yarn/releases
!.yarn/plugins
!.yarn/patches
.pnp.*
cc-test-reporter
package-lock.json
Expand Down
123 changes: 89 additions & 34 deletions .yarn/patches/@polkadot-api-derive-npm-13.2.1-19d2cc1087.patch

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions packages/page-staking/src/Targets/Validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ function Validator ({ allSlashes, canSelect, filterName, info: { accountId, bond
return null;
}

console.log(nominatedBy);

return (
<tr>
<Table.Column.Favorite
Expand Down
8 changes: 4 additions & 4 deletions packages/page-staking/src/Validators/Address/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ interface StakingState {
stakeOwn?: BN;
}

function expandInfo ({ exposureMeta, exposurePaged, validatorPrefs }: ValidatorInfo): StakingState {
let nominators: NominatorValue[] | undefined;
function expandInfo ({ exposureMeta, nominators, validatorPrefs }: ValidatorInfo): StakingState {
let nominatorsParsed: NominatorValue[] | undefined;
let stakeTotal: BN | undefined;
let stakeOther: BN | undefined;
let stakeOwn: BN | undefined;

if (exposureMeta?.total) {
nominators = exposurePaged.others.map(({ value, who }) => ({
nominatorsParsed = nominators.map(({ value, who }) => ({
nominatorId: who.toString(),
value: value.unwrap()
}));
Expand All @@ -60,7 +60,7 @@ function expandInfo ({ exposureMeta, exposurePaged, validatorPrefs }: ValidatorI

return {
commission: commission?.toHuman(),
nominators,
nominators: nominatorsParsed,
stakeOther,
stakeOwn,
stakeTotal
Expand Down
3 changes: 2 additions & 1 deletion packages/page-staking/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { Inflation } from '@polkadot/react-hooks/types';
import type { Vec } from '@polkadot/types';
import type { AccountId, Balance, BlockNumber, EraIndex, Hash, SessionIndex, ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
import type { SpStakingExposurePage, SpStakingPagedExposureMetadata } from '@polkadot/types/lookup';
import type { SpStakingExposurePage, SpStakingIndividualExposure, SpStakingPagedExposureMetadata } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util';

export type Nominators = Record<string, string[]>;
Expand Down Expand Up @@ -69,6 +69,7 @@ export interface ValidatorInfo extends ValidatorInfoRank {
knownLength: BN;
lastPayout?: BN;
minNominated: BN;
nominators: Vec<SpStakingIndividualExposure>;
numNominators: number;
numRecentPayouts: number;
skipRewards: boolean;
Expand Down
25 changes: 7 additions & 18 deletions packages/page-staking/src/useSortedTargets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

import type { ApiPromise } from '@polkadot/api';
import type { DeriveSessionInfo, DeriveStakingElected, DeriveStakingQuery, DeriveStakingWaiting } from '@polkadot/api-derive/types';
import type { DeriveSessionInfo, DeriveStakingElected, DeriveStakingWaiting } from '@polkadot/api-derive/types';
import type { Inflation } from '@polkadot/react-hooks/types';
import type { Option, u32, Vec } from '@polkadot/types';
import type { PalletStakingStakingLedger, SpStakingExposure, SpStakingExposurePage, SpStakingIndividualExposure, SpStakingPagedExposureMetadata } from '@polkadot/types/lookup';
import type { PalletStakingStakingLedger, SpStakingExposure, SpStakingExposurePage, SpStakingPagedExposureMetadata } from '@polkadot/types/lookup';
import type { EraValidators, SortedTargets, TargetSortBy, ValidatorInfo } from './types.js';

import { useMemo } from 'react';
Expand Down Expand Up @@ -35,18 +35,6 @@ interface OldLedger {
claimedRewards: Vec<u32>;
}

interface PatchedDeriveStakingQuery extends DeriveStakingQuery {
allOtherNominators: Vec<SpStakingIndividualExposure>;
}

interface PatchedDeriveStakingElected extends DeriveStakingElected {
info: PatchedDeriveStakingQuery[];
}

interface PatchedDeriveStakingWaiting extends DeriveStakingWaiting {
info: PatchedDeriveStakingQuery[];
}

const EMPTY_PARTIAL: Partial<SortedTargets> = {};
const DEFAULT_FLAGS_ELECTED = { withController: true, withExposure: true, withExposureErasStakersLegacy: true, withExposureMeta: true, withPrefs: true };
const DEFAULT_FLAGS_WAITING = { withController: true, withExposureErasStakersLegacy: true, withExposureMeta: true, withPrefs: true };
Expand Down Expand Up @@ -187,7 +175,7 @@ function getForwardCompatibleExposureData (api: ApiPromise, legacyExposure: SpSt
};
}

function extractSingle (api: ApiPromise, allAccounts: string[], derive: PatchedDeriveStakingElected | PatchedDeriveStakingWaiting, favorites: string[], { activeEra, lastEra }: LastEra, historyDepth?: BN, withReturns?: boolean): [ValidatorInfo[], Record<string, BN>] {
function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveStakingElected | DeriveStakingWaiting, favorites: string[], { activeEra, lastEra }: LastEra, historyDepth?: BN, withReturns?: boolean): [ValidatorInfo[], Record<string, BN>] {
const nominators: Record<string, BN> = {};
const emptyExposure = api.createType('SpStakingExposurePage');
const emptyExposureMeta = api.createType('SpStakingPagedExposureMetadata');
Expand Down Expand Up @@ -254,6 +242,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: PatchedD
? lastEraPayout
: undefined,
minNominated,
nominators: allOtherNominators,
numNominators: expMeta?.nominatorCount.toNumber() ?? 0,
numRecentPayouts: earliestEra
? rewards.filter((era) => era.gte(earliestEra)).length
Expand Down Expand Up @@ -292,7 +281,7 @@ function addReturns (inflation: Inflation, baseInfo: Partial<SortedTargets>): Pa
return { ...baseInfo, validators: sortValidators(validators) };
}

function extractBaseInfo (api: ApiPromise, allAccounts: string[], electedDerive: PatchedDeriveStakingElected, waitingDerive: PatchedDeriveStakingWaiting, favorites: string[], totalIssuance: BN, lastEraInfo: LastEra, historyDepth?: BN): Partial<SortedTargets> {
function extractBaseInfo (api: ApiPromise, allAccounts: string[], electedDerive: DeriveStakingElected, waitingDerive: DeriveStakingWaiting, favorites: string[], totalIssuance: BN, lastEraInfo: LastEra, historyDepth?: BN): Partial<SortedTargets> {
const [elected, nominators] = extractSingle(api, allAccounts, electedDerive, favorites, lastEraInfo, historyDepth, true);
const [waiting] = extractSingle(api, allAccounts, waitingDerive, favorites, lastEraInfo);
const activeTotals = elected
Expand Down Expand Up @@ -351,8 +340,8 @@ function useSortedTargetsImpl (favorites: string[], withLedger: boolean): Sorted
api.query.staking.minValidatorBond,
api.query.balances?.totalIssuance
], OPT_MULTI);
const electedInfo = useCall<PatchedDeriveStakingElected>(api.derive.staking.electedInfo, [{ ...DEFAULT_FLAGS_ELECTED, withClaimedRewardsEras: withLedger, withLedger }]);
const waitingInfo = useCall<PatchedDeriveStakingWaiting>(api.derive.staking.waitingInfo, [{ ...DEFAULT_FLAGS_WAITING, withClaimedRewardsEras: withLedger, withLedger }]);
const electedInfo = useCall<DeriveStakingElected>(api.derive.staking.electedInfo, [{ ...DEFAULT_FLAGS_ELECTED, withClaimedRewardsEras: withLedger, withLedger }]);
const waitingInfo = useCall<DeriveStakingWaiting>(api.derive.staking.waitingInfo, [{ ...DEFAULT_FLAGS_WAITING, withClaimedRewardsEras: withLedger, withLedger }]);
const lastEraInfo = useCall<LastEra>(api.derive.session.info, undefined, OPT_ERA);
const eraValidators = useCall<EraValidators>(api.query.elections.currentEraValidators);

Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ __metadata:

"@polkadot/api-derive@patch:@polkadot/api-derive@npm%3A13.2.1#~/.yarn/patches/@polkadot-api-derive-npm-13.2.1-19d2cc1087.patch":
version: 13.2.1
resolution: "@polkadot/api-derive@patch:@polkadot/api-derive@npm%3A13.2.1#~/.yarn/patches/@polkadot-api-derive-npm-13.2.1-19d2cc1087.patch::version=13.2.1&hash=50f2f4"
resolution: "@polkadot/api-derive@patch:@polkadot/api-derive@npm%3A13.2.1#~/.yarn/patches/@polkadot-api-derive-npm-13.2.1-19d2cc1087.patch::version=13.2.1&hash=ebde46"
dependencies:
"@polkadot/api": "npm:13.2.1"
"@polkadot/api-augment": "npm:13.2.1"
Expand All @@ -1416,7 +1416,7 @@ __metadata:
"@polkadot/util-crypto": "npm:^13.1.1"
rxjs: "npm:^7.8.1"
tslib: "npm:^2.7.0"
checksum: 10/634a405935c195c741167ae9420010f4a8104fc36a7f5012b26eeb99b37e906a70494d4d8ba7bdf0c295a70a05e3c57fa35b36b0760adabf6e2ce316ef390d88
checksum: 10/9e61105efbd24dc76b3e04a83edc05f7b7d777fd05946f06780442f9175b309fbc0190a45d80d4b042127b3da09bd7db353bca82af3fb699a9ac83926bcaf800
languageName: node
linkType: hard

Expand Down

0 comments on commit 4ade054

Please sign in to comment.