diff --git a/packages/apps/public/locales/en/app-bounties.json b/packages/apps/public/locales/en/app-bounties.json index 08a6b46739..6c0797dfa1 100644 --- a/packages/apps/public/locales/en/app-bounties.json +++ b/packages/apps/public/locales/en/app-bounties.json @@ -1,8 +1,11 @@ { "Bounties": "Bounties", + "Claimable": "Claimable", "No open bounties": "No open bounties", + "beneficiary": "beneficiary", "bounties": "bounties", "curator": "curator", + "payout due": "payout due", "title": "title", "update due": "update due", "value": "value", diff --git a/packages/apps/public/locales/en/translation.json b/packages/apps/public/locales/en/translation.json index c7e111a5fc..e24a177dca 100644 --- a/packages/apps/public/locales/en/translation.json +++ b/packages/apps/public/locales/en/translation.json @@ -22,6 +22,7 @@ "Change democracy delegation": "", "Change this account's password": "", "Claim": "", + "Claimable": "", "Clear expired democracy locks": "", "Close": "", "Contracts": "", @@ -209,6 +210,7 @@ "parent": "", "payment": "", "payout": "", + "payout due": "", "payout/stash": "", "payout/validator": "", "per block": "", diff --git a/packages/page-bounties/src/Bounties.tsx b/packages/page-bounties/src/Bounties.tsx index 7eaf8ed575..7d4d61b026 100644 --- a/packages/page-bounties/src/Bounties.tsx +++ b/packages/page-bounties/src/Bounties.tsx @@ -23,11 +23,11 @@ function Bounties (): React.ReactElement { const headerRef = useRef([ [t('bounties'), 'start'], [t('title'), 'start'], - [], [t('value'), 'start'], - [], [t('curator'), 'start'], [t('update due'), 'start'], + [t('beneficiary'), 'start'], + [t('payout due'), 'start'], [], [] ]); diff --git a/packages/page-bounties/src/Bounty.tsx b/packages/page-bounties/src/Bounty.tsx index 45498befd0..91a6667bb8 100644 --- a/packages/page-bounties/src/Bounty.tsx +++ b/packages/page-bounties/src/Bounty.tsx @@ -3,6 +3,7 @@ import type { BlockNumber, Bounty as BountyType } from '@polkadot/types/interfaces'; +import BN from 'bn.js'; import React, { useCallback, useMemo, useState } from 'react'; import styled from 'styled-components'; @@ -10,7 +11,7 @@ import { AddressSmall, Icon, LinkExternal } from '@polkadot/react-components'; import { BlockToTime, FormatBalance } from '@polkadot/react-query'; import { formatNumber } from '@polkadot/util'; -import { getBountyStatus } from './helpers'; +import { getBountyStatus } from './helpers/getBountyStatus'; import { useTranslation } from './translate'; interface Props { @@ -24,16 +25,16 @@ interface Props { const EMPTY_CELL = '-'; function Bounty ({ bestNumber, bounty, className = '', description, index }: Props): React.ReactElement { - const { t } = useTranslation(); const [isExpanded, setIsExpanded] = useState(false); const { bond, curatorDeposit, fee, proposer, status, value }: BountyType = bounty; const updateStatus = useCallback(() => getBountyStatus(status), [status]); - const { bountyStatus, curator, updateDue } = updateStatus(); + const { beneficiary, bountyStatus, curator, unlockAt, updateDue } = updateStatus(); const blocksUntilUpdate = useMemo(() => updateDue?.sub(bestNumber), [bestNumber, updateDue]); + const blocksUntilPayout = useMemo(() => unlockAt?.sub(bestNumber), [bestNumber, unlockAt]); const handleOnIconClick = () => { setIsExpanded(!isExpanded); @@ -44,14 +45,11 @@ function Bounty ({ bestNumber, bounty, className = '', description, index }: Pro {bountyStatus} {description} - - - {curator ? : EMPTY_CELL} - - {updateDue ? : EMPTY_CELL} - {updateDue && t('{{blocks}} blocks', { replace: { blocks: formatNumber(blocksUntilUpdate) } })} - + {curator ? : EMPTY_CELL} + + {beneficiary ? : EMPTY_CELL} + Curators deposit -
{curator ? : EMPTY_CELL }
-
{curator ? : EMPTY_CELL }
+
{curator ? : EMPTY_CELL}
+
{curator ? : EMPTY_CELL}
@@ -102,11 +100,26 @@ function Bounty ({ bestNumber, bounty, className = '', description, index }: Pro ); } +function DueBlocks ({ dueBlocks }: { dueBlocks: BN | undefined }): JSX.Element { + const { t } = useTranslation(); + + if (!dueBlocks) { + return <>{EMPTY_CELL}; + } + + return dueBlocks.gtn(0) + ? <> + + {t('{{blocks}} blocks', { replace: { blocks: formatNumber(dueBlocks) } })} + + : <>{t('Claimable')}; +} + export default React.memo(styled(Bounty)` & .links { display: inline-flex; } - + & .table-column-icon { width: 52px; padding: 0; @@ -126,7 +139,6 @@ export default React.memo(styled(Bounty)` } & .column-with-label { - width: 110px; vertical-align: middle; padding: 0; div { diff --git a/packages/page-bounties/src/helpers/getBountyStatus.spec.ts b/packages/page-bounties/src/helpers/getBountyStatus.spec.ts new file mode 100644 index 0000000000..8ed7471f91 --- /dev/null +++ b/packages/page-bounties/src/helpers/getBountyStatus.spec.ts @@ -0,0 +1,38 @@ +// Copyright 2017-2020 @polkadot/app-bounties authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { TypeRegistry } from '@polkadot/types/create'; + +import { getBountyStatus } from './getBountyStatus'; + +describe('get bounty status', () => { + let registry: TypeRegistry; + + beforeEach(() => { + registry = new TypeRegistry(); + }); + + it('for CuratorProposed state it has curator defined', () => { + const bountyStatus = getBountyStatus(registry.createType('BountyStatus', 'CuratorProposed')); + + expect(bountyStatus.bountyStatus).toEqual('Curator Proposed'); + expect(bountyStatus.curator).toBeDefined(); + }); + + it('for Active state it has curator and update due defined', () => { + const bountyStatus = getBountyStatus(registry.createType('BountyStatus', 'Active')); + + expect(bountyStatus.bountyStatus).toEqual('Active'); + expect(bountyStatus.curator).toBeDefined(); + expect(bountyStatus.updateDue).toBeDefined(); + }); + + it('for PendingPayout state it has curator, beneficiary and unlock_at defined', () => { + const bountyStatus = getBountyStatus(registry.createType('BountyStatus', 'PendingPayout')); + + expect(bountyStatus.bountyStatus).toEqual('Pending Payout'); + expect(bountyStatus.curator).toBeDefined(); + expect(bountyStatus.beneficiary).toBeDefined(); + expect(bountyStatus.unlockAt).toBeDefined(); + }); +}); diff --git a/packages/page-bounties/src/helpers.ts b/packages/page-bounties/src/helpers/getBountyStatus.ts similarity index 68% rename from packages/page-bounties/src/helpers.ts rename to packages/page-bounties/src/helpers/getBountyStatus.ts index ae233aeb53..e310166641 100644 --- a/packages/page-bounties/src/helpers.ts +++ b/packages/page-bounties/src/helpers/getBountyStatus.ts @@ -3,7 +3,7 @@ import type { BountyStatus } from '@polkadot/types/interfaces'; -import { BountyStatusType } from './types'; +import { BountyStatusType } from '../types'; export const getBountyStatus = (status: BountyStatus): BountyStatusType => { const statusAsString = status.type; @@ -19,6 +19,7 @@ export const getBountyStatus = (status: BountyStatus): BountyStatusType => { if (status.isCuratorProposed) { result = { ...result, + bountyStatus: 'Curator Proposed', curator: status.asCuratorProposed.curator }; } @@ -31,5 +32,15 @@ export const getBountyStatus = (status: BountyStatus): BountyStatusType => { }; } + if (status.isPendingPayout) { + result = { + ...result, + beneficiary: status.asPendingPayout.beneficiary, + bountyStatus: 'Pending Payout', + curator: status.asPendingPayout.curator, + unlockAt: status.asPendingPayout.unlockAt + }; + } + return result; }; diff --git a/packages/page-bounties/src/types.ts b/packages/page-bounties/src/types.ts index 4cd182decf..0c26b262a7 100644 --- a/packages/page-bounties/src/types.ts +++ b/packages/page-bounties/src/types.ts @@ -4,9 +4,9 @@ import type { AccountId, BlockNumber } from '@polkadot/types/interfaces/runtime'; export interface BountyStatusType { - beneficiary: string | undefined; + beneficiary: AccountId | undefined; bountyStatus: string; curator: AccountId | undefined; - unlockAt: number | undefined; + unlockAt: BlockNumber | undefined; updateDue: BlockNumber | undefined; }