Skip to content

Conversation

@michalconsensys
Copy link
Contributor

@michalconsensys michalconsensys commented Nov 7, 2025

Description

Fixes PnL calculation when closing positions. Previously the UI used ref which did not trigger a recalculation of the PnL. To solve the issue we refer to the variable without using ref.

Changelog

CHANGELOG entry: Fixed PnL calculation to use current price

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2035

Manual testing steps

Feature: Close position

  Scenario: User closes a position 
    Given I have an open long position for BTC
    And the current market price is $50,000
    And my entry price was $45,000
    When I click on close position
    Then the P&L shown should be calculated using the current price

Screenshots/Recordings

Before

Simulator Screenshot - iPhone 16e - 2025-11-07 at 10 46 59

After

Simulator Screenshot - iPhone 16e - 2025-11-07 at 10 46 40

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

Use currentPrice directly (not a ref) for close-position positionValue and PnL, updating memo dependencies to reflect live price.

  • Perps Close Position View (PerpsClosePositionView.tsx):
    • Calculations:
      • Replace ref-based price with direct currentPrice for positionValue and P&L computations.
      • Update useMemo dependencies to include currentPrice for live recalculation.
    • Cleanup:
      • Remove unused useRef for current price and related comments.

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

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

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.

@michalconsensys michalconsensys added the team-perps Perps team label Nov 7, 2025
@github-actions github-actions bot added the size-S label Nov 7, 2025
@michalconsensys michalconsensys changed the title fix(perps): use current price to compute pnl fix(perps): use current price to compute PnL Nov 7, 2025
@michalconsensys michalconsensys marked this pull request as ready for review November 7, 2025 09:55
@michalconsensys michalconsensys requested a review from a team as a code owner November 7, 2025 09:55
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 7, 2025

@nickewansmith
Copy link
Contributor

Hey @michalconsensys thanks for jumping on this. I think #22229 will address it as well and may make this unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants