Bounties - Show on the extend bounty expiry modal the new expiry date (#4593)

This commit is contained in:
Ewa Kowalska 2021-02-04 11:21:59 +01:00 committed by GitHub
parent 33b6dada3d
commit 3272ffab43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -3,9 +3,11 @@
import type { AccountId, BountyIndex } from '@polkadot/types/interfaces';
import React, { useCallback, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import { increaseDateByBlocks } from '@polkadot/app-bounties/helpers/increaseDateByBlocks';
import { Input, InputAddress, Modal, TxButton } from '@polkadot/react-components';
import { useBlockTime } from '@polkadot/react-hooks';
import { truncateTitle } from '../helpers';
import { useBounties } from '../hooks';
@ -20,13 +22,16 @@ interface Props {
function ExtendBountyExpiryAction ({ curatorId, description, index, toggleOpen }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { extendBountyExpiry } = useBounties();
const { bountyUpdatePeriod, extendBountyExpiry } = useBounties();
const [remark, setRemark] = useState('');
const [blockTime, timeAsText] = useBlockTime(bountyUpdatePeriod);
const onRemarkChange = useCallback((value: string) => {
setRemark(value);
}, []);
const expiryDate = useMemo(() => bountyUpdatePeriod && increaseDateByBlocks(bountyUpdatePeriod, blockTime), [bountyUpdatePeriod, blockTime]);
return (
<>
<Modal
@ -52,6 +57,21 @@ function ExtendBountyExpiryAction ({ curatorId, description, index, toggleOpen }
<p>{t<string>('Only curator can extend the bounty time.')}</p>
</Modal.Column>
</Modal.Columns>
{expiryDate &&
<Modal.Columns>
<Modal.Column>
<Input
help={t<string>('The extended expiry date does not depend on the current expiry date.')}
isDisabled
label={t<string>('new expiry date and time')}
value={`${expiryDate.toLocaleDateString()} ${expiryDate.toLocaleTimeString()}`}
/>
</Modal.Column>
<Modal.Column>
<p>{t<string>(`Bounty expiry time will be set to ${timeAsText} from now.`)}</p>
</Modal.Column>
</Modal.Columns>
}
<Modal.Columns>
<Modal.Column>
<Input

View File

@ -0,0 +1,8 @@
// Copyright 2017-2021 @polkadot/app-treasury authors & contributors
// SPDX-License-Identifier: Apache-2.0
import BN from 'bn.js';
export function increaseDateByBlocks (blocks: BN, blockTime: number): Date {
return new Date(Date.now() + blocks.muln(blockTime).toNumber());
}