diff --git a/packages/page-assets/src/Overview/Asset.tsx b/packages/page-assets/src/Overview/Asset.tsx index 8c2f023c6c..d0f94a19a4 100644 --- a/packages/page-assets/src/Overview/Asset.tsx +++ b/packages/page-assets/src/Overview/Asset.tsx @@ -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 { +function Asset ({ className, value: { details, id, isIssuerMe, metadata } }: Props): React.ReactElement { 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 )} {/* {formatNumber(metadata?.decimals)} */} {/* {metadata?.symbol.toUtf8()} */} + {details && metadata && isIssuerMe && ( + + )} ); } diff --git a/packages/page-assets/src/Overview/Assets.tsx b/packages/page-assets/src/Overview/Assets.tsx index 5197329a24..b9f581a211 100644 --- a/packages/page-assets/src/Overview/Assets.tsx +++ b/packages/page-assets/src/Overview/Assets.tsx @@ -26,7 +26,8 @@ function Assets ({ assetIds, className }: Props): React.ReactElement { [t('admin'), 'address media--1200'], [t('issuer'), 'address media--1300'], [t('freezer'), 'address media--1400'], - [t('supply')] + [t('supply')], + [] ]); return ( diff --git a/packages/page-assets/src/Overview/Mint/Mint.tsx b/packages/page-assets/src/Overview/Mint/Mint.tsx new file mode 100644 index 0000000000..85840d1bef --- /dev/null +++ b/packages/page-assets/src/Overview/Mint/Mint.tsx @@ -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 { + const { t } = useTranslation(); + const { api } = useApi(); + const [amount, setAmount] = useState(null); + const [recipientId, setRecipientId] = useState(null); + + const isAmountValid = useMemo( + () => amount && amount.gte(minBalance), + [amount, minBalance] + ); + + const [siDecimals, siSymbol] = useMemo( + () => [metadata.decimals.toNumber(), metadata.symbol.toUtf8().toUpperCase()], + [metadata] + ); + + return ( + ('mint asset')} + size='large' + > + + ('The recipient account for this minting operation.')}> + ('issuer account')} + /> + + ('The recipient account for this minting operation.')}> + ('mint to address')} + onChange={setRecipientId} + type='allPlus' + /> + + ('The amount of tokens to issue to the account.')}> + ('amount to issue')} + onChange={setAmount} + siDecimals={siDecimals} + siSymbol={siSymbol} + /> + + + + ('Mint')} + onStart={onClose} + params={[id, recipientId, amount]} + tx={api.tx.assets.mint} + /> + + + ); +} + +export default React.memo(Mint); diff --git a/packages/page-assets/src/Overview/Mint/index.tsx b/packages/page-assets/src/Overview/Mint/index.tsx new file mode 100644 index 0000000000..a0672075d5 --- /dev/null +++ b/packages/page-assets/src/Overview/Mint/index.tsx @@ -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 { + const { t } = useTranslation(); + const [isOpen, toggleOpen] = useToggle(); + + return ( + <> +