Add close bounty modal and show proposed curator based on proposeCurator motion (#4476)

This commit is contained in:
Ewa Kowalska 2021-01-22 15:09:57 +01:00 committed by GitHub
parent 204d2520a4
commit 7f80a06fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 267 additions and 22 deletions

View File

@ -16,6 +16,8 @@
"Choose a curator whose background and expertise is such that they are capable of determining when the task is complete.": "Choose a curator whose background and expertise is such that they are capable of determining when the task is complete.",
"Claim": "Claim",
"Claimable": "Claimable",
"Close": "Close",
"Close Bounty": "Close Bounty",
"Curator has been proposed by council. The bounty is waiting for curator to accept the role.": "Curator has been proposed by council. The bounty is waiting for curator to accept the role.",
"Curator under voting": "Curator under voting",
"Curator's deposit": "Curator's deposit",
@ -31,6 +33,7 @@
"Only curator can extend the bounty time.": "Only curator can extend the bounty time.",
"Part of the bounty value that will go to the Curator as a reward for their work": "Part of the bounty value that will go to the Curator as a reward for their work",
"Propose Curator": "Propose Curator",
"Proposed Curator": "Proposed Curator",
"Proposer": "Proposer",
"Proposer bond depends on bounty title length.": "Proposer bond depends on bounty title length.",
"Reject": "Reject",
@ -38,7 +41,9 @@
"Select an account which (after a successful vote) will act as a curator.": "Select an account which (after a successful vote) will act as a curator.",
"Select the account you wish to propose the bounty from.": "Select the account you wish to propose the bounty from.",
"Select the council account you wish to use to create a motion for the Bounty.": "Select the council account you wish to use to create a motion for the Bounty.",
"Select the council account you wish to use to create a proposal for closing bounty.": "Select the council account you wish to use to create a proposal for closing bounty.",
"The council member that will create a motion, submission equates to an \"aye\" vote for chosen option.": "The council member that will create a motion, submission equates to an \"aye\" vote for chosen option.",
"The council member that will create the close bounty proposal, submission equates to an \"aye\" vote.": "The council member that will create the close bounty proposal, submission equates to an \"aye\" vote.",
"The council member that will create the motion.": "The council member that will create the motion.",
"The description of this bounty": "The description of this bounty",
"The note on the extension.": "The note on the extension.",
@ -48,6 +53,7 @@
"This account will propose the bounty. Bond amount will be reserved on its balance.": "This account will propose the bounty. Bond amount will be reserved on its balance.",
"This action will create a Council motion to assign a Curator.": "This action will create a Council motion to assign a Curator.",
"This action will create a Council motion to either approve or reject the Bounty.": "This action will create a Council motion to either approve or reject the Bounty.",
"This action will create a Council proposal to close the Bounty.": "This action will create a Council proposal to close the Bounty.",
"This action will extend expiry time of the selected bounty.": "This action will extend expiry time of the selected bounty.",
"This amount will be reserved from origin account and returned on approval or slashed upon rejection.": "This amount will be reserved from origin account and returned on approval or slashed upon rejection.",
"This bounty has received approval and is currently being implemented.": "This bounty has received approval and is currently being implemented.",
@ -64,6 +70,7 @@
"bounty remark": "bounty remark",
"bounty requested allocation": "bounty requested allocation",
"bounty title": "bounty title",
"close bounty": "close bounty",
"curator": "curator",
"curator account": "curator account",
"curator's fee": "curator's fee",
@ -72,6 +79,7 @@
"next burn": "next burn",
"past": "past",
"payout due": "payout due",
"propose with account": "propose with account",
"proposing account": "proposing account",
"select curator": "select curator",
"spend period": "spend period",

View File

@ -26,17 +26,17 @@ import { aliceSigner, MemoryStore } from '@polkadot/test-support/keyring';
import { TypeRegistry } from '@polkadot/types/create';
import { keyring } from '@polkadot/ui-keyring';
import { defaultAccounts,
import { alice,
bob,
defaultAccounts,
defaultBalance,
defaultBountyApi,
defaultMembers,
defaultTreasury } from '../test/hooks/defaults';
defaultTreasury,
ferdie } from '../test/hooks/defaults';
import Bounties from './Bounties';
import { BountyApi } from './hooks';
const alice = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
const bob = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
const mockMembers = defaultMembers;
const mockAccounts = defaultAccounts;
const mockTreasury = defaultTreasury;
@ -302,6 +302,37 @@ describe('Bounties', () => {
});
});
describe('close bounty modal', () => {
it('creates closeBounty proposal', async () => {
const bounty = bountyWith({ status: 'Funded' });
const { findByText, getByRole } = renderOneBounty(bounty);
const closeButton = await findByText('Close');
fireEvent.click(closeButton);
expect(await findByText('This action will create a Council proposal to close the Bounty.')).toBeTruthy();
const combobox = getByRole('combobox');
const proposingAccountInput = combobox.children[0];
fireEvent.change(proposingAccountInput, { target: { value: ferdie } });
const closeBountyButton = getByRole('button', { name: 'Close Bounty' });
fireEvent.click(closeBountyButton);
expect(queueExtrinsic).toHaveBeenCalledWith(expect.objectContaining({ accountId: ferdie, extrinsic: 'mockProposeExtrinsic' }));
});
it('Not available when close bounty motion already exists', async () => {
const bounty = bountyWith({ status: 'Funded' });
const proposals = [aProposal(augmentedApi.tx.bounties.closeBounty(0))];
const { findByText } = renderOneBounty(bounty, proposals);
await expect(findByText('Close')).rejects.toThrow();
});
});
describe('extend bounty expiry action modal', () => {
it('queues extend bounty expiry extrinsic on submit', async () => {
const bounty = bountyWith({ status: 'Active' });
@ -392,6 +423,33 @@ describe('Bounties', () => {
});
});
describe('Proposed Curator extended status', () => {
it('Funded and propose curator motion', async () => {
const bounty = bountyWith({ status: 'Funded' });
const proposals = [aProposal(augmentedApi.tx.bounties.proposeCurator(0, alice, 1))];
const { findByText } = renderOneBounty(bounty, proposals);
expect(await findByText('Proposed Curator')).toBeTruthy();
});
it('Funded and no propose curator motion', async () => {
const bounty = bountyWith({ status: 'Funded' });
const { findByText } = renderOneBounty(bounty);
await expect(findByText('Proposed Curator')).rejects.toThrow();
});
it('CuratorProposed', async () => {
const bounty = bountyWith({ status: 'CuratorProposed' });
const { findByText } = renderOneBounty(bounty);
await expect(findByText('Proposed Curator')).rejects.toThrow();
});
});
describe('Voters', () => {
it('aye and nay', async () => {
const bounty = bountyWith({ status: 'Proposed' });
@ -450,8 +508,8 @@ describe('Bounties', () => {
});
});
describe('Description', () => {
it('Beneficiary', async () => {
describe('Beneficiary description', () => {
it('PendingPayout status', async () => {
const bounty = bountyWith({ status: 'PendingPayout' });
const proposals = [aProposal(augmentedApi.tx.bounties.awardBounty(0, '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z'))];
@ -459,5 +517,13 @@ describe('Bounties', () => {
expect(await findByText('Beneficiary')).toBeTruthy();
});
it('Other status', async () => {
const bounty = bountyWith({ status: 'Active' });
const { findByText } = renderOneBounty(bounty);
await expect(findByText('Beneficiary')).rejects.toThrow();
});
});
});

View File

@ -13,10 +13,12 @@ import { ThemeProps } from '@polkadot/react-components/types';
import { BlockToTime, FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
import { getProposalToDisplay } from './helpers/extendedStatuses';
import VotingResultsColumn from './Voting/VotersColumn';
import { BountyActions } from './BountyActions';
import BountyInfos from './BountyInfos';
import BountyStatusView from './BountyStatusView';
import Curator from './Curator';
import { getBountyStatus } from './helpers';
import { useTranslation } from './translate';
@ -49,6 +51,18 @@ function Bounty ({ bestNumber, bounty, className = '', description, index, propo
const blocksUntilUpdate = useMemo(() => updateDue?.sub(bestNumber), [bestNumber, updateDue]);
const blocksUntilPayout = useMemo(() => unlockAt?.sub(bestNumber), [bestNumber, unlockAt]);
const curatorToRender = useMemo(() => {
if (curator) {
return { curator, isFromProposal: false };
}
const proposalToDisplay = proposals && getProposalToDisplay(proposals, status);
return (proposalToDisplay?.proposal.method === 'proposeCurator')
? { curator: proposalToDisplay.proposal.args[1], isFromProposal: true }
: null;
}, [curator, proposals, status]);
const handleOnIconClick = useCallback(
() => setIsExpanded((isExpanded) => !isExpanded),
[]
@ -75,7 +89,14 @@ function Bounty ({ bestNumber, bounty, className = '', description, index, propo
</div>
</td>
<td><FormatBalance value={value} /></td>
<td>{curator && <AddressSmall value={curator} />}</td>
<td>
{curatorToRender && (
<Curator
curator={curatorToRender.curator}
isFromProposal={curatorToRender.isFromProposal}
/>
)}
</td>
<td>
{blocksUntilPayout
? <DueBlocks

View File

@ -9,6 +9,7 @@ import React, { useCallback, useMemo } from 'react';
import BountyClaimAction from './BountyClaimAction';
import BountyCuratorProposedActions from './BountyCuratorProposedActions';
import BountyInitiateVoting from './BountyInitiateVoting';
import CloseBounty from './CloseBounty';
import ExtendBountyExpiryAction from './ExtendBountyExpiryAction';
import { getBountyStatus } from './helpers';
import ProposeCuratorAction from './ProposeCuratorAction';
@ -35,20 +36,22 @@ export function BountyActions ({ bestNumber, description, index, proposals, stat
<BountyInitiateVoting
index={index}
proposals={proposals}
/>}
{status.isFunded && (
/>
}
{status.isFunded &&
<ProposeCuratorAction
description={description}
index={index}
proposals={proposals}
value={value}
/>
)}
}
{status.isCuratorProposed && curator &&
<BountyCuratorProposedActions
curatorId={curator}
index={index}
/>}
/>
}
{status.isActive && curator &&
<ExtendBountyExpiryAction
curatorId={curator}
@ -56,12 +59,19 @@ export function BountyActions ({ bestNumber, description, index, proposals, stat
index={index}
/>
}
{(status.isFunded || status.isActive || status.isCuratorProposed) &&
<CloseBounty
index={index}
proposals={proposals}
/>
}
{status.isPendingPayout && beneficiary && blocksUntilPayout &&
<BountyClaimAction
beneficiaryId={beneficiary}
index={index}
payoutDue={blocksUntilPayout}
/>}
/>
}
</>
);
}

View File

@ -5,8 +5,9 @@ import type { AccountId, BountyIndex } from '@polkadot/types/interfaces';
import React, { useMemo } from 'react';
import { useBounties } from '@polkadot/app-bounties/hooks';
import { TxButton } from '@polkadot/react-components';
import { useAccounts, useApi } from '@polkadot/react-hooks';
import { useAccounts } from '@polkadot/react-hooks';
import { useTranslation } from './translate';
@ -17,7 +18,7 @@ interface Props {
function BountyCuratorProposedActions ({ curatorId, index }: Props) {
const { t } = useTranslation();
const { api } = useApi();
const { acceptCurator, unassignCurator } = useBounties();
const { allAccounts } = useAccounts();
const isCurator = useMemo(() => allAccounts.includes(curatorId.toString()), [allAccounts, curatorId]);
@ -30,14 +31,14 @@ function BountyCuratorProposedActions ({ curatorId, index }: Props) {
icon='check'
label={t<string>('Accept')}
params={[index]}
tx={(api.tx.bounties || api.tx.treasury).acceptCurator}
tx={acceptCurator}
/>
<TxButton
accountId={curatorId}
icon='times'
label={t<string>('Reject')}
params={[index]}
tx={(api.tx.bounties || api.tx.treasury).unassignCurator}
tx={unassignCurator}
/>
</>
)

View File

@ -0,0 +1,97 @@
// Copyright 2017-2021 @polkadot/app-treasury authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { BountyIndex } from '@polkadot/types/interfaces';
import BN from 'bn.js';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { getTreasuryProposalThreshold } from '@polkadot/apps-config';
import { Button, InputAddress, Modal, TxButton } from '@polkadot/react-components';
import { useApi, useMembers, useToggle } from '@polkadot/react-hooks';
import { useBounties } from './hooks';
import { useTranslation } from './translate';
interface Props {
index: BountyIndex;
proposals?: DeriveCollectiveProposal[];
}
function CloseBounty ({ index, proposals }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const { isMember, members } = useMembers();
const { closeBounty } = useBounties();
const [isOpen, toggleOpen] = useToggle();
const [accountId, setAccountId] = useState<string | null>(null);
const [threshold, setThreshold] = useState<BN>();
useEffect((): void => {
members && setThreshold(
new BN(Math.ceil(members.length * getTreasuryProposalThreshold(api)))
);
}, [api, members]);
const closeBountyProposal = useRef(closeBounty(index));
const existingCloseBountyProposal = useMemo(() => proposals?.find(({ proposal }) => proposal.method === 'closeBounty'), [proposals]);
return isMember && !existingCloseBountyProposal
? (
<>
<Button
icon='step-forward'
isDisabled={false}
label={t<string>('Close')}
onClick={toggleOpen}
/>
{isOpen && (
<Modal
header={t<string>('close bounty')}
size='large'
>
<Modal.Content>
<Modal.Columns>
<Modal.Column>
<p>{t<string>('This action will create a Council proposal to close the Bounty.')}</p>
</Modal.Column>
<Modal.Column>
</Modal.Column>
</Modal.Columns>
<Modal.Columns>
<Modal.Column>
<InputAddress
filter={members}
help={t<string>('Select the council account you wish to use to create a proposal for closing bounty.')}
label={t<string>('propose with account')}
onChange={setAccountId}
type='account'
withLabel
/>
</Modal.Column>
<Modal.Column>
<p>{t<string>('The council member that will create the close bounty proposal, submission equates to an "aye" vote.')}</p>
</Modal.Column>
</Modal.Columns>
</Modal.Content>
<Modal.Actions onCancel={toggleOpen}>
<TxButton
accountId={accountId}
icon='ban'
isDisabled={false}
label={t<string>('Close Bounty')}
onStart={toggleOpen}
params={[threshold, closeBountyProposal.current, closeBountyProposal.current.length]}
tx={api.tx.council.propose}
/>
</Modal.Actions>
</Modal>
)}
</>
)
: null;
}
export default React.memo(CloseBounty);

View File

@ -0,0 +1,29 @@
// Copyright 2017-2021 @polkadot/app-bounties authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec } from '@polkadot/types/types';
import React from 'react';
import { AddressSmall } from '@polkadot/react-components';
import Description from './Description';
import { useTranslation } from './translate';
interface Props {
curator: Codec;
isFromProposal: boolean;
}
function Curator ({ curator, isFromProposal }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
return (
<div>
<AddressSmall value={curator.toString()} />
{isFromProposal && <Description description={t<string>('Proposed Curator')} />}
</div>
);
}
export default React.memo(Curator);

View File

@ -10,6 +10,7 @@ import { useApi, useCall } from '@polkadot/react-hooks';
import { BalanceOf, BlockNumber, BountyIndex } from '@polkadot/types/interfaces';
export type BountyApi = {
acceptCurator: ((...args: any[]) => SubmittableExtrinsic<'promise'>);
approveBounty: ((...args: any[]) => SubmittableExtrinsic<'promise'>);
bestNumber?: BlockNumber,
bounties?: DeriveBounties,
@ -23,6 +24,7 @@ export type BountyApi = {
maximumReasonLength: number,
proposeBounty: ((...args: any[]) => SubmittableExtrinsic<'promise'>);
proposeCurator: ((...args: any[]) => SubmittableExtrinsic<'promise'>);
unassignCurator: ((...args: any[]) => SubmittableExtrinsic<'promise'>);
};
export function useBounties (): BountyApi {
@ -38,11 +40,14 @@ export function useBounties (): BountyApi {
const proposeBounty = (api.tx.bounties || api.tx.treasury).proposeBounty;
const proposeCurator = (api.tx.bounties || api.tx.treasury).proposeCurator;
const claimBounty = (api.tx.bounties || api.tx.treasury).claimBounty;
const acceptCurator = (api.tx.bounties || api.tx.treasury).acceptCurator;
const approveBounty = (api.tx.bounties || api.tx.treasury).approveBounty;
const closeBounty = (api.tx.bounties || api.tx.treasury).closeBounty;
const extendBountyExpiry = (api.tx.bounties || api.tx.treasury).extendBountyExpiry;
const unassignCurator = (api.tx.bounties || api.tx.treasury).unassignCurator;
return {
acceptCurator,
approveBounty,
bestNumber,
bounties,
@ -55,6 +60,7 @@ export function useBounties (): BountyApi {
extendBountyExpiry,
maximumReasonLength,
proposeBounty,
proposeCurator
proposeCurator,
unassignCurator
};
}

View File

@ -9,18 +9,20 @@ import { balanceOf } from '@polkadot/test-support/creation/balance';
import { BlockNumber } from '@polkadot/types/interfaces';
export const defaultBountyApi: BountyApi = {
acceptCurator: jest.fn(),
approveBounty: jest.fn(),
bestNumber: new BN(1) as BlockNumber,
bounties: [] as DeriveBounties,
bountyDepositBase: new BN(1),
bountyValueMinimum: new BN(1),
claimBounty: jest.fn(),
closeBounty: jest.fn(),
closeBounty: jest.fn().mockReturnValue({ length: 4 }),
dataDepositPerByte: new BN(1),
extendBountyExpiry: jest.fn().mockReturnValue('mockProposeExtrinsic'),
maximumReasonLength: 100,
proposeBounty: jest.fn(),
proposeCurator: jest.fn()
proposeCurator: jest.fn(),
unassignCurator: jest.fn()
};
export const defaultBalance = balanceOf(1);
@ -31,6 +33,11 @@ export const defaultTreasury = {
value: balanceOf(1)
};
export const defaultMembers = { isMember: true };
export const alice = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
export const bob = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
export const ferdie = '5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL';
export const defaultCurator = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
export const defaultAccounts = { allAccounts: ['5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM'] };
export const defaultMembers = { isMember: true, members: [alice, bob, ferdie] };
export const defaultAccounts = { allAccounts: [defaultCurator] };