From 34829fee017e85168fcd5e9d57db3137811d117f Mon Sep 17 00:00:00 2001 From: HrithikSampson Date: Sat, 21 Sep 2024 22:35:51 +0530 Subject: [PATCH] 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, }}