From b86bcb8a31e369d8cbd2527b398cb28349022bea Mon Sep 17 00:00:00 2001 From: Jaco Date: Sun, 5 Jun 2022 09:39:59 +0200 Subject: [PATCH] Pass through historyDepth (#7699) --- packages/apps/src/WarmUp.tsx | 3 +-- packages/page-staking/src/Payouts/Stash.tsx | 5 +++-- packages/page-staking/src/Payouts/Validator.tsx | 5 +++-- packages/page-staking/src/Payouts/index.tsx | 6 ++++-- packages/page-staking/src/Payouts/useEraBlocks.ts | 9 ++++----- packages/page-staking/src/index.tsx | 1 + packages/page-staking/src/types.ts | 1 + packages/page-staking/src/useSortedTargets.ts | 1 + 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/apps/src/WarmUp.tsx b/packages/apps/src/WarmUp.tsx index f02a917249..7964ec7f82 100644 --- a/packages/apps/src/WarmUp.tsx +++ b/packages/apps/src/WarmUp.tsx @@ -10,11 +10,10 @@ function WarmUp (): React.ReactElement { const indexes = useCall(isApiReady && api.derive.accounts?.indexes); const registrars = useCall(isApiReady && api.query.identity?.registrars); const issuance = useCall(isApiReady && api.query.balances?.totalIssuance); - const historyDepth = useCall(isApiReady && api.query.staking?.historyDepth); const [hasValues, setHasValues] = useState(false); useEffect((): void => { - setHasValues(!!historyDepth || !!indexes || !!issuance || !!registrars); + setHasValues(!!indexes || !!issuance || !!registrars); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/packages/page-staking/src/Payouts/Stash.tsx b/packages/page-staking/src/Payouts/Stash.tsx index d3882a211b..106f41aab4 100644 --- a/packages/page-staking/src/Payouts/Stash.tsx +++ b/packages/page-staking/src/Payouts/Stash.tsx @@ -14,6 +14,7 @@ import { createErasString } from './util'; interface Props { className?: string; + historyDepth?: BN; payout: PayoutStash; } @@ -22,9 +23,9 @@ interface EraInfo { oldestEra?: BN; } -function Stash ({ className = '', payout: { available, rewards, stashId } }: Props): React.ReactElement { +function Stash ({ className = '', historyDepth, payout: { available, rewards, stashId } }: Props): React.ReactElement { const [{ eraStr, oldestEra }, setEraInfo] = useState({ eraStr: '' }); - const eraBlocks = useEraBlocks(oldestEra); + const eraBlocks = useEraBlocks(historyDepth, oldestEra); useEffect((): void => { rewards && setEraInfo({ diff --git a/packages/page-staking/src/Payouts/Validator.tsx b/packages/page-staking/src/Payouts/Validator.tsx index 71810fa262..405df0bfd6 100644 --- a/packages/page-staking/src/Payouts/Validator.tsx +++ b/packages/page-staking/src/Payouts/Validator.tsx @@ -16,6 +16,7 @@ import { createErasString } from './util'; interface Props { className?: string; + historyDepth?: BN; isDisabled?: boolean; payout: PayoutValidator; } @@ -44,7 +45,7 @@ function extractState (payout: PayoutValidator): State { return { eraStr, nominators, numNominators: Object.keys(nominators).length, oldestEra: payout.eras[0]?.era }; } -function Validator ({ className = '', isDisabled, payout }: Props): React.ReactElement { +function Validator ({ className = '', historyDepth, isDisabled, payout }: Props): React.ReactElement { const { t } = useTranslation(); const { eraStr, nominators, numNominators, oldestEra } = useMemo( @@ -52,7 +53,7 @@ function Validator ({ className = '', isDisabled, payout }: Props): React.ReactE [payout] ); - const eraBlocks = useEraBlocks(oldestEra); + const eraBlocks = useEraBlocks(historyDepth, oldestEra); return ( diff --git a/packages/page-staking/src/Payouts/index.tsx b/packages/page-staking/src/Payouts/index.tsx index e565ce40e4..6676328f2c 100644 --- a/packages/page-staking/src/Payouts/index.tsx +++ b/packages/page-staking/src/Payouts/index.tsx @@ -23,6 +23,7 @@ import Validator from './Validator'; interface Props { className?: string; + historyDepth?: BN; isInElection?: boolean; ownPools?: OwnPool[]; ownValidators: StakerState[]; @@ -158,14 +159,13 @@ function getOptions (blockTime: BN, eraLength: BN | undefined, historyDepth: BN return eraSelection; } -function Payouts ({ className = '', isInElection, ownPools, ownValidators }: Props): React.ReactElement { +function Payouts ({ className = '', historyDepth, isInElection, ownPools, ownValidators }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const [hasOwnValidators] = useState(() => ownValidators.length !== 0); const [myStashesIndex, setMyStashesIndex] = useState(() => hasOwnValidators ? 0 : 1); const [eraSelectionIndex, setEraSelectionIndex] = useState(0); const eraLength = useCall(api.derive.session.eraLength); - const historyDepth = useCall(api.query.staking.historyDepth); const blockTime = useBlockInterval(); const poolStashes = useMemo( @@ -268,6 +268,7 @@ function Payouts ({ className = '', isInElection, ownPools, ownValidators }: Pro > {!isLoadingRewards && stashes?.map((payout): React.ReactNode => ( @@ -281,6 +282,7 @@ function Payouts ({ className = '', isInElection, ownPools, ownValidators }: Pro > {!isLoadingRewards && validators.filter(({ available }) => !available.isZero()).map((payout): React.ReactNode => ( (api.query.staking.historyDepth); const progress = useCall(api.derive.session.progress); const forcing = useCall(api.query.staking.forceEra); return useMemo( - () => (depth && era && forcing && progress && progress.sessionLength.gt(BN_ONE)) + () => (historyDepth && era && forcing && progress && progress.sessionLength.gt(BN_ONE)) ? ( forcing.isForceAlways ? progress.sessionLength : progress.eraLength ).mul( - depth + historyDepth .sub(progress.activeEra) .iadd(era) .iadd(BN_ONE) @@ -33,7 +32,7 @@ function useEraBlocksImpl (era?: BN): BN | undefined { : progress.eraProgress ) : undefined, - [depth, era, forcing, progress] + [era, forcing, historyDepth, progress] ); } diff --git a/packages/page-staking/src/index.tsx b/packages/page-staking/src/index.tsx index 4d2e667470..e86923d9ca 100644 --- a/packages/page-staking/src/index.tsx +++ b/packages/page-staking/src/index.tsx @@ -163,6 +163,7 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement