diff --git a/packages/page-council/src/Motions/index.tsx b/packages/page-council/src/Motions/index.tsx index 0c1860fa21..94948d25ba 100644 --- a/packages/page-council/src/Motions/index.tsx +++ b/packages/page-council/src/Motions/index.tsx @@ -3,11 +3,11 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { DeriveCollectiveProposals, DeriveCollectiveProposal } from '@polkadot/api-derive/types'; -import { AccountId } from '@polkadot/types/interfaces'; +import { BlockNumber, AccountId } from '@polkadot/types/interfaces'; import React from 'react'; import { Button, Table } from '@polkadot/react-components'; -import { useMembers } from '@polkadot/react-hooks'; +import { useApi, useCall, useMembers } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; import Motion from './Motion'; @@ -23,7 +23,10 @@ interface Props { function Proposals ({ className, motions, prime }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); + const bestNumber = useCall(api.derive.chain.bestNumber, []); const { isMember, members } = useMembers(); + const filtered = bestNumber && motions?.filter(({ votes }) => votes?.end.gt(bestNumber)); return (
@@ -44,7 +47,7 @@ function Proposals ({ className, motions, prime }: Props): React.ReactElement - {motions?.map((motion: DeriveCollectiveProposal): React.ReactNode => ( + {filtered?.map((motion: DeriveCollectiveProposal): React.ReactNode => ( !!votes).length; -} - export default function useCounter (): number { const { api, isApiReady } = useApi(); - const counter = useCall(isApiReady && api.derive.council?.proposals, [], { - transform - }) || 0; + const [counter, setCounter] = useState(0); + const bestNumber = useCall(isApiReady && api.derive.chain.bestNumber, []); + const proposals = useCall(isApiReady && api.derive.council?.proposals, []); + + useEffect((): void => { + bestNumber && proposals && setCounter((prev: number): number => { + const filtered = proposals.filter(({ votes }) => votes?.end.gt(bestNumber)); + + return filtered.length !== prev + ? filtered.length + : prev; + }); + }, [bestNumber, proposals]); return counter; }