Skip to content

fix(perps): decouple home sort from market list and remove leverage skeleton blink [TAT-2544 TAT-2454] cp-7.66.0#25977

Merged
gambinish merged 11 commits intomainfrom
perps/tat-2544-tat-2454
Feb 13, 2026
Merged

fix(perps): decouple home sort from market list and remove leverage skeleton blink [TAT-2544 TAT-2454] cp-7.66.0#25977
gambinish merged 11 commits intomainfrom
perps/tat-2544-tat-2454

Conversation

@gambinish
Copy link
Copy Markdown
Member

@gambinish gambinish commented Feb 11, 2026

Description

  1. Decouple Perps Home sorting from Market List sorting

The Perps Home sections (Crypto, Stocks, Commodities, Forex) were reading the same sort preference that the Market List search writes to. This meant that when a user changed the sort in the market search (e.g., to "Funding Rate"), the home screen sections would also re-sort — which isn't the intended behavior. Home sections should always surface the highest-volume markets regardless of what the user does in search.

The fix removes the dependency on selectPerpsMarketFilterPreferences in usePerpsHomeData and hardcodes the home sort to Volume descending. The Market List continues to use and persist its own sort preference independently.

  1. Remove skeleton loader blink on leverage bottom sheet

When adjusting leverage via the slider or preset buttons, the liquidation banner and liquidation price would rapidly toggle between a skeleton placeholder and the actual value. This created a jarring "blink" effect — especially during slider drags, where every tick triggered the skeleton. The current price row right below it just updates its value in place with no loading state, making the inconsistency more noticeable.

The fix caches the last valid liquidation price and percentage in refs, so the UI always shows either the latest calculated value or the previously known one. On first open (before any calculation has completed), it shows -- as a placeholder instead of a skeleton shimmer. The banner colors (safe/caution/medium/high) are unaffected because they're driven by the leverage slider position, not the liquidation price calculation.

Changelog

CHANGELOG entry: Fixed a flickering skeleton loader on the leverage bottom sheet when adjusting leverage, and decoupled Perps Home sorting from the market search sort preference so home sections always sort by volume.

Related issues

Fixes: TAT-2544
Fixes: TAT-2454

Manual testing steps

Feature: Perps Home sections sort independently from Market List

  Scenario: Home sections always sort by volume
    Given user is on the Perps Home screen

    When user opens the Market List and changes sort to "Funding Rate"
    And user navigates back to Perps Home
    Then all home sections (Crypto, Stocks, Commodities, Forex) remain sorted by descending volume

Feature: Leverage bottom sheet liquidation display

  Scenario: No skeleton blink when dragging leverage slider
    Given user opens the leverage bottom sheet on any market

    When user drags the leverage slider back and forth
    Then the liquidation banner text and price update in place without skeleton flashing
    And the banner color transitions smoothly based on leverage risk level

  Scenario: No skeleton blink when tapping preset buttons
    Given user opens the leverage bottom sheet

    When user taps different preset leverage buttons (2x, 5x, 10x, etc.)
    Then the liquidation values tick to the new values without a skeleton placeholder appearing

  Scenario: Initial open shows placeholder
    Given user opens the leverage bottom sheet for the first time

    When the liquidation price has not yet been calculated
    Then the liquidation price and percentage show "--" until the first value arrives

Screenshots/Recordings

Screen.Recording.2026-02-11.at.10.46.59.AM.mov
Screen.Recording.2026-02-11.at.10.47.41.AM.mov

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Touches user-facing trading UI state around liquidation calculations and introduces timing/cache logic that could regress displayed values if edge cases slip through, though changes are localized and covered by updated tests.

Overview
Fixes Perps Home market sections to always sort by volume (default direction), removing their dependency on the Market List’s persisted sort preference so Home no longer re-sorts when users change Market List search sorting.

Reworks the leverage bottom sheet liquidation display to avoid flicker and stale values: caches the last valid liquidation price for passive updates, shows -- when no value is available, and only shows skeleton placeholders after a user-initiated leverage change (with a minimum display time to avoid stale in-flight responses clearing loading too early). Also adds a fixed minHeight to the warning container to prevent layout shift when the percentage wraps.

Updates/expands tests to mock react-native-skeleton-placeholder and to cover placeholder vs. skeleton behavior, including ensuring stale cached prices aren’t shown after leverage changes while pressing the already-active leverage does not trigger loading UI.

Written by Cursor Bugbot for commit bbd35e3. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-perps Perps team label Feb 11, 2026
@gambinish gambinish added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Feb 11, 2026
@gambinish gambinish marked this pull request as ready for review February 11, 2026 20:25
@gambinish gambinish requested a review from a team as a code owner February 11, 2026 20:25
geositta
geositta previously approved these changes Feb 11, 2026
Copy link
Copy Markdown
Contributor

@geositta geositta left a comment

Choose a reason for hiding this comment

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

I think we should probably have a follow up because using the cached price here is a valid decision quality risk: user could choose leverage based on a stale displayed liquidation price, especially on more volatile assets. If they leave the card open for a minute or two the price could diverge considerably. The other scenario of a mismatch would be a HL API error.

@aganglada aganglada removed the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Feb 12, 2026
@aganglada aganglada changed the title fix(perps): decouple home sort from market list and remove leverage skeleton blink [TAT-2544 TAT-2454] fix(perps): decouple home sort from market list and remove leverage skeleton blink [TAT-2544 TAT-2454] cp-7.66.0 Feb 12, 2026
@gambinish
Copy link
Copy Markdown
Member Author

gambinish commented Feb 12, 2026

@geositta I ended up with this as a solution:

  1. Show skeleton when changing leverage. This was where there was the most discrepancy between the cached and new liquidation prices that could cause user's to misunderstand their leverage's impact on their liquidation price.

  2. I'm keeping the behavior where we are not showing the skeleton on every price change. That was the bug that was initially reported. Not too worried about this drifting too much since we're updating it a split second after every price change.

  3. Adding a min height to the banner to prevent weird layout shift between 1 to 2 lines of the card.

Here's a recording:

Screen.Recording.2026-02-12.at.10.31.59.AM.mov

@gambinish gambinish requested a review from geositta February 12, 2026 18:39
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are focused on the Perps (perpetuals trading) feature:

  1. PerpsLeverageBottomSheet.tsx: Major UI/UX improvements including:

    • Replaced internal Skeleton component with react-native-skeleton-placeholder
    • Added caching mechanism for liquidation prices to avoid skeleton blinking during passive price updates
    • Added leverageChanged state tracking to show skeleton only when user actively changes leverage
    • Added minimum skeleton display time to prevent stale API calls from prematurely clearing the skeleton
    • These changes affect how the leverage bottom sheet renders and handles loading states
  2. PerpsLeverageBottomSheet.styles.ts: Added minHeight: 60 to prevent layout shift when warning text wraps between one and two lines

  3. PerpsLeverageBottomSheet.test.tsx: Updated tests to reflect new skeleton behavior and added tests for stale cache prevention

  4. usePerpsHomeData.ts: Simplified sorting logic by removing selectPerpsMarketFilterPreferences selector and using default values (Volume sort, default direction). This affects how markets are sorted in the Perps home view.

Tag selection rationale:

  • SmokePerps: Directly tests perpetuals trading functionality including the leverage bottom sheet and home view
  • SmokeWalletPlatform: Per tag description, Perps is a section inside the Trending tab, so changes to Perps views affect Trending
  • SmokeConfirmations: Per tag description, when selecting SmokePerps, also select SmokeConfirmations (Add Funds deposits are on-chain transactions)

Performance Test Selection:
The changes to PerpsLeverageBottomSheet.tsx include significant UI rendering optimizations: replacing the Skeleton component with react-native-skeleton-placeholder, adding caching for liquidation prices, and implementing minimum skeleton display times. These changes directly affect how the Perps leverage UI renders and could impact performance. The @PerformancePreps tag covers perps market loading and position management which aligns with these changes.

View GitHub Actions results

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

liquidationPrice: '2400.00', // Old price still in hook state
isCalculating: true,
error: null,
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

mockReturnValue leaks to subsequent tests via clearAllMocks

Low Severity

The mockReturnValue call on usePerpsLiquidationPrice permanently overrides the default mock implementation (the one that calculates based on params). Since beforeEach uses jest.clearAllMocks() — which clears call history but does not reset implementations — this override leaks to every subsequent test in the file. Currently those tests pass by coincidence (values happen to match or assertions don't depend on liquidation specifics), but any future test relying on the default calculated mock would silently receive { liquidationPrice: '2400.00', isCalculating: true } instead.

Additional Locations (1)

Fix in Cursor Fix in Web

Triggered by project rule: Unit Testing Guidelines

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@geositta geositta left a comment

Choose a reason for hiding this comment

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

Thanks for thinking through this! The useEffect is pretty complex but makes sense. A styling follow up might be to make the skeleton the same tone rather than white/silver color that contrasts with the red or green.

@gambinish gambinish added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit f95e2bb Feb 13, 2026
95 checks passed
@gambinish gambinish deleted the perps/tat-2544-tat-2454 branch February 13, 2026 01:23
@github-actions github-actions bot locked and limited conversation to collaborators Feb 13, 2026
@metamaskbot metamaskbot added the release-7.67.0 Issue or pull request that will be included in release 7.67.0 label Feb 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.67.0 Issue or pull request that will be included in release 7.67.0 size-M team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants