import { Add, Remove } from '@mui/icons-material' import clsx from 'clsx' import { FieldErrors, useFieldArray, useFormContext } from 'react-hook-form' import { useTranslation } from 'react-i18next' import { Button, ButtonLink, CodeMirrorInput, FormSwitch, IconButton, InputErrorMessage, InputLabel, TextInput, Tooltip, useChain, } from '@dao-dao/stateless' import { ChainId, ProposalExecutionMetadataEditorData } from '@dao-dao/types' import { validateJSON, validateRequired } from '@dao-dao/utils' export type ProposalExecutionMetadataEditorProps = { /** * Field errors for the form fields. */ errors?: FieldErrors /** * Field name prefix for the form fields, if the `metadata` field is nested * within another field. */ fieldNamePrefix?: string /** * Optional container class name. */ className?: string } /** * A form for editing proposal execution metadata. It expects to be within a * form context whose data has a `metadata` field with type * `ProposalExecutionMetadata`. */ export const ProposalExecutionMetadataEditor = ({ errors, fieldNamePrefix = '', className, }: ProposalExecutionMetadataEditorProps) => { const { t } = useTranslation() const { chainId } = useChain() const { watch, register, control, setValue, clearErrors } = useFormContext() const metadataFieldName = (fieldNamePrefix + 'metadata') as 'metadata' const metadataEnabled = watch(`${metadataFieldName}.enabled`) const { fields: gaiaMetaprotocolsExtensionDataFields, append: appendGaiaMetaprotocolsExtensionData, remove: removeGaiaMetaprotocolsExtensionData, } = useFieldArray({ control, name: `${metadataFieldName}.gaiaMetaprotocolsExtensionData`, }) return (
setValue(`${metadataFieldName}.enabled`, !metadataEnabled) } title />
{metadataEnabled && (
{/* Gaia Metaprotocols Extension Data only supported on Cosmos Hub */} {(chainId === ChainId.CosmosHubMainnet || chainId === ChainId.CosmosHubProviderTestnet) && (
0 ? 'pb-6' : 'pb-4' )} >
See the{' '} Cosmos Network docs {' '} for more information. } />
{gaiaMetaprotocolsExtensionDataFields.map(({ id }, index) => (
{ removeGaiaMetaprotocolsExtensionData(index) clearErrors( `${metadataFieldName}.gaiaMetaprotocolsExtensionData.${index}` ) }} size="sm" variant="secondary" />
))}
)}
)}
) }