Skip to content

Improve profile PnL calculation#373

Closed
CedrikNikita wants to merge 3 commits intodevelopfrom
feature/improve-profile-pnl-calculation
Closed

Improve profile PnL calculation#373
CedrikNikita wants to merge 3 commits intodevelopfrom
feature/improve-profile-pnl-calculation

Conversation

@CedrikNikita
Copy link
Copy Markdown
Collaborator

@CedrikNikita CedrikNikita commented Nov 21, 2025

fixes #362


Note

Compute PnL from chart values (incl. hover) instead of fetching, and optimize crosshair/hover performance with memoization and stable handlers.

  • Account Portfolio (src/components/Account/AccountPortfolio.tsx):
    • PnL calculation:
      • Replace backend useQuery PnL fetch with local derivation from rechartsData for current and hovered points.
      • Remove background prefetching for other time ranges; simplify readiness logic to depend on value/history only.
    • Hover/interaction:
      • Add handleChartHover via useCallback and pass to RechartsChart.
      • Optimize crosshair Y fallback using precomputed minValue/maxValue; include them in effect deps.
    • Performance/UX:
      • Precompute min/max once per data change to avoid repeated scans during hover.
      • Keep portfolio value display responsive without waiting for PnL data.

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

@netlify
Copy link
Copy Markdown

netlify bot commented Nov 21, 2025

Deploy Preview for fancy-gelato-7cdad5 ready!

Name Link
🔨 Latest commit 8e427eb
🔍 Latest deploy log https://app.netlify.com/projects/fancy-gelato-7cdad5/deploys/692020b2a7e1620008e76385
😎 Deploy Preview https://deploy-preview-373--fancy-gelato-7cdad5.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

to,
},
};
}, [rechartsData, convertTo]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: PnL calculation incorrectly includes deposits and withdrawals

The new PnL calculation computes profit/loss as the difference between portfolio values at the start and end of the time window. This incorrectly treats deposits and withdrawals as gains or losses. For example, if a user deposits 100 AE mid-period, it appears as a 100 AE profit. True PnL requires tracking the cost basis of investments, which the removed backend calculation provided. The same issue affects the hover PnL calculation at lines 1086-1132.

Fix in Cursor Fix in Web

@Andreea167
Copy link
Copy Markdown

I tried to reproduce it -> for the increse of pnl with AE seems to be ok

I tried to simulate for the loss again, could not simulate it for some reason since always show 0 AE

However I navigated to https://deploy-preview-373--fancy-gelato-7cdad5.netlify.app/trends/leaderboard and took the last account with a -25$ pnl in the last 30 days and take a look at his profile:
Bug: the minus -$ is shown, but the -AE equivalnce is not shown

account: ak_25LoeDiZB9bATDCYCJT5mtgnfEvBmURAqecQDgmZ85eErfroFH
Screenshot 2025-11-21 at 12 39 30
Screenshot 2025-11-21 at 12 39 40

@CedrikNikita CedrikNikita marked this pull request as draft November 21, 2025 11:15
@CedrikNikita CedrikNikita deleted the feature/improve-profile-pnl-calculation branch April 1, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P&L doesn't seems always accurate

2 participants