Fix actionQueue session counter (#4940)

* Fix session counter

* Fix param types
This commit is contained in:
Jaco Greeff 2021-03-26 08:33:12 +01:00 committed by GitHub
parent 5b08996e27
commit c0c09f1488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 16 deletions

View File

@ -17,8 +17,6 @@ interface Props {
}
function LeaseBlocks ({ children, className, leasePeriod, value }: Props): React.ReactElement<Props> | null {
console.log(JSON.stringify({ leasePeriod, value }));
const blocks = useMemo(
() => leasePeriod && value &&
bnToBn(value)

View File

@ -1,33 +1,37 @@
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type BN from 'bn.js';
import type { ParaId, SessionIndex } from '@polkadot/types/interfaces';
import type { QueuedAction } from './types';
import { useMemo } from 'react';
import { useApi, useCall, useCallMulti } from '@polkadot/react-hooks';
import { BN_FIVE, BN_FOUR, BN_ONE, BN_THREE, BN_TWO } from '@polkadot/util';
import { useApi, useCall } from '@polkadot/react-hooks';
import { BN_EIGHT, BN_FIVE, BN_FOUR, BN_NINE, BN_ONE, BN_SEVEN, BN_SIX, BN_TEN, BN_THREE, BN_TWO } from '@polkadot/util';
const INC = [BN_ONE, BN_TWO, BN_THREE, BN_FOUR, BN_FIVE];
const INC = [BN_ONE, BN_TWO, BN_THREE, BN_FOUR, BN_FIVE, BN_SIX, BN_SEVEN, BN_EIGHT, BN_NINE, BN_TEN];
const callOpts = {
withParams: true
};
export default function useActionsQueue (): QueuedAction[] {
const { api } = useApi();
const currentIndex = useCall<SessionIndex>(api.query.session.currentIndex);
const nextActions = useCallMulti<ParaId[][]>(
currentIndex
? INC.map((inc) => [api.query.paras.actionsQueue, currentIndex.add(inc)])
: []
);
const queryIndexes = useMemo(() => currentIndex && INC.map((i) => currentIndex.add(i)), [currentIndex]);
const nextActions = useCall<[[BN[]], ParaId[][]]>(queryIndexes && api.query.paras.actionsQueue.multi, [queryIndexes], callOpts);
return useMemo(
(): QueuedAction[] =>
currentIndex && nextActions
? nextActions.filter((paraIds) => paraIds.length).map((paraIds, index) => ({
paraIds,
sessionIndex: currentIndex.add(INC[index])
}))
nextActions
? nextActions[0][0]
.map((sessionIndex, index) => ({
paraIds: nextActions[1][index],
sessionIndex
}))
.filter(({ paraIds }) => paraIds.length)
: [],
[currentIndex, nextActions]
[nextActions]
);
}