Skip to content

Commit e0a3038

Browse files
committed
fix: hide chain avatar beside Popular Networks in token and activity filters
The filter label uses global enabled network count while the avatar used only popular-EVM "all selected", so one deselected popular chain or added custom network could show an Ethereum icon next to Popular Networks. Fixes #29948
1 parent c1071c4 commit e0a3038

4 files changed

Lines changed: 49 additions & 16 deletions

File tree

app/components/UI/shared/BaseControlBar/BaseControlBar.test.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useNavigation } from '@react-navigation/native';
99
import { strings } from '../../../../../locales/i18n';
1010
import ButtonBase from '../../../../component-library/components/Buttons/Button/foundation/ButtonBase';
1111
import ButtonIcon from '../../../../component-library/components/Buttons/ButtonIcon';
12+
import Avatar from '../../../../component-library/components/Avatars/Avatar';
1213

1314
// Mock dependencies
1415
jest.mock('../../../../util/networks', () => ({
@@ -205,6 +206,8 @@ describe('BaseControlBar', () => {
205206
useNetworksByNamespaceModule.useNetworksByCustomNamespace.mockReturnValue({
206207
areAllNetworksSelected: false,
207208
totalEnabledNetworksCount: 2,
209+
networkCount: 10,
210+
selectedCount: 9,
208211
});
209212
useStylesModule.useStyles.mockReturnValue({ styles: defaultStyles });
210213
useNetworkEnablementModule.useNetworkEnablement.mockReturnValue({
@@ -289,19 +292,28 @@ describe('BaseControlBar', () => {
289292
expect(getByText('wallet.current_network')).toBeTruthy();
290293
});
291294

292-
it('shows network avatar when not all networks selected', () => {
295+
it('does not show network avatar beside "Popular Networks" when multiple networks enabled', () => {
293296
useNetworksByNamespaceModule.useNetworksByCustomNamespace.mockReturnValue(
294297
{
295298
areAllNetworksSelected: false,
296299
totalEnabledNetworksCount: 2,
297300
},
298301
);
299302

300-
renderComponent();
301-
// Avatar should be rendered (tested via component structure)
302-
expect(
303-
useNetworksByNamespaceModule.useNetworksByCustomNamespace,
304-
).toHaveBeenCalled();
303+
const { UNSAFE_queryAllByType } = renderComponent();
304+
expect(UNSAFE_queryAllByType(Avatar)).toHaveLength(0);
305+
});
306+
307+
it('shows network avatar when one network enabled and not all popular selected', () => {
308+
useNetworksByNamespaceModule.useNetworksByCustomNamespace.mockReturnValue(
309+
{
310+
areAllNetworksSelected: false,
311+
totalEnabledNetworksCount: 1,
312+
},
313+
);
314+
315+
const { UNSAFE_getAllByType } = renderComponent();
316+
expect(UNSAFE_getAllByType(Avatar).length).toBeGreaterThan(0);
305317
});
306318

307319
it('does not show network avatar when all networks selected', () => {

app/components/UI/shared/BaseControlBar/BaseControlBar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ const BaseControlBar: React.FC<BaseControlBarProps> = ({
125125
}, [customIsDisabled]);
126126

127127
const displayAllNetworks = totalEnabledNetworksCount > 1;
128+
const showNetworkFilterAvatar =
129+
!displayAllNetworks && !areAllNetworksSelected;
128130

129131
// Shared navigation handlers
130132
const defaultHandleFilterControls = useCallback(() => {
@@ -148,7 +150,7 @@ const BaseControlBar: React.FC<BaseControlBarProps> = ({
148150
// Shared network label rendering
149151
const renderNetworkLabel = () => (
150152
<View style={styles.networkManagerWrapper}>
151-
{!areAllNetworksSelected && (
153+
{showNetworkFilterAvatar && (
152154
<View style={styles.networkAvatarWrapper}>
153155
<Avatar
154156
variant={AvatarVariant.Network}

app/components/Views/ActivityView/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { useCurrentNetworkInfo } from '../../hooks/useCurrentNetworkInfo';
4141
import {
4242
NetworkType,
4343
useNetworksByCustomNamespace,
44-
useNetworksByNamespace,
4544
} from '../../hooks/useNetworksByNamespace/useNetworksByNamespace';
4645
import { useStyles } from '../../hooks/useStyles';
4746
import ErrorBoundary from '../ErrorBoundary';
@@ -96,15 +95,17 @@ const ActivityView = () => {
9695
const networkName = useSelector(selectNetworkName);
9796

9897
const { enabledNetworks, getNetworkInfo } = useCurrentNetworkInfo();
99-
const { areAllNetworksSelected } = useNetworksByNamespace({
98+
const {
99+
areAllNetworksSelected: areAllEvmPopularNetworksEnabled,
100+
totalEnabledNetworksCount,
101+
} = useNetworksByCustomNamespace({
100102
networkType: NetworkType.Popular,
103+
namespace: KnownCaipNamespace.Eip155,
101104
});
102105

103-
const { areAllNetworksSelected: areAllEvmPopularNetworksEnabled } =
104-
useNetworksByCustomNamespace({
105-
networkType: NetworkType.Popular,
106-
namespace: KnownCaipNamespace.Eip155,
107-
});
106+
const displayAllNetworks = totalEnabledNetworksCount > 1;
107+
const showNetworkFilterAvatar =
108+
!displayAllNetworks && !areAllEvmPopularNetworksEnabled;
108109

109110
const currentNetworkName = getNetworkInfo(0)?.networkName;
110111

@@ -255,7 +256,7 @@ const ActivityView = () => {
255256
label={
256257
<>
257258
<View style={styles.networkManagerWrapper}>
258-
{!areAllNetworksSelected && (
259+
{showNetworkFilterAvatar && (
259260
<Avatar
260261
variant={AvatarVariant.Network}
261262
size={AvatarSize.Xs}
@@ -267,7 +268,7 @@ const ActivityView = () => {
267268
variant={TextVariant.BodyMDMedium}
268269
numberOfLines={1}
269270
>
270-
{enabledNetworks.length > 1
271+
{displayAllNetworks
271272
? strings('wallet.popular_networks')
272273
: (currentNetworkName ??
273274
strings('wallet.current_network'))}

app/components/Views/ActivityView/index.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ jest.mock('../../../core/Engine', () => ({
139139
}));
140140

141141
let mockAreAllEvmPopularNetworksEnabled = false;
142+
/** Must mirror controller: label uses totalEnabledNetworksCount > 1 */
143+
let mockTotalEnabledNetworksCount = 2;
142144

143145
jest.mock('../../hooks/useNetworksByNamespace/useNetworksByNamespace', () => ({
144146
useNetworksByNamespace: () => ({
@@ -151,6 +153,7 @@ jest.mock('../../hooks/useNetworksByNamespace/useNetworksByNamespace', () => ({
151153
useNetworksByCustomNamespace: () => ({
152154
networks: [],
153155
areAllNetworksSelected: mockAreAllEvmPopularNetworksEnabled,
156+
totalEnabledNetworksCount: mockTotalEnabledNetworksCount,
154157
}),
155158
NetworkType: {
156159
Popular: 'popular',
@@ -286,6 +289,7 @@ describe('ActivityView', () => {
286289
mockPerpsEnabled = false;
287290
mockPredictEnabled = false;
288291
mockAreAllEvmPopularNetworksEnabled = false;
292+
mockTotalEnabledNetworksCount = 2;
289293
clearRenderedTabs();
290294
mockRoute.params = {};
291295
});
@@ -301,12 +305,26 @@ describe('ActivityView', () => {
301305
});
302306

303307
it('displays "Popular networks" text when multiple networks are enabled', () => {
308+
mockTotalEnabledNetworksCount = 2;
309+
mockAreAllEvmPopularNetworksEnabled = false;
310+
304311
const { getByText } = renderComponent(mockInitialState);
305312

306313
expect(getByText('Popular networks')).toBeOnTheScreen();
307314
});
308315

316+
it('does not render network avatar beside Popular networks when multiple networks enabled', () => {
317+
mockTotalEnabledNetworksCount = 2;
318+
mockAreAllEvmPopularNetworksEnabled = false;
319+
320+
const { getByText, queryByTestId } = renderComponent(mockInitialState);
321+
322+
expect(getByText('Popular networks')).toBeOnTheScreen();
323+
expect(queryByTestId('network-avatar-image')).toBeNull();
324+
});
325+
309326
it('displays network name when single network is enabled', () => {
327+
mockTotalEnabledNetworksCount = 1;
310328
const singleNetworkInfo = {
311329
enabledNetworks: [{ chainId: '0x1', enabled: true }],
312330
getNetworkInfo: jest.fn(() => ({

0 commit comments

Comments
 (0)