ghost-portal/packages/page-referenda/src/useCounter.ts
Jaco 4929b1c6fd
Update headers for 2023 (#8665)
* Update headers for 2023

* Adjust env-config
2023-01-01 10:32:05 +02:00

33 lines
819 B
TypeScript

// Copyright 2017-2023 @polkadot/app-referenda authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PalletReferenda } from './types';
import { useMemo } from 'react';
import { createNamedHook } from '@polkadot/react-hooks';
import useReferenda from './useReferenda';
export function useCounterNamed (palletReferenda: PalletReferenda): number {
const [grouped] = useReferenda(palletReferenda);
return useMemo(
() => grouped
? grouped.reduce((total, { referenda }) =>
total + (
referenda
? referenda.filter(({ info }) => info.isOngoing).length
: 0
), 0)
: 0,
[grouped]
);
}
function useCounterImpl (): number {
return useCounterNamed('referenda');
}
export default createNamedHook('useCounter', useCounterImpl);