Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 15 additions & 1 deletion app/components/UI/Trending/components/FilterBar/FilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
ellipsizeMode?: 'tail' | 'head' | 'middle' | 'clip';
/** Optional Tailwind class overrides for layout in custom contexts */
twClassName?: string;
/** Optional icon name to show before the label (e.g., for sort direction indicators) */
iconName?: IconName;
}

export const FilterButton: React.FC<FilterButtonProps> = ({
Expand All @@ -27,6 +29,7 @@
numberOfLines,
ellipsizeMode,
twClassName,
iconName,
}) => {
const tw = useTailwind();

Expand All @@ -43,8 +46,15 @@
disabled={disabled}
>
<View style={tw`flex-row items-center justify-center gap-1`}>
{iconName && (
<Icon

Check warning on line 50 in app/components/UI/Trending/components/FilterBar/FilterBar.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'Icon' is deprecated.

See more on https://sonarcloud.io/project/issues?id=metamask-mobile&issues=AZ4CEtWz3p748isTBQp_&open=AZ4CEtWz3p748isTBQp_&pullRequest=29809
name={iconName}
color={IconColor.Alternative}
size={IconSize.Xs}
/>
)}
<Text
style={tw`min-w-0 shrink text-[14px] font-medium text-default`}
style={tw`min-w-0 text-[14px] font-medium text-default`}
Comment thread
sahar-fehri marked this conversation as resolved.
Outdated
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
numberOfLines={numberOfLines}
ellipsizeMode={ellipsizeMode}
>
Expand All @@ -64,6 +74,8 @@
priceChangeButtonText: string;
onPriceChangePress: () => void;
isPriceChangeDisabled?: boolean;
/** Optional icon name for the price change button */
priceChangeIconName?: IconName;

networkName: string;
onNetworkPress: () => void;
Expand All @@ -81,6 +93,7 @@
priceChangeButtonText,
onPriceChangePress,
isPriceChangeDisabled = false,
priceChangeIconName,
networkName,
onNetworkPress,
extraFilters,
Expand All @@ -95,6 +108,7 @@
label={priceChangeButtonText}
onPress={onPriceChangePress}
disabled={isPriceChangeDisabled}
iconName={priceChangeIconName}
/>
<View style={tw`ml-2 min-w-0 shrink flex-row items-center gap-2`}>
<FilterButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const TokenListPageLayout: React.FC<TokenListPageLayoutProps> = ({
priceChangeButtonText={filters.priceChangeButtonText}
onPriceChangePress={filters.handlePriceChangePress}
isPriceChangeDisabled={searchResults.length === 0}
priceChangeIconName={filters.priceChangeSortDirectionIcon}
networkName={filters.selectedNetworkName}
onNetworkPress={filters.handleAllNetworksPress}
extraFilters={extraFilters}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TimeOption,
} from '../../components/TrendingTokensBottomSheet';
import type { CaipChainId } from '@metamask/utils';
import { IconName } from '../../../../../component-library/components/Icons/Icon';

const mockGoBack = jest.fn();
jest.mock('@react-navigation/native', () => ({
Expand Down Expand Up @@ -284,6 +285,50 @@ describe('useTokenListFilters', () => {
});
});

describe('priceChangeSortDirectionIcon', () => {
it('returns Arrow2Down for descending sort direction', () => {
const { result } = renderFilters();

expect(result.current.priceChangeSortDirectionIcon).toBe(
IconName.Arrow2Down,
);
});

it('returns Arrow2Up for ascending sort direction', () => {
const { result } = renderFilters();

act(() =>
result.current.handlePriceChangeSelect(
PriceChangeOption.Volume,
SortDirection.Ascending,
),
);

expect(result.current.priceChangeSortDirectionIcon).toBe(
IconName.Arrow2Up,
);
});

it('updates when sort direction changes', () => {
const { result } = renderFilters();

expect(result.current.priceChangeSortDirectionIcon).toBe(
IconName.Arrow2Down,
);

act(() =>
result.current.handlePriceChangeSelect(
PriceChangeOption.PriceChange,
SortDirection.Ascending,
),
);

expect(result.current.priceChangeSortDirectionIcon).toBe(
IconName.Arrow2Up,
);
});
});

describe('filterContext', () => {
it('reflects current filter state', () => {
const { result } = renderFilters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import type { TrendingFilterContext } from '../../components/TrendingTokensList/TrendingTokensList';
import TrendingFeedSessionManager from '../../services/TrendingFeedSessionManager';
import { useNetworkName } from '../useNetworkName/useNetworkName';
import { IconName } from '../../../../../component-library/components/Icons/Icon';

interface UseTokenListFiltersOptions {
/**
Expand Down Expand Up @@ -49,6 +50,7 @@ export interface TokenListFilters {
) => void;
handlePriceChangePress: () => void;
priceChangeButtonText: string;
priceChangeSortDirectionIcon: IconName;

// Time
selectedTimeOption: TimeOption;
Expand Down Expand Up @@ -189,6 +191,14 @@ export const useTokenListFilters = (
}
}, [selectedPriceChangeOption]);

const priceChangeSortDirectionIcon = useMemo(
() =>
priceChangeSortDirection === SortDirection.Ascending
? IconName.Arrow2Up
: IconName.Arrow2Down,
[priceChangeSortDirection],
);

const filterContext: TrendingFilterContext = useMemo(
() => ({
timeFilter: selectedTimeOption,
Expand Down Expand Up @@ -226,6 +236,7 @@ export const useTokenListFilters = (
handlePriceChangeSelect,
handlePriceChangePress,
priceChangeButtonText,
priceChangeSortDirectionIcon,
selectedTimeOption,
setSelectedTimeOption,
refreshing,
Expand Down
Loading