Use derive call in Bounty's useCounter (#4290)

* Use derive call in Bounty's useCounter

* Remove derive.treasury from useCall
This commit is contained in:
MiZiet 2020-12-29 16:19:11 +01:00 committed by GitHub
parent 22b54bdbb9
commit 6421bd360c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,18 +1,17 @@
// Copyright 2017-2020 @polkadot/app-bounties authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { BountyIndex } from '@polkadot/types/interfaces';
import { useMemo } from 'react';
import { DeriveBounties } from '@polkadot/api-derive/types';
import { useApi, useCall } from '@polkadot/react-hooks';
export default function useCounter (): number {
const { api, isApiReady } = useApi();
const bounties = useCall<BountyIndex>(isApiReady && (api.query.bounties || api.query.treasury)?.bountyCount);
const bounties = useCall<DeriveBounties>(isApiReady && api.derive.bounties?.bounties);
return useMemo(
() => bounties?.toNumber() || 0,
() => bounties?.length || 0,
[bounties]
);
}