Skip to content

Commit d9edc95

Browse files
chore: hiding network selectors in empty tabs
1 parent cec4495 commit d9edc95

File tree

10 files changed

+211
-122
lines changed

10 files changed

+211
-122
lines changed

app/components/UI/CollectibleContracts/index.js

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
RefreshControl,
1313
ActivityIndicator,
1414
} from 'react-native';
15-
import { useTailwind } from '@metamask/design-system-twrnc-preset';
15+
1616
import { FlashList } from '@shopify/flash-list';
1717
import { connect, useSelector } from 'react-redux';
1818
import { fontStyles } from '../../../styles/common';
@@ -176,7 +176,6 @@ const CollectibleContracts = ({
176176
}) => {
177177
// Start tracing component loading
178178
const isFirstRender = useRef(true);
179-
const tw = useTailwind();
180179
if (isFirstRender.current) {
181180
trace({ name: TraceName.CollectibleContractsComponent });
182181
}
@@ -500,16 +499,20 @@ const CollectibleContracts = ({
500499

501500
const renderEmpty = useCallback(
502501
() => (
503-
<CollectiblesEmptyState
504-
onDiscoverCollectibles={goToAddCollectible}
505-
actionButtonProps={{
506-
testID: WalletViewSelectorsIDs.IMPORT_NFT_BUTTON,
507-
isDisabled: !isAddNFTEnabled,
508-
}}
509-
style={tw.style('mx-auto')}
510-
/>
502+
<>
503+
{!isNftFetchingProgress && (
504+
<CollectiblesEmptyState
505+
onAction={goToAddCollectible}
506+
actionButtonProps={{
507+
testID: WalletViewSelectorsIDs.IMPORT_NFT_BUTTON,
508+
isDisabled: !isAddNFTEnabled,
509+
}}
510+
twClassName="mx-auto mt-4"
511+
/>
512+
)}
513+
</>
511514
),
512-
[goToAddCollectible, tw, isAddNFTEnabled],
515+
[goToAddCollectible, isAddNFTEnabled, isNftFetchingProgress],
513516
);
514517

515518
const renderList = useCallback(
@@ -564,6 +567,13 @@ const CollectibleContracts = ({
564567
chainId: firstEnabledChainId,
565568
});
566569

570+
// Determine if we should show the network selector
571+
// Show when there are NFTs (contracts, collectibles, or favorites) and not in loading state
572+
const shouldShowNetworkSelector =
573+
filteredCollectibleContracts.length > 0 ||
574+
collectibles.length > 0 ||
575+
favoriteCollectibles.length > 0;
576+
567577
// End trace when component has finished initial loading
568578
useEffect(() => {
569579
endTrace({ name: TraceName.CollectibleContractsComponent });
@@ -575,60 +585,62 @@ const CollectibleContracts = ({
575585
style={styles.BarWrapper}
576586
testID={WalletViewSelectorsIDs.NFT_TAB_CONTAINER}
577587
>
578-
<View style={styles.actionBarWrapper}>
579-
<View style={styles.controlButtonOuterWrapper}>
580-
<ButtonBase
581-
testID={WalletViewSelectorsIDs.COLLECTIBLES_NETWORK_FILTER}
582-
label={
583-
<>
584-
{isRemoveGlobalNetworkSelectorEnabled() ? (
585-
<View style={styles.networkManagerWrapper}>
586-
{!areAllNetworksSelected && (
587-
<Avatar
588-
variant={AvatarVariant.Network}
589-
size={AvatarSize.Xs}
590-
name={networkName}
591-
imageSource={networkImageSource}
592-
/>
593-
)}
588+
{shouldShowNetworkSelector && (
589+
<View style={styles.actionBarWrapper}>
590+
<View style={styles.controlButtonOuterWrapper}>
591+
<ButtonBase
592+
testID={WalletViewSelectorsIDs.COLLECTIBLES_NETWORK_FILTER}
593+
label={
594+
<>
595+
{isRemoveGlobalNetworkSelectorEnabled() ? (
596+
<View style={styles.networkManagerWrapper}>
597+
{!areAllNetworksSelected && (
598+
<Avatar
599+
variant={AvatarVariant.Network}
600+
size={AvatarSize.Xs}
601+
name={networkName}
602+
imageSource={networkImageSource}
603+
/>
604+
)}
605+
<TextComponent
606+
variant={TextVariant.BodyMDMedium}
607+
style={styles.controlButtonText}
608+
numberOfLines={1}
609+
>
610+
{enabledNetworks.length > 1
611+
? strings('wallet.popular_networks')
612+
: currentNetworkName ??
613+
strings('wallet.current_network')}
614+
</TextComponent>
615+
</View>
616+
) : (
594617
<TextComponent
595618
variant={TextVariant.BodyMDMedium}
596619
style={styles.controlButtonText}
597620
numberOfLines={1}
598621
>
599-
{enabledNetworks.length > 1
622+
{isAllNetworks && isPopularNetwork && isEvmSelected
600623
? strings('wallet.popular_networks')
601-
: currentNetworkName ??
602-
strings('wallet.current_network')}
624+
: networkName ?? strings('wallet.current_network')}
603625
</TextComponent>
604-
</View>
605-
) : (
606-
<TextComponent
607-
variant={TextVariant.BodyMDMedium}
608-
style={styles.controlButtonText}
609-
numberOfLines={1}
610-
>
611-
{isAllNetworks && isPopularNetwork && isEvmSelected
612-
? strings('wallet.popular_networks')
613-
: networkName ?? strings('wallet.current_network')}
614-
</TextComponent>
615-
)}
616-
</>
617-
}
618-
isDisabled={isDisabled}
619-
onPress={showFilterControls}
620-
endIconName={
621-
isEvmSelected || isMultichainAccountsState2Enabled
622-
? IconName.ArrowDown
623-
: undefined
624-
}
625-
style={
626-
isDisabled ? styles.controlButtonDisabled : styles.controlButton
627-
}
628-
disabled={isDisabled}
629-
/>
626+
)}
627+
</>
628+
}
629+
isDisabled={isDisabled}
630+
onPress={showFilterControls}
631+
endIconName={
632+
isEvmSelected || isMultichainAccountsState2Enabled
633+
? IconName.ArrowDown
634+
: undefined
635+
}
636+
style={
637+
isDisabled ? styles.controlButtonDisabled : styles.controlButton
638+
}
639+
disabled={isDisabled}
640+
/>
641+
</View>
630642
</View>
631-
</View>
643+
)}
632644
{renderList()}
633645
</View>
634646
);

app/components/UI/CollectibleContracts/index.test.tsx

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,13 @@ describe('CollectibleContracts', () => {
11421142
},
11431143
allNftContracts: {
11441144
[MOCK_ADDRESS]: {
1145-
'0x1': [],
1145+
'0x1': [
1146+
{
1147+
address: '0x1234567890123456789012345678901234567890',
1148+
name: 'Test NFT Collection',
1149+
symbol: 'TNFT',
1150+
},
1151+
],
11461152
},
11471153
},
11481154
},
@@ -1154,7 +1160,18 @@ describe('CollectibleContracts', () => {
11541160
push: jest.fn(),
11551161
};
11561162
const { getByTestId } = renderWithProvider(
1157-
<CollectibleContracts navigation={mockNavigation} />,
1163+
<CollectibleContracts
1164+
navigation={mockNavigation}
1165+
collectibleContracts={{
1166+
'0x1': [
1167+
{
1168+
address: '0x1234567890123456789012345678901234567890',
1169+
name: 'Test NFT Collection',
1170+
symbol: 'TNFT',
1171+
},
1172+
],
1173+
}}
1174+
/>,
11581175
{
11591176
state: mockState,
11601177
},
@@ -1208,7 +1225,13 @@ describe('CollectibleContracts', () => {
12081225
},
12091226
allNftContracts: {
12101227
[MOCK_ADDRESS]: {
1211-
'0x1': [],
1228+
'0x1': [
1229+
{
1230+
address: '0x1234567890123456789012345678901234567890',
1231+
name: 'Test NFT Collection',
1232+
symbol: 'TNFT',
1233+
},
1234+
],
12121235
},
12131236
},
12141237
},
@@ -1220,7 +1243,18 @@ describe('CollectibleContracts', () => {
12201243
push: jest.fn(),
12211244
};
12221245
const { getByTestId } = renderWithProvider(
1223-
<CollectibleContracts navigation={mockNavigation} />,
1246+
<CollectibleContracts
1247+
navigation={mockNavigation}
1248+
collectibleContracts={{
1249+
'0x1': [
1250+
{
1251+
address: '0x1234567890123456789012345678901234567890',
1252+
name: 'Test NFT Collection',
1253+
symbol: 'TNFT',
1254+
},
1255+
],
1256+
}}
1257+
/>,
12241258
{
12251259
state: mockState,
12261260
},
@@ -1373,17 +1407,36 @@ describe('CollectibleContracts', () => {
13731407
},
13741408
allNftContracts: {
13751409
[MOCK_ADDRESS]: {
1376-
'0x1': [],
1410+
'0x1': [
1411+
{
1412+
address: '0x1234567890123456789012345678901234567890',
1413+
name: 'Test NFT Collection',
1414+
symbol: 'TNFT',
1415+
},
1416+
],
13771417
},
13781418
},
13791419
},
13801420
},
13811421
},
13821422
};
13831423

1384-
const { getByText } = renderWithProvider(<CollectibleContracts />, {
1385-
state: mockState,
1386-
});
1424+
const { getByText } = renderWithProvider(
1425+
<CollectibleContracts
1426+
collectibleContracts={{
1427+
'0x1': [
1428+
{
1429+
address: '0x1234567890123456789012345678901234567890',
1430+
name: 'Test NFT Collection',
1431+
symbol: 'TNFT',
1432+
},
1433+
],
1434+
}}
1435+
/>,
1436+
{
1437+
state: mockState,
1438+
},
1439+
);
13871440

13881441
expect(getByText('Popular networks')).toBeDefined();
13891442
});

app/components/UI/CollectiblesEmptyState/CollectiblesEmptyState.test.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ describe('CollectiblesEmptyState', () => {
2424
// Button should not render when no onAction is provided
2525
});
2626

27-
it('calls onDiscoverCollectibles when action button is pressed', () => {
28-
const mockOnDiscoverCollectibles = jest.fn();
27+
it('calls onAction when action button is pressed', () => {
28+
const mockOnAction = jest.fn();
2929
const { getByText } = renderWithProvider(
30-
<CollectiblesEmptyState
31-
onDiscoverCollectibles={mockOnDiscoverCollectibles}
32-
/>,
30+
<CollectiblesEmptyState onAction={mockOnAction} />,
3331
);
3432

3533
fireEvent.press(getByText('Import NFTs'));
36-
expect(mockOnDiscoverCollectibles).toHaveBeenCalledTimes(1);
34+
expect(mockOnAction).toHaveBeenCalledTimes(1);
3735
});
3836
});

app/components/UI/CollectiblesEmptyState/CollectiblesEmptyState.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import emptyStateNftsLight from '../../../images/empty-state-nfts-light.png';
1111
import emptyStateNftsDark from '../../../images/empty-state-nfts-dark.png';
1212

1313
interface CollectiblesEmptyStateProps extends TabEmptyStateProps {
14-
onDiscoverCollectibles?: () => void;
14+
onAction?: () => void;
1515
}
1616

1717
export const CollectiblesEmptyState: React.FC<CollectiblesEmptyStateProps> = ({
18-
onDiscoverCollectibles,
18+
onAction,
1919
...props
2020
}) => {
2121
const collectiblesImage = useAssetFromTheme(
@@ -34,7 +34,7 @@ export const CollectiblesEmptyState: React.FC<CollectiblesEmptyStateProps> = ({
3434
}
3535
description={strings('wallet.nft_empty_description')}
3636
actionButtonText={strings('wallet.discover_nfts')}
37-
onAction={onDiscoverCollectibles}
37+
onAction={onAction}
3838
{...props}
3939
/>
4040
);

app/components/UI/DeFiPositions/DeFiPositionsList.test.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,6 @@ describe('DeFiPositionsList', () => {
328328
expect(
329329
await findByTestId(WalletViewSelectorsIDs.DEFI_POSITIONS_CONTAINER),
330330
).toBeOnTheScreen();
331-
expect(
332-
await findByTestId(WalletViewSelectorsIDs.DEFI_POSITIONS_NETWORK_FILTER),
333-
).toBeOnTheScreen();
334331
expect(
335332
await findByText(`Lend, borrow, and trade, right in your wallet.`),
336333
).toBeOnTheScreen();
@@ -446,11 +443,6 @@ describe('DeFiPositionsList', () => {
446443
expect(
447444
await findByTestId(WalletViewSelectorsIDs.DEFI_POSITIONS_CONTAINER),
448445
).toBeOnTheScreen();
449-
expect(
450-
await findByTestId(
451-
WalletViewSelectorsIDs.DEFI_POSITIONS_NETWORK_FILTER,
452-
),
453-
).toBeOnTheScreen();
454446
expect(
455447
await findByText(`Lend, borrow, and trade, right in your wallet.`),
456448
).toBeOnTheScreen();

app/components/UI/DeFiPositions/DeFiPositionsList.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useMemo } from 'react';
22
import { View, FlatList } from 'react-native';
33
import { strings } from '../../../../locales/i18n';
44
import { useSelector } from 'react-redux';
5-
import { useTailwind } from '@metamask/design-system-twrnc-preset';
65
import {
76
selectChainId,
87
selectIsAllNetworks,
@@ -41,7 +40,6 @@ export interface DeFiPositionsListProps {
4140

4241
const DeFiPositionsList: React.FC<DeFiPositionsListProps> = () => {
4342
const { styles } = useStyles(styleSheet, undefined);
44-
const tw = useTailwind();
4543
const isAllNetworks = useSelector(selectIsAllNetworks);
4644
const currentChainId = useSelector(selectChainId) as Hex;
4745
const tokenSortConfig = useSelector(selectTokenSortConfig);
@@ -138,8 +136,7 @@ const DeFiPositionsList: React.FC<DeFiPositionsListProps> = () => {
138136
// No positions found for the current account
139137
return (
140138
<View testID={WalletViewSelectorsIDs.DEFI_POSITIONS_CONTAINER}>
141-
<DeFiPositionsControlBar />
142-
<DefiEmptyState style={tw.style('mx-auto')} />
139+
<DefiEmptyState twClassName="mx-auto mt-4" />
143140
</View>
144141
);
145142
}

app/components/UI/Perps/Views/PerpsTabView/PerpsTabView.styles.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ const styleSheet = (params: { theme: Theme }) => {
99
tradeInfoContainer: {
1010
paddingBottom: 12,
1111
},
12-
firstTimeIcon: {
13-
width: 48,
14-
height: 48,
15-
marginTop: 16,
16-
marginBottom: 8,
17-
},
1812
wrapper: {
1913
flex: 1,
2014
backgroundColor: colors.background.default,
@@ -25,7 +19,6 @@ const styleSheet = (params: { theme: Theme }) => {
2519
contentContainer: {
2620
flexGrow: 1,
2721
},
28-
section: {},
2922
sectionHeader: {
3023
flexDirection: 'row',
3124
justifyContent: 'space-between',

0 commit comments

Comments
 (0)