import { Button, Input, Textarea } from '@gear-js/ui'; import { useEffect, useMemo } from 'react'; import { FormProvider, useForm, useWatch } from 'react-hook-form'; import { useProgram } from '@/features/program'; import { useStateRead } from '@/hooks'; import { getPreformattedText, isNullOrUndefined } from '@/shared/helpers'; import { BackButton } from '@/shared/ui/backButton'; import { Box } from '@/shared/ui/box'; import { isHumanTypesRepr, useMetadata } from '@/features/metadata'; import { FormPayload, getPayloadFormValues, getSubmitPayload } from '@/features/formPayload'; import ReadSVG from '@/shared/assets/images/actions/read.svg?react'; import { FormValues, INITIAL_VALUES } from '../../model'; import { downloadJson } from '../../helpers'; import { useProgramId } from '../../hooks'; import styles from './Full.module.scss'; const Full = () => { const programId = useProgramId(); const { data: program } = useProgram(programId); const { metadata, isMetadataReady } = useMetadata(program?.metahash); const { state, isStateRead, isState, readFullState, resetState } = useStateRead(programId); // TODOFORM: // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const methods = useForm({ defaultValues: INITIAL_VALUES }); const { control } = methods; const payloadValue = useWatch({ control, name: 'payload' }); useEffect(() => { resetState(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [payloadValue]); const payloadFormValues = useMemo( () => metadata && isHumanTypesRepr(metadata.types.state) && !isNullOrUndefined(metadata.types.state.input) ? getPayloadFormValues(metadata, metadata.types.state.input) : undefined, [metadata], ); const handleSubmit = ({ payload }: FormValues) => { if (!metadata) return; readFullState(metadata, getSubmitPayload(payload) || '0x'); }; return ( <>

Read Program State

{isMetadataReady ? ( payloadFormValues && ) : (