Add Unnote image ability (#8626)

This commit is contained in:
Jaco 2022-12-25 12:06:21 +02:00 committed by GitHub
parent 55a12cc107
commit ae11b36a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 2 deletions

View File

@ -0,0 +1,43 @@
// Copyright 2017-2022 @polkadot/app-preimages authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Preimage } from '../types';
import React, { useMemo } from 'react';
import { TxButton } from '@polkadot/react-components';
import { useAccounts, useApi } from '@polkadot/react-hooks';
import { useTranslation } from '../translate';
interface Props {
className?: string;
value: Preimage;
}
function Free ({ className, value: { count, deposit, proposalHash, status } }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const { allAccounts } = useAccounts();
const isAvailable = useMemo(
() => count === 0 && status && status.isUnrequested && deposit && allAccounts.includes(deposit.who),
[allAccounts, count, deposit, status]
);
if (!isAvailable || !deposit) {
return null;
}
return (
<TxButton
accountId={deposit.who}
className={className}
icon='minus'
label={t<string>('Unnote')}
params={[proposalHash]}
tx={api.tx.preimage.unnotePreimage}
/>
);
}
export default React.memo(Free);

View File

@ -9,6 +9,7 @@ import { formatNumber } from '@polkadot/util';
import usePreimage from '../usePreimage';
import Call from './Call';
import Free from './Free';
import Hash from './Hash';
interface Props {
@ -29,9 +30,12 @@ function Preimage ({ className, value }: Props): React.ReactElement<Props> {
<td className='number'>
{info?.status?.type}
</td>
<td className='number'>
<td className='number media--1400'>
{info && info.count !== 0 && formatNumber(info.count)}
</td>
<td className='button'>
{info && <Free value={info} />}
</td>
</tr>
);
}

View File

@ -28,7 +28,8 @@ function Hashes ({ className }: Props): React.ReactElement<Props> {
[undefined, 'media--1300'],
[t('size')],
[t('status')],
[t('count')]
[t('count'), 'media--1400'],
[]
]);
return (