From c5d8cebce84ae85ef080d35b44c59e49bbf284f0 Mon Sep 17 00:00:00 2001 From: plondon Date: Tue, 7 Mar 2023 09:12:45 -0500 Subject: [PATCH] fix(payment method): skip step if only one method --- src/preview.tsx | 6 ----- .../PaymentMethod/PaymentMethod.test.tsx | 25 +++++++++++++++++++ src/steps/PaymentMethod/index.tsx | 11 ++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/preview.tsx b/src/preview.tsx index b0b02e3b..c56a48d4 100644 --- a/src/preview.tsx +++ b/src/preview.tsx @@ -19,12 +19,6 @@ root.render( }; }, }, - selection: { - amount: '10000', - assetId: '53adbb94-6a68-4eeb-af49-6b6d9e84a1f4', - fiat: 'USD', - rate: 2, - }, style: { theme: 'dark', }, diff --git a/src/steps/PaymentMethod/PaymentMethod.test.tsx b/src/steps/PaymentMethod/PaymentMethod.test.tsx index b23246e5..a00445c8 100644 --- a/src/steps/PaymentMethod/PaymentMethod.test.tsx +++ b/src/steps/PaymentMethod/PaymentMethod.test.tsx @@ -112,6 +112,31 @@ describe('Payment Selection', () => { }); }); +describe('Payment Selection', () => { + beforeEach(() => { + render( + {}} + /> + ); + }); + + it('skips the payment selection step if there is only one payment method', async () => { + const bitcoin = await screen.findByText('Bitcoin'); + fireEvent.click(bitcoin); + const payToAddress = await screen.findByText('Pay to Address'); + expect(payToAddress).toBeInTheDocument(); + const back = await screen.findByLabelText('Back'); + await act(async () => { + fireEvent.click(back); + }); + expect(await screen.findByText('Select Asset')).toBeInTheDocument(); + }); +}); + describe('Payment Method Errors', () => { it('renders', () => { render(); diff --git a/src/steps/PaymentMethod/index.tsx b/src/steps/PaymentMethod/index.tsx index 0cfa900f..257ba268 100644 --- a/src/steps/PaymentMethod/index.tsx +++ b/src/steps/PaymentMethod/index.tsx @@ -140,6 +140,17 @@ const PaymentMethod: React.FC = () => { } }, [data?.methodsForNetwork?.length]); + useEffect(() => { + if (data?.methodsForNetwork?.[0] && data?.methodsForNetwork?.length === 1) { + // @ts-ignore + if (state.prevStep >= state.steps.indexOf(Steps[Steps.PaymentMethod])) { + dispatch({ payload: Steps.AssetSelection, type: 'SET_STEP' }); + } else { + selectMethod(data.methodsForNetwork[0]); + } + } + }, [data?.methodsForNetwork?.length]); + if ( state.requiredPaymentMethod && data?.methodsForNetwork?.find(