Filter council by proposal end (#2593)
This commit is contained in:
parent
d9d33d7a1b
commit
ecf795c249
@ -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<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const bestNumber = useCall<BlockNumber>(api.derive.chain.bestNumber, []);
|
||||
const { isMember, members } = useMembers();
|
||||
const filtered = bestNumber && motions?.filter(({ votes }) => votes?.end.gt(bestNumber));
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
@ -44,7 +47,7 @@ function Proposals ({ className, motions, prime }: Props): React.ReactElement<Pr
|
||||
/>
|
||||
</Button.Group>
|
||||
<Table
|
||||
empty={motions && t('No council motions')}
|
||||
empty={filtered && t('No council motions')}
|
||||
header={[
|
||||
[t('motions'), 'start', 2],
|
||||
[t('threshold')],
|
||||
@ -54,7 +57,7 @@ function Proposals ({ className, motions, prime }: Props): React.ReactElement<Pr
|
||||
[undefined, undefined, 2]
|
||||
]}
|
||||
>
|
||||
{motions?.map((motion: DeriveCollectiveProposal): React.ReactNode => (
|
||||
{filtered?.map((motion: DeriveCollectiveProposal): React.ReactNode => (
|
||||
<Motion
|
||||
isMember={isMember}
|
||||
key={motion.hash.toHex()}
|
||||
|
||||
@ -3,18 +3,26 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { DeriveCollectiveProposals } from '@polkadot/api-derive/types';
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useApi, useCall } from '@polkadot/react-hooks';
|
||||
|
||||
function transform (motions: DeriveCollectiveProposals): number {
|
||||
return motions.filter(({ votes }): boolean => !!votes).length;
|
||||
}
|
||||
|
||||
export default function useCounter (): number {
|
||||
const { api, isApiReady } = useApi();
|
||||
const counter = useCall<number>(isApiReady && api.derive.council?.proposals, [], {
|
||||
transform
|
||||
}) || 0;
|
||||
const [counter, setCounter] = useState(0);
|
||||
const bestNumber = useCall<BlockNumber>(isApiReady && api.derive.chain.bestNumber, []);
|
||||
const proposals = useCall<DeriveCollectiveProposals>(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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user