Display bounties counter in menu (#4189)

* Display bounties counter in menu

* Remove account check from bounties useCounter
This commit is contained in:
MiZiet 2020-12-10 16:47:14 +01:00 committed by GitHub
parent d9c81b5fa5
commit 50ec421529
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -4,7 +4,7 @@
import type { TFunction } from 'i18next';
import type { Route } from './types';
import Component from '@polkadot/app-bounties';
import Component, { useCounter } from '@polkadot/app-bounties';
export default function create (t: TFunction): Route {
return {
@ -17,6 +17,7 @@ export default function create (t: TFunction): Route {
group: 'governance',
icon: 'coins',
name: 'bounties',
text: t('nav.bounties', 'Bounties', { ns: 'apps-routing' })
text: t('nav.bounties', 'Bounties', { ns: 'apps-routing' }),
useCounter
};
}

View File

@ -8,6 +8,8 @@ import { Tabs } from '@polkadot/react-components';
import Bounties from './Bounties';
import { useTranslation } from './translate';
export { default as useCounter } from './useCounter';
interface Props {
basePath: string;
}

View File

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