Skip to content

Commit 7811cf2

Browse files
fix(ramp): guard headless checkout dismissal
1 parent cd1bf23 commit 7811cf2

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

app/components/UI/Ramp/Views/Checkout/Checkout.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,11 @@ describe('Checkout', () => {
810810

811811
await act(async () => {
812812
fireEvent.press(getByTestId('trigger-http-error-main-uri'));
813+
fireEvent.press(getByTestId('trigger-http-error-main-uri'));
813814
});
814815

815-
expect(mockFailSession).toHaveBeenCalledWith('hs-1', expect.any(Error));
816-
expect(mockParentPop).toHaveBeenCalled();
816+
expect(mockFailSession).toHaveBeenCalledTimes(1);
817+
expect(mockParentPop).toHaveBeenCalledTimes(1);
817818
});
818819

819820
it('treats an empty provider callback as user dismissal when headless', async () => {
@@ -837,12 +838,11 @@ describe('Checkout', () => {
837838

838839
const { getByTestId } = renderWithProvider(<Checkout />, {}, true, false);
839840

841+
fireEvent.press(getByTestId('checkout-close-button'));
840842
fireEvent.press(getByTestId('checkout-close-button'));
841843

842-
expect(mockCloseSession).toHaveBeenCalledWith('hs-1', {
843-
reason: 'user_dismissed',
844-
});
845-
expect(mockParentPop).toHaveBeenCalled();
844+
expect(mockCloseSession).toHaveBeenCalledTimes(1);
845+
expect(mockParentPop).toHaveBeenCalledTimes(1);
846846
});
847847

848848
it('closes and dismisses the headless flow when Checkout unmounts with a live session', () => {

app/components/UI/Ramp/Views/Checkout/Checkout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ const Checkout = () => {
203203

204204
const failHeadlessCheckout = useCallback(
205205
(checkoutError: unknown) => {
206-
if (!failSession(headlessSessionId, checkoutError)) {
206+
if (
207+
hasTerminatedHeadlessSessionRef.current ||
208+
!failSession(headlessSessionId, checkoutError)
209+
) {
207210
return false;
208211
}
209212
hasTerminatedHeadlessSessionRef.current = true;
@@ -438,6 +441,9 @@ const Checkout = () => {
438441
const handleClosePress = useCallback(() => {
439442
handleCancelPress();
440443
if (headlessSessionId) {
444+
if (hasTerminatedHeadlessSessionRef.current) {
445+
return;
446+
}
441447
hasTerminatedHeadlessSessionRef.current = true;
442448
closeSession(headlessSessionId, { reason: 'user_dismissed' });
443449
dismissActiveHeadlessFlow();

0 commit comments

Comments
 (0)