import React, { useRef, useState } from 'react'; import { createForm } from '@formily/core'; import { createSchemaField } from '@formily/react'; import Modal, { ModalProps } from '@/components/Modal'; // import { fetchTableData } from '@/utils/table'; import { Form, FormItem, Input, NumberPicker } from '@formily/antd'; import { Button } from 'antd'; import { initWeb3, NFTMint } from '@/utils/web3'; import { getContractInfo } from '@/services/contract'; import { getNFTContractList, mintNFT } from '@/services/nft'; import { ContractType } from '@/constants/enum/contract'; interface AddNftModalPropsType extends ModalProps { onOk: () => void; onCancel: () => void; // loading: boolean; } const SchemaField = createSchemaField({ components: { FormItem, Input, NumberPicker, }, }); const form = createForm({}); const AddNftModal = ({ onOk, onCancel, ...rest }: AddNftModalPropsType) => { const [loading, setLoading] = useState(false); const handleOk = async () => { form.submit(async () => { setLoading(true); const formState = form.getFormState(); await initWeb3(); const contractInfo = await getContractInfo({ erc: ContractType.NFT721 }); const res = await getNFTContractList(); const tx_hash = await NFTMint({ abi: contractInfo.abi, address: res.items[0].address, toAddress: formState.values.toAddress, name: formState.values.name, }); console.log('tx_hash = ', tx_hash); formState.values.tx_hash = tx_hash; await mintNFT(formState.values); setLoading(false); onOk(); }); }; const handleCancel = () => { onCancel(); }; return ( 取消 , , ]} {...rest} >
); }; export default AddNftModal;