Skip to content

Commit

Permalink
Merge pull request #2990 from Giveth/fix-create-project-input
Browse files Browse the repository at this point in the history
Fix create project input
  • Loading branch information
MohammadPCh authored Aug 6, 2023
2 parents 2cd782e + 011bd12 commit 4e78088
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
30 changes: 28 additions & 2 deletions src/components/views/create/CreateProjectAddAddressModal.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 (
<Modal
closeModal={closeModal}
closeModal={closeModalAndClearErrorsAndResetValue}
isAnimating={isAnimating}
headerTitlePosition='left'
headerTitle='Add new Address'
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/create/WalletAddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const WalletAddressInput: FC<IProps> = ({
register={register}
registerName={inputName}
registerOptions={{ validate: addressValidation }}
error={isAddressUsed ? undefined : error}
error={isAddressUsed || !value ? undefined : error}
/>
{delayedResolvedENS && (
<InlineToast
Expand Down

0 comments on commit 4e78088

Please sign in to comment.