Skip to content

Commit 864bf3d

Browse files
fix: handle 'title' as an alias for 'name' in asset sorting (#37900)
<!-- 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 fixes an issue where sorting assets by "Token name" was not working because the sort key was being passed as 'title' instead of 'name'. The `sortAssetsWithPriority` function in `ui/components/app/assets/util/sortAssetsWithPriority.ts` has been updated to treat 'title' as an alias for 'name'. A new test case has been added to `ui/components/app/assets/util/sortAssetsWithPriority.test.ts` to verify that sorting by 'title' works as expected. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/37900?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: fix token asset sorting ## **Related issues** Fixes: #37687 ## **Manual testing steps** See issue ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** https://www.loom.com/share/5b74edf6097b455bae03ab2d9d2eee3c ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > <sup>[Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) is generating a summary for commit 1dca2d6. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent eadd65b commit 864bf3d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ui/components/app/assets/util/sortAssetsWithPriority.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ describe('sortAssetsWithPriority', () => {
5050
]);
5151
});
5252

53+
it('sorts by name when key is "title"', () => {
54+
const assets = [
55+
createMockAsset({ name: 'Asset B', fiatBalance: 400 }),
56+
createMockAsset({ name: 'Asset A', fiatBalance: 600 }),
57+
createMockAsset({ name: 'Asset Z', fiatBalance: 500 }),
58+
];
59+
60+
const sortedAssets = sortAssetsWithPriority(assets, {
61+
key: 'title',
62+
order: 'asc',
63+
sortCallback: 'alphaNumeric',
64+
});
65+
66+
expect(extractAssetNames(sortedAssets)).toStrictEqual([
67+
'Asset A',
68+
'Asset B',
69+
'Asset Z',
70+
]);
71+
});
72+
5373
it('sorts by fiat balance when key is "tokenFiatAmount"', () => {
5474
const assets = [
5575
createMockAsset({ name: 'Asset B', fiatBalance: 400 }),

ui/components/app/assets/util/sortAssetsWithPriority.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function sortAssetsWithPriority(
1111
array: Asset[],
1212
criteria: SortCriteria,
1313
): Asset[] {
14-
if (criteria.key === 'name') {
14+
if (criteria.key === 'name' || criteria.key === 'title') {
1515
return sortAssets(array, {
1616
key: 'name',
1717
order: 'asc',

0 commit comments

Comments
 (0)