Repository navigation
Commit 3f06885
authored
feat: add wide screen token table sort controls (#47835)
<!--
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 affects the new wide screen experience only, where the Token
List renders as a new Token Table. This PR adds in sort controls to the
4 headers: Token, Price, 24h Change, Balance. When sorted, they stay
local to the table and are not written to the saved sort preference (the
existing `tokenSortConfig`). So the sort preference in state is
unchanged, and DeFi still uses that preference, as well as
non-widescreen Token List.
The down arrow is the default: A–Z, or the highest value first. The
first click on a column selects that default. Another click reverses it.
Missing and non-finite prices and 24h changes sort last in both
directions. Equal prices and changes fall back to the token name.
Low-balance tokens collapse only for a high-to-low balance sort.
Changing the saved sort clears the header selection.
If a user hasn't sorted on the table, it will show the active sort
currently being used in the `tokenSortConfig` i.e. Token (alphabetical)
or Balance (descending).
Piece | File | Change
-- | -- | --
TokenTable, TokenTableHeader |
ui/components/app/assets/token-table/token-table.tsx | Header buttons
and the local sort state.
useTokenSortOverride |
ui/components/app/assets/hooks/useTokenSortOverride.ts | New. Turns the
header click into the sort override, and reads price or 24h only when
that column is selected.
useTokenListData | ui/components/app/assets/hooks/useTokenListData.ts |
Takes the override, filters before sorting, and collapses low-balance
tokens only for a high-to-low balance sort.
sortTokenAssets |
ui/components/app/assets/util/sortAssetsWithPriority.ts | New. Applies
the header override. The saved-preference sort stays in
sortAssetsWithPriority.
getCachedSpotPrice, getCachedPercentChange | shared/lib/token-price.ts |
New. Shared price and 24h reads.
TokenCellPercentChange |
ui/components/app/assets/token-cell/cells/token-cell-percent-change.tsx
| 24h change now comes from getCachedPercentChange.
useCachedPrice | ui/pages/asset/hooks/useCurrentPrice.ts | Spot price
now comes from getCachedSpotPrice.
## **Changelog**
CHANGELOG entry: Adds sort controls to the wide screen Token Table
## **Related issues**
Part fixes: https://consensyssoftware.atlassian.net/browse/CEUX-1482
## **Manual testing steps**
1. Open the home screen at least 768px wide, so the token table is
shown.
2. Click Price. The arrow points down and the highest price is first.
Tokens with no price stay at the bottom.
2. Click Price again. The arrow points up, the lowest price is first,
and tokens with no price stay at the bottom.
3. Widen the table until 24h change is its own column, and repeat those
two clicks. The largest gain is first, then the largest loss. Missing
changes stay at the bottom.
4. Click Token, then Balance. The first click on Token is A–Z. Balance
starts as the saved high-to-low sort, so the first click reverses it.
5. With the balance arrow pointing down, confirm low-balance tokens are
behind the collapsed section. Reverse the balance sort, or sort by
price, and confirm those tokens appear in the list.
7. Sort by price, then narrow the window below 768px. The token list
replaces the table, and widening it again does not restore the price
sort.
8. Verify that one smaller screens there is no difference to the
existing Token List sort behaviour
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
https://github.com/user-attachments/assets/2243f5b4-503f-4b42-8133-987ddc147d6f
## **Pre-merge author checklist**
- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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]
> **Low Risk**
> UI-only sorting and shared price read helpers with test coverage;
saved global sort preference behavior is explicitly preserved.
>
> **Overview**
> Adds **click-to-sort headers** on the wide-screen **Token Table** for
Token, Price, 24h Change, and Balance. Sorting is **session-local** (not
written to `tokenSortConfig`); the UI reflects the saved preference
until a header is clicked, then clears header sort when that preference
changes. Headers show direction arrows and accessible **sorted
ascending/descending** labels.
>
> Sorting is driven by a new **`sortTokenAssets`** path (optional header
override) wired through **`useTokenSortOverride`** and an optional
**`sortOverride`** on **`useTokenListData`**. Price and 24h sorts use
shared **`getCachedSpotPrice`** / **`getCachedPercentChange`** helpers
(also used by **`useCachedPrice`** and token cell 24h display).
Missing/non-finite values sort last; low-value token collapse still
applies only for high-to-low balance sort.
>
> Locale strings and broad unit/integration tests cover header toggling,
preference reset, and sort ordering.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
3d99580. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 388b476 commit 3f06885
13 files changed
Lines changed: 1072 additions & 161 deletions
File tree
- app/_locales
- en_GB
- en
- ui
- components/app/assets
- hooks
- token-cell/cells
- token-list
- token-table
- util
- pages/asset/hooks
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
0 commit comments