Skip to content

Commit

Permalink
Merge pull request #147 from map3xyz/phil/map-191-regression-payment-…
Browse files Browse the repository at this point in the history
…methods-with-just-one

fix(payment method): skip step if only one method
  • Loading branch information
plondon authored Mar 7, 2023
2 parents 0d7e298 + 0823e7c commit 8d9852b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ root.render(
};
},
},
selection: {
amount: '10000',
assetId: '53adbb94-6a68-4eeb-af49-6b6d9e84a1f4',
fiat: 'USD',
rate: 2,
},
style: {
theme: 'dark',
},
Expand Down
25 changes: 25 additions & 0 deletions src/steps/PaymentMethod/PaymentMethod.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,31 @@ describe('Payment Selection', () => {
});
});

describe('Payment Selection', () => {
beforeEach(() => {
render(
<App
config={{
...mockConfig,
}}
onClose={() => {}}
/>
);
});

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(<PaymentMethod />);
Expand Down
11 changes: 11 additions & 0 deletions src/steps/PaymentMethod/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ const PaymentMethod: React.FC<Props> = () => {
}
}, [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(
Expand Down

0 comments on commit 8d9852b

Please sign in to comment.