use leaseOffset in current period calc (#6284)

This commit is contained in:
Jaco 2021-10-13 18:33:30 +03:00 committed by GitHub
parent 74380c4df5
commit 558279ec92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ import type { LeasePeriod } from './types';
import { useMemo } from 'react';
import { useApi, useBestNumber } from '@polkadot/react-hooks';
import { BN_ZERO } from '@polkadot/util';
export default function useLeasePeriod (): LeasePeriod | undefined {
const { api } = useApi();
@ -18,10 +19,11 @@ export default function useLeasePeriod (): LeasePeriod | undefined {
}
const length = api.consts.slots.leasePeriod as BlockNumber;
const progress = bestNumber.mod(length);
const startNumber = bestNumber.sub((api.consts.slots.leaseOffset as BlockNumber) || BN_ZERO);
const progress = startNumber.mod(length);
return {
currentPeriod: bestNumber.div(length),
currentPeriod: startNumber.div(length),
length,
progress,
remainder: length.sub(progress)