-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(ramp): migrate sell amount keypad to MMDS BottomSheetDialog #33311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
georgewrmarshall
wants to merge
10
commits into
main
Choose a base branch
from
cursor/ramp-sell-keypad-mmds-bottomsheet-35fc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
61bb9eb
fix(ramp): migrate sell amount keypad to MMDS BottomSheetDialog
cursoragent 8eee7f3
test(ramp): remove BottomSheetDialog mock, assert via testID
cursoragent 36bf2e4
fix(lint): use implicit arrow returns in ramp keypad files
cursoragent b18b15b
chore(ci): retrigger CI after infra flake failures
cursoragent 05552df
test(ramp): add keypad bottom sheet lifecycle coverage
cursoragent 82a8dea
style(test): format BuildQuote tests and restore mocks in afterEach
cursoragent ed6ed34
fix(ramp): migrate Aggregator QuickAmounts to MMDS large buttons
georgewrmarshall 2fa46bc
fix(ramp): align Aggregator BuildQuote keypad UI with Swap MMDS patterns
georgewrmarshall 99b643a
chore(ui): deprecate Base SelectorButton in favor of MMDS SelectButton
georgewrmarshall 23e93ab
fix(ramp): use navigateWithDetails for BuildQuote selector modals
georgewrmarshall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import React from 'react'; | ||
| import { Limits, Payment } from '@consensys/on-ramp-sdk'; | ||
| import { act, fireEvent, screen } from '@testing-library/react-native'; | ||
| import { Pressable, Text } from 'react-native'; | ||
| import { BackHandler, Pressable, Text } from 'react-native'; | ||
| import type BN4 from 'bnjs4'; | ||
| import { renderScreen } from '../../../../../../util/test/renderWithProvider'; | ||
| import BuildQuote from './BuildQuote'; | ||
|
|
@@ -336,6 +336,7 @@ describe('BuildQuote View', () => { | |
| mockPop.mockClear(); | ||
| mockTrackEvent.mockClear(); | ||
| jest.clearAllMocks(); | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
|
|
@@ -785,9 +786,15 @@ describe('BuildQuote View', () => { | |
| mockUseFiatCurrenciesValues.currentFiatCurrency?.denomSymbol; | ||
| fireEvent.press(getByRoleButton(`${symbol}${initialAmount}`)); | ||
| fireEvent.press(getByRoleButton(`${symbol}${quickAmount}`)); | ||
| expect(getByRoleButton(`${symbol}${quickAmount}`)).toBeOnTheScreen(); | ||
| expect( | ||
| screen.queryAllByRole('button', { name: `${symbol}${quickAmount}` }), | ||
| ).toHaveLength(2); | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_CONFIRM_BUTTON), | ||
| ).toBeOnTheScreen(); | ||
| expect( | ||
| screen.queryByRole('button', { | ||
| name: `${symbol}${mockUseLimitsInitialValues?.limits?.quickAmounts?.[1]}`, | ||
| }), | ||
| ).not.toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('validates the max limit', () => { | ||
|
|
@@ -847,16 +854,162 @@ describe('BuildQuote View', () => { | |
| ).not.toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press(screen.getByTestId(BuildQuoteSelectors.AMOUNT_INPUT)); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).toBeOnTheScreen(); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_INPUT_CURSOR), | ||
| ).toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press(getByRoleButton('1')); | ||
| fireEvent.press(getByRoleButton('Done')); | ||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).not.toBeOnTheScreen(); | ||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_INPUT_CURSOR), | ||
| ).not.toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('replaces quick amounts with Done confirm when an amount is entered', () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Locks in the exclusive quick-amount vs Done slot for buy flow. After a digit is entered, presets must disappear and the confirm testID must appear so keypad height and CTA behavior stay aligned with Swaps. |
||
| render(BuildQuote); | ||
| const denomSymbol = | ||
| mockUseFiatCurrenciesValues.currentFiatCurrency?.denomSymbol; | ||
| const quickAmount = | ||
| mockUseLimitsInitialValues?.limits?.quickAmounts?.[0]?.toString(); | ||
|
|
||
| fireEvent.press(getByRoleButton(`${denomSymbol}0`)); | ||
|
|
||
| expect(getByRoleButton(`${denomSymbol}${quickAmount}`)).toBeOnTheScreen(); | ||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_CONFIRM_BUTTON), | ||
| ).not.toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press(getByRoleButton('1')); | ||
|
|
||
| expect( | ||
| screen.queryByRole('button', { | ||
| name: `${denomSymbol}${quickAmount}`, | ||
| }), | ||
| ).not.toBeOnTheScreen(); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_CONFIRM_BUTTON), | ||
| ).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('dismisses the amount keypad when hardware back is pressed', () => { | ||
| let backPressHandler: (() => boolean | undefined) | undefined; | ||
| jest | ||
| .spyOn(BackHandler, 'addEventListener') | ||
| .mockImplementation((_event, handler) => { | ||
| backPressHandler = handler as () => boolean | undefined; | ||
| return { remove: jest.fn() }; | ||
| }); | ||
|
|
||
| render(BuildQuote); | ||
| const denomSymbol = | ||
| mockUseFiatCurrenciesValues.currentFiatCurrency?.denomSymbol; | ||
|
|
||
| fireEvent.press(getByRoleButton(`${denomSymbol}0`)); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).toBeOnTheScreen(); | ||
|
|
||
| let handled: boolean | undefined; | ||
| act(() => { | ||
| handled = backPressHandler?.(); | ||
| }); | ||
|
|
||
| expect(handled).toBe(true); | ||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).not.toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('closes the amount keypad before opening the region selector', async () => { | ||
| render(BuildQuote); | ||
| const denomSymbol = | ||
| mockUseFiatCurrenciesValues.currentFiatCurrency?.denomSymbol; | ||
|
|
||
| fireEvent.press(getByRoleButton(`${denomSymbol}0`)); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).toBeOnTheScreen(); | ||
|
|
||
| await act(async () => | ||
| fireEvent.press( | ||
| getByRoleButton(mockUseRegionsValues.selectedRegion?.emoji), | ||
| ), | ||
| ); | ||
|
|
||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).not.toBeOnTheScreen(); | ||
| expect(mockNavigate).toHaveBeenCalledWith('RampModals', { | ||
| screen: 'RampRegionSelectorModal', | ||
| params: { | ||
| regions: mockRegionsData, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('closes the amount keypad before opening the asset selector', () => { | ||
| render(BuildQuote); | ||
| const denomSymbol = | ||
| mockUseFiatCurrenciesValues.currentFiatCurrency?.denomSymbol; | ||
|
|
||
| fireEvent.press(getByRoleButton(`${denomSymbol}0`)); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press(getByRoleButton(mockCryptoCurrenciesData[0].name)); | ||
|
|
||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).not.toBeOnTheScreen(); | ||
| expect(mockNavigate).toHaveBeenCalledWith( | ||
| ...createTokenSelectModalNavigationDetails({ | ||
| tokens: mockCryptoCurrenciesData, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('closes the amount keypad before opening the payment method selector', () => { | ||
| render(BuildQuote); | ||
| const denomSymbol = | ||
| mockUseFiatCurrenciesValues.currentFiatCurrency?.denomSymbol; | ||
|
|
||
| fireEvent.press(getByRoleButton(`${denomSymbol}0`)); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press(getByRoleButton('Change')); | ||
|
|
||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).not.toBeOnTheScreen(); | ||
| expect(mockNavigate).toHaveBeenCalledWith( | ||
| 'RampModals', | ||
| expect.objectContaining({ | ||
| screen: 'RampPaymentMethodSelectorModal', | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('removes the hardware back listener on unmount', () => { | ||
| const mockRemove = jest.fn(); | ||
| jest | ||
| .spyOn(BackHandler, 'addEventListener') | ||
| .mockReturnValue({ remove: mockRemove }); | ||
|
|
||
| const { unmount } = render(BuildQuote); | ||
| unmount(); | ||
|
|
||
| expect(mockRemove).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does not reset the amount when switching assets in the buy flow', () => { | ||
| const AssetSwitcher = () => { | ||
| const [, setSelectedAssetVersion] = React.useState(0); | ||
|
|
@@ -906,6 +1059,42 @@ describe('BuildQuote View', () => { | |
| mockUseRampSDKValues.isSell = true; | ||
| }); | ||
|
|
||
| it('opens the amount keypad bottom sheet when the sell amount input is pressed', () => { | ||
| render(BuildQuote); | ||
| const symbol = mockUseRampSDKValues.selectedAsset?.symbol; | ||
|
|
||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).not.toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press(getByRoleButton(`0 ${symbol}`)); | ||
|
|
||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('closes the amount keypad before opening the fiat selector in sell mode', () => { | ||
| render(BuildQuote); | ||
| const symbol = mockUseRampSDKValues.selectedAsset?.symbol; | ||
|
|
||
| fireEvent.press(getByRoleButton(`0 ${symbol}`)); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press(getByRoleButton(mockFiatCurrenciesData[0].symbol)); | ||
|
|
||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_BOTTOM_SHEET), | ||
| ).not.toBeOnTheScreen(); | ||
| expect(mockNavigate).toHaveBeenCalledWith( | ||
| ...createFiatSelectorModalNavigationDetails({ | ||
| currencies: mockFiatCurrenciesData, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('updates the amount input', () => { | ||
| render(BuildQuote); | ||
| const initialAmount = '0'; | ||
|
|
@@ -992,14 +1181,56 @@ describe('BuildQuote View', () => { | |
| fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`)); | ||
| fireEvent.press(getByRoleButton('25%')); | ||
| expect(getByRoleButton(`0.25 ${symbol}`)).toBeTruthy(); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_CONFIRM_BUTTON), | ||
| ).toBeOnTheScreen(); | ||
| expect( | ||
| screen.queryByRole('button', { name: 'Max' }), | ||
| ).not.toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('sets max amount from quick amount when amount is zero', () => { | ||
| render(BuildQuote); | ||
|
|
||
| fireEvent.press(getByRoleButton(`0.25 ${symbol}`)); | ||
| mockUseBalanceValues.balanceBN = toTokenMinimalUnit( | ||
| '1', | ||
| mockUseRampSDKValues.selectedAsset?.decimals || 18, | ||
| ) as BN4; | ||
| const symbol = mockUseRampSDKValues.selectedAsset?.symbol; | ||
| fireEvent.press(getByRoleButton(`0 ${symbol}`)); | ||
| fireEvent.press(getByRoleButton('Max')); | ||
| expect(getByRoleButton(`1 ${symbol}`)).toBeTruthy(); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_CONFIRM_BUTTON), | ||
| ).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('updates the amount input up to the max considering gas for native asset', () => { | ||
| it('replaces quick amounts with Done confirm when a sell amount is entered', () => { | ||
| mockUseBalanceValues.balanceBN = toTokenMinimalUnit( | ||
| '1', | ||
| mockUseRampSDKValues.selectedAsset?.decimals || 18, | ||
| ) as BN4; | ||
| render(BuildQuote); | ||
| const symbol = mockUseRampSDKValues.selectedAsset?.symbol; | ||
|
|
||
| fireEvent.press(getByRoleButton(`0 ${symbol}`)); | ||
|
|
||
| expect(getByRoleButton('25%')).toBeOnTheScreen(); | ||
| expect( | ||
| screen.queryByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_CONFIRM_BUTTON), | ||
| ).not.toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press(getByRoleButton('1')); | ||
|
|
||
| expect( | ||
| screen.queryByRole('button', { name: '25%' }), | ||
| ).not.toBeOnTheScreen(); | ||
| expect( | ||
| screen.getByTestId(BuildQuoteSelectors.AMOUNT_KEYPAD_CONFIRM_BUTTON), | ||
| ).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('updates the amount input up to the max considering gas for native asset', () => { | ||
| const initialAmount = '0'; | ||
| const quickAmount = 'Max'; | ||
| mockUseRampSDKValues = { | ||
|
|
@@ -1026,14 +1257,14 @@ describe('BuildQuote View', () => { | |
| mockUseRampSDKValues.selectedAsset?.decimals || 18, | ||
| ) as BN4, | ||
| }; | ||
| render(BuildQuote); | ||
| const symbol = mockUseRampSDKValues.selectedAsset?.symbol; | ||
| fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`)); | ||
| fireEvent.press(getByRoleButton(quickAmount)); | ||
| expect(getByRoleButton(`0.73 ${symbol}`)).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('updates the amount input up to the percentage considering gas', () => { | ||
| render(BuildQuote); | ||
| const initialAmount = '0'; | ||
| mockUseRampSDKValues = { | ||
| ...mockUseRampSDKInitialValues, | ||
|
|
@@ -1059,6 +1290,7 @@ describe('BuildQuote View', () => { | |
| mockUseRampSDKValues.selectedAsset?.decimals || 18, | ||
| ) as BN4, | ||
| }; | ||
| render(BuildQuote); | ||
| const symbol = mockUseRampSDKValues.selectedAsset?.symbol; | ||
| fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`)); | ||
| fireEvent.press(getByRoleButton('75%')); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marks the legacy Base SelectorButton deprecated now that Aggregator BuildQuote and AccountSelector no longer depend on it. Points new select triggers at MMDS SelectButton, consistent with the component-library SelectButton deprecation.