Asset minting modal (#5127)
This commit is contained in:
parent
eda9dc1c53
commit
5033d18bcd
@ -9,12 +9,14 @@ import { AddressSmall } from '@polkadot/react-components';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import Mint from './Mint';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
value: AssetInfo;
|
||||
}
|
||||
|
||||
function Asset ({ className, value: { details, id, metadata } }: Props): React.ReactElement<Props> {
|
||||
function Asset ({ className, value: { details, id, isIssuerMe, metadata } }: Props): React.ReactElement<Props> {
|
||||
const format = useMemo(
|
||||
() => metadata && [metadata.decimals.toNumber(), metadata.symbol.toUtf8()],
|
||||
[metadata]
|
||||
@ -36,6 +38,13 @@ function Asset ({ className, value: { details, id, metadata } }: Props): React.R
|
||||
)}</td>
|
||||
{/* <td className='number'>{formatNumber(metadata?.decimals)}</td> */}
|
||||
{/* <td className='upper'>{metadata?.symbol.toUtf8()}</td> */}
|
||||
<td className='button'>{details && metadata && isIssuerMe && (
|
||||
<Mint
|
||||
details={details}
|
||||
id={id}
|
||||
metadata={metadata}
|
||||
/>
|
||||
)}</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
@ -26,7 +26,8 @@ function Assets ({ assetIds, className }: Props): React.ReactElement<Props> {
|
||||
[t('admin'), 'address media--1200'],
|
||||
[t('issuer'), 'address media--1300'],
|
||||
[t('freezer'), 'address media--1400'],
|
||||
[t('supply')]
|
||||
[t('supply')],
|
||||
[]
|
||||
]);
|
||||
|
||||
return (
|
||||
|
||||
86
packages/page-assets/src/Overview/Mint/Mint.tsx
Normal file
86
packages/page-assets/src/Overview/Mint/Mint.tsx
Normal file
@ -0,0 +1,86 @@
|
||||
// Copyright 2017-2021 @polkadot/app-assets authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AssetDetails, AssetId, AssetMetadata } from '@polkadot/types/interfaces';
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
import { InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
|
||||
import { useApi } from '@polkadot/react-hooks';
|
||||
|
||||
import { useTranslation } from '../../translate';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
details: AssetDetails;
|
||||
id: AssetId;
|
||||
metadata: AssetMetadata;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
function Mint ({ className, details: { issuer, minBalance }, id, metadata, onClose }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const [amount, setAmount] = useState<BN | null>(null);
|
||||
const [recipientId, setRecipientId] = useState<string | null>(null);
|
||||
|
||||
const isAmountValid = useMemo(
|
||||
() => amount && amount.gte(minBalance),
|
||||
[amount, minBalance]
|
||||
);
|
||||
|
||||
const [siDecimals, siSymbol] = useMemo(
|
||||
() => [metadata.decimals.toNumber(), metadata.symbol.toUtf8().toUpperCase()],
|
||||
[metadata]
|
||||
);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
className={className}
|
||||
header={t<string>('mint asset')}
|
||||
size='large'
|
||||
>
|
||||
<Modal.Content>
|
||||
<Modal.Columns hint={t<string>('The recipient account for this minting operation.')}>
|
||||
<InputAddress
|
||||
defaultValue={issuer}
|
||||
isDisabled
|
||||
label={t<string>('issuer account')}
|
||||
/>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The recipient account for this minting operation.')}>
|
||||
<InputAddress
|
||||
label={t<string>('mint to address')}
|
||||
onChange={setRecipientId}
|
||||
type='allPlus'
|
||||
/>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The amount of tokens to issue to the account.')}>
|
||||
<InputBalance
|
||||
autoFocus
|
||||
isError={!isAmountValid}
|
||||
isZeroable={false}
|
||||
label={t<string>('amount to issue')}
|
||||
onChange={setAmount}
|
||||
siDecimals={siDecimals}
|
||||
siSymbol={siSymbol}
|
||||
/>
|
||||
</Modal.Columns>
|
||||
</Modal.Content>
|
||||
<Modal.Actions onCancel={onClose}>
|
||||
<TxButton
|
||||
accountId={issuer}
|
||||
icon='plus'
|
||||
isDisabled={!recipientId || !isAmountValid}
|
||||
label={t<string>('Mint')}
|
||||
onStart={onClose}
|
||||
params={[id, recipientId, amount]}
|
||||
tx={api.tx.assets.mint}
|
||||
/>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Mint);
|
||||
46
packages/page-assets/src/Overview/Mint/index.tsx
Normal file
46
packages/page-assets/src/Overview/Mint/index.tsx
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2017-2021 @polkadot/app-assets authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AssetDetails, AssetId, AssetMetadata } from '@polkadot/types/interfaces';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { Button } from '@polkadot/react-components';
|
||||
import { useToggle } from '@polkadot/react-hooks';
|
||||
|
||||
import { useTranslation } from '../../translate';
|
||||
import Modal from './Mint';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
details: AssetDetails;
|
||||
id: AssetId;
|
||||
metadata: AssetMetadata;
|
||||
}
|
||||
|
||||
function Mint ({ className, details, id, metadata }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const [isOpen, toggleOpen] = useToggle();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
icon='plus'
|
||||
isDisabled={metadata.isFrozen.isTrue}
|
||||
label={t<string>('Mint')}
|
||||
onClick={toggleOpen}
|
||||
/>
|
||||
{isOpen && (
|
||||
<Modal
|
||||
className={className}
|
||||
details={details}
|
||||
id={id}
|
||||
metadata={metadata}
|
||||
onClose={toggleOpen}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Mint);
|
||||
Loading…
Reference in New Issue
Block a user