Skip to content

Commit

Permalink
feat: Sort/Import Tokens in Mobile (#11618)
Browse files Browse the repository at this point in the history
## **Description**

Implements Token Sorting on mobile. This is the mobile implementation of
the same feature on extension:
MetaMask/metamask-extension#27184

Note that this currently includes a patch of the
`PreferencesController`. There is a corresponding PR in core to add this
to a formal controller release:
MetaMask/core#4747

## **Related issues**

Fixes: https://consensyssoftware.atlassian.net/browse/MMASSETS-357

## **Manual testing steps**

Go to Portfolio Screen
Sort should allow sorting by declining fiat balance by default. Users
can then toggle and sort alphabetically or by declining fiat balance.

Import button should function the same as the import token link in
footer

## **Screenshots/Recordings**


https://github.com/user-attachments/assets/f9a9cf52-ef23-4705-a7db-ae5ecdc232f7

## **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.

---------

Co-authored-by: salimtb <[email protected]>
  • Loading branch information
gambinish and salimtb authored Oct 22, 2024
1 parent aea845f commit 0738030
Show file tree
Hide file tree
Showing 18 changed files with 657 additions and 64 deletions.
7 changes: 7 additions & 0 deletions app/actions/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ export function toggleDeviceNotification(deviceNotificationEnabled) {
deviceNotificationEnabled,
};
}

export function setTokenSortConfig(tokenSortConfig) {
return {
type: 'SET_TOKEN_SORT_CONFIG',
tokenSortConfig,
};
}
6 changes: 3 additions & 3 deletions app/components/UI/Tokens/TokenList/TokenListFooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ import { TokenI } from '../../types';

interface TokenListFooterProps {
tokens: TokenI[];
isAddTokenEnabled: boolean;
goToAddToken: () => void;
showDetectedTokens: () => void;
isAddTokenEnabled: boolean;
}

export const TokenListFooter = ({
tokens,
isAddTokenEnabled,
goToAddToken,
showDetectedTokens,
isAddTokenEnabled,
}: TokenListFooterProps) => {
const navigation = useNavigation();
const { colors } = useTheme();
Expand Down Expand Up @@ -108,7 +108,7 @@ export const TokenListFooter = ({
style={styles.add}
onPress={goToAddToken}
disabled={!isAddTokenEnabled}
testID={WalletViewSelectorsIDs.IMPORT_TOKEN_BUTTON}
testID={WalletViewSelectorsIDs.IMPORT_TOKEN_FOOTER_LINK}
>
<Text style={styles.centered}>
<Text style={styles.emptyText}>
Expand Down
19 changes: 7 additions & 12 deletions app/components/UI/Tokens/TokenList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import { TokenListItem } from './TokenListItem';
interface TokenListProps {
tokens: TokenI[];
refreshing: boolean;
isAddTokenEnabled: boolean;
onRefresh: () => void;
showRemoveMenu: (arg: TokenI) => void;
goToAddToken: () => void;
setIsAddTokenEnabled: (arg: boolean) => void;
}

interface TokenListNavigationParamList {
Expand All @@ -34,8 +37,11 @@ interface TokenListNavigationParamList {
export const TokenList = ({
tokens,
refreshing,
isAddTokenEnabled,
onRefresh,
showRemoveMenu,
goToAddToken,
setIsAddTokenEnabled,
}: TokenListProps) => {
const navigation =
useNavigation<
Expand All @@ -48,20 +54,9 @@ export const TokenList = ({
const detectedTokens = useSelector(selectDetectedTokens);

const [showScamWarningModal, setShowScamWarningModal] = useState(false);
const [isAddTokenEnabled, setIsAddTokenEnabled] = useState(true);

const styles = createStyles(colors);

const goToAddToken = () => {
setIsAddTokenEnabled(false);
navigation.push('AddAsset', { assetType: 'token' });
trackEvent(MetaMetricsEvents.TOKEN_IMPORT_CLICKED, {
source: 'manual',
chain_id: getDecimalChainId(chainId),
});
setIsAddTokenEnabled(true);
};

const showDetectedTokens = () => {
navigation.navigate(...createDetectedTokensNavDetails());
trackEvent(MetaMetricsEvents.TOKEN_IMPORT_CLICKED, {
Expand Down Expand Up @@ -89,9 +84,9 @@ export const TokenList = ({
ListFooterComponent={
<TokenListFooter
tokens={tokens}
isAddTokenEnabled={isAddTokenEnabled}
goToAddToken={goToAddToken}
showDetectedTokens={showDetectedTokens}
isAddTokenEnabled={isAddTokenEnabled}
/>
}
refreshControl={
Expand Down
Loading

0 comments on commit 0738030

Please sign in to comment.