Repository navigation
fix: compute portfolio dayChange from analytics snapshots instead of Math.random - #76
Open
devgodfreytem wants to merge 1 commit into
Open
devgodfreytem wants to merge 1 commit into
devgodfreytem wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #57
What changed
StellarService.getPortfolio():dayChange(what/portfolio/:idand the dashboard show) no longer comes fromMath.random().calculateDayChangenow callsanalyticsService.getChangeForWindow(portfolioId, 24h, 2h). That compares theanalytics_snapshotsrow closest to 24h ago, within a 2h window, with the latest row. It's the same calculationcalculatePerformanceMetricsalready uses fordailyChange.dayChangeisnull, not a made-up number.Dashboard.tsxandPerformanceChart.tsxalready rendernullas "—".backend/src/test/dayChange.test.tschecks that the snapshot change is used with the 24h/2h window, thatMath.randomis never called, that the value isnullwithout history, and that it's stable across calls.Why
How to test
cd backend && npm test -- dayChangeNotes:
main:dbGetSnapshotAt/dbGetClosestSnapshot,getChangeForWindow, the 7d/30d/all-time changes, and the frontend's null handling. This PR removes the last random value on the portfolio path.frontend/src/components/AssetCard.tsxandfrontend/src/services/browserPriceService.tsstill useMath.random()for per-asset demo price changes. They aren't part of this issue's portfolio path.