Skip to content

Commit 39957e8

Browse files
authored
feat: refactor asset list controls and move them to tab bar when wide layout is used (#47747)
<!-- 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** Normally the Tokens, DeFi, and NFTs controls sit on their own row under the account tabs. On wide layout, they now sit on the tab row to utilise the additional space better. The controls stay mounted and are portaled into a host node (via `TabControls`) that the wide layout moves into the end of the tab bar (the "tab end slot"). The slot sits in the sticky tab row, so the controls stay put while the token table scrolls. The popup and a narrow sidepanel keep the controls on the row below the tabs. As part of this PR, I've done a refactor of the asset list control bar. Each tab now composes only the controls it shows, rather than everything being driven from the `asset-list-control-bar.tsx` file. MMDS components replace legacy ones. Functionality is completely unchanged. An unused prop `showTokensLink` was removed as it was never called with `false` and always defaulted to `true`, therefore that path was never used. Change made | Files affected -- | -- Split out of asset-list-control-bar.tsx | asset-controls.tsx, network-filter.tsx, sort-by-button.tsx, token-options-menu.tsx, nft-options-menu.tsx, defi-options-menu.tsx, manage-tokens-button.tsx, use-open-token-management.ts Shared popover and refresh row | use-control-popover.ts, options-menu.tsx, refresh-item.tsx Moved the more button | import-control/import-control.tsx → asset-list-control-bar/options-button.tsx Removed the old composer | asset-list-control-bar.tsx, asset-list-control-bar.test.tsx, asset-list-control-bar.stories.tsx, index.ts, index.scss, import-control/index.ts Removed showTokensLinks | asset-list.tsx, account-overview-tabs.tsx, account-overview-non-evm.tsx Tabs compose their own controls | asset-list.tsx, nfts-tab.tsx, defi-tab.tsx, activity-list.tsx Wide layout moves the row onto the tab bar | tab-controls.tsx, tab-end-slot.ts, tabs.tsx, tabs.scss ## **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: Moved the network filter and asset controls onto the account tab row in the wide layout ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/CEUX-1368 ## **Manual testing steps** 1. Run the extension and open the home screen with the fullscreen redesign on and the window at least 768px wide. 2. On Tokens, confirm the network filter, sort button, and more menu sit on the tab row. Open sort and the more menu and confirm only one stays open. Use Manage tokens and Refresh list. 3. On NFTs, confirm there is no sort button. On an EVM account, use Import NFTs and Refresh. On a non-EVM account, confirm the more control opens token management. 4. On DeFi with positions, confirm sort and the refresh menu. With no positions, confirm sort is hidden. With DeFi V1, confirm there is no more menu. 5. On Activity, confirm only the network filter is shown and it stays under the tabs, not on the tab row. 6. Shrink the window below 768px, and open the popup. Confirm the controls sit under the tabs again and the popup layout is unchanged. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** Wide layout: <img width="1204" height="802" alt="image" src="https://github.com/user-attachments/assets/efc00c44-8453-4b09-8cef-45e3ea82574d" /> Wide layout after scrolling down (asset control bar is sticky in the tab bar): <img width="1204" height="803" alt="image" src="https://github.com/user-attachments/assets/5edcad7e-77cd-4a3a-80fb-cae32967e980" /> Non-wide layout shows no change to existing asset control bar: <img width="400" height="602" alt="image" src="https://github.com/user-attachments/assets/7e59da9b-cd26-4f2f-9858-0c123583aa89" /> ## **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] > **Medium Risk** > Large UI refactor that preserves network-filter side effects (`setTokenNetworkFilter`, `setActiveNetwork`, enabled-network fallbacks); regressions could affect filtering, refresh/actions, or wide-layout stickiness without being obvious in unit tests. > > **Overview** > Refactors the home asset control bar from a single `AssetListControlBar` into composable pieces (`AssetControls`, `NetworkFilter`, `SortByButton`, and tab-specific options menus) so Tokens, NFTs, DeFi, and Activity each mount only the controls they need. Shared popover behavior and “only one menu open” state live in `AssetControls` / `useControlPopover`. > > On **wide layout**, controls stay mounted but **`TabControls`** portals them into a new **tab end slot** on the sticky tab row; narrow popup/sidepanel layouts keep controls in a row under the tabs. Activity still uses only the network filter and does not move onto the tab bar. > > Removes the unused **`showTokensLinks`** prop and related tests, deletes the old control-bar module/styles/stories, splits tests across the new components, and updates tabs SCSS for the end-slot layout instead of negative-margin `overview-tab-controls`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit eabc20d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 2560458 commit 39957e8

44 files changed

Lines changed: 1802 additions & 1638 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎test/e2e/page-objects/pages/networks/network-filter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Driver } from '../../../webdriver/driver';
1313
* Related: `SelectNetworkModal` (what `open()` opens), `TokensTab` / `DefiTab`
1414
* (the lists this filters).
1515
*
16-
* @see ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx
16+
* @see ui/components/app/assets/asset-list/asset-list-control-bar/network-filter.tsx
1717
*/
1818
class NetworkFilter {
1919
private readonly driver: Driver;

‎test/jest/console-baseline-unit.json‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@
172172
"error: StorageService: Failed to remove item:": 1,
173173
"error: StorageService: Failed to set item:": 1
174174
},
175-
"ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.test.tsx": {
176-
"MetaMask: Background connection not initialized": 9,
177-
"React: PropTypes validation failures": 1
178-
},
179175
"ui/components/app/assets/nfts/nft-details/nft-details.test.js": {
180176
"MetaMask: Background connection not initialized": 1,
181177
"React: Act warnings (component updates not wrapped)": 5,

‎ui/components/app/app-components.scss‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
@import 'srp-input-import/srp-input-import';
5454
@import 'snaps/snap-privacy-warning/index';
5555
@import 'tab-bar/index';
56-
@import 'assets/asset-list/asset-list-control-bar/index';
5756
@import 'assets/asset-list/sort-control/index';
5857
@import 'assets/token-cell/token-cell';
5958
@import 'transaction-breakdown/index';
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import React, {
2+
createContext,
3+
useCallback,
4+
useContext,
5+
useMemo,
6+
useState,
7+
} from 'react';
8+
import {
9+
Box,
10+
BoxAlignItems,
11+
BoxFlexDirection,
12+
BoxJustifyContent,
13+
} from '@metamask/design-system-react';
14+
import { getEnvironmentType } from '../../../../../../shared/lib/environment-type';
15+
import {
16+
ENVIRONMENT_TYPE_NOTIFICATION,
17+
ENVIRONMENT_TYPE_POPUP,
18+
} from '../../../../../../shared/constants/app';
19+
20+
type AssetControlsContextValue = {
21+
isOpen: (id: string) => boolean;
22+
toggle: (id: string) => void;
23+
close: () => void;
24+
};
25+
26+
const AssetControlsContext = createContext<AssetControlsContextValue | null>(
27+
null,
28+
);
29+
30+
export const assetControlIconButtonClassName =
31+
'flex h-8 w-8 items-center justify-center rounded-lg border-0 bg-transparent hover:bg-hover active:bg-pressed';
32+
33+
export const useAssetControls = () => {
34+
const context = useContext(AssetControlsContext);
35+
if (!context) {
36+
throw new Error('Asset controls must render inside AssetControls');
37+
}
38+
return context;
39+
};
40+
41+
export const useAssetControl = (id: string) => {
42+
const { isOpen, toggle, close } = useAssetControls();
43+
return {
44+
isOpen: isOpen(id),
45+
toggle: () => toggle(id),
46+
close,
47+
};
48+
};
49+
50+
export const useIsControlBarFullScreen = () => {
51+
const windowType = getEnvironmentType();
52+
return (
53+
windowType !== ENVIRONMENT_TYPE_NOTIFICATION &&
54+
windowType !== ENVIRONMENT_TYPE_POPUP
55+
);
56+
};
57+
58+
export const controlPopoverStyle = (
59+
isFullScreen: boolean,
60+
minWidth: string,
61+
) => ({
62+
zIndex: 10,
63+
display: 'flex' as const,
64+
flexDirection: 'column' as const,
65+
padding: 0,
66+
minWidth: isFullScreen ? minWidth : '',
67+
});
68+
69+
type AssetControlsProps = {
70+
children: React.ReactNode;
71+
'data-testid'?: string;
72+
};
73+
74+
/**
75+
* The asset control row. The network filter sits at the start and
76+
* {@link AssetControlsActions} sits at the end. Only one menu is open at a
77+
* time.
78+
*
79+
* @param props - The component props.
80+
* @param props.children - The filter and the actions group.
81+
* @param props.data-testid
82+
*/
83+
export const AssetControls = ({
84+
children,
85+
'data-testid': dataTestId,
86+
}: AssetControlsProps) => {
87+
const [openId, setOpenId] = useState<string | null>(null);
88+
const toggle = useCallback((id: string) => {
89+
setOpenId((current) => (current === id ? null : id));
90+
}, []);
91+
const close = useCallback(() => {
92+
setOpenId(null);
93+
}, []);
94+
const isOpen = useCallback((id: string) => openId === id, [openId]);
95+
const value = useMemo(
96+
() => ({ isOpen, toggle, close }),
97+
[close, isOpen, toggle],
98+
);
99+
100+
return (
101+
<AssetControlsContext.Provider value={value}>
102+
<Box
103+
className="asset-list-control-bar"
104+
marginHorizontal={4}
105+
paddingTop={4}
106+
paddingBottom={1}
107+
data-testid={dataTestId}
108+
>
109+
<Box
110+
flexDirection={BoxFlexDirection.Row}
111+
justifyContent={BoxJustifyContent.Between}
112+
>
113+
{children}
114+
</Box>
115+
</Box>
116+
</AssetControlsContext.Provider>
117+
);
118+
};
119+
120+
type AssetControlsActionsProps = {
121+
children: React.ReactNode;
122+
};
123+
124+
/**
125+
* The action buttons at the end of the asset control row.
126+
*
127+
* @param props - The component props.
128+
* @param props.children - Sort, options, and refresh buttons.
129+
*/
130+
export const AssetControlsActions = ({
131+
children,
132+
}: AssetControlsActionsProps) => (
133+
<Box
134+
flexDirection={BoxFlexDirection.Row}
135+
alignItems={BoxAlignItems.Center}
136+
justifyContent={BoxJustifyContent.End}
137+
>
138+
{children}
139+
</Box>
140+
);

‎ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.stories.tsx‎

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)