// Copyright 2017-2025 @pezkuwi/app-assets authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { BatchOptions } from '@pezkuwi/react-hooks/types'; import type { BN } from '@pezkuwi/util'; import type { InfoState, TeamState } from './types.js'; import React, { useMemo, useState } from 'react'; import { Button, Modal, TxButton } from '@pezkuwi/react-components'; import { useApi, useStepper, useTxBatch } from '@pezkuwi/react-hooks'; import { useTranslation } from '../../translate.js'; import Info from './Info.js'; import Team from './Team.js'; interface Props { assetIds: BN[]; className?: string; onClose: () => void; openId: BN; } const BATCH_OPTS: BatchOptions = { type: 'all' }; function Create ({ assetIds, className, onClose, openId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const [step, nextStep, prevStep] = useStepper(); const [asset, setAsset] = useState(null); const [team, setTeam] = useState(null); 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_OPTS); return ( {step === 1 && ( )} {step === 2 && asset && ( )} {step === 1 &&