Fix Staking with latest breaking changes! (#10498)
* Update pjs deps * Rework useSortedTargets with breaking changes * lint * Fix kickNominees * Fix ChartStake * Lots of remaining fixes!!!!! * app-routing * Remove withClaimedRewardsEras * Fix useSortedTargets * Fix small nits * More nits
This commit is contained in:
parent
ca3f368d47
commit
7a897eab81
30
package.json
30
package.json
@ -91,24 +91,24 @@
|
||||
"source-map-explorer": "^2.5.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"@polkadot/api": "^10.13.1",
|
||||
"@polkadot/api-augment": "^10.13.1",
|
||||
"@polkadot/api-base": "^10.13.1",
|
||||
"@polkadot/api-contract": "^10.13.1",
|
||||
"@polkadot/api-derive": "^10.13.1",
|
||||
"@polkadot/api": "^11.0.1",
|
||||
"@polkadot/api-augment": "^11.0.1",
|
||||
"@polkadot/api-base": "^11.0.1",
|
||||
"@polkadot/api-contract": "^11.0.1",
|
||||
"@polkadot/api-derive": "^11.0.1",
|
||||
"@polkadot/hw-ledger": "^12.6.2",
|
||||
"@polkadot/keyring": "^12.6.2",
|
||||
"@polkadot/networks": "^12.6.2",
|
||||
"@polkadot/phishing": "^0.22.5",
|
||||
"@polkadot/rpc-augment": "^10.13.1",
|
||||
"@polkadot/rpc-core": "^10.13.1",
|
||||
"@polkadot/rpc-provider": "^10.13.1",
|
||||
"@polkadot/types": "^10.13.1",
|
||||
"@polkadot/types-augment": "^10.13.1",
|
||||
"@polkadot/types-codec": "^10.13.1",
|
||||
"@polkadot/types-create": "^10.13.1",
|
||||
"@polkadot/types-known": "^10.13.1",
|
||||
"@polkadot/types-support": "^10.13.1",
|
||||
"@polkadot/phishing": "^0.22.6",
|
||||
"@polkadot/rpc-augment": "^11.0.1",
|
||||
"@polkadot/rpc-core": "^11.0.1",
|
||||
"@polkadot/rpc-provider": "^11.0.1",
|
||||
"@polkadot/types": "^11.0.1",
|
||||
"@polkadot/types-augment": "^11.0.1",
|
||||
"@polkadot/types-codec": "^11.0.1",
|
||||
"@polkadot/types-create": "^11.0.1",
|
||||
"@polkadot/types-known": "^11.0.1",
|
||||
"@polkadot/types-support": "^11.0.1",
|
||||
"@polkadot/util": "^12.6.2",
|
||||
"@polkadot/util-crypto": "^12.6.2",
|
||||
"@polkadot/wasm-crypto": "^7.3.2",
|
||||
|
||||
@ -37,12 +37,12 @@
|
||||
"@peaqnetwork/type-definitions": "0.0.4",
|
||||
"@pendulum-chain/type-definitions": "0.3.8",
|
||||
"@phala/typedefs": "0.2.33",
|
||||
"@polkadot/api": "^10.13.1",
|
||||
"@polkadot/api-derive": "^10.13.1",
|
||||
"@polkadot/api": "^11.0.1",
|
||||
"@polkadot/api-derive": "^11.0.1",
|
||||
"@polkadot/networks": "^12.6.2",
|
||||
"@polkadot/react-identicon": "^3.6.6",
|
||||
"@polkadot/types": "^10.13.1",
|
||||
"@polkadot/types-codec": "^10.13.1",
|
||||
"@polkadot/types": "^11.0.1",
|
||||
"@polkadot/types-codec": "^11.0.1",
|
||||
"@polkadot/util": "^12.6.2",
|
||||
"@polkadot/wasm-util": "^7.3.2",
|
||||
"@polkadot/x-fetch": "^12.6.2",
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { u32, Vec } from '@polkadot/types';
|
||||
import type { PalletStakingStakingLedger, SpStakingExposure } from '@polkadot/types/lookup';
|
||||
import type { SpStakingPagedExposureMetadata } from '@polkadot/types/lookup';
|
||||
import type { Route, TFunction } from './types.js';
|
||||
|
||||
import Component from '@polkadot/app-staking';
|
||||
@ -14,12 +14,12 @@ import { assert, BN_ONE } from '@polkadot/util';
|
||||
function needsApiCheck (api: ApiPromise): boolean {
|
||||
try {
|
||||
// we need a known Exposure type
|
||||
const { others: [{ value, who }], own, total } = api.registry.createType<SpStakingExposure>(
|
||||
unwrapStorageType(api.registry, api.query.staking.erasStakers.creator.meta.type),
|
||||
{ others: [{ value: BN_ONE, who: ZERO_ACCOUNT }], own: BN_ONE, total: BN_ONE }
|
||||
const { nominatorCount, own, pageCount, total } = api.registry.createType<SpStakingPagedExposureMetadata>(
|
||||
unwrapStorageType(api.registry, api.query.staking.erasStakersOverview.creator.meta.type),
|
||||
{ nominatorCount: BN_ONE, own: BN_ONE, pageCount: BN_ONE, total: BN_ONE }
|
||||
);
|
||||
|
||||
assert(total && own && value && who && total.eq(BN_ONE) && own.eq(BN_ONE) && value.eq(BN_ONE), 'Needs a known Exposure type');
|
||||
assert(total && own && nominatorCount && pageCount && total.eq(BN_ONE) && own.eq(BN_ONE), 'Needs a known Exposure type');
|
||||
} catch {
|
||||
console.warn('Unable to create known-shape Exposure type, disabling staking route');
|
||||
|
||||
@ -47,21 +47,12 @@ function needsApiCheck (api: ApiPromise): boolean {
|
||||
|
||||
// For compatibility - `api.query.staking.ledger` returns `legacyClaimedRewards` instead of `claimedRewards` as of v1.4
|
||||
try {
|
||||
const v = api.registry.createType<PalletStakingStakingLedger>(
|
||||
unwrapStorageType(api.registry, api.query.staking.ledger.creator.meta.type),
|
||||
{ claimedRewards: [1, 2, 3] }
|
||||
const v = api.registry.createType<Vec<u32>>(
|
||||
unwrapStorageType(api.registry, api.query.staking.claimedRewards.creator.meta.type),
|
||||
[0]
|
||||
);
|
||||
|
||||
if ((v as unknown as { claimedRewards: Vec<u32> }).claimedRewards) {
|
||||
assert((v as unknown as { claimedRewards: Vec<u32> }).claimedRewards.eq([1, 2, 3]), 'Needs a claimedRewards array');
|
||||
} else {
|
||||
const v = api.registry.createType<PalletStakingStakingLedger>(
|
||||
unwrapStorageType(api.registry, api.query.staking.ledger.creator.meta.type),
|
||||
{ legacyClaimedRewards: [1, 2, 3] }
|
||||
);
|
||||
|
||||
assert(v.legacyClaimedRewards.eq([1, 2, 3]), 'Needs a legacyClaimedRewards array');
|
||||
}
|
||||
assert(v.eq([0]), 'Needs a legacyClaimedRewards array');
|
||||
} catch {
|
||||
console.warn('No known legacyClaimedRewards or claimedRewards inside staking ledger, disabling staking route');
|
||||
|
||||
@ -76,7 +67,7 @@ export default function create (t: TFunction): Route {
|
||||
Component,
|
||||
display: {
|
||||
needsApi: [
|
||||
'query.staking.erasStakers',
|
||||
'query.staking.erasStakersOverview',
|
||||
'tx.staking.bond'
|
||||
],
|
||||
needsApiCheck
|
||||
|
||||
@ -17,11 +17,11 @@
|
||||
"version": "0.136.2-2-x",
|
||||
"dependencies": {
|
||||
"@polkadot/hw-ledger": "^12.6.2",
|
||||
"@polkadot/phishing": "^0.22.5",
|
||||
"@polkadot/phishing": "^6",
|
||||
"@polkadot/react-components": "^0.136.2-2-x",
|
||||
"@polkadot/react-hooks": "^0.136.2-2-x",
|
||||
"@polkadot/util": "^12.6.2",
|
||||
"@polkadot/vanitygen": "^0.56.7",
|
||||
"@polkadot/vanitygen": "^0.56.8",
|
||||
"detect-browser": "^5.3.0",
|
||||
"file-saver": "^2.0.5"
|
||||
},
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
"type": "module",
|
||||
"version": "0.136.2-2-x",
|
||||
"dependencies": {
|
||||
"@polkadot/api-contract": "^10.13.1",
|
||||
"@polkadot/api-contract": "^11.0.1",
|
||||
"eventemitter3": "^5.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@ -34,7 +34,7 @@ function KickNominees ({ className = '', controllerId, nominating, onClose, stas
|
||||
const queryInfo = useCall<DeriveStakingQuery>(api.derive.staking.query, [stashId, accountOpts]);
|
||||
|
||||
const nominators = useMemo(
|
||||
() => queryInfo?.exposure?.others.map(({ who }) => who.toString()),
|
||||
() => queryInfo?.exposurePaged.isSome && queryInfo?.exposurePaged.unwrap().others.map(({ who }) => who.toString()),
|
||||
[queryInfo]
|
||||
);
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import type { LineData, Props } from './types.js';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { useApi, useCall } from '@polkadot/react-hooks';
|
||||
import { BN, formatBalance } from '@polkadot/util';
|
||||
import { BN, BN_ZERO, formatBalance } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate.js';
|
||||
import Chart from './Chart.js';
|
||||
@ -16,24 +16,27 @@ import { balanceToNumber } from './util.js';
|
||||
const COLORS_STAKE = [undefined, '#8c2200', '#acacac'];
|
||||
|
||||
function extractStake (labels: string[], exposures: DeriveOwnExposure[], divisor: BN): LineData {
|
||||
const cliSet = new Array<number>(labels.length);
|
||||
const expSet = new Array<number>(labels.length);
|
||||
const expPagedSet = new Array<number>(labels.length);
|
||||
const expMetaSet = new Array<number>(labels.length);
|
||||
const avgSet = new Array<number>(labels.length);
|
||||
const [total, avgCount] = exposures.reduce(([total, avgCount], { clipped }) => {
|
||||
const cli = balanceToNumber(clipped.total?.unwrap(), divisor);
|
||||
const [total, avgCount] = exposures.reduce(([total, avgCount], { exposureMeta }) => {
|
||||
const expMeta = exposureMeta.isSome && exposureMeta.unwrap();
|
||||
const expM = balanceToNumber((expMeta && expMeta.total?.unwrap()) || BN_ZERO, divisor);
|
||||
|
||||
if (cli > 0) {
|
||||
total += cli;
|
||||
if (expM > 0) {
|
||||
total += expM;
|
||||
avgCount++;
|
||||
}
|
||||
|
||||
return [total, avgCount];
|
||||
}, [0, 0]);
|
||||
|
||||
exposures.forEach(({ clipped, era, exposure }): void => {
|
||||
exposures.forEach(({ era, exposureMeta, exposurePaged }): void => {
|
||||
const expPaged = exposurePaged.isSome && exposurePaged.unwrap();
|
||||
const expMeta = exposureMeta.isSome && exposureMeta.unwrap();
|
||||
// Darwinia Crab doesn't have the total field
|
||||
const cli = balanceToNumber(clipped.total?.unwrap(), divisor);
|
||||
const exp = balanceToNumber(exposure.total?.unwrap(), divisor);
|
||||
const expP = balanceToNumber((expPaged && expPaged.pageTotal?.unwrap()) || BN_ZERO, divisor);
|
||||
const expM = balanceToNumber((expMeta && expMeta.total?.unwrap()) || BN_ZERO, divisor);
|
||||
const avg = avgCount > 0
|
||||
? Math.ceil(total * 100 / avgCount) / 100
|
||||
: 0;
|
||||
@ -41,12 +44,12 @@ function extractStake (labels: string[], exposures: DeriveOwnExposure[], divisor
|
||||
|
||||
if (index !== -1) {
|
||||
avgSet[index] = avg;
|
||||
cliSet[index] = cli;
|
||||
expSet[index] = exp;
|
||||
expPagedSet[index] = expP;
|
||||
expMetaSet[index] = expM;
|
||||
}
|
||||
});
|
||||
|
||||
return [cliSet, expSet, avgSet];
|
||||
return [expPagedSet, expMetaSet, avgSet];
|
||||
}
|
||||
|
||||
function ChartStake ({ labels, validatorId }: Props): React.ReactElement<Props> {
|
||||
@ -75,7 +78,7 @@ function ChartStake ({ labels, validatorId }: Props): React.ReactElement<Props>
|
||||
);
|
||||
|
||||
const legends = useMemo(() => [
|
||||
t('{{currency}} clipped', { replace: { currency } }),
|
||||
t('{{currency}} paged', { replace: { currency } }),
|
||||
t('{{currency}} total', { replace: { currency } }),
|
||||
t('{{currency}} average', { replace: { currency } })
|
||||
], [currency, t]);
|
||||
|
||||
@ -50,19 +50,19 @@ interface StakingState {
|
||||
stakeOwn?: BN;
|
||||
}
|
||||
|
||||
function expandInfo ({ exposure, validatorPrefs }: ValidatorInfo, minCommission?: BN): StakingState {
|
||||
function expandInfo ({ exposureMeta, exposurePaged, validatorPrefs }: ValidatorInfo, minCommission?: BN): StakingState {
|
||||
let nominators: NominatorValue[] | undefined;
|
||||
let stakeTotal: BN | undefined;
|
||||
let stakeOther: BN | undefined;
|
||||
let stakeOwn: BN | undefined;
|
||||
|
||||
if (exposure?.total) {
|
||||
nominators = exposure.others.map(({ value, who }) => ({
|
||||
if (exposureMeta?.total) {
|
||||
nominators = exposurePaged.others.map(({ value, who }) => ({
|
||||
nominatorId: who.toString(),
|
||||
value: value.unwrap()
|
||||
}));
|
||||
stakeTotal = exposure.total?.unwrap() || BN_ZERO;
|
||||
stakeOwn = exposure.own.unwrap();
|
||||
stakeTotal = exposureMeta.total?.unwrap() || BN_ZERO;
|
||||
stakeOwn = exposureMeta.own.unwrap();
|
||||
stakeOther = stakeTotal.sub(stakeOwn);
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Inflation } from '@polkadot/react-hooks/types';
|
||||
import type { AccountId, Balance, BlockNumber, EraIndex, Exposure, Hash, SessionIndex, ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
|
||||
import type { AccountId, Balance, BlockNumber, EraIndex, Hash, SessionIndex, ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
|
||||
import type { SpStakingExposurePage, SpStakingPagedExposureMetadata } from '@polkadot/types/lookup';
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
export type Nominators = Record<string, string[]>;
|
||||
@ -51,7 +52,8 @@ export interface ValidatorInfo extends ValidatorInfoRank {
|
||||
bondShare: number;
|
||||
bondTotal: BN;
|
||||
commissionPer: number;
|
||||
exposure: Exposure;
|
||||
exposurePaged: SpStakingExposurePage;
|
||||
exposureMeta: SpStakingPagedExposureMetadata
|
||||
isActive: boolean;
|
||||
isBlocking: boolean;
|
||||
isElected: boolean;
|
||||
|
||||
@ -36,7 +36,9 @@ interface OldLedger {
|
||||
}
|
||||
|
||||
const EMPTY_PARTIAL: Partial<SortedTargets> = {};
|
||||
const DEFAULT_FLAGS_ELECTED = { withController: true, withExposure: true, withPrefs: true };
|
||||
// To get claimedRewards, activate `withClaimedRewardsEras` to true.
|
||||
// Currently its turned off because of performance issues.
|
||||
const DEFAULT_FLAGS_ELECTED = { withClaimedRewardsEras: false, withController: true, withExposure: true, withExposureMeta: true, withPrefs: true };
|
||||
const DEFAULT_FLAGS_WAITING = { withController: true, withPrefs: true };
|
||||
|
||||
const OPT_ERA = {
|
||||
@ -68,8 +70,10 @@ const OPT_MULTI = {
|
||||
})
|
||||
};
|
||||
|
||||
function getLegacyRewards (ledger: PalletStakingStakingLedger): u32[] {
|
||||
return ledger.legacyClaimedRewards || (ledger as unknown as OldLedger).claimedRewards || [];
|
||||
function getLegacyRewards (ledger: PalletStakingStakingLedger, claimedRewardsEras: Vec<u32>): u32[] {
|
||||
const legacyRewards = ledger.legacyClaimedRewards || (ledger as unknown as OldLedger).claimedRewards || [];
|
||||
|
||||
return legacyRewards.concat(claimedRewardsEras.toArray());
|
||||
}
|
||||
|
||||
function mapIndex (mapBy: TargetSortBy): (info: ValidatorInfo, index: number) => ValidatorInfo {
|
||||
@ -128,16 +132,18 @@ function sortValidators (list: ValidatorInfo[]): ValidatorInfo[] {
|
||||
|
||||
function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveStakingElected | DeriveStakingWaiting, favorites: string[], { activeEra, eraLength, lastEra, sessionLength }: LastEra, historyDepth?: BN, withReturns?: boolean): [ValidatorInfo[], Record<string, BN>] {
|
||||
const nominators: Record<string, BN> = {};
|
||||
const emptyExposure = api.createType('Exposure');
|
||||
const emptyExposure = api.createType('SpStakingExposurePage');
|
||||
const emptyExposureMeta = api.createType('SpStakingPagedExposureMetadata');
|
||||
const earliestEra = historyDepth && lastEra.sub(historyDepth).iadd(BN_ONE);
|
||||
const list = new Array<ValidatorInfo>(derive.info.length);
|
||||
|
||||
for (let i = 0; i < derive.info.length; i++) {
|
||||
const { accountId, exposure = emptyExposure, stakingLedger, validatorPrefs } = derive.info[i];
|
||||
|
||||
const { accountId, claimedRewardsEras, exposureMeta, exposurePaged, stakingLedger, validatorPrefs } = derive.info[i];
|
||||
const exp = exposurePaged.isSome && exposurePaged.unwrap();
|
||||
const expMeta = exposureMeta.isSome && exposureMeta.unwrap();
|
||||
// some overrides (e.g. Darwinia Crab) does not have the own/total field in Exposure
|
||||
let [bondOwn, bondTotal] = exposure.total
|
||||
? [exposure.own.unwrap(), exposure.total.unwrap()]
|
||||
let [bondOwn, bondTotal] = exp && expMeta
|
||||
? [expMeta.own.unwrap(), expMeta.total.unwrap()]
|
||||
: [BN_ZERO, BN_ZERO];
|
||||
|
||||
const skipRewards = bondTotal.isZero();
|
||||
@ -147,7 +153,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
|
||||
}
|
||||
|
||||
// some overrides (e.g. Darwinia Crab) does not have the value field in IndividualExposure
|
||||
const minNominated = (exposure.others || []).reduce((min: BN, { value = api.createType('Compact<Balance>') }): BN => {
|
||||
const minNominated = ((exp && exp.others) || []).reduce((min: BN, { value = api.createType('Compact<Balance>') }): BN => {
|
||||
const actual = value.unwrap();
|
||||
|
||||
return min.isZero() || actual.lt(min)
|
||||
@ -156,7 +162,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
|
||||
}, BN_ZERO);
|
||||
|
||||
const key = accountId.toString();
|
||||
const rewards = getLegacyRewards(stakingLedger);
|
||||
const rewards = getLegacyRewards(stakingLedger, claimedRewardsEras);
|
||||
|
||||
const lastEraPayout = !lastEra.isZero()
|
||||
? rewards[rewards.length - 1]
|
||||
@ -169,12 +175,13 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
|
||||
bondShare: 0,
|
||||
bondTotal,
|
||||
commissionPer: validatorPrefs.commission.unwrap().toNumber() / 10_000_000,
|
||||
exposure,
|
||||
exposureMeta: expMeta || emptyExposureMeta,
|
||||
exposurePaged: exp || emptyExposure,
|
||||
isActive: !skipRewards,
|
||||
isBlocking: !!(validatorPrefs.blocked && validatorPrefs.blocked.isTrue),
|
||||
isElected: !isWaitingDerive(derive) && derive.nextElected.some((e) => e.eq(accountId)),
|
||||
isFavorite: favorites.includes(key),
|
||||
isNominating: (exposure.others || []).reduce((isNominating, indv): boolean => {
|
||||
isNominating: ((exp && exp.others) || []).reduce((isNominating, indv): boolean => {
|
||||
const nominator = indv.who.toString();
|
||||
|
||||
nominators[nominator] = (nominators[nominator] || BN_ZERO).add(indv.value?.toBn() || BN_ZERO);
|
||||
@ -188,7 +195,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
|
||||
? lastEra.sub(lastEraPayout).mul(eraLength)
|
||||
: undefined,
|
||||
minNominated,
|
||||
numNominators: (exposure.others || []).length,
|
||||
numNominators: ((exp && exp.others) || []).length,
|
||||
numRecentPayouts: earliestEra
|
||||
? rewards.filter((era) => era.gte(earliestEra)).length
|
||||
: 0,
|
||||
|
||||
@ -20,10 +20,10 @@
|
||||
"path": false
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "^10.13.1",
|
||||
"@polkadot/extension-compat-metamask": "^0.47.1",
|
||||
"@polkadot/extension-dapp": "^0.47.1",
|
||||
"@polkadot/rpc-provider": "^10.13.1",
|
||||
"@polkadot/api": "^11.0.1",
|
||||
"@polkadot/extension-compat-metamask": "^0.47.2",
|
||||
"@polkadot/extension-dapp": "^0.47.2",
|
||||
"@polkadot/rpc-provider": "^11.0.1",
|
||||
"fflate": "^0.8.1",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
|
||||
@ -6,9 +6,9 @@ import type { ApiPromise } from '@polkadot/api';
|
||||
import type { SubmittableExtrinsic } from '@polkadot/api/types';
|
||||
import type { DeriveAccountFlags, DeriveAccountRegistration } from '@polkadot/api-derive/types';
|
||||
import type { DisplayedJudgement } from '@polkadot/react-components/types';
|
||||
import type { u128 } from '@polkadot/types';
|
||||
import type { AccountId, BlockNumber, Call, Exposure, Hash, SessionIndex, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import type { PalletPreimageRequestStatus, PalletStakingRewardDestination, PalletStakingStakingLedger } from '@polkadot/types/lookup';
|
||||
import type { Option, u32, u128, Vec } from '@polkadot/types';
|
||||
import type { AccountId, BlockNumber, Call, Hash, SessionIndex, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import type { PalletPreimageRequestStatus, PalletStakingRewardDestination, PalletStakingStakingLedger, SpStakingExposurePage, SpStakingPagedExposureMetadata } from '@polkadot/types/lookup';
|
||||
import type { ICompact, IExtrinsic, INumber, Registry } from '@polkadot/types/types';
|
||||
import type { KeyringJson$Meta } from '@polkadot/ui-keyring/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
@ -144,7 +144,9 @@ export interface UseAccountInfo {
|
||||
export interface StakerState {
|
||||
controllerId: string | null;
|
||||
destination?: PalletStakingRewardDestination | null;
|
||||
exposure?: Exposure;
|
||||
exposurePaged?: Option<SpStakingExposurePage>;
|
||||
exposureMeta?: Option<SpStakingPagedExposureMetadata>
|
||||
claimedRewardsEras?: Vec<u32>
|
||||
hexSessionIdNext: string | null;
|
||||
hexSessionIdQueue: string | null;
|
||||
isLoading: boolean;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { DeriveEraPoints, DeriveEraRewards, DeriveStakerReward } from '@polkadot/api-derive/types';
|
||||
import type { u32 } from '@polkadot/types';
|
||||
import type { u32, Vec } from '@polkadot/types';
|
||||
import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { PalletStakingStakingLedger } from '@polkadot/types/lookup';
|
||||
import type { StakerState } from './types.js';
|
||||
@ -46,8 +46,10 @@ const EMPTY_STATE: State = {
|
||||
|
||||
const OPT_REWARDS = { withParams: true };
|
||||
|
||||
function getLegacyRewards (ledger: PalletStakingStakingLedger): u32[] {
|
||||
return ledger.legacyClaimedRewards || (ledger as unknown as { claimedRewards: u32[] }).claimedRewards || [];
|
||||
function getLegacyRewards (ledger: PalletStakingStakingLedger, claimedRewardsEras?: Vec<u32>): u32[] {
|
||||
const legacyRewards = ledger.legacyClaimedRewards || (ledger as unknown as { claimedRewards: u32[] }).claimedRewards || [];
|
||||
|
||||
return legacyRewards.concat(claimedRewardsEras?.toArray() || []);
|
||||
}
|
||||
|
||||
function getRewards ([[stashIds], available]: [[string[]], DeriveStakerReward[][]]): State {
|
||||
@ -135,9 +137,9 @@ function useOwnEraRewardsImpl (maxEras?: number, ownValidators?: StakerState[],
|
||||
});
|
||||
setFiltered({ filteredEras, validatorEras });
|
||||
} else if (ownValidators?.length) {
|
||||
ownValidators.forEach(({ stakingLedger, stashId }): void => {
|
||||
ownValidators.forEach(({ claimedRewardsEras, stakingLedger, stashId }): void => {
|
||||
if (stakingLedger) {
|
||||
const eras = filteredEras.filter((era) => !getLegacyRewards(stakingLedger).some((c) => era.eq(c)));
|
||||
const eras = filteredEras.filter((era) => !getLegacyRewards(stakingLedger, claimedRewardsEras).some((c) => era.eq(c)));
|
||||
|
||||
if (eras.length) {
|
||||
validatorEras.push({ eras, stashId });
|
||||
|
||||
@ -26,7 +26,17 @@ function toIdString (id?: AccountId | null): string | null {
|
||||
: null;
|
||||
}
|
||||
|
||||
function getStakerState (stashId: string, allAccounts: string[], [isOwnStash, { controllerId: _controllerId, exposure, nextSessionIds: _nextSessionIds, nominators, rewardDestination, sessionIds: _sessionIds, stakingLedger, validatorPrefs }, validateInfo]: [boolean, DeriveStakingAccount, ValidatorInfo]): StakerState {
|
||||
// To get claimedRewards, activate `withClaimedRewardsEras` to true.
|
||||
// Currently its turned off because of performance issues.
|
||||
const QUERY_OPTS = {
|
||||
withClaimedRewardsEras: false,
|
||||
withDestination: true,
|
||||
withLedger: true,
|
||||
withNominations: true,
|
||||
withPrefs: true
|
||||
};
|
||||
|
||||
function getStakerState (stashId: string, allAccounts: string[], [isOwnStash, { claimedRewardsEras, controllerId: _controllerId, exposureMeta, exposurePaged, nextSessionIds: _nextSessionIds, nominators, rewardDestination, sessionIds: _sessionIds, stakingLedger, validatorPrefs }, validateInfo]: [boolean, DeriveStakingAccount, ValidatorInfo]): StakerState {
|
||||
const isStashNominating = !!(nominators?.length);
|
||||
const isStashValidating = !(Array.isArray(validateInfo) ? validateInfo[1].isEmpty : validateInfo.isEmpty);
|
||||
const nextSessionIds = _nextSessionIds instanceof Map
|
||||
@ -40,9 +50,11 @@ function getStakerState (stashId: string, allAccounts: string[], [isOwnStash, {
|
||||
const controllerId = toIdString(_controllerId);
|
||||
|
||||
return {
|
||||
claimedRewardsEras,
|
||||
controllerId,
|
||||
destination: rewardDestination,
|
||||
exposure,
|
||||
exposureMeta,
|
||||
exposurePaged,
|
||||
hexSessionIdNext: u8aToHex(nextConcat, 48),
|
||||
hexSessionIdQueue: u8aToHex(currConcat.length ? currConcat : nextConcat, 48),
|
||||
isLoading: false,
|
||||
@ -77,7 +89,7 @@ function useOwnStashInfosImpl (): StakerState[] | undefined {
|
||||
if (ownStashes.length) {
|
||||
const stashIds = ownStashes.map(([stashId]) => stashId);
|
||||
const fns = [
|
||||
[api.derive.staking.accounts, stashIds],
|
||||
[api.derive.staking.accounts, stashIds, QUERY_OPTS],
|
||||
[api.query.staking.validators.multi, stashIds]
|
||||
] as unknown as CombinatorFunction[];
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
"testcontainers": "^10.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/types-support": "^10.13.1",
|
||||
"@polkadot/types-support": "^11.0.1",
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"tsconfig-paths": "^4.2.0"
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user