-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add EarnTokenSelector component for stablecoin lending (#13595)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR introduces a new `EarnTokenSelector` component to enhance the Input screen for stablecoin lending. The component provides a more intuitive way to select and view earning opportunities, displaying token information, APR, and balance in a unified interface. This PR also adds the token selector on the Input screen behind the stablecoin feature flag. ## **Related issues** Fixes: [STAKE-899](https://consensyssoftware.atlassian.net/browse/STAKE-899) ## **Manual testing steps** 1. Turn on the stablecoin lending feature flag in .js.env 2. Click on earn button in the wallet actions 3. Select a token 4. You should be redirected to the input screen with a new token selector component 5. Select any other token from token selector and you should see the details for that token ## **Screenshots/Recordings** https://github.com/user-attachments/assets/f2c85572-8deb-4c66-b24c-4768290d1425 ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. [STAKE-899]: https://consensyssoftware.atlassian.net/browse/STAKE-899?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
Showing
9 changed files
with
796 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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 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 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
36 changes: 36 additions & 0 deletions
36
app/components/UI/Stake/components/EarnTokenSelector/EarnTokenSelector.styles.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// app/components/UI/Stake/components/EarnTokenSelector/EarnTokenSelector.styles.ts | ||
import { StyleSheet } from 'react-native'; | ||
import { Theme } from '../../../../../util/theme/models'; | ||
|
||
export default (params: { theme: Theme }) => { | ||
const { theme } = params; | ||
|
||
return StyleSheet.create({ | ||
container: { | ||
backgroundColor: theme.colors.background.default, | ||
borderRadius: 8, | ||
minHeight: 56, | ||
borderWidth: 1, | ||
borderColor: theme.colors.border.default, | ||
}, | ||
startAccessoryContainer: { | ||
marginRight: 8, | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
endAccessoryContainer: { | ||
alignItems: 'flex-end', | ||
}, | ||
aprText: { | ||
color: theme.colors.success.default, | ||
marginBottom: 2, | ||
}, | ||
tokenText: { | ||
marginLeft: 8, | ||
}, | ||
networkAvatar: { | ||
width: 24, | ||
height: 24, | ||
}, | ||
}); | ||
}; |
86 changes: 86 additions & 0 deletions
86
app/components/UI/Stake/components/EarnTokenSelector/EarnTokenSelector.test.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// app/components/UI/Stake/components/EarnTokenSelector/EarnTokenSelector.test.tsx | ||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react-native'; | ||
import EarnTokenSelector from './'; | ||
import renderWithProvider from '../../../../../util/test/renderWithProvider'; | ||
import { MOCK_USDC_MAINNET_ASSET } from '../../__mocks__/mockData'; | ||
import { backgroundState } from '../../../../../util/test/initial-root-state'; | ||
import { TokenI } from '../../../../UI/Tokens/types'; | ||
|
||
const mockNavigate = jest.fn(); | ||
|
||
const MOCK_APR_VALUES: { [symbol: string]: string } = { | ||
Ethereum: '2.3', | ||
USDC: '4.5', | ||
USDT: '4.1', | ||
DAI: '5.0', | ||
}; | ||
|
||
jest.mock('@react-navigation/native', () => { | ||
const actualNav = jest.requireActual('@react-navigation/native'); | ||
return { | ||
...actualNav, | ||
useNavigation: () => ({ | ||
navigate: mockNavigate, | ||
}), | ||
}; | ||
}); | ||
|
||
// Mock the useEarnTokenDetails hook | ||
jest.mock('../../hooks/useEarnTokenDetails', () => ({ | ||
useEarnTokenDetails: () => ({ | ||
getTokenWithBalanceAndApr: (token: TokenI) => ({ | ||
...token, | ||
apr: MOCK_APR_VALUES[token.symbol] || '0.0', | ||
tokenBalanceFormatted: token.symbol === 'USDC' ? '6.84314 USDC' : '0', | ||
balanceFiat: token.symbol === 'USDC' ? '$6.84' : '$0.00', | ||
}), | ||
}), | ||
})); | ||
|
||
describe('EarnTokenSelector', () => { | ||
const mockProps = { | ||
token: MOCK_USDC_MAINNET_ASSET, | ||
}; | ||
|
||
const mockInitialState = { | ||
engine: { | ||
backgroundState, | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders correctly', () => { | ||
const { toJSON } = renderWithProvider( | ||
<EarnTokenSelector {...mockProps} />, | ||
{ | ||
state: mockInitialState, | ||
}, | ||
); | ||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('displays token symbol and APR', () => { | ||
const { getByText } = renderWithProvider( | ||
<EarnTokenSelector {...mockProps} />, | ||
{ state: mockInitialState }, | ||
); | ||
expect(getByText('4.5% APR')).toBeDefined(); | ||
expect(getByText('6.84314 USDC')).toBeDefined(); | ||
}); | ||
|
||
it('navigates to earn token list when pressed', () => { | ||
const { getByTestId } = renderWithProvider( | ||
<EarnTokenSelector {...mockProps} />, | ||
{ state: mockInitialState }, | ||
); | ||
const button = getByTestId('earn-token-selector'); | ||
fireEvent.press(button); | ||
expect(mockNavigate).toHaveBeenCalledWith('StakeModals', { | ||
screen: 'EarnTokenList', | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.