-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Add tokens full page #21628
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
Open
brianacnguyen
wants to merge
6
commits into
main
Choose a base branch
from
feat/tokens-full-page
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.
+478
−316
Open
feat: Add tokens full page #21628
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b574e9
Added full tokens page
brianacnguyen 90e374a
Added tests to TokensFullView
brianacnguyen ae658c4
Added View all Tokens button to help review
brianacnguyen 3555f5d
Removed unnecessary additions
brianacnguyen 50f4b0b
Updated tests
brianacnguyen bd8fb40
Removed TokenListFooter
brianacnguyen 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import React, { useCallback } from 'react'; | ||
| import { View } from 'react-native'; | ||
| import { useTheme } from '../../../../util/theme'; | ||
| import { TokenI } from '../types'; | ||
| import { TokenListItem } from './TokenListItem'; | ||
| import { WalletViewSelectorsIDs } from '../../../../../e2e/selectors/wallet/WalletView.selectors'; | ||
| import createStyles from '../styles'; | ||
|
|
||
| interface TokenListViewProps { | ||
| tokenKeys: TokenI[]; | ||
| showRemoveMenu: (token: TokenI) => void; | ||
| setShowScamWarningModal: () => void; | ||
| } | ||
|
|
||
| const TokenListView = ({ | ||
| tokenKeys, | ||
| showRemoveMenu, | ||
| setShowScamWarningModal, | ||
| }: TokenListViewProps) => { | ||
| const { colors } = useTheme(); | ||
| const styles = createStyles(colors); | ||
|
|
||
| const renderTokenListItem = useCallback( | ||
| (token: TokenI, index: number) => { | ||
| const assetKey = { | ||
| address: token.address, | ||
| chainId: token.chainId, | ||
| isStaked: token.isStaked, | ||
| }; | ||
|
|
||
| return ( | ||
| <TokenListItem | ||
| key={`${token.address}-${token.chainId}-${ | ||
| token.isStaked ? 'staked' : 'unstaked' | ||
| }-${index}`} | ||
| assetKey={assetKey} | ||
| showRemoveMenu={showRemoveMenu} | ||
| setShowScamWarningModal={setShowScamWarningModal} | ||
| privacyMode={false} | ||
| showPercentageChange | ||
| /> | ||
| ); | ||
| }, | ||
| [showRemoveMenu, setShowScamWarningModal], | ||
| ); | ||
|
|
||
| return ( | ||
| <View | ||
| style={styles.wrapper} | ||
| testID={WalletViewSelectorsIDs.TOKENS_CONTAINER_LIST} | ||
| > | ||
| <View style={styles.wrapper}> | ||
| {tokenKeys.map((token, index) => renderTokenListItem(token, index))} | ||
| </View> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default TokenListView; | ||
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
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 |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ import ScrollableTabView, { | |
| } from '@tommasini/react-native-scrollable-tab-view'; | ||
| import { strings } from '../../../../locales/i18n'; | ||
| import AddCustomCollectible from '../../UI/AddCustomCollectible'; | ||
| import { getImportTokenNavbarOptions } from '../../UI/Navbar'; | ||
| import BottomSheetHeader from '../../../component-library/components/BottomSheets/BottomSheetHeader'; | ||
| import { isTokenDetectionSupportedForNetwork } from '@metamask/assets-controllers'; | ||
| import { | ||
| selectEvmChainId, | ||
|
|
@@ -104,22 +104,9 @@ const AddAsset = () => { | |
| return tokensData && Object.keys(tokensData).length > 0; | ||
| }, [selectedNetwork, tokenListForAllChains]); | ||
|
|
||
| const updateNavBar = useCallback(() => { | ||
| navigation.setOptions( | ||
| getImportTokenNavbarOptions( | ||
| `add_asset.${assetType === TOKEN ? TOKEN_TITLE : NFT_TITLE}`, | ||
| true, | ||
| navigation, | ||
| colors, | ||
| true, | ||
| 0, | ||
| ), | ||
| ); | ||
| }, [assetType, colors, navigation]); | ||
|
|
||
| useEffect(() => { | ||
| updateNavBar(); | ||
| }, [updateNavBar]); | ||
| const handleBackPress = useCallback(() => { | ||
| navigation.goBack(); | ||
| }, [navigation]); | ||
|
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. The Import assets page was moved to the main stack to work with both the Tokens tab and tokens full page, so the header needs to be refactored to go inside the page |
||
|
|
||
| const goToSecuritySettings = () => { | ||
| navigation.navigate(Routes.MODAL.ROOT_MODAL_FLOW, { | ||
|
|
@@ -147,6 +134,9 @@ const AddAsset = () => { | |
|
|
||
| return ( | ||
| <SafeAreaView style={styles.wrapper} testID={`add-${assetType}-screen`}> | ||
| <BottomSheetHeader onBack={handleBackPress}> | ||
| {strings(`add_asset.${assetType === TOKEN ? TOKEN_TITLE : NFT_TITLE}`)} | ||
| </BottomSheetHeader> | ||
| {assetType !== 'token' && ( | ||
| <View style={styles.infoWrapper}> | ||
| <Banner | ||
|
|
||
71 changes: 71 additions & 0 deletions
71
app/components/Views/TokensFullView/TokensFullView.test.ts
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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { renderScreen } from '../../../util/test/renderWithProvider'; | ||
| import TokensFullView from './TokensFullView'; | ||
|
|
||
| // Mock only external dependencies that are not under test | ||
| jest.mock('@metamask/design-system-twrnc-preset', () => ({ | ||
| useTailwind: () => (className: string) => ({ className }), | ||
| })); | ||
|
|
||
| jest.mock('../../../components/hooks/useMetrics', () => ({ | ||
| useMetrics: () => ({ | ||
| trackEvent: jest.fn(), | ||
| createEventBuilder: jest.fn(), | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('@react-navigation/native', () => ({ | ||
| ...jest.requireActual('@react-navigation/native'), | ||
| useNavigation: () => ({ | ||
| goBack: jest.fn(), | ||
| navigate: jest.fn(), | ||
| }), | ||
| })); | ||
|
|
||
| describe('TokensFullView', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('renders header with title and back button', () => { | ||
| const { getByTestId } = renderScreen(TokensFullView, { | ||
| name: 'TokensFullView', | ||
| }); | ||
|
|
||
| expect(getByTestId('bottom-sheet-header')).toBeOnTheScreen(); | ||
| expect(getByTestId('header-title')).toBeOnTheScreen(); | ||
| expect(getByTestId('back-button')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('renders token list control bar with add button', () => { | ||
| const { getByTestId } = renderScreen(TokensFullView, { | ||
| name: 'TokensFullView', | ||
| }); | ||
|
|
||
| expect(getByTestId('token-list-control-bar')).toBeOnTheScreen(); | ||
| expect(getByTestId('add-token-button')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('renders token list component', () => { | ||
| const { getByTestId } = renderScreen(TokensFullView, { | ||
| name: 'TokensFullView', | ||
| }); | ||
|
|
||
| expect(getByTestId('token-list')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('displays token count in token list', () => { | ||
| const { getByTestId } = renderScreen(TokensFullView, { | ||
| name: 'TokensFullView', | ||
| }); | ||
|
|
||
| expect(getByTestId('token-count')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('shows loader when tokens are loading', () => { | ||
| const { getByTestId } = renderScreen(TokensFullView, { | ||
| name: 'TokensFullView', | ||
| }); | ||
|
|
||
| expect(getByTestId('loader')).toBeOnTheScreen(); | ||
| }); | ||
| }); |
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.
Bug: Token List Ignores User Privacy Settings
The
TokenListViewcomponent hardcodes theprivacyModeprop tofalseforTokenListItem, preventing it from respecting the user's privacy settings.