Conversation
|
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. |
app/components/UI/Perps/components/PerpsLeverageBottomSheet/PerpsLeverageBottomSheet.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
app/components/UI/Perps/components/PerpsLeverageBottomSheet/PerpsLeverageBottomSheet.tsx
Outdated
Show resolved
Hide resolved
…k-mobile into perps/tat-2544-tat-2454
|
@geositta I ended up with this as a solution:
Here's a recording: Screen.Recording.2026-02-12.at.10.31.59.AM.mov |
app/components/UI/Perps/components/PerpsLeverageBottomSheet/PerpsLeverageBottomSheet.tsx
Show resolved
Hide resolved
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Tag selection rationale:
Performance Test Selection: |
| liquidationPrice: '2400.00', // Old price still in hook state | ||
| isCalculating: true, | ||
| error: null, | ||
| }); |
There was a problem hiding this comment.
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)
Triggered by project rule: Unit Testing Guidelines
|
geositta
left a comment
There was a problem hiding this comment.
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.





Description
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
selectPerpsMarketFilterPreferencesinusePerpsHomeDataand hardcodes the home sort to Volume descending. The Market List continues to use and persist its own sort preference independently.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
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
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 fixedminHeightto the warning container to prevent layout shift when the percentage wraps.Updates/expands tests to mock
react-native-skeleton-placeholderand 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.