Display bounties counter in menu (#4189)
* Display bounties counter in menu * Remove account check from bounties useCounter
This commit is contained in:
parent
d9c81b5fa5
commit
50ec421529
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
20
packages/page-bounties/src/useCounter.ts
Normal file
20
packages/page-bounties/src/useCounter.ts
Normal 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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user