import { Button, FileInput } from '@gear-js/ui'; import { FormProvider, useForm } from 'react-hook-form'; import { FileTypes } from '@/shared/config'; import { useChain, useCodeUpload, useContractApiWithFile } from '@/hooks'; import { Box } from '@/shared/ui/box'; import { Subheader } from '@/shared/ui/subheader'; import { BackButton } from '@/shared/ui/backButton'; import { UploadMetadata } from '@/features/uploadMetadata'; import PlusSVG from '@/shared/assets/images/actions/plus.svg?react'; import { CodeVoucherSelect } from '@/features/voucher'; import { useWasmFile } from '@/features/code'; import { Input } from '@/shared/ui'; import styles from './UploadCode.module.scss'; const defaultValues = { name: '', voucherId: '', }; const UploadCode = () => { const { isDevChain } = useChain(); const form = useForm({ defaultValues }); const file = useWasmFile('code'); const { metadata, sails, isLoading, ...contractApi } = useContractApiWithFile(file.buffer); const uploadCode = useCodeUpload(); const resetForm = () => { form.reset(); file.reset(); metadata.reset(); }; const handleWasmFileChange = (value: File | undefined) => { form.reset(); contractApi.reset(); file.handleChange(value); }; const handleSubmit = form.handleSubmit((data: typeof defaultValues) => { if (!file.buffer) return; uploadCode({ optBuffer: file.buffer, metadata, sails, resolve: resetForm, ...data }); }); return ( <>