Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 13 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 @@ export interface FilterButtonProps {
ellipsizeMode?: 'tail' | 'head' | 'middle' | 'clip';
/** Optional Tailwind class overrides for layout in custom contexts */
twClassName?: string;
/** Optional icon name to replace the default ArrowDown icon */
iconName?: IconName;
}

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

Expand All @@ -43,8 +46,13 @@ export const FilterButton: React.FC<FilterButtonProps> = ({
disabled={disabled}
>
<View style={tw`flex-row items-center justify-center gap-1`}>
<Icon
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 +72,8 @@ export interface FilterBarProps {
priceChangeButtonText: string;
onPriceChangePress: () => void;
isPriceChangeDisabled?: boolean;
/** Optional icon name for the price change button */
priceChangeIconName?: IconName;

networkName: string;
onNetworkPress: () => void;
Expand All @@ -81,6 +91,7 @@ const FilterBar: React.FC<FilterBarProps> = ({
priceChangeButtonText,
onPriceChangePress,
isPriceChangeDisabled = false,
priceChangeIconName,
networkName,
onNetworkPress,
extraFilters,
Expand All @@ -95,6 +106,7 @@ const FilterBar: React.FC<FilterBarProps> = ({
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