Skip to content

Commit ddc377c

Browse files
committed
chore: minor changes
1 parent c3ba7cb commit ddc377c

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

app/components/UI/Perps/hooks/usePerpsMarketListView.test.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,27 +305,50 @@ describe('usePerpsMarketListView', () => {
305305
});
306306
});
307307

308-
it('defaultSortOptionId overrides the saved sort preference', () => {
308+
it('defaultSortOptionId overrides the saved sort option and resets direction to default', () => {
309309
let selectorCallCount = 0;
310310
mockUseSelector.mockImplementation(() => {
311311
selectorCallCount++;
312312
if (selectorCallCount % 2 === 1) {
313313
return ['BTC'];
314314
}
315-
// Saved preference is volume/desc
316-
return { optionId: 'volume', direction: 'desc' };
315+
// Saved preference is volume/asc — user had it sorted ascending
316+
return { optionId: 'volume', direction: 'asc' };
317317
});
318318

319319
renderHook(() =>
320320
usePerpsMarketListView({ defaultSortOptionId: 'priceChange' }),
321321
);
322322

323+
// Option overridden → direction must reset to default (desc), not carry 'asc'
323324
expect(mockUsePerpsSorting).toHaveBeenCalledWith({
324325
initialOptionId: 'priceChange',
325326
initialDirection: 'desc',
326327
});
327328
});
328329

330+
it('preserves saved direction when defaultSortOptionId matches the saved option', () => {
331+
let selectorCallCount = 0;
332+
mockUseSelector.mockImplementation(() => {
333+
selectorCallCount++;
334+
if (selectorCallCount % 2 === 1) {
335+
return ['BTC'];
336+
}
337+
// Saved preference is priceChange/asc
338+
return { optionId: 'priceChange', direction: 'asc' };
339+
});
340+
341+
renderHook(() =>
342+
usePerpsMarketListView({ defaultSortOptionId: 'priceChange' }),
343+
);
344+
345+
// Same option — carry the saved direction, don't reset
346+
expect(mockUsePerpsSorting).toHaveBeenCalledWith({
347+
initialOptionId: 'priceChange',
348+
initialDirection: 'asc',
349+
});
350+
});
351+
329352
it('falls back to saved sort preference when defaultSortOptionId is not provided', () => {
330353
let selectorCallCount = 0;
331354
mockUseSelector.mockImplementation(() => {

app/components/UI/Perps/hooks/usePerpsMarketListView.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { usePerpsMarkets } from './usePerpsMarkets';
44
import { usePerpsSearch } from './usePerpsSearch';
55
import { usePerpsSorting } from './usePerpsSorting';
66
import {
7+
MARKET_SORTING_CONFIG,
78
sortMarkets,
89
type PerpsMarketData,
910
type MarketTypeFilter,
@@ -203,11 +204,19 @@ export const usePerpsMarketListView = ({
203204
}, [searchedMarkets, marketTypeFilter]);
204205

205206
// Use sorting hook for sort state and sorting logic.
206-
// defaultSortOptionId (from navigation params) takes precedence over the saved user preference.
207+
// defaultSortOptionId (from navigation params) takes precedence over the saved user
208+
// preference. When it overrides a *different* option, reset direction to the default
209+
// so the market list opens sorted the same way the explore feed displayed it (always desc).
210+
// When there is no override, or the override matches the saved option, carry the saved direction.
211+
const isOptionOverridden =
212+
defaultSortOptionId !== undefined &&
213+
defaultSortOptionId !== savedSortPreference.optionId;
207214
const sortingHook = usePerpsSorting({
208215
initialOptionId: (defaultSortOptionId ??
209216
savedSortPreference.optionId) as SortOptionId,
210-
initialDirection: savedSortPreference.direction,
217+
initialDirection: isOptionOverridden
218+
? MARKET_SORTING_CONFIG.DefaultDirection
219+
: savedSortPreference.direction,
211220
});
212221

213222
// Wrap handleOptionChange to save preference to PerpsController

0 commit comments

Comments
 (0)