From a39b561099d0f97f42339997fd5ee6cbebb47799 Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Tue, 10 Sep 2024 07:11:27 +0530 Subject: [PATCH 01/15] fix: network modal showing while the page is loading --- src/components/views/donate/OnTime/OneTimeDonationCard.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx index f977521755..53335f2251 100644 --- a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx +++ b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx @@ -367,6 +367,7 @@ const CryptoDonation: FC<{ { setIsSanctioned(false); + setShowChangeNetworkModal(false); }} /> )} From d305aaac3e004feec835f13a16a7dcc97617f7c0 Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Tue, 10 Sep 2024 11:29:14 +0530 Subject: [PATCH 02/15] keep the sanctions modal until the page has redirected to all pages --- src/components/modals/SanctionedModal.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/modals/SanctionedModal.tsx b/src/components/modals/SanctionedModal.tsx index da8ccdbcb9..0bd4a9a169 100644 --- a/src/components/modals/SanctionedModal.tsx +++ b/src/components/modals/SanctionedModal.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { brandColors, Button, @@ -21,12 +21,26 @@ interface SanctionModalProps { export const SanctionModal: React.FC = ({ closeModal }) => { const { formatMessage } = useIntl(); + const [isRedirecting, setIsRedirecting] = useState(false); const router = useRouter(); const navigateToAllProjects = () => { + setIsRedirecting(true); router.push(Routes.AllProjects); - closeModal(); }; + useEffect(() => { + const handleRouteChangeComplete = () => { + closeModal(); + setIsRedirecting(false); + }; + if(isRedirecting) { + router.events.on('routeChangeComplete', handleRouteChangeComplete); + } + return () => { + router.events.off('routeChangeComplete', handleRouteChangeComplete); + }; + }, [isRedirecting]); + return ( Date: Tue, 10 Sep 2024 11:34:51 +0530 Subject: [PATCH 03/15] fix: run linter --- src/components/modals/SanctionedModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/modals/SanctionedModal.tsx b/src/components/modals/SanctionedModal.tsx index 0bd4a9a169..c603d84afd 100644 --- a/src/components/modals/SanctionedModal.tsx +++ b/src/components/modals/SanctionedModal.tsx @@ -33,7 +33,7 @@ export const SanctionModal: React.FC = ({ closeModal }) => { closeModal(); setIsRedirecting(false); }; - if(isRedirecting) { + if (isRedirecting) { router.events.on('routeChangeComplete', handleRouteChangeComplete); } return () => { From 69eaf288b1bda5c9ae96492245f98b1a5701efda Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Thu, 12 Sep 2024 17:44:18 +0530 Subject: [PATCH 04/15] fix: multiple donation modal shown together --- .../modals/DonationByProjectOwner.tsx | 26 +++++++--- src/components/views/donate/DonateIndex.tsx | 48 +++++++++++++++--- src/components/views/donate/DonationCard.tsx | 6 +-- .../donate/OnTime/OneTimeDonationCard.tsx | 50 ++++++++----------- src/context/donate.context.tsx | 30 +++++++++++ 5 files changed, 112 insertions(+), 48 deletions(-) diff --git a/src/components/modals/DonationByProjectOwner.tsx b/src/components/modals/DonationByProjectOwner.tsx index 62978d202b..ace4ed5397 100644 --- a/src/components/modals/DonationByProjectOwner.tsx +++ b/src/components/modals/DonationByProjectOwner.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { brandColors, Button, @@ -12,27 +12,37 @@ import { useRouter } from 'next/router'; import { Modal } from '@/components/modals/Modal'; import Routes from '@/lib/constants/Routes'; import { mediaQueries } from '@/lib/constants/constants'; -import { useModalAnimation } from '@/hooks/useModalAnimation'; // Define the props interface interface DonationByProjectOwnerProps { - setShowDonationByProjectOwner: ( - showDonationByProjectOwner: boolean, - ) => void; + closeModal: () => void; } export const DonationByProjectOwner: React.FC = ({ - setShowDonationByProjectOwner, + closeModal, }) => { const { formatMessage } = useIntl(); const router = useRouter(); - const { closeModal } = useModalAnimation(setShowDonationByProjectOwner); + const [isRedirecting, setIsRedirecting] = useState(false); const navigateToAllProjects = () => { + setIsRedirecting(true); router.push(Routes.AllProjects); - closeModal(); }; + useEffect(() => { + const handleRouteChangeComplete = () => { + closeModal(); + setIsRedirecting(false); + }; + if (isRedirecting) { + router.events.on('routeChangeComplete', handleRouteChangeComplete); + } + return () => { + router.events.off('routeChangeComplete', handleRouteChangeComplete); + }; + }, [isRedirecting]); + return ( { const { formatMessage } = useIntl(); @@ -56,11 +60,13 @@ const DonateIndex: FC = () => { qrDonationStatus, draftDonationData, hasActiveQFRound, + currentDonateModal, setSuccessDonation, setQRDonationStatus, setDraftDonationData, setPendingDonationExists, startTimer, + setDonateModalByPriority, } = useDonateData(); const { renewExpirationDate, retrieveDraftDonation } = useQRCodeDonation(project); @@ -78,6 +84,7 @@ const DonateIndex: FC = () => { const [showQRCode, setShowQRCode] = React.useState( !!router.query.draft_donation, ); + const { walletAddress: address } = useGeneralWallet(); const [stopTimer, setStopTimer] = React.useState void)>(); useEffect(() => { @@ -87,10 +94,32 @@ const DonateIndex: FC = () => { }; }, [dispatch]); + const validateSanctions = async () => { + if (project.organization?.label === 'endaoment' && address) { + // We just need to check if the wallet is sanctioned for endaoment projects + const sanctioned = await isWalletSanctioned(address); + if (sanctioned) { + setDonateModalByPriority( + DonateModalPriorityValues.OFACSanctionListModal, + ); + return; + } + } + }; + useEffect(() => { - setShowDonationByProjectOwner( - userData?.id !== undefined && userData?.id === project.adminUser.id, - ); + validateSanctions(); + }, [project, address]); + + useEffect(() => { + if ( + userData?.id !== undefined && + userData?.id === project.adminUser.id + ) { + setDonateModalByPriority( + DonateModalPriorityValues.DonationByProjectOwner, + ); + } }, [userData?.id, project.adminUser]); useEffect(() => { @@ -221,11 +250,14 @@ const DonateIndex: FC = () => { <> - {showDonationByProjectOwner && ( + {currentDonateModal === + DonateModalPriorityValues.DonationByProjectOwner && ( { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} /> )} {alreadyDonated && ( diff --git a/src/components/views/donate/DonationCard.tsx b/src/components/views/donate/DonationCard.tsx index 7495dc964f..e69ebaab77 100644 --- a/src/components/views/donate/DonationCard.tsx +++ b/src/components/views/donate/DonationCard.tsx @@ -53,7 +53,7 @@ export const DonationCard: FC = ({ address.chainType === ChainType.EVM && address.networkId === config.OPTIMISM_NETWORK_NUMBER, ); - + const isEndaomentProject = project?.organization?.label === 'endaoment'; const isOwnerOnEVM = project?.adminUser?.walletAddress && isAddress(project.adminUser?.walletAddress); @@ -94,10 +94,10 @@ export const DonationCard: FC = ({ // If both conditions are met, set the active tab to 'RECURRING' using the setTab function. // This ensures that the 'RECURRING' tab is active by default if project has Op Address. useEffect(() => { - if (!router.query.tab && hasOpAddress) { + if (!router.query.tab && hasOpAddress && !isEndaomentProject) { setTab(ETabs.RECURRING); } - }, [router.query, hasOpAddress]); + }, [router.query, hasOpAddress, isEndaomentProject]); return ( diff --git a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx index 53335f2251..eb8ac4692a 100644 --- a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx +++ b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx @@ -35,7 +35,10 @@ import { useAppDispatch, useAppSelector } from '@/features/hooks'; import DonateToGiveth from '@/components/views/donate/DonateToGiveth'; import SaveGasFees from './SaveGasFees'; import SwitchToAcceptedChain from '@/components/views/donate/SwitchToAcceptedChain'; -import { useDonateData } from '@/context/donate.context'; +import { + DonateModalPriorityValues, + useDonateData, +} from '@/context/donate.context'; import { useModalCallback } from '@/hooks/useModalCallback'; import DonateQFEligibleNetworks from './DonateQFEligibleNetworks'; import { getActiveRound } from '@/helpers/qf'; @@ -58,8 +61,6 @@ import { TokenIcon } from '../TokenIcon/TokenIcon'; import { SelectTokenModal } from './SelectTokenModal/SelectTokenModal'; import { Spinner } from '@/components/Spinner'; import { useSolanaBalance } from '@/hooks/useSolanaBalance'; -import { isWalletSanctioned } from '@/services/donation'; -import SanctionModal from '@/components/modals/SanctionedModal'; const CryptoDonation: FC<{ setIsQRDonation: (isQRDonation: boolean) => void; @@ -76,7 +77,13 @@ const CryptoDonation: FC<{ const router = useRouter(); const { isSignedIn } = useAppSelector(state => state.user); - const { project, hasActiveQFRound, selectedOneTimeToken } = useDonateData(); + const { + project, + hasActiveQFRound, + selectedOneTimeToken, + currentDonateModal, + setDonateModalByPriority, + } = useDonateData(); const dispatch = useAppDispatch(); const { @@ -97,7 +104,6 @@ const CryptoDonation: FC<{ const [showDonateModal, setShowDonateModal] = useState(false); const [showInsufficientModal, setShowInsufficientModal] = useState(false); const [showChangeNetworkModal, setShowChangeNetworkModal] = useState(false); - const [isSanctioned, setIsSanctioned] = useState(false); const [acceptedChains, setAcceptedChains] = useState( [], ); @@ -149,10 +155,6 @@ const CryptoDonation: FC<{ address => address.chainType === ChainType.STELLAR, ); - useEffect(() => { - validateSanctions(); - }, [project, address]); - useEffect(() => { if ( (networkId || @@ -327,17 +329,6 @@ const CryptoDonation: FC<{ } }, [selectedTokenBalance, amount, selectedOneTimeToken?.address, gasfee]); - const validateSanctions = async () => { - if (project?.organization?.label === 'endaoment' && address) { - // We just need to check if the wallet is sanctioned for endaoment projects - const sanctioned = await isWalletSanctioned(address); - if (sanctioned) { - setIsSanctioned(true); - return; - } - } - }; - const amountErrorText = useMemo(() => { const totalAmount = Number(formatUnits(gasfee, tokenDecimals)).toFixed( 10, @@ -352,6 +343,14 @@ const CryptoDonation: FC<{ ); }, [gasfee, tokenDecimals, selectedOneTimeToken?.symbol, formatMessage]); + useEffect(() => { + if (showChangeNetworkModal && acceptedChains) { + setDonateModalByPriority( + DonateModalPriorityValues.ShowNetworkModal, + ); + } + }, [showChangeNetworkModal, acceptedChains]); + // We need givethDonationAmount here because we need to calculate the donation share // for Giveth. If user want to donate minimal amount to projecct, the donation share for Giveth // has to be 0, disabled in UI and DonationModal @@ -363,21 +362,14 @@ const CryptoDonation: FC<{ return ( - {isSanctioned && ( - { - setIsSanctioned(false); - setShowChangeNetworkModal(false); - }} - /> - )} {showQFModal && ( )} - {!isSanctioned && showChangeNetworkModal && acceptedChains && ( + {currentDonateModal === + DonateModalPriorityValues.ShowNetworkModal && ( >; + currentDonateModal: DonateModalPriorityValues; + setDonateModalByPriority: ( + changeCurrentModal: DonateModalPriorityValues, + ) => void; setSelectedRecurringToken: Dispatch< SetStateAction >; @@ -64,13 +68,24 @@ interface IProviderProps { project: IProject; } +export enum DonateModalPriorityValues { + None, + ShowNetworkModal, + DonationByProjectOwner, + OFACSanctionListModal, +} + const DonateContext = createContext({ setSuccessDonation: () => {}, setSelectedOneTimeToken: () => {}, setSelectedRecurringToken: () => {}, project: {} as IProject, + currentDonateModal: DonateModalPriorityValues.None, tokenStreams: {}, fetchProject: async () => {}, + setDonateModalByPriority: ( + changeCurrentModal: DonateModalPriorityValues, + ) => {}, draftDonationData: {} as IDraftDonation, fetchDraftDonation: async () => {}, qrDonationStatus: 'waiting', @@ -105,6 +120,8 @@ export const DonateProvider: FC = ({ children, project }) => { const [successDonation, setSuccessDonation] = useState(); const [projectData, setProjectData] = useState(project); + const [currentDonateModal, setCurrentDonateModal] = + useState(DonateModalPriorityValues.None); const { chain } = useAccount(); @@ -113,6 +130,17 @@ export const DonateProvider: FC = ({ children, project }) => { setSelectedRecurringToken(undefined); }, [chain]); + const setDonateModalByPriority = useCallback( + (changeModal: DonateModalPriorityValues) => { + if (changeModal === DonateModalPriorityValues.None) { + setCurrentDonateModal(DonateModalPriorityValues.None); + } else if (changeModal > currentDonateModal) { + setCurrentDonateModal(changeModal); + } + }, + [currentDonateModal], + ); + const fetchProject = useCallback(async () => { const { data } = (await client.query({ query: FETCH_PROJECT_BY_SLUG_DONATION, @@ -149,6 +177,8 @@ export const DonateProvider: FC = ({ children, project }) => { selectedOneTimeToken, pendingDonationExists, selectedRecurringToken, + setDonateModalByPriority, + currentDonateModal, setSelectedOneTimeToken, setSelectedRecurringToken, tokenStreams, From ff6405ec14f17c8dfcab869f705615b82739dfcd Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Thu, 12 Sep 2024 18:38:45 +0530 Subject: [PATCH 05/15] add OFAC Sanction Modal --- src/components/views/donate/DonateIndex.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index faed61d5c1..aa7c4bac6b 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -50,6 +50,7 @@ import { IDraftDonation } from '@/apollo/types/gqlTypes'; import StorageLabel from '@/lib/localStorage'; import DonationByProjectOwner from '@/components/modals/DonationByProjectOwner'; import { isWalletSanctioned } from '@/services/donation'; +import SanctionModal from '@/components/modals/SanctionedModal'; const DonateIndex: FC = () => { const { formatMessage } = useIntl(); @@ -260,6 +261,18 @@ const DonateIndex: FC = () => { }} /> )} + + {currentDonateModal === + DonateModalPriorityValues.OFACSanctionListModal && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} + {alreadyDonated && ( From d502cece2b9334077f0aeb8bd9de6fa36d73417e Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Sat, 21 Sep 2024 19:24:32 +0530 Subject: [PATCH 06/15] fix; Donate Modals glitching effect --- src/components/views/donate/DonateIndex.tsx | 57 +++++++++++-------- .../donate/OnTime/OneTimeDonationCard.tsx | 23 +++++--- src/context/donate.context.tsx | 47 +++++++++++++++ 3 files changed, 95 insertions(+), 32 deletions(-) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index aa7c4bac6b..ffb51b16f4 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -1,4 +1,4 @@ -import React, { FC, useEffect, useState } from 'react'; +import React, { FC, useEffect } from 'react'; import styled from 'styled-components'; import { Col, @@ -62,12 +62,14 @@ const DonateIndex: FC = () => { draftDonationData, hasActiveQFRound, currentDonateModal, + highestModalPriorityUnchecked, setSuccessDonation, setQRDonationStatus, setDraftDonationData, setPendingDonationExists, startTimer, setDonateModalByPriority, + setIsModalPriorityChecked, } = useDonateData(); const { renewExpirationDate, retrieveDraftDonation } = useQRCodeDonation(project); @@ -75,8 +77,7 @@ const DonateIndex: FC = () => { const alreadyDonated = useAlreadyDonatedToProject(project); const { userData } = useAppSelector(state => state.user); - const [showDonationByProjectOwner, setShowDonationByProjectOwner] = - useState(false); + const dispatch = useAppDispatch(); const isSafeEnv = useIsSafeEnvironment(); const { isOnSolana } = useGeneralWallet(); @@ -106,6 +107,9 @@ const DonateIndex: FC = () => { return; } } + setIsModalPriorityChecked( + DonateModalPriorityValues.OFACSanctionListModal, + ); }; useEffect(() => { @@ -121,6 +125,9 @@ const DonateIndex: FC = () => { DonateModalPriorityValues.DonationByProjectOwner, ); } + setIsModalPriorityChecked( + DonateModalPriorityValues.DonationByProjectOwner, + ); }, [userData?.id, project.adminUser]); useEffect(() => { @@ -251,27 +258,31 @@ const DonateIndex: FC = () => { <> - {currentDonateModal === - DonateModalPriorityValues.DonationByProjectOwner && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} + {(highestModalPriorityUnchecked == 'All Checked' || + currentDonateModal >= highestModalPriorityUnchecked) && + currentDonateModal === + DonateModalPriorityValues.DonationByProjectOwner && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} - {currentDonateModal === - DonateModalPriorityValues.OFACSanctionListModal && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} + {(highestModalPriorityUnchecked == 'All Checked' || + currentDonateModal >= highestModalPriorityUnchecked) && + currentDonateModal === + DonateModalPriorityValues.OFACSanctionListModal && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} {alreadyDonated && ( diff --git a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx index eb8ac4692a..5c4dd1f8f0 100644 --- a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx +++ b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx @@ -82,7 +82,9 @@ const CryptoDonation: FC<{ hasActiveQFRound, selectedOneTimeToken, currentDonateModal, + highestModalPriorityUnchecked, setDonateModalByPriority, + setIsModalPriorityChecked, } = useDonateData(); const dispatch = useAppDispatch(); @@ -349,6 +351,7 @@ const CryptoDonation: FC<{ DonateModalPriorityValues.ShowNetworkModal, ); } + setIsModalPriorityChecked(DonateModalPriorityValues.ShowNetworkModal); }, [showChangeNetworkModal, acceptedChains]); // We need givethDonationAmount here because we need to calculate the donation share @@ -368,15 +371,17 @@ const CryptoDonation: FC<{ setShowModal={setShowQFModal} /> )} - {currentDonateModal === - DonateModalPriorityValues.ShowNetworkModal && ( - chain.chainType !== ChainType.STELLAR, - )} - /> - )} + {(highestModalPriorityUnchecked == 'All Checked' || + currentDonateModal >= highestModalPriorityUnchecked) && + currentDonateModal === + DonateModalPriorityValues.ShowNetworkModal && ( + chain.chainType !== ChainType.STELLAR, + )} + /> + )} {showInsufficientModal && ( >; + setIsModalPriorityChecked: ( + modalChecked: DonateModalPriorityValues, + ) => void; + highestModalPriorityUnchecked: DonateModalPriorityValues | 'All Checked'; fetchProject: () => Promise; draftDonationData?: IDraftDonation; fetchDraftDonation?: ( @@ -79,8 +84,10 @@ const DonateContext = createContext({ setSuccessDonation: () => {}, setSelectedOneTimeToken: () => {}, setSelectedRecurringToken: () => {}, + setIsModalPriorityChecked: (modalChecked: DonateModalPriorityValues) => {}, project: {} as IProject, currentDonateModal: DonateModalPriorityValues.None, + highestModalPriorityUnchecked: DonateModalPriorityValues.None, tokenStreams: {}, fetchProject: async () => {}, setDonateModalByPriority: ( @@ -117,6 +124,13 @@ export const DonateProvider: FC = ({ children, project }) => { const [selectedRecurringToken, setSelectedRecurringToken] = useState< ISelectTokenWithBalance | undefined >(); + const isModalStatusChecked = useRef< + Map + >(new Map()); + const [highestModalPriorityUnchecked, setHighestModalPriorityUnchecked] = + useState( + DonateModalPriorityValues.None, + ); const [successDonation, setSuccessDonation] = useState(); const [projectData, setProjectData] = useState(project); @@ -130,6 +144,37 @@ export const DonateProvider: FC = ({ children, project }) => { setSelectedRecurringToken(undefined); }, [chain]); + const setIsModalPriorityChecked = useCallback( + (modalChecked: DonateModalPriorityValues): void => { + if ( + highestModalPriorityUnchecked != 'All Checked' && + modalChecked > highestModalPriorityUnchecked + ) { + isModalStatusChecked.current.set(modalChecked, true); + let highestModalStatusUnchecked = + DonateModalPriorityValues.None; + let isAllChecked = true; + const modals = Object.values(DonateModalPriorityValues).filter( + modal => typeof modal !== 'string', + ); + for (const modalStatus of modals) { + if (!isModalStatusChecked.current.get(modalStatus)) { + highestModalStatusUnchecked = modalStatus; + } + isAllChecked = + isAllChecked && + isModalStatusChecked.current.get(modalStatus) + ? true + : false; + } + setHighestModalPriorityUnchecked( + isAllChecked ? 'All Checked' : highestModalStatusUnchecked, + ); + } + }, + [], + ); + const setDonateModalByPriority = useCallback( (changeModal: DonateModalPriorityValues) => { if (changeModal === DonateModalPriorityValues.None) { @@ -190,6 +235,8 @@ export const DonateProvider: FC = ({ children, project }) => { startTimer, setQRDonationStatus: setStatus, setPendingDonationExists, + highestModalPriorityUnchecked, + setIsModalPriorityChecked, draftDonationLoading: loading, }} > From edaa8a538090179536eba039437f78078b846fd3 Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Sat, 21 Sep 2024 20:29:44 +0530 Subject: [PATCH 07/15] chore: fix build errors --- src/context/donate.context.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/context/donate.context.tsx b/src/context/donate.context.tsx index aeb7f96523..18e62ee68f 100644 --- a/src/context/donate.context.tsx +++ b/src/context/donate.context.tsx @@ -125,7 +125,7 @@ export const DonateProvider: FC = ({ children, project }) => { ISelectTokenWithBalance | undefined >(); const isModalStatusChecked = useRef< - Map + Map >(new Map()); const [highestModalPriorityUnchecked, setHighestModalPriorityUnchecked] = useState( @@ -154,18 +154,18 @@ export const DonateProvider: FC = ({ children, project }) => { let highestModalStatusUnchecked = DonateModalPriorityValues.None; let isAllChecked = true; - const modals = Object.values(DonateModalPriorityValues).filter( + const modals: DonateModalPriorityValues[] = Object.values( + DonateModalPriorityValues, + ).filter( modal => typeof modal !== 'string', - ); + ) as DonateModalPriorityValues[]; for (const modalStatus of modals) { if (!isModalStatusChecked.current.get(modalStatus)) { highestModalStatusUnchecked = modalStatus; } isAllChecked = isAllChecked && - isModalStatusChecked.current.get(modalStatus) - ? true - : false; + !!isModalStatusChecked.current.get(modalStatus); } setHighestModalPriorityUnchecked( isAllChecked ? 'All Checked' : highestModalStatusUnchecked, From 34829fee017e85168fcd5e9d57db3137811d117f Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Sat, 21 Sep 2024 22:35:51 +0530 Subject: [PATCH 08/15] fix: OFAC Sanction Modal Check --- src/context/donate.context.tsx | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/context/donate.context.tsx b/src/context/donate.context.tsx index 18e62ee68f..8c1a77b7b1 100644 --- a/src/context/donate.context.tsx +++ b/src/context/donate.context.tsx @@ -127,10 +127,9 @@ export const DonateProvider: FC = ({ children, project }) => { const isModalStatusChecked = useRef< Map >(new Map()); - const [highestModalPriorityUnchecked, setHighestModalPriorityUnchecked] = - useState( - DonateModalPriorityValues.None, - ); + const highestModalPriorityUnchecked = useRef< + DonateModalPriorityValues | 'All Checked' + >(DonateModalPriorityValues.None); const [successDonation, setSuccessDonation] = useState(); const [projectData, setProjectData] = useState(project); @@ -147,8 +146,10 @@ export const DonateProvider: FC = ({ children, project }) => { const setIsModalPriorityChecked = useCallback( (modalChecked: DonateModalPriorityValues): void => { if ( - highestModalPriorityUnchecked != 'All Checked' && - modalChecked > highestModalPriorityUnchecked + highestModalPriorityUnchecked.current != 'All Checked' && + (modalChecked <= highestModalPriorityUnchecked.current || + highestModalPriorityUnchecked.current === + DonateModalPriorityValues.None) ) { isModalStatusChecked.current.set(modalChecked, true); let highestModalStatusUnchecked = @@ -164,12 +165,13 @@ export const DonateProvider: FC = ({ children, project }) => { highestModalStatusUnchecked = modalStatus; } isAllChecked = - isAllChecked && - !!isModalStatusChecked.current.get(modalStatus); + (isAllChecked && + !!isModalStatusChecked.current.get(modalStatus)) || + modalStatus === DonateModalPriorityValues.None; } - setHighestModalPriorityUnchecked( - isAllChecked ? 'All Checked' : highestModalStatusUnchecked, - ); + highestModalPriorityUnchecked.current = isAllChecked + ? 'All Checked' + : highestModalStatusUnchecked; } }, [], @@ -235,7 +237,8 @@ export const DonateProvider: FC = ({ children, project }) => { startTimer, setQRDonationStatus: setStatus, setPendingDonationExists, - highestModalPriorityUnchecked, + highestModalPriorityUnchecked: + highestModalPriorityUnchecked.current, setIsModalPriorityChecked, draftDonationLoading: loading, }} From 3c6e005ff467e90fae871852024d4cba2a36662b Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Tue, 24 Sep 2024 01:18:31 +0530 Subject: [PATCH 09/15] fix: coderabbitai suggestions --- src/components/views/donate/DonateIndex.tsx | 49 +++++++++---------- .../donate/OnTime/OneTimeDonationCard.tsx | 22 ++++----- src/context/donate.context.tsx | 22 ++++++--- 3 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index ffb51b16f4..20388d877b 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -61,8 +61,7 @@ const DonateIndex: FC = () => { qrDonationStatus, draftDonationData, hasActiveQFRound, - currentDonateModal, - highestModalPriorityUnchecked, + shouldRenderModal, setSuccessDonation, setQRDonationStatus, setDraftDonationData, @@ -258,31 +257,29 @@ const DonateIndex: FC = () => { <> - {(highestModalPriorityUnchecked == 'All Checked' || - currentDonateModal >= highestModalPriorityUnchecked) && - currentDonateModal === - DonateModalPriorityValues.DonationByProjectOwner && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} + {shouldRenderModal( + DonateModalPriorityValues.DonationByProjectOwner, + ) && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} - {(highestModalPriorityUnchecked == 'All Checked' || - currentDonateModal >= highestModalPriorityUnchecked) && - currentDonateModal === - DonateModalPriorityValues.OFACSanctionListModal && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} + {shouldRenderModal( + DonateModalPriorityValues.OFACSanctionListModal, + ) && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} {alreadyDonated && ( diff --git a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx index 5c4dd1f8f0..2b85826afc 100644 --- a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx +++ b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx @@ -81,8 +81,7 @@ const CryptoDonation: FC<{ project, hasActiveQFRound, selectedOneTimeToken, - currentDonateModal, - highestModalPriorityUnchecked, + shouldRenderModal, setDonateModalByPriority, setIsModalPriorityChecked, } = useDonateData(); @@ -371,17 +370,14 @@ const CryptoDonation: FC<{ setShowModal={setShowQFModal} /> )} - {(highestModalPriorityUnchecked == 'All Checked' || - currentDonateModal >= highestModalPriorityUnchecked) && - currentDonateModal === - DonateModalPriorityValues.ShowNetworkModal && ( - chain.chainType !== ChainType.STELLAR, - )} - /> - )} + {shouldRenderModal(DonateModalPriorityValues.ShowNetworkModal) && ( + chain.chainType !== ChainType.STELLAR, + )} + /> + )} {showInsufficientModal && ( void; + shouldRenderModal: (modalToRender: DonateModalPriorityValues) => boolean; selectedOneTimeToken?: IProjectAcceptedToken; selectedRecurringToken?: ISelectTokenWithBalance; setSelectedOneTimeToken: Dispatch< SetStateAction >; - currentDonateModal: DonateModalPriorityValues; setDonateModalByPriority: ( changeCurrentModal: DonateModalPriorityValues, ) => void; @@ -53,7 +53,6 @@ interface IDonateContext { setIsModalPriorityChecked: ( modalChecked: DonateModalPriorityValues, ) => void; - highestModalPriorityUnchecked: DonateModalPriorityValues | 'All Checked'; fetchProject: () => Promise; draftDonationData?: IDraftDonation; fetchDraftDonation?: ( @@ -86,13 +85,12 @@ const DonateContext = createContext({ setSelectedRecurringToken: () => {}, setIsModalPriorityChecked: (modalChecked: DonateModalPriorityValues) => {}, project: {} as IProject, - currentDonateModal: DonateModalPriorityValues.None, - highestModalPriorityUnchecked: DonateModalPriorityValues.None, tokenStreams: {}, fetchProject: async () => {}, setDonateModalByPriority: ( changeCurrentModal: DonateModalPriorityValues, ) => {}, + shouldRenderModal: (modalToRender: DonateModalPriorityValues) => false, draftDonationData: {} as IDraftDonation, fetchDraftDonation: async () => {}, qrDonationStatus: 'waiting', @@ -143,6 +141,18 @@ export const DonateProvider: FC = ({ children, project }) => { setSelectedRecurringToken(undefined); }, [chain]); + const shouldRenderModal = useCallback( + (modalToRender: DonateModalPriorityValues): boolean => { + return ( + (highestModalPriorityUnchecked.current === 'All Checked' || + currentDonateModal >= + highestModalPriorityUnchecked.current) && + currentDonateModal === modalToRender + ); + }, + [currentDonateModal], + ); + const setIsModalPriorityChecked = useCallback( (modalChecked: DonateModalPriorityValues): void => { if ( @@ -225,7 +235,7 @@ export const DonateProvider: FC = ({ children, project }) => { pendingDonationExists, selectedRecurringToken, setDonateModalByPriority, - currentDonateModal, + shouldRenderModal, setSelectedOneTimeToken, setSelectedRecurringToken, tokenStreams, @@ -237,8 +247,6 @@ export const DonateProvider: FC = ({ children, project }) => { startTimer, setQRDonationStatus: setStatus, setPendingDonationExists, - highestModalPriorityUnchecked: - highestModalPriorityUnchecked.current, setIsModalPriorityChecked, draftDonationLoading: loading, }} From f1fe063ea1c793134b2b8c46b5ae6d77aef5a07d Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Tue, 24 Sep 2024 03:43:24 +0530 Subject: [PATCH 10/15] manually revet coderabbit suggestions as it is causing glitching again --- src/components/views/donate/DonateIndex.tsx | 53 ++++++++++--------- .../donate/OnTime/OneTimeDonationCard.tsx | 22 ++++---- src/context/donate.context.tsx | 24 +++------ 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index 6d9ff04f59..5d6f62936a 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -61,7 +61,8 @@ const DonateIndex: FC = () => { qrDonationStatus, draftDonationData, hasActiveQFRound, - shouldRenderModal, + currentDonateModal, + highestModalPriorityUnchecked, setSuccessDonation, setQRDonationStatus, setDraftDonationData, @@ -158,7 +159,7 @@ const DonateIndex: FC = () => { ], givBackEligible: isTokenEligibleForGivback && - project.isGivbackEligible && + project.verified && isSignedIn && isEnabled, chainId: config.STELLAR_NETWORK_NUMBER, @@ -257,29 +258,31 @@ const DonateIndex: FC = () => { <> - {shouldRenderModal( - DonateModalPriorityValues.DonationByProjectOwner, - ) && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} + {(highestModalPriorityUnchecked == 'All Checked' || + currentDonateModal >= highestModalPriorityUnchecked) && + currentDonateModal === + DonateModalPriorityValues.DonationByProjectOwner && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} - {shouldRenderModal( - DonateModalPriorityValues.OFACSanctionListModal, - ) && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} + {(highestModalPriorityUnchecked == 'All Checked' || + currentDonateModal >= highestModalPriorityUnchecked) && + currentDonateModal === + DonateModalPriorityValues.OFACSanctionListModal && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} {alreadyDonated && ( @@ -415,4 +418,4 @@ const ButtonStyled = styled(Button)` text-transform: capitalize; `; -export default DonateIndex; +export default DonateIndex; \ No newline at end of file diff --git a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx index c9b43603a8..36957f03ca 100644 --- a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx +++ b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx @@ -81,7 +81,8 @@ const CryptoDonation: FC<{ project, hasActiveQFRound, selectedOneTimeToken, - shouldRenderModal, + currentDonateModal, + highestModalPriorityUnchecked, setDonateModalByPriority, setIsModalPriorityChecked, } = useDonateData(); @@ -370,14 +371,17 @@ const CryptoDonation: FC<{ setShowModal={setShowQFModal} /> )} - {shouldRenderModal(DonateModalPriorityValues.ShowNetworkModal) && ( - chain.chainType !== ChainType.STELLAR, - )} - /> - )} + {(highestModalPriorityUnchecked == 'All Checked' || + currentDonateModal >= highestModalPriorityUnchecked) && + currentDonateModal === + DonateModalPriorityValues.ShowNetworkModal && ( + chain.chainType !== ChainType.STELLAR, + )} + /> + )} {showInsufficientModal && ( void; - shouldRenderModal: (modalToRender: DonateModalPriorityValues) => boolean; selectedOneTimeToken?: IProjectAcceptedToken; selectedRecurringToken?: ISelectTokenWithBalance; setSelectedOneTimeToken: Dispatch< SetStateAction >; + currentDonateModal: DonateModalPriorityValues; setDonateModalByPriority: ( changeCurrentModal: DonateModalPriorityValues, ) => void; @@ -53,6 +53,7 @@ interface IDonateContext { setIsModalPriorityChecked: ( modalChecked: DonateModalPriorityValues, ) => void; + highestModalPriorityUnchecked: DonateModalPriorityValues | 'All Checked'; fetchProject: () => Promise; draftDonationData?: IDraftDonation; fetchDraftDonation?: ( @@ -85,12 +86,13 @@ const DonateContext = createContext({ setSelectedRecurringToken: () => {}, setIsModalPriorityChecked: (modalChecked: DonateModalPriorityValues) => {}, project: {} as IProject, + currentDonateModal: DonateModalPriorityValues.None, + highestModalPriorityUnchecked: DonateModalPriorityValues.None, tokenStreams: {}, fetchProject: async () => {}, setDonateModalByPriority: ( changeCurrentModal: DonateModalPriorityValues, ) => {}, - shouldRenderModal: (modalToRender: DonateModalPriorityValues) => false, draftDonationData: {} as IDraftDonation, fetchDraftDonation: async () => {}, qrDonationStatus: 'waiting', @@ -141,18 +143,6 @@ export const DonateProvider: FC = ({ children, project }) => { setSelectedRecurringToken(undefined); }, [chain]); - const shouldRenderModal = useCallback( - (modalToRender: DonateModalPriorityValues): boolean => { - return ( - (highestModalPriorityUnchecked.current === 'All Checked' || - currentDonateModal >= - highestModalPriorityUnchecked.current) && - currentDonateModal === modalToRender - ); - }, - [currentDonateModal], - ); - const setIsModalPriorityChecked = useCallback( (modalChecked: DonateModalPriorityValues): void => { if ( @@ -235,7 +225,7 @@ export const DonateProvider: FC = ({ children, project }) => { pendingDonationExists, selectedRecurringToken, setDonateModalByPriority, - shouldRenderModal, + currentDonateModal, setSelectedOneTimeToken, setSelectedRecurringToken, tokenStreams, @@ -247,6 +237,8 @@ export const DonateProvider: FC = ({ children, project }) => { startTimer, setQRDonationStatus: setStatus, setPendingDonationExists, + highestModalPriorityUnchecked: + highestModalPriorityUnchecked.current, setIsModalPriorityChecked, draftDonationLoading: loading, }} @@ -262,4 +254,4 @@ export const useDonateData = () => { throw new Error('useDonateData must be used within a Provider'); } return context; -}; +}; \ No newline at end of file From a842504c4a3b71f5ff4292e37d780a78cc7c31be Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Tue, 24 Sep 2024 03:44:14 +0530 Subject: [PATCH 11/15] run linter --- src/components/views/donate/DonateIndex.tsx | 2 +- src/context/donate.context.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index 5d6f62936a..ffb51b16f4 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -418,4 +418,4 @@ const ButtonStyled = styled(Button)` text-transform: capitalize; `; -export default DonateIndex; \ No newline at end of file +export default DonateIndex; diff --git a/src/context/donate.context.tsx b/src/context/donate.context.tsx index 83e7bf0e40..8c1a77b7b1 100644 --- a/src/context/donate.context.tsx +++ b/src/context/donate.context.tsx @@ -254,4 +254,4 @@ export const useDonateData = () => { throw new Error('useDonateData must be used within a Provider'); } return context; -}; \ No newline at end of file +}; From e803c77f42d4bcadcc10841de1ad638354afa746 Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Tue, 24 Sep 2024 09:38:39 +0530 Subject: [PATCH 12/15] fix: timeout to add check of the modals later --- src/components/views/donate/DonateIndex.tsx | 65 ++++++++++--------- .../donate/OnTime/OneTimeDonationCard.tsx | 28 ++++---- src/context/donate.context.tsx | 22 +++++-- 3 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index ffb51b16f4..8e076be0fc 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -61,8 +61,7 @@ const DonateIndex: FC = () => { qrDonationStatus, draftDonationData, hasActiveQFRound, - currentDonateModal, - highestModalPriorityUnchecked, + shouldRenderModal, setSuccessDonation, setQRDonationStatus, setDraftDonationData, @@ -107,9 +106,11 @@ const DonateIndex: FC = () => { return; } } - setIsModalPriorityChecked( - DonateModalPriorityValues.OFACSanctionListModal, - ); + setTimeout(() => { + setIsModalPriorityChecked( + DonateModalPriorityValues.OFACSanctionListModal, + ); + }, 0); }; useEffect(() => { @@ -125,9 +126,11 @@ const DonateIndex: FC = () => { DonateModalPriorityValues.DonationByProjectOwner, ); } - setIsModalPriorityChecked( - DonateModalPriorityValues.DonationByProjectOwner, - ); + setTimeout(() => { + setIsModalPriorityChecked( + DonateModalPriorityValues.DonationByProjectOwner, + ); + }, 0); }, [userData?.id, project.adminUser]); useEffect(() => { @@ -258,31 +261,29 @@ const DonateIndex: FC = () => { <> - {(highestModalPriorityUnchecked == 'All Checked' || - currentDonateModal >= highestModalPriorityUnchecked) && - currentDonateModal === - DonateModalPriorityValues.DonationByProjectOwner && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} + {shouldRenderModal( + DonateModalPriorityValues.DonationByProjectOwner, + ) && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} - {(highestModalPriorityUnchecked == 'All Checked' || - currentDonateModal >= highestModalPriorityUnchecked) && - currentDonateModal === - DonateModalPriorityValues.OFACSanctionListModal && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} + {shouldRenderModal( + DonateModalPriorityValues.OFACSanctionListModal, + ) && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} {alreadyDonated && ( diff --git a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx index 36957f03ca..8a0ca75892 100644 --- a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx +++ b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx @@ -81,8 +81,7 @@ const CryptoDonation: FC<{ project, hasActiveQFRound, selectedOneTimeToken, - currentDonateModal, - highestModalPriorityUnchecked, + shouldRenderModal, setDonateModalByPriority, setIsModalPriorityChecked, } = useDonateData(); @@ -351,7 +350,11 @@ const CryptoDonation: FC<{ DonateModalPriorityValues.ShowNetworkModal, ); } - setIsModalPriorityChecked(DonateModalPriorityValues.ShowNetworkModal); + setTimeout(() => { + setIsModalPriorityChecked( + DonateModalPriorityValues.ShowNetworkModal, + ); + }, 0); }, [showChangeNetworkModal, acceptedChains]); // We need givethDonationAmount here because we need to calculate the donation share @@ -371,17 +374,14 @@ const CryptoDonation: FC<{ setShowModal={setShowQFModal} /> )} - {(highestModalPriorityUnchecked == 'All Checked' || - currentDonateModal >= highestModalPriorityUnchecked) && - currentDonateModal === - DonateModalPriorityValues.ShowNetworkModal && ( - chain.chainType !== ChainType.STELLAR, - )} - /> - )} + {shouldRenderModal(DonateModalPriorityValues.ShowNetworkModal) && ( + chain.chainType !== ChainType.STELLAR, + )} + /> + )} {showInsufficientModal && ( >; - currentDonateModal: DonateModalPriorityValues; setDonateModalByPriority: ( changeCurrentModal: DonateModalPriorityValues, ) => void; @@ -53,7 +52,7 @@ interface IDonateContext { setIsModalPriorityChecked: ( modalChecked: DonateModalPriorityValues, ) => void; - highestModalPriorityUnchecked: DonateModalPriorityValues | 'All Checked'; + shouldRenderModal: (modalRender: DonateModalPriorityValues) => boolean; fetchProject: () => Promise; draftDonationData?: IDraftDonation; fetchDraftDonation?: ( @@ -86,13 +85,12 @@ const DonateContext = createContext({ setSelectedRecurringToken: () => {}, setIsModalPriorityChecked: (modalChecked: DonateModalPriorityValues) => {}, project: {} as IProject, - currentDonateModal: DonateModalPriorityValues.None, - highestModalPriorityUnchecked: DonateModalPriorityValues.None, tokenStreams: {}, fetchProject: async () => {}, setDonateModalByPriority: ( changeCurrentModal: DonateModalPriorityValues, ) => {}, + shouldRenderModal: (modalRender: DonateModalPriorityValues) => false, draftDonationData: {} as IDraftDonation, fetchDraftDonation: async () => {}, qrDonationStatus: 'waiting', @@ -188,6 +186,18 @@ export const DonateProvider: FC = ({ children, project }) => { [currentDonateModal], ); + const shouldRenderModal = useCallback( + (modalRender: DonateModalPriorityValues) => { + return ( + (highestModalPriorityUnchecked.current == 'All Checked' || + currentDonateModal >= + highestModalPriorityUnchecked.current) && + currentDonateModal === modalRender + ); + }, + [currentDonateModal], + ); + const fetchProject = useCallback(async () => { const { data } = (await client.query({ query: FETCH_PROJECT_BY_SLUG_DONATION, @@ -225,8 +235,8 @@ export const DonateProvider: FC = ({ children, project }) => { pendingDonationExists, selectedRecurringToken, setDonateModalByPriority, - currentDonateModal, setSelectedOneTimeToken, + shouldRenderModal, setSelectedRecurringToken, tokenStreams, fetchProject, @@ -237,8 +247,6 @@ export const DonateProvider: FC = ({ children, project }) => { startTimer, setQRDonationStatus: setStatus, setPendingDonationExists, - highestModalPriorityUnchecked: - highestModalPriorityUnchecked.current, setIsModalPriorityChecked, draftDonationLoading: loading, }} From 969417aac1966b3f96eafff5709cc0aa581a4ef5 Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Thu, 26 Sep 2024 16:12:21 +0530 Subject: [PATCH 13/15] run linter: --- src/components/views/donate/DonateIndex.tsx | 94 ++++++++++----------- src/context/donate.context.tsx | 2 +- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index 6d320a913d..0e683482a8 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -268,54 +268,54 @@ const DonateIndex: FC = () => { <> - - {shouldRenderModal( - DonateModalPriorityValues.DonationByProjectOwner, - ) && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} - - {shouldRenderModal( - DonateModalPriorityValues.OFACSanctionListModal, - ) && ( - { - setDonateModalByPriority( - DonateModalPriorityValues.None, - ); - }} - /> - )} - - {showAlreadyDonatedWrapper && ( - - - - {formatMessage({ - id: 'component.already_donated.incorrect_estimate', - })} - - - )} - {!isSafeEnv && - hasActiveQFRound && - !isOnSolana && - (!isQRDonation || - (isQRDonation && isStellarIncludedInQF)) && ( - + + {shouldRenderModal( + DonateModalPriorityValues.DonationByProjectOwner, + ) && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} + + {shouldRenderModal( + DonateModalPriorityValues.OFACSanctionListModal, + ) && ( + { + setDonateModalByPriority( + DonateModalPriorityValues.None, + ); + }} + /> + )} + + {showAlreadyDonatedWrapper && ( + + + + {formatMessage({ + id: 'component.already_donated.incorrect_estimate', + })} + + )} - - - - + )} + + + + diff --git a/src/context/donate.context.tsx b/src/context/donate.context.tsx index 179ed97832..5a9c6f29cb 100644 --- a/src/context/donate.context.tsx +++ b/src/context/donate.context.tsx @@ -174,7 +174,7 @@ export const DonateProvider: FC = ({ children, project }) => { const setDonateModalByPriority = useCallback( (changeModal: DonateModalPriorityValues) => { - if(!isModalStatusChecked.current.get(changeModal)) { + if (!isModalStatusChecked.current.get(changeModal)) { setIsModalPriorityChecked(changeModal); } if (changeModal === DonateModalPriorityValues.None) { From 593d3d4c5d8c415cd65abff6f26eb299b3256586 Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Thu, 26 Sep 2024 17:45:29 +0530 Subject: [PATCH 14/15] fix: for non-endaoment project modal --- src/components/views/donate/DonateIndex.tsx | 3 +++ src/components/views/donate/OneTime/OneTimeDonationCard.tsx | 2 ++ src/context/donate.context.tsx | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index 0e683482a8..59885603e3 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -71,6 +71,7 @@ const DonateIndex: FC = () => { activeStartedRound, startTimer, setDonateModalByPriority, + setIsModalPriorityChecked, } = useDonateData(); const { renewExpirationDate, retrieveDraftDonation } = useQRCodeDonation(project); @@ -114,6 +115,7 @@ const DonateIndex: FC = () => { return; } } + setIsModalPriorityChecked(DonateModalPriorityValues.OFACSanctionListModal); }; useEffect(() => { @@ -129,6 +131,7 @@ const DonateIndex: FC = () => { DonateModalPriorityValues.DonationByProjectOwner, ); } + setIsModalPriorityChecked(DonateModalPriorityValues.DonationByProjectOwner); }, [userData?.id, project.adminUser]); useEffect(() => { diff --git a/src/components/views/donate/OneTime/OneTimeDonationCard.tsx b/src/components/views/donate/OneTime/OneTimeDonationCard.tsx index 24cc575987..85d2663aea 100644 --- a/src/components/views/donate/OneTime/OneTimeDonationCard.tsx +++ b/src/components/views/donate/OneTime/OneTimeDonationCard.tsx @@ -86,6 +86,7 @@ const CryptoDonation: FC<{ selectedOneTimeToken, shouldRenderModal, setDonateModalByPriority, + setIsModalPriorityChecked, } = useDonateData(); const dispatch = useAppDispatch(); @@ -336,6 +337,7 @@ const CryptoDonation: FC<{ DonateModalPriorityValues.ShowNetworkModal, ); } + setIsModalPriorityChecked(DonateModalPriorityValues.ShowNetworkModal); }, [showChangeNetworkModal, acceptedChains]); // We need givethDonationAmount here because we need to calculate the donation share diff --git a/src/context/donate.context.tsx b/src/context/donate.context.tsx index 5a9c6f29cb..1303182a19 100644 --- a/src/context/donate.context.tsx +++ b/src/context/donate.context.tsx @@ -50,6 +50,7 @@ interface IDonateContext { setSelectedRecurringToken: Dispatch< SetStateAction >; + setIsModalPriorityChecked: (modal: DonateModalPriorityValues) => void; shouldRenderModal: (modalRender: DonateModalPriorityValues) => boolean; fetchProject: () => Promise; draftDonationData?: IDraftDonation; @@ -85,9 +86,10 @@ const DonateContext = createContext({ tokenStreams: {}, fetchProject: async () => {}, setDonateModalByPriority: ( - changeCurrentModal: DonateModalPriorityValues, + changeModal: DonateModalPriorityValues, ) => {}, shouldRenderModal: (modalRender: DonateModalPriorityValues) => false, + setIsModalPriorityChecked: (modal: DonateModalPriorityValues) => {}, draftDonationData: {} as IDraftDonation, fetchDraftDonation: async () => {}, qrDonationStatus: 'waiting', @@ -242,6 +244,7 @@ export const DonateProvider: FC = ({ children, project }) => { setSelectedOneTimeToken, shouldRenderModal, setSelectedRecurringToken, + setIsModalPriorityChecked, tokenStreams, fetchProject, draftDonationData: draftDonation as IDraftDonation, From c7854e2b6844b19469921ab120dfd5bbbbbeb0a5 Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Thu, 26 Sep 2024 17:56:59 +0530 Subject: [PATCH 15/15] run linter --- src/components/views/donate/DonateIndex.tsx | 8 ++++++-- src/context/donate.context.tsx | 4 +--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/views/donate/DonateIndex.tsx b/src/components/views/donate/DonateIndex.tsx index 59885603e3..7369bf6b1e 100644 --- a/src/components/views/donate/DonateIndex.tsx +++ b/src/components/views/donate/DonateIndex.tsx @@ -115,7 +115,9 @@ const DonateIndex: FC = () => { return; } } - setIsModalPriorityChecked(DonateModalPriorityValues.OFACSanctionListModal); + setIsModalPriorityChecked( + DonateModalPriorityValues.OFACSanctionListModal, + ); }; useEffect(() => { @@ -131,7 +133,9 @@ const DonateIndex: FC = () => { DonateModalPriorityValues.DonationByProjectOwner, ); } - setIsModalPriorityChecked(DonateModalPriorityValues.DonationByProjectOwner); + setIsModalPriorityChecked( + DonateModalPriorityValues.DonationByProjectOwner, + ); }, [userData?.id, project.adminUser]); useEffect(() => { diff --git a/src/context/donate.context.tsx b/src/context/donate.context.tsx index 1303182a19..43358bd0be 100644 --- a/src/context/donate.context.tsx +++ b/src/context/donate.context.tsx @@ -85,9 +85,7 @@ const DonateContext = createContext({ project: {} as IProject, tokenStreams: {}, fetchProject: async () => {}, - setDonateModalByPriority: ( - changeModal: DonateModalPriorityValues, - ) => {}, + setDonateModalByPriority: (changeModal: DonateModalPriorityValues) => {}, shouldRenderModal: (modalRender: DonateModalPriorityValues) => false, setIsModalPriorityChecked: (modal: DonateModalPriorityValues) => {}, draftDonationData: {} as IDraftDonation,