Skip to content

Commit 387f2ac

Browse files
fix(assets): place the token ticker under the token name (#47552)
## **Description** The token details header used the ticker as its title. [ASSETS-4256](https://consensyssoftware.atlassian.net/browse/ASSETS-4256) settles the layout as the token name on the title line, with the ticker directly beneath it. This mirrors the mobile change in [MetaMask/metamask-mobile#38497](MetaMask/metamask-mobile#38497). What changed: - The header title is the token name, falling back to the symbol when the name is missing. - The ticker is shown on the subtitle line in the title color when it differs from the name. Comparison trims whitespace and is case-sensitive, so `Pepe` / `PEPE` shows both. - The contract address sits on the same line as the ticker. EVM addresses render as `0x..` plus the last four characters. Other addresses render as the first and last four characters. The copy control is unchanged. - A long ticker ellipsizes, and the address stays fully visible on that line. - When the name and ticker match (for example `ETH`), the ticker line is omitted so the symbol is not repeated. Only presentation changes. Data, copy behavior, and badges are unchanged. ## **Changelog** CHANGELOG entry: Showed the token ticker under the token name on the token details page ## **Related issues** Fixes: Refs: https://consensyssoftware.atlassian.net/browse/ASSETS-4256 ## **Manual testing steps** ```gherkin Feature: token details header identity Scenario: token name and ticker differ Given a token whose name is Pepe and whose ticker is PEPE When the user opens that token on the token details page Then the header title is Pepe And PEPE is shown on the line directly under the name And the contract address is shown on that same line as 0x..XXXX And tapping the address copies the full contract address Scenario: token name and ticker match Given a token whose name and ticker are both ETH When the user opens that token on the token details page Then the header shows ETH once And no second ticker line is shown Scenario: long ticker Given a token with a long ticker When the user opens that token on the token details page Then the ticker is truncated with an ellipsis And the contract address and copy control remain fully visible ``` ## **Screenshots/Recordings** Captured from a running test build, opened through asset deeplinks. ### **Before** The previous header used the ticker as the title and a longer address truncation. ### **After** The title is the token name. The ticker sits on the line beneath it, in the title color, next to the compact address. When the metadata name is the ticker itself, that second ticker is omitted. <details> <summary>Token details header screenshots (ERC-20, Solana, Tron, native)</summary> **Chainlink**: title Chainlink Token, ticker LINK, address `0x..86CA` ![Chainlink header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/erc20-link.png) **Uniswap**: title Uniswap, ticker UNI, address `0x..F984` ![Uniswap header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/erc20-uni.png) **Pepe**: title Pepe, ticker PEPE, address `0x..1933` ![Pepe header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/erc20-pepe.png) **USDC**: title USDC, address `0x..eB48` (name matches ticker, so no second ticker line) ![USDC header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/erc20-usdc.png) **Solana Bonk**: title Bonk, ticker BONK, address `DezX..B263` ![Bonk header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/solana-bonk.png) **Tron Tether**: title Tether, ticker USDT, address `TR7N..Lj6t` ![Tether header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/tron-usdt.png) **Native ETH**: title Ethereum, ticker ETH, no address ![Ethereum header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/native-eth.png) **Native SOL**: title SOL, no address (name matches ticker) ![SOL header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/native-sol.png) **Native TRX**: title TRON, ticker TRX, no address ![TRON header](https://gist.githubusercontent.com/Prithpal-Sooriya/5ea3570dc37f070bc962e649abf93758/raw/cc6b08bcc0c9c83c726162feb721c58466c8dbd7/native-trx.png) </details> ## **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 - [ ] 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. [ASSETS-4256]: https://consensyssoftware.atlassian.net/browse/ASSETS-4256?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Presentation-only changes on the asset details header; copy behavior and asset data paths are unchanged aside from display-name selection. > > **Overview** > The token details header no longer uses the ticker as the main title. It now shows the **token name** (from metadata via new `resolveTokenDisplayName`, with symbol fallback) and, when the symbol differs from that title (case-sensitive, trimmed), a **subtitle row** with the ticker plus the contract copy control on one line. > > **Contract addresses** switch from `shortenAddress` to a compact format: EVM as `0x..` + last four characters; Solana/Tron-style as first four + `..` + last four. Long tickers ellipsize while the address stays fully visible; duplicate name/ticker (e.g. ETH) drops the extra ticker line. The avatar badge is vertically centered against the name block. > > `AssetPage`, `native-asset`, and `token-asset` pass `name` through; copy-on-click still uses the full address. Tests cover header layout, address formatting, and name resolution. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0629cd1. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1752c4c commit 387f2ac

8 files changed

Lines changed: 365 additions & 47 deletions

‎ui/pages/asset/components/asset-page-header.test.tsx‎

Lines changed: 177 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,189 @@ describe('AssetPageHeader', () => {
3636
(useCopyToClipboard as jest.Mock).mockReturnValue([false, mockHandleCopy]);
3737
});
3838

39-
it('renders the token symbol as the title', () => {
39+
it('renders the token symbol as the title when no name is provided', () => {
4040
renderHeader();
4141

4242
expect(screen.getByTestId('asset-name')).toHaveTextContent('USDC');
43+
expect(
44+
screen.queryByTestId('asset-page-header-ticker'),
45+
).not.toBeInTheDocument();
46+
});
47+
48+
it('renders the token name with the ticker on the address row', () => {
49+
renderHeader({ name: 'USD Coin', symbol: 'USDC' });
50+
51+
const title = screen.getByTestId('asset-name');
52+
const ticker = screen.getByTestId('asset-page-header-ticker');
53+
54+
expect(title).toHaveTextContent('USD Coin');
55+
expect(title).toHaveClass('text-default');
56+
expect(ticker).toHaveTextContent('USDC');
57+
expect(ticker).toHaveClass('text-default');
58+
59+
const subtitle = screen.getByTestId('asset-page-header-subtitle');
60+
expect(subtitle).toHaveTextContent('USDC');
61+
const address = screen.getByTestId('asset-page-header-address');
62+
63+
expect(subtitle).toHaveTextContent('0x..5831');
64+
expect(address.querySelector('p')).toHaveClass('text-alternative');
65+
expect(subtitle).not.toHaveTextContent('USD Coin');
66+
});
67+
68+
it('renders an EVM contract address as 0x.. plus its last four characters', () => {
69+
renderHeader({
70+
name: '(PoS) Tether USD',
71+
symbol: 'USDT',
72+
contractAddress: '0x514910771AF9Ca656af840dff83E8264EcF986CA',
73+
});
74+
75+
expect(screen.getByTestId('asset-page-header-ticker')).toHaveTextContent(
76+
'USDT',
77+
);
78+
expect(screen.getByTestId('asset-page-header-address')).toHaveTextContent(
79+
'0x..86CA',
80+
);
81+
});
82+
83+
it('renders a Solana contract address with its first and last four characters', () => {
84+
renderHeader({
85+
name: 'Stonk',
86+
symbol: 'STONK',
87+
contractAddress: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263',
88+
});
89+
90+
expect(screen.getByTestId('asset-page-header-ticker')).toHaveTextContent(
91+
'STONK',
92+
);
93+
expect(screen.getByTestId('asset-page-header-address')).toHaveTextContent(
94+
'DezX..B263',
95+
);
96+
});
97+
98+
it('renders a Tron contract address with its first and last four characters', () => {
99+
renderHeader({
100+
name: 'Sun Token',
101+
symbol: 'SUN',
102+
contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
103+
});
104+
105+
const subtitle = screen.getByTestId('asset-page-header-subtitle');
106+
107+
expect(subtitle).toHaveTextContent('SUN');
108+
expect(subtitle).toHaveTextContent('TR7N..Lj6t');
109+
});
110+
111+
it('keeps a short non-EVM address intact', () => {
112+
renderHeader({
113+
name: 'Short',
114+
symbol: 'SHORT',
115+
contractAddress: 'ABCD1234',
116+
});
117+
118+
expect(screen.getByTestId('asset-page-header-address')).toHaveTextContent(
119+
'ABCD1234',
120+
);
121+
});
122+
123+
it('ellipsizes a long ticker and keeps the contract address on the same line', () => {
124+
const longTicker = 'SUPERCALIFRAGILISTIC';
125+
renderHeader({
126+
name: 'Long Symbol Token',
127+
symbol: longTicker,
128+
});
129+
130+
const ticker = screen.getByTestId('asset-page-header-ticker');
131+
const address = screen.getByTestId('asset-page-header-address');
132+
133+
expect(ticker).toHaveTextContent(longTicker);
134+
expect(ticker).toHaveClass('shrink');
135+
expect(address).toHaveClass('shrink-0');
136+
expect(address).toHaveTextContent('0x..5831');
137+
});
138+
139+
it('keeps a long native ticker on one line when there is no contract address', () => {
140+
const longTicker = 'SUPERCALIFRAGILISTIC';
141+
renderHeader({
142+
name: 'Long Native Token',
143+
symbol: longTicker,
144+
contractAddress: undefined,
145+
});
146+
147+
const ticker = screen.getByTestId('asset-page-header-ticker');
148+
149+
expect(ticker).toHaveTextContent(longTicker);
150+
expect(ticker).toHaveClass('shrink');
151+
expect(
152+
screen.queryByTestId('asset-page-header-address'),
153+
).not.toBeInTheDocument();
154+
});
155+
156+
it('renders the ticker under the name when there is no contract address', () => {
157+
renderHeader({
158+
name: 'Ethereum',
159+
symbol: 'ETH',
160+
contractAddress: undefined,
161+
});
162+
163+
expect(screen.getByTestId('asset-name')).toHaveTextContent('Ethereum');
164+
expect(screen.getByTestId('asset-page-header-ticker')).toHaveTextContent(
165+
'ETH',
166+
);
167+
expect(
168+
screen.queryByTestId('asset-page-header-address'),
169+
).not.toBeInTheDocument();
170+
});
171+
172+
it('renders the ticker below the name when they differ only by case', () => {
173+
renderHeader({
174+
name: 'Pepe',
175+
symbol: 'PEPE',
176+
contractAddress: undefined,
177+
});
178+
179+
expect(screen.getByTestId('asset-name')).toHaveTextContent('Pepe');
180+
expect(screen.getByTestId('asset-page-header-ticker')).toHaveTextContent(
181+
'PEPE',
182+
);
183+
});
184+
185+
it('omits the ticker line when it matches the token name', () => {
186+
renderHeader({
187+
name: 'ETH',
188+
symbol: 'ETH',
189+
contractAddress: undefined,
190+
});
191+
192+
expect(screen.getByTestId('asset-name')).toHaveTextContent('ETH');
193+
expect(
194+
screen.queryByTestId('asset-page-header-ticker'),
195+
).not.toBeInTheDocument();
196+
expect(
197+
screen.queryByTestId('asset-page-header-subtitle'),
198+
).not.toBeInTheDocument();
199+
});
200+
201+
it('trims the token name before comparing it with the ticker', () => {
202+
renderHeader({
203+
name: ' ETH ',
204+
symbol: 'ETH',
205+
contractAddress: undefined,
206+
});
207+
208+
expect(screen.getByTestId('asset-name')).toHaveTextContent('ETH');
209+
expect(
210+
screen.queryByTestId('asset-page-header-ticker'),
211+
).not.toBeInTheDocument();
43212
});
44213

45214
it('renders the token avatar with a network badge', () => {
46-
renderHeader();
215+
renderHeader({ name: 'Chainlink Token', symbol: 'LINK' });
47216

48-
expect(screen.getByTestId('asset-page-header-avatar')).toBeInTheDocument();
217+
const avatar = screen.getByTestId('asset-page-header-avatar');
218+
expect(avatar).toBeInTheDocument();
49219
expect(screen.getByAltText('Arbitrum One')).toBeInTheDocument();
220+
expect(avatar.parentElement?.parentElement).toHaveClass('self-center');
221+
expect(avatar.parentElement?.parentElement).not.toHaveClass('self-start');
50222
});
51223

52224
it('renders badges passed as the title end accessory', () => {
@@ -75,11 +247,11 @@ describe('AssetPageHeader', () => {
75247
});
76248

77249
describe('contract address', () => {
78-
it('renders the shortened contract address', () => {
250+
it('renders the compact contract address', () => {
79251
renderHeader();
80252

81253
expect(screen.getByTestId('asset-page-header-address')).toHaveTextContent(
82-
'0xaf88d...e5831',
254+
'0x..5831',
83255
);
84256
});
85257

0 commit comments

Comments
 (0)