Handle pending payout status in bounty (#4223)
* Handle PendingPayout bounty status * Apply review changes
This commit is contained in:
parent
c9777e2e16
commit
4117180c66
@ -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",
|
||||
|
||||
@ -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": "",
|
||||
|
||||
@ -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'],
|
||||
[],
|
||||
[]
|
||||
]);
|
||||
|
||||
@ -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<Props> {
|
||||
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
|
||||
<tr className={className}>
|
||||
<td>{bountyStatus}</td>
|
||||
<td>{description}</td>
|
||||
<td className='column-with-label'/>
|
||||
<td><FormatBalance value={value} /></td>
|
||||
<td className='column-with-label'/>
|
||||
<td>{curator ? <AddressSmall value={curator}/> : EMPTY_CELL}</td>
|
||||
<td>
|
||||
{updateDue ? <BlockToTime blocks={blocksUntilUpdate} /> : EMPTY_CELL}
|
||||
{updateDue && t<string>('{{blocks}} blocks', { replace: { blocks: formatNumber(blocksUntilUpdate) } })}
|
||||
</td>
|
||||
<td>{curator ? <AddressSmall value={curator} /> : EMPTY_CELL}</td>
|
||||
<td><DueBlocks dueBlocks={blocksUntilUpdate} /></td>
|
||||
<td>{beneficiary ? <AddressSmall value={beneficiary} /> : EMPTY_CELL}</td>
|
||||
<td><DueBlocks dueBlocks={blocksUntilPayout} /></td>
|
||||
<td className='table-column-icon'>
|
||||
<LinkExternal
|
||||
data={index}
|
||||
@ -91,8 +89,8 @@ function Bounty ({ bestNumber, bounty, className = '', description, index }: Pro
|
||||
<div className='label'>Curators deposit</div>
|
||||
</td>
|
||||
<td>
|
||||
<div className='inline-balance'>{curator ? <FormatBalance value={fee} /> : EMPTY_CELL }</div>
|
||||
<div className='inline-balance'>{curator ? <FormatBalance value={curatorDeposit} /> : EMPTY_CELL }</div>
|
||||
<div className='inline-balance'>{curator ? <FormatBalance value={fee} /> : EMPTY_CELL}</div>
|
||||
<div className='inline-balance'>{curator ? <FormatBalance value={curatorDeposit} /> : EMPTY_CELL}</div>
|
||||
</td>
|
||||
<td />
|
||||
<td />
|
||||
@ -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)
|
||||
? <>
|
||||
<BlockToTime blocks={dueBlocks} />
|
||||
{t<string>('{{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 {
|
||||
|
||||
38
packages/page-bounties/src/helpers/getBountyStatus.spec.ts
Normal file
38
packages/page-bounties/src/helpers/getBountyStatus.spec.ts
Normal file
@ -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();
|
||||
});
|
||||
});
|
||||
@ -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;
|
||||
};
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user