Bump polkadot-js deps (#10106)

* Bump polkadot-js deps

* Adjust (now optional) maxNominatorRewardedPerValidator usage

* Adjust usePreimage usage to align with latest Substrate

* Adjust unclaimed rewards retrieval

* Adjust StakingLedger import

* Adjust hooks for getLegacyRewards

* Adjust StakingLedger imports
This commit is contained in:
Jaco 2023-12-18 17:23:43 +02:00 committed by GitHub
parent d3bec55866
commit d94c086c79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 477 additions and 453 deletions

View File

@ -91,34 +91,34 @@
"source-map-explorer": "^2.5.3"
},
"resolutions": {
"@polkadot/api": "^10.11.1",
"@polkadot/api-augment": "^10.11.1",
"@polkadot/api-base": "^10.11.1",
"@polkadot/api-contract": "^10.11.1",
"@polkadot/api-derive": "^10.11.1",
"@polkadot/hw-ledger": "^12.6.1",
"@polkadot/keyring": "^12.6.1",
"@polkadot/networks": "^12.6.1",
"@polkadot/api": "^10.11.2",
"@polkadot/api-augment": "^10.11.2",
"@polkadot/api-base": "^10.11.2",
"@polkadot/api-contract": "^10.11.2",
"@polkadot/api-derive": "^10.11.2",
"@polkadot/hw-ledger": "^12.6.2",
"@polkadot/keyring": "^12.6.2",
"@polkadot/networks": "^12.6.2",
"@polkadot/phishing": "^0.22.1",
"@polkadot/rpc-augment": "^10.11.1",
"@polkadot/rpc-core": "^10.11.1",
"@polkadot/rpc-provider": "^10.11.1",
"@polkadot/types": "^10.11.1",
"@polkadot/types-augment": "^10.11.1",
"@polkadot/types-codec": "^10.11.1",
"@polkadot/types-create": "^10.11.1",
"@polkadot/types-known": "^10.11.1",
"@polkadot/types-support": "^10.11.1",
"@polkadot/util": "^12.6.1",
"@polkadot/util-crypto": "^12.6.1",
"@polkadot/wasm-crypto": "^7.3.1",
"@polkadot/x-bigint": "^12.6.1",
"@polkadot/x-fetch": "^12.6.1",
"@polkadot/x-global": "^12.6.1",
"@polkadot/x-randomvalues": "^12.6.1",
"@polkadot/x-textdecoder": "^12.6.1",
"@polkadot/x-textencoder": "^12.6.1",
"@polkadot/x-ws": "^12.6.1",
"typescript": "^5.2.2"
"@polkadot/rpc-augment": "^10.11.2",
"@polkadot/rpc-core": "^10.11.2",
"@polkadot/rpc-provider": "^10.11.2",
"@polkadot/types": "^10.11.2",
"@polkadot/types-augment": "^10.11.2",
"@polkadot/types-codec": "^10.11.2",
"@polkadot/types-create": "^10.11.2",
"@polkadot/types-known": "^10.11.2",
"@polkadot/types-support": "^10.11.2",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@polkadot/wasm-crypto": "^7.3.2",
"@polkadot/x-bigint": "^12.6.2",
"@polkadot/x-fetch": "^12.6.2",
"@polkadot/x-global": "^12.6.2",
"@polkadot/x-randomvalues": "^12.6.2",
"@polkadot/x-textdecoder": "^12.6.2",
"@polkadot/x-textencoder": "^12.6.2",
"@polkadot/x-ws": "^12.6.2",
"typescript": "^5.3.3"
}
}

View File

@ -37,16 +37,16 @@
"@peaqnetwork/type-definitions": "0.0.4",
"@pendulum-chain/type-definitions": "0.3.7",
"@phala/typedefs": "0.2.33",
"@polkadot/api": "^10.11.1",
"@polkadot/api-derive": "^10.11.1",
"@polkadot/networks": "^12.6.1",
"@polkadot/api": "^10.11.2",
"@polkadot/api-derive": "^10.11.2",
"@polkadot/networks": "^12.6.2",
"@polkadot/react-identicon": "^3.6.4",
"@polkadot/types": "^10.11.1",
"@polkadot/types-codec": "^10.11.1",
"@polkadot/util": "^12.6.1",
"@polkadot/types": "^10.11.2",
"@polkadot/types-codec": "^10.11.2",
"@polkadot/util": "^12.6.2",
"@polkadot/wasm-util": "^7.3.2",
"@polkadot/x-fetch": "^12.6.1",
"@polkadot/x-ws": "^12.6.1",
"@polkadot/x-fetch": "^12.6.2",
"@polkadot/x-ws": "^12.6.2",
"@polymeshassociation/polymesh-types": "5.5.2",
"@snowfork/snowbridge-types": "0.2.7",
"@sora-substrate/type-definitions": "1.20.1",

View File

@ -16,12 +16,12 @@
"type": "module",
"version": "0.133.2-27-x",
"dependencies": {
"@polkadot/hw-ledger": "^12.6.1",
"@polkadot/hw-ledger": "^12.6.2",
"@polkadot/phishing": "^0.22.1",
"@polkadot/react-components": "^0.133.2-27-x",
"@polkadot/react-hooks": "^0.133.2-27-x",
"@polkadot/util": "^12.6.1",
"@polkadot/vanitygen": "^0.56.1",
"@polkadot/util": "^12.6.2",
"@polkadot/vanitygen": "^0.56.2",
"detect-browser": "^5.3.0",
"file-saver": "^2.0.5"
},

View File

@ -16,7 +16,7 @@
"type": "module",
"version": "0.133.2-27-x",
"dependencies": {
"@polkadot/api-contract": "^10.11.1",
"@polkadot/api-contract": "^10.11.2",
"eventemitter3": "^5.0.1"
},
"peerDependencies": {

View File

@ -3,7 +3,8 @@
import type { DeriveBalancesAll } from '@polkadot/api-derive/types';
import type { Option } from '@polkadot/types';
import type { AccountId, StakingLedger } from '@polkadot/types/interfaces';
import type { AccountId } from '@polkadot/types/interfaces';
import type { PalletStakingStakingLedger } from '@polkadot/types/lookup';
import React, { useEffect, useState } from 'react';
@ -32,7 +33,7 @@ const OPT_BOND = {
};
const OPT_STASH = {
transform: (value: Option<StakingLedger>): string | null =>
transform: (value: Option<PalletStakingStakingLedger>): string | null =>
value.isSome
? value.unwrap().stash.toString()
: null

View File

@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { StakingLedger } from '@polkadot/types/interfaces';
import type { PalletStakingStakingLedger } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util';
import React, { useState } from 'react';
@ -18,7 +18,7 @@ import useUnbondDuration from '../useUnbondDuration.js';
interface Props {
controllerId?: string | null;
onClose: () => void;
stakingLedger?: StakingLedger;
stakingLedger?: PalletStakingStakingLedger;
stashId: string;
}

View File

@ -1,6 +1,7 @@
// Copyright 2017-2023 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { u32 } from '@polkadot/types';
import type { BN } from '@polkadot/util';
import type { SortedTargets } from '../../types.js';
import type { NominateInfo } from './types.js';
@ -59,9 +60,9 @@ function Nominate ({ className = '', controllerId, nominating, onChange, poolId,
}, [api, onChange, poolId, selected]);
const maxNominations = api.consts.staking.maxNominatorRewardedPerValidator
? api.consts.staking.maxNominatorRewardedPerValidator.toNumber()
? (api.consts.staking.maxNominatorRewardedPerValidator as u32).toNumber()
: api.consts.staking.maxNominations
? (api.consts.staking.maxNominations as unknown as BN).toNumber()
? (api.consts.staking.maxNominations as u32).toNumber()
: MAX_NOMINATIONS;
return (

View File

@ -4,7 +4,7 @@
import type { ApiPromise } from '@polkadot/api';
import type { QueryableStorageMultiArg } from '@polkadot/api/types';
import type { DeriveSessionIndexes } from '@polkadot/api-derive/types';
import type { Option } from '@polkadot/types';
import type { Option, u32 } from '@polkadot/types';
import type { EraIndex, Exposure, Nominations, SlashingSpans } from '@polkadot/types/interfaces';
import { useEffect, useState } from 'react';
@ -21,7 +21,7 @@ interface Inactives {
}
function extractState (api: ApiPromise, stashId: string, slashes: Option<SlashingSpans>[], nominees: string[], { activeEra }: DeriveSessionIndexes, submittedIn: EraIndex, exposures: Exposure[]): Inactives {
const max = api.consts.staking?.maxNominatorRewardedPerValidator;
const max = api.consts.staking?.maxNominatorRewardedPerValidator as u32;
// chilled
// NOTE With the introduction of the SlashReported event,

View File

@ -1,6 +1,8 @@
// Copyright 2017-2023 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { u32 } from '@polkadot/types';
import React from 'react';
import { Badge } from '@polkadot/react-components';
@ -13,7 +15,7 @@ interface Props {
function MaxBadge ({ numNominators }: Props): React.ReactElement<Props> | null {
const { api } = useApi();
const max = api.consts.staking?.maxNominatorRewardedPerValidator;
const max = api.consts.staking?.maxNominatorRewardedPerValidator as u32;
if (!numNominators || !max || max.gten(numNominators)) {
return null;

View File

@ -3,6 +3,7 @@
import type { ApiPromise } from '@polkadot/api';
import type { SubmittableExtrinsic } from '@polkadot/api/types';
import type { u32 } from '@polkadot/types';
import type { EraIndex } from '@polkadot/types/interfaces';
import type { PayoutValidator } from './types.js';
@ -61,7 +62,7 @@ function PayButton ({ className, isAll, isDisabled, payout }: Props): React.Reac
const [txs, setTxs] = useState<SubmittableExtrinsic<'promise'>[] | null>(null);
const batchOpts = useMemo(
() => ({
max: 36 * 64 / (api.consts.staking.maxNominatorRewardedPerValidator?.toNumber() || 64)
max: 36 * 64 / ((api.consts.staking.maxNominatorRewardedPerValidator as u32)?.toNumber() || 64)
}),
[api]
);

View File

@ -219,7 +219,7 @@ function Targets ({ className = '', isInElection, nominatedBy, ownStashes, targe
daysPayout,
isBabe: !!api.consts.babe,
isQueryFiltered,
maxPaid: api.consts.staking?.maxNominatorRewardedPerValidator
maxPaid: api.consts.staking?.maxNominatorRewardedPerValidator as u32
}),
[api, daysPayout, isQueryFiltered, toggles]
);

View File

@ -1,6 +1,7 @@
// Copyright 2017-2023 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { u32 } from '@polkadot/types';
import type { NominatorValue } from './types.js';
import React, { useMemo } from 'react';
@ -63,7 +64,7 @@ function StakeOther ({ nominators, stakeOther }: Props): React.ReactElement<Prop
const { api } = useApi();
const [rewarded, rewardedTotal, unrewarded, unrewardedTotal] = useMemo(
() => extractTotals(api.consts.staking?.maxNominatorRewardedPerValidator, nominators, stakeOther),
() => extractTotals(api.consts.staking?.maxNominatorRewardedPerValidator as u32, nominators, stakeOther),
[api, nominators, stakeOther]
);

View File

@ -4,7 +4,8 @@
import type { ApiPromise } from '@polkadot/api';
import type { DeriveSessionInfo, DeriveStakingElected, DeriveStakingWaiting } from '@polkadot/api-derive/types';
import type { Inflation } from '@polkadot/react-hooks/types';
import type { Option, u32 } from '@polkadot/types';
import type { Option, u32, Vec } from '@polkadot/types';
import type { PalletStakingStakingLedger } from '@polkadot/types/lookup';
import type { SortedTargets, TargetSortBy, ValidatorInfo } from './types.js';
import { useMemo } from 'react';
@ -30,6 +31,10 @@ interface MultiResult {
totalIssuance?: BN;
}
interface OldLedger {
claimedRewards: Vec<u32>;
}
const EMPTY_PARTIAL: Partial<SortedTargets> = {};
const DEFAULT_FLAGS_ELECTED = { withController: true, withExposure: true, withPrefs: true };
const DEFAULT_FLAGS_WAITING = { withController: true, withPrefs: true };
@ -63,6 +68,10 @@ const OPT_MULTI = {
})
};
function getLegacyRewards (ledger: PalletStakingStakingLedger): u32[] {
return ledger.legacyClaimedRewards || (ledger as unknown as OldLedger).claimedRewards || [];
}
function mapIndex (mapBy: TargetSortBy): (info: ValidatorInfo, index: number) => ValidatorInfo {
return (info, index): ValidatorInfo => {
info[mapBy] = index + 1;
@ -147,8 +156,10 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
}, BN_ZERO);
const key = accountId.toString();
const rewards = getLegacyRewards(stakingLedger);
const lastEraPayout = !lastEra.isZero()
? stakingLedger.claimedRewards[stakingLedger.claimedRewards.length - 1]
? rewards[rewards.length - 1]
: undefined;
list[i] = {
@ -171,7 +182,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
return isNominating || allAccounts.includes(nominator);
}, allAccounts.includes(key)),
key,
knownLength: activeEra.sub(stakingLedger.claimedRewards[0] || activeEra),
knownLength: activeEra.sub(rewards[0] || activeEra),
// only use if it is more recent than historyDepth
lastPayout: earliestEra && lastEraPayout && lastEraPayout.gt(earliestEra) && !sessionLength.eq(BN_ONE)
? lastEra.sub(lastEraPayout).mul(eraLength)
@ -179,7 +190,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt
minNominated,
numNominators: (exposure.others || []).length,
numRecentPayouts: earliestEra
? stakingLedger.claimedRewards.filter((era) => era.gte(earliestEra)).length
? rewards.filter((era) => era.gte(earliestEra)).length
: 0,
rankBondOther: 0,
rankBondOwn: 0,

View File

@ -20,10 +20,10 @@
"path": false
},
"dependencies": {
"@polkadot/api": "^10.11.1",
"@polkadot/api": "^10.11.2",
"@polkadot/extension-compat-metamask": "^0.46.6",
"@polkadot/extension-dapp": "^0.46.6",
"@polkadot/rpc-provider": "^10.11.1",
"@polkadot/rpc-provider": "^10.11.2",
"fflate": "^0.8.1",
"rxjs": "^7.8.1"
},

View File

@ -19,15 +19,15 @@
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@polkadot/keyring": "^12.6.1",
"@polkadot/keyring": "^12.6.2",
"@polkadot/react-api": "^0.133.2-27-x",
"@polkadot/react-identicon": "^3.6.4",
"@polkadot/react-qr": "^3.6.4",
"@polkadot/react-query": "^0.133.2-27-x",
"@polkadot/ui-keyring": "^3.6.4",
"@polkadot/ui-settings": "^3.6.4",
"@polkadot/util": "^12.6.1",
"@polkadot/util-crypto": "^12.6.1",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"chart.js": "^4.4.1",
"chartjs-plugin-annotation": "^3.0.1",
"chartjs-plugin-crosshair": "^1.2.0",

View File

@ -16,8 +16,8 @@
"type": "module",
"version": "0.133.2-27-x",
"dependencies": {
"@polkadot/hw-ledger": "^12.6.1",
"@polkadot/hw-ledger-transports": "^12.6.1",
"@polkadot/hw-ledger": "^12.6.2",
"@polkadot/hw-ledger-transports": "^12.6.2",
"is-ipfs": "^8.0.1"
},
"peerDependencies": {

View File

@ -6,8 +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 { AccountId, Balance, BlockNumber, Call, Exposure, Hash, RewardDestination, SessionIndex, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces';
import type { PalletPreimageRequestStatus } from '@polkadot/types/lookup';
import type { u128 } from '@polkadot/types';
import type { AccountId, BlockNumber, Call, Exposure, Hash, RewardDestination, SessionIndex, ValidatorPrefs } from '@polkadot/types/interfaces';
import type { PalletPreimageRequestStatus, PalletStakingStakingLedger } 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';
@ -52,14 +53,14 @@ export interface Inflation {
export interface Slash {
accountId: AccountId;
amount: Balance;
amount: u128;
}
export interface SessionRewards {
blockHash: Hash;
blockNumber: BlockNumber;
isEventsEmpty: boolean;
reward: Balance;
reward: u128;
sessionIndex: SessionIndex;
slashes: Slash[];
}
@ -153,7 +154,7 @@ export interface StakerState {
isStashValidating: boolean;
nominating?: string[];
sessionIds: string[];
stakingLedger?: StakingLedger;
stakingLedger?: PalletStakingStakingLedger;
stashId: string;
validatorPrefs?: ValidatorPrefs;
}

View File

@ -3,7 +3,9 @@
import type { ApiPromise } from '@polkadot/api';
import type { DeriveEraPoints, DeriveEraRewards, DeriveStakerReward } from '@polkadot/api-derive/types';
import type { u32 } from '@polkadot/types';
import type { EraIndex } from '@polkadot/types/interfaces';
import type { PalletStakingStakingLedger } from '@polkadot/types/lookup';
import type { StakerState } from './types.js';
import { useEffect, useState } from 'react';
@ -44,6 +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 getRewards ([[stashIds], available]: [[string[]], DeriveStakerReward[][]]): State {
const allRewards: Record<string, DeriveStakerReward[]> = {};
@ -131,7 +137,7 @@ function useOwnEraRewardsImpl (maxEras?: number, ownValidators?: StakerState[],
} else if (ownValidators?.length) {
ownValidators.forEach(({ stakingLedger, stashId }): void => {
if (stakingLedger) {
const eras = filteredEras.filter((era) => !stakingLedger.claimedRewards.some((c) => era.eq(c)));
const eras = filteredEras.filter((era) => !getLegacyRewards(stakingLedger).some((c) => era.eq(c)));
if (eras.length) {
validatorEras.push({ eras, stashId });

View File

@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { Bytes } from '@polkadot/types';
import type { AccountId, Balance, Call, Hash } from '@polkadot/types/interfaces';
import type { Bytes, u32, u128 } from '@polkadot/types';
import type { AccountId, Call, Hash } from '@polkadot/types/interfaces';
import type { FrameSupportPreimagesBounded, PalletPreimageRequestStatus } from '@polkadot/types/lookup';
import type { ITuple } from '@polkadot/types/types';
import type { HexString } from '@polkadot/util/types';
@ -31,6 +31,15 @@ interface StatusParams {
type Result = 'unknown' | 'hash' | 'hashAndLen';
interface OldUnrequested {
deposit: ITuple<[AccountId, u128]>;
}
interface OldRequested {
deposit: Option<ITuple<[AccountId, u128]>>;
len: Option<u32>;
}
/**
* @internal Determine if we are working with current generation (H256,u32)
* or previous generation H256 params to the preimageFor storage entry
@ -140,7 +149,7 @@ function createResult (interimResult: PreimageStatus, optBytes: Option<Bytes> |
}
/** @internal Helper to unwrap a deposit tuple into a structure */
function convertDeposit (deposit?: [AccountId, Balance] | null): PreimageDeposit | undefined {
function convertDeposit (deposit?: [AccountId, u128] | null): PreimageDeposit | undefined {
return deposit
? {
amount: deposit[1],
@ -163,11 +172,15 @@ function getBytesParams (interimResult: PreimageStatus, optStatus: Option<Pallet
// FIXME Cannot recall how to deal with these
// (unlike Unrequested below, didn't have an example)
} else {
const { count, deposit, len } = asRequested;
result.count = count.toNumber();
result.deposit = convertDeposit(deposit.unwrapOr(null));
result.proposalLength = len.unwrapOr(BN_ZERO);
result.count = asRequested.count.toNumber();
result.deposit = convertDeposit(
asRequested.maybeTicket
? asRequested.maybeTicket.unwrapOr(null)
: (asRequested as unknown as OldRequested).deposit.unwrapOr(null)
);
result.proposalLength = asRequested.maybeLen
? asRequested.maybeLen.unwrapOr(BN_ZERO)
: (asRequested as unknown as OldRequested).len.unwrapOr(BN_ZERO);
}
} else if (result.status.isUnrequested) {
const asUnrequested = result.status.asUnrequested;
@ -175,13 +188,11 @@ function getBytesParams (interimResult: PreimageStatus, optStatus: Option<Pallet
if (asUnrequested instanceof Option) {
result.deposit = convertDeposit(
// old-style conversion
(asUnrequested as Option<ITuple<[AccountId, Balance]>>).unwrapOr(null)
(asUnrequested as Option<ITuple<[AccountId, u128]>>).unwrapOr(null)
);
} else {
const { deposit, len } = result.status.asUnrequested;
result.deposit = convertDeposit(deposit);
result.proposalLength = len;
result.deposit = convertDeposit(asUnrequested.ticket || (asUnrequested as unknown as OldUnrequested).deposit);
result.proposalLength = asUnrequested.len;
}
} else {
console.error(`Unhandled PalletPreimageRequestStatus type: ${result.status.type}`);

View File

@ -16,7 +16,7 @@
"type": "module",
"version": "0.133.2-27-x",
"dependencies": {
"@polkadot/hw-ledger": "^12.6.1",
"@polkadot/hw-ledger": "^12.6.2",
"@polkadot/react-components": "^0.133.2-27-x"
},
"peerDependencies": {

View File

@ -20,7 +20,7 @@
"testcontainers": "^10.4.0"
},
"devDependencies": {
"@polkadot/types-support": "^10.11.1",
"@polkadot/types-support": "^10.11.2",
"@testing-library/jest-dom": "^5.17.0",
"tsconfig-paths": "^4.2.0"
},

727
yarn.lock

File diff suppressed because it is too large Load Diff