From 98ffd30c775f3bddfdd3383d2cb133e986149af4 Mon Sep 17 00:00:00 2001 From: Jaco Date: Tue, 15 Nov 2022 13:45:36 +0200 Subject: [PATCH] Ensure staking slashes checks (#8350) --- .../react-hooks/src/useAvailableSlashes.ts | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/react-hooks/src/useAvailableSlashes.ts b/packages/react-hooks/src/useAvailableSlashes.ts index ba57494eea..26e840e403 100644 --- a/packages/react-hooks/src/useAvailableSlashes.ts +++ b/packages/react-hooks/src/useAvailableSlashes.ts @@ -8,7 +8,7 @@ import type { PalletStakingUnappliedSlash } from '@polkadot/types/lookup'; import { useEffect, useState } from 'react'; -import { BN, BN_ONE } from '@polkadot/util'; +import { BN, BN_ONE, BN_ZERO } from '@polkadot/util'; import { createNamedHook } from './createNamedHook'; import { useApi } from './useApi'; @@ -26,21 +26,13 @@ function useAvailableSlashesImpl (): [BN, PalletStakingUnappliedSlash[]][] { useEffect((): Unsub => { let unsub: Unsub | undefined; - const [from, isEarliest] = api.query.staking?.earliestUnappliedSlash - ? [earliestSlash && earliestSlash.unwrapOr(null), true] - : indexes - ? [indexes.activeEra, false] - : [null, false]; + const [from, offset] = api.query.staking?.earliestUnappliedSlash + ? [earliestSlash && earliestSlash.unwrapOr(null), BN_ZERO] + : [indexes?.activeEra, api.consts.staking?.slashDeferDuration]; - if (mountedRef.current && indexes && from) { + if (mountedRef.current && indexes && from && offset) { const range: BN[] = []; - const end = isEarliest - // any <= activeEra (we include activeEra since slashes are immediately reflected) - // NOTE: the era refers to where the slashes actually ocurred - ? indexes.activeEra - // we don't have access to earliestUnappliedSlash, use duration - // NOTE: the era refers to where these are to be applied - : indexes.activeEra.add(api.consts.staking.slashDeferDuration); + const end = indexes.activeEra.add(offset); let start = new BN(from); while (start.lte(end)) {