From c231b66f6b39b31f950cc2e0f76854497df66db3 Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 23 Apr 2021 11:54:51 +0300 Subject: [PATCH] Asset modal rework (min balance with decimals) (#5126) * Asset modal rework (min balance with decimals) * Language cleanups --- .../src/Overview/Create/Create.tsx | 68 ++++++++------- .../page-assets/src/Overview/Create/Info.tsx | 79 ++++++++++++++---- .../src/Overview/Create/Metadata.tsx | 83 ------------------- .../page-assets/src/Overview/Create/Team.tsx | 16 ++-- .../page-assets/src/Overview/Create/types.ts | 11 +-- packages/react-components/src/InputNumber.tsx | 35 ++++---- 6 files changed, 126 insertions(+), 166 deletions(-) delete mode 100644 packages/page-assets/src/Overview/Create/Metadata.tsx diff --git a/packages/page-assets/src/Overview/Create/Create.tsx b/packages/page-assets/src/Overview/Create/Create.tsx index 63a8855eff..b83bc23ec0 100644 --- a/packages/page-assets/src/Overview/Create/Create.tsx +++ b/packages/page-assets/src/Overview/Create/Create.tsx @@ -2,16 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 import type { AssetId } from '@polkadot/types/interfaces'; -import type { InfoState, MetadataState, TeamState } from './types'; +import type { InfoState, TeamState } from './types'; import React, { useMemo, useState } from 'react'; import { Button, Modal, TxButton } from '@polkadot/react-components'; -import { useStepper, useTxBatch } from '@polkadot/react-hooks'; +import { useApi, useStepper, useTxBatch } from '@polkadot/react-hooks'; import { useTranslation } from '../../translate'; import Info from './Info'; -import Metadata from './Metadata'; import Team from './Team'; interface Props { @@ -26,21 +25,43 @@ const BATCH_OPTIONS = { function Create ({ assetIds, className, onClose }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [step, nextStep, prevStep] = useStepper(); const [asset, setAsset] = useState(null); - const [metadata, setMetadata] = useState(null); const [team, setTeam] = useState(null); - const txs = useMemo(() => asset && metadata && team && ( - team.teamTx - ? [asset.createTx, metadata.metadataTx, team.teamTx] - : [asset.createTx, metadata.metadataTx] - ), [asset, metadata, team]); + + const [createTx, metadataTx] = useMemo( + () => asset + ? [ + api.tx.assets.create(asset.assetId, asset.accountId, asset.minBalance), + api.tx.assets.setMetadata(asset.assetId, asset.assetName, asset.assetSymbol, asset.assetDecimals) + ] + : [null, null], + [api, asset] + ); + + const teamTx = useMemo( + () => asset && team && (team.adminId !== asset.accountId || team.freezerId !== asset.accountId || team.issuerId !== asset.accountId) + ? api.tx.assets.setTeam(asset.assetId, team.issuerId, team.adminId, team.freezerId) + : null, + [api, asset, team] + ); + + const txs = useMemo( + () => createTx && metadataTx && team && ( + teamTx + ? [createTx, metadataTx, teamTx] + : [createTx, metadataTx] + ), + [createTx, metadataTx, team, teamTx] + ); + const extrinsic = useTxBatch(txs, BATCH_OPTIONS); return ( ('create asset {{step}}/{{steps}}', { replace: { step, steps: 3 } })} + header={t('create asset {{step}}/{{steps}}', { replace: { step, steps: 2 } })} size='large' > {step === 1 && ( @@ -50,17 +71,9 @@ function Create ({ assetIds, className, onClose }: Props): React.ReactElement )} - {step === 2 && ( - - )} - {step === 3 && ( + {step === 2 && asset && ( @@ -75,21 +88,6 @@ function Create ({ assetIds, className, onClose }: Props): React.ReactElement } {step === 2 && ( - <> -