From 80b5ebd68beaf873f0a4fd6f0eb6eaf3d96be4b2 Mon Sep 17 00:00:00 2001 From: yash-signal Date: Fri, 22 Aug 2025 16:10:38 -0500 Subject: [PATCH] Show donations confirm discard modal when clicking back button twice --- ts/components/PreferencesDonateFlow.tsx | 28 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/ts/components/PreferencesDonateFlow.tsx b/ts/components/PreferencesDonateFlow.tsx index 00af45a11b..65054c78ff 100644 --- a/ts/components/PreferencesDonateFlow.tsx +++ b/ts/components/PreferencesDonateFlow.tsx @@ -135,6 +135,17 @@ export function PreferencesDonateFlow({ CardFormValues | undefined >(); + const hasCardFormData = useMemo(() => { + if (!cardFormValues) { + return false; + } + return ( + cardFormValues.cardNumber !== '' || + cardFormValues.cardExpiration !== '' || + cardFormValues.cardCvc !== '' + ); + }, [cardFormValues]); + // When changing currency, clear out the last selected amount const handleAmountPickerCurrencyChanged = useCallback((value: string) => { setAmount(undefined); @@ -184,14 +195,19 @@ export function PreferencesDonateFlow({ clearWorkflow(); } }; - const isConfirmationNeeded = Boolean( - step === 'paymentDetails' && - !isCardFormDisabled && - (!workflow || !isPaymentDetailFinalizedInWorkflow(workflow)) - ); + const isConfirmationNeeded = + hasCardFormData && + !isCardFormDisabled && + (!workflow || !isPaymentDetailFinalizedInWorkflow(workflow)); confirmDiscardIf(isConfirmationNeeded, onDiscard); - }, [clearWorkflow, confirmDiscardIf, isCardFormDisabled, step, workflow]); + }, [ + clearWorkflow, + confirmDiscardIf, + hasCardFormData, + isCardFormDisabled, + workflow, + ]); tryClose.current = onTryClose; let innerContent: JSX.Element;