Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 74 additions & 57 deletions app/components/UI/CollectibleContracts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
RefreshControl,
ActivityIndicator,
} from 'react-native';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer using useTailwind hook because we can use the twClassName prop directly in the CollectiblesEmptyState component


import { FlashList } from '@shopify/flash-list';
import { connect, useSelector } from 'react-redux';
import { fontStyles } from '../../../styles/common';
Expand Down Expand Up @@ -176,7 +176,6 @@ const CollectibleContracts = ({
}) => {
// Start tracing component loading
const isFirstRender = useRef(true);
const tw = useTailwind();
if (isFirstRender.current) {
trace({ name: TraceName.CollectibleContractsComponent });
}
Expand Down Expand Up @@ -500,16 +499,21 @@ const CollectibleContracts = ({

const renderEmpty = useCallback(
() => (
<CollectiblesEmptyState
onDiscoverCollectibles={goToAddCollectible}
actionButtonProps={{
testID: WalletViewSelectorsIDs.IMPORT_NFT_BUTTON,
isDisabled: !isAddNFTEnabled,
}}
style={tw.style('mx-auto')}
/>
<>
{!isNftFetchingProgress && (
<CollectiblesEmptyState
onAction={goToAddCollectible}
actionButtonProps={{
testID: WalletViewSelectorsIDs.IMPORT_NFT_BUTTON,
isDisabled: !isAddNFTEnabled,
}}
twClassName="mx-auto mt-4"
testID="collectibles-empty-state"
/>
)}
</>
),
[goToAddCollectible, tw, isAddNFTEnabled],
[goToAddCollectible, isAddNFTEnabled, isNftFetchingProgress],
);

const renderList = useCallback(
Expand Down Expand Up @@ -564,6 +568,17 @@ const CollectibleContracts = ({
chainId: firstEnabledChainId,
});

// Determine if we should show the network selector
// Show when there are NFTs (contracts, collectibles, or favorites)
// Memoized to avoid unnecessary recalculations on every render
const shouldShowNetworkSelector = useMemo(
() =>
filteredCollectibleContracts.length > 0 ||
collectibles.length > 0 ||
favoriteCollectibles.length > 0,
[filteredCollectibleContracts, collectibles, favoriteCollectibles],
);

// End trace when component has finished initial loading
useEffect(() => {
endTrace({ name: TraceName.CollectibleContractsComponent });
Expand All @@ -575,60 +590,62 @@ const CollectibleContracts = ({
style={styles.BarWrapper}
testID={WalletViewSelectorsIDs.NFT_TAB_CONTAINER}
>
<View style={styles.actionBarWrapper}>
<View style={styles.controlButtonOuterWrapper}>
<ButtonBase
testID={WalletViewSelectorsIDs.COLLECTIBLES_NETWORK_FILTER}
label={
<>
{isRemoveGlobalNetworkSelectorEnabled() ? (
<View style={styles.networkManagerWrapper}>
{!areAllNetworksSelected && (
<Avatar
variant={AvatarVariant.Network}
size={AvatarSize.Xs}
name={networkName}
imageSource={networkImageSource}
/>
)}
{shouldShowNetworkSelector && (
Comment on lines -578 to +593
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad visualization of changes here but we are changing the network selector to be rendered conditionally. No other changes

<View style={styles.actionBarWrapper}>
<View style={styles.controlButtonOuterWrapper}>
<ButtonBase
testID={WalletViewSelectorsIDs.COLLECTIBLES_NETWORK_FILTER}
label={
<>
{isRemoveGlobalNetworkSelectorEnabled() ? (
<View style={styles.networkManagerWrapper}>
{!areAllNetworksSelected && (
<Avatar
variant={AvatarVariant.Network}
size={AvatarSize.Xs}
name={networkName}
imageSource={networkImageSource}
/>
)}
<TextComponent
variant={TextVariant.BodyMDMedium}
style={styles.controlButtonText}
numberOfLines={1}
>
{enabledNetworks.length > 1
? strings('wallet.popular_networks')
: currentNetworkName ??
strings('wallet.current_network')}
</TextComponent>
</View>
) : (
<TextComponent
variant={TextVariant.BodyMDMedium}
style={styles.controlButtonText}
numberOfLines={1}
>
{enabledNetworks.length > 1
{isAllNetworks && isPopularNetwork && isEvmSelected
? strings('wallet.popular_networks')
: currentNetworkName ??
strings('wallet.current_network')}
: networkName ?? strings('wallet.current_network')}
</TextComponent>
</View>
) : (
<TextComponent
variant={TextVariant.BodyMDMedium}
style={styles.controlButtonText}
numberOfLines={1}
>
{isAllNetworks && isPopularNetwork && isEvmSelected
? strings('wallet.popular_networks')
: networkName ?? strings('wallet.current_network')}
</TextComponent>
)}
</>
}
isDisabled={isDisabled}
onPress={showFilterControls}
endIconName={
isEvmSelected || isMultichainAccountsState2Enabled
? IconName.ArrowDown
: undefined
}
style={
isDisabled ? styles.controlButtonDisabled : styles.controlButton
}
disabled={isDisabled}
/>
)}
</>
}
isDisabled={isDisabled}
onPress={showFilterControls}
endIconName={
isEvmSelected || isMultichainAccountsState2Enabled
? IconName.ArrowDown
: undefined
}
style={
isDisabled ? styles.controlButtonDisabled : styles.controlButton
}
disabled={isDisabled}
/>
</View>
</View>
</View>
)}
{renderList()}
</View>
);
Expand Down
Loading
Loading