diff --git a/src/components/views/create/CreateProjectAddAddressModal.tsx b/src/components/views/create/CreateProjectAddAddressModal.tsx index 15e1d8f8af..15806e0112 100644 --- a/src/components/views/create/CreateProjectAddAddressModal.tsx +++ b/src/components/views/create/CreateProjectAddAddressModal.tsx @@ -1,8 +1,11 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import styled from 'styled-components'; +import { useFormContext } from 'react-hook-form'; import { Modal } from '@/components/modals/Modal'; import { useModalAnimation } from '@/hooks/useModalAnimation'; import WalletAddressInput from './WalletAddressInput'; +import config from '@/configuration'; +import { EInputs } from './CreateProject'; interface ICreateProjectAddAddressModal { setShowModal: (show: number | undefined) => void; @@ -27,9 +30,32 @@ const CreateProjectAddAddressModal = ({ setShowModal(undefined), ); + const isGnosis = networkId === config.XDAI_NETWORK_NUMBER; + const isPolygon = networkId === config.POLYGON_NETWORK_NUMBER; + const isCelo = networkId === config.CELO_NETWORK_NUMBER; + const isOptimism = networkId === config.OPTIMISM_NETWORK_NUMBER; + + const inputName = isGnosis + ? EInputs.gnosisAddress + : isPolygon + ? EInputs.polygonAddress + : isCelo + ? EInputs.celoAddress + : isOptimism + ? EInputs.optimismAddress + : EInputs.mainAddress; + + const { clearErrors, setValue } = useFormContext(); + + const closeModalAndClearErrorsAndResetValue = useCallback(() => { + clearErrors(inputName); + setValue(inputName, ''); + closeModal(); + }, []); + return ( = ({ register={register} registerName={inputName} registerOptions={{ validate: addressValidation }} - error={isAddressUsed ? undefined : error} + error={isAddressUsed || !value ? undefined : error} /> {delayedResolvedENS && (