Draw net contributions beside total value on the account chart
Upstream PR: we-promise/sure#5297 (pull/5297), same branch, same commit.
Moved 2026-11-18. we-promise/sure#4029 is closed and replaced by we-promise/sure#5297 (top of the returns stack, bottom we-promise/sure#5129, on we-promise/sure#5296). How the two relate: same commits. up/net-contributions-chart is at 358de3ef0 in both repositories. Base changed from mirror/upstream-main to up/net-contributions-model (#848, the pre-flight for we-promise/sure#5296), so this PR now shows only its own diff. There was one conflict, in time_series_chart_controller.js: upstream replaced _resizeObserver with _settledResize, and this PR's _comparisonPoints sits beside it. The seven upstream review threads were answered on we-promise/sure#4029 before it closed. Full unit suite on 358de3ef0 on beastpc: 17,366 runs, 0 failures (the 8 errors are ReleaseNotesWorkflowTest, no node in the image). The system test account_chart_net_contributions_test.rb passes (2 runs). Rubocop and Biome are clean.
Updated 2026-11-15: rebased onto the new portfolio stack. we-promise/sure#4197 and we-promise/sure#4198 (pre-flights #443 and #444) were replaced by we-promise/sure#5088 and we-promise/sure#5089 (the returns stack, bottom we-promise/sure#5129; pre-flights #707 and #708). up/net-contributions-chart is now d8b2cb6e5, one commit on we-promise/sure#4028's rebuilt 91375e09d, which sits on up/portfolio-journal-flows-v3. Its content equals the previous head (6bcda368b) with main merged in, exactly. Same commits as we-promise/sure#4029. Full suite on d8b2cb6e5: 16,371 runs, 0 failures; the 8 errors are ReleaseNotesWorkflowTest, which needs node, missing in the test image. Rubocop, erb_lint and Brakeman are clean. Older notes below refer to #443/#444 and we-promise/sure#4197/we-promise/sure#4198, which are superseded.
Part of #326
Upstream pre-flight for the chart half of we-promise/sure#4008. Upstream PR: we-promise/sure#5297 (pull/5297), replacing the closed we-promise/sure#4029. How the two relate: same branch, same commit.
Rebuilt on 2026-10-08, on the owner's decision, together with #343. The branch was force-pushed from 64899409d to 30b570dea: the same chart commit, cherry-picked onto #343's rebuilt branch, with only the understated note and one comment reworded. The rebuild was first opened as #381, which is now closed as a duplicate. cubic's open finding here (an unvalued withdrawal makes the line too high, so "understated" is the wrong word) is tracked in #383.
Updated 2026-10-23, merge-down: the head moved from 1b6576989 (the adversarial review fixes, comment 6349335822) to b6b9791da, a merge of up/net-contributions-model at 2ca797345. That merge brings #444 at fc400f58f and #443 at c285e4a49, the daily returns and journal flow review fixes since 2026-10-15, so this branch now carries them. The one overlap, config/locales/views/components/fr.yml, keeps upstream's new French wording and this PR's net_contributions keys. No chart code changed, and no net contributions test expectation changed. Full suite on b6b9791da: 13,082 runs, 60,102 assertions, 0 failures, 0 errors, 36 skips, on Ruby 3.4.9. Net contributions, chart and portfolio model tests on 2ca797345: 306 runs, 0 failures.
Updated 2026-10-15: the head moved from fdf6e2322 to 87cdb576e, a clean merge of #343 at f41a201b4 (#443's and #444's overnight review fixes). No chart code changed. Full suite on 87cdb576e: 11,939 runs, 54,892 assertions, 0 failures, 0 errors, 34 skips. Brakeman 0 warnings.
Updated 2026-10-14 (2), stack fix pass: the head moved from 08f400b76 to fdf6e2322, a clean merge of up/net-contributions-model at 8e5c9266c (see #343). It fixes B1 of nightly 6172435393, the transfer fan-out, with option A: FlowClassifier#sql_joins gives one row per entry (#443 51c7d69c5). It also brings the flow FX, excluded-entry and journal-carry fixes. No chart code changed. Full suite on fdf6e2322: 11,932 runs, 54,863 assertions, 0 failures, 0 errors, 34 skips. Brakeman reports 0 warnings. The root cause (per-leg unique indexes on transfers) is raised separately as jaysbeekay/sure#459 / we-promise/sure#4225.
Updated 2026-10-10: carries the fix for #382. Upstream we-promise/sure#4009 has merged (dd8f7326f on the mirror), which makes #382's defect live on this branch's line. up/net-contributions-chart is now at 35c7c6825: a merge of up/net-contributions-model at bff73a1c1, which carries #382's fix (see #343). Clean merge. Fail-first on this branch: twelve #382 tests fail on the code before the fix and pass with it. Full suite on the branch: one failure, the known Provider::OpenaiTest Ruby 3.3 vs 3.4 string; brakeman 0 warnings. Not yet in the branch: #382's deferred flat-anchor-day edge, owned by the upstream-sync PR, and a rebase onto today's upstream main, which this stack still predates.
Updated 2026-10-13: rebased onto upstream main, owner's decision. Force-pushed from af9a07964 to 21e209447, on #343's rebased head 1fb0df306. This PR's one commit is unchanged. Details in comment 6144261889. Full suite on 21e209447: 11,878 runs, 0 failures, 0 errors, 34 skips.
The upstream description follows, as posted.
Rebuilt on 2026-10-08, together with we-promise/sure#4028. It's the same chart, now drawing we-promise/sure#4028's series, which reads Portfolio::DailyReturns. The previous version (64899409d) had no reviews.
This PR is the last of a stack:
- we-promise/sure#3557 added the flow classifier (merged).
- we-promise/sure#4197 adds
Portfolio::DailyReturns, and we-promise/sure#4198 values a journalled security at its position. Their fork pre-flights are jaysbeekay/sure#443 and jaysbeekay/sure#444, both cut from currentmain. - we-promise/sure#4028 adds the net contributions series, read from those daily returns.
- This PR draws the series. It is built on we-promise/sure#4028's branch (
up/net-contributions-model).
Rebased onto main (3e35aaa07) on 2026-10-13, on top of we-promise/sure#4028's rebased branch. GitHub still shows the parents' commits here. This PR's own commits:
21e209447Draw net contributions beside total value on the account chartecffa0d03Say net contributions may be incomplete, not understated0bfec27e4Pin the null percent for zero net contributions08f400b76Test the net contributions line in the browser
6b9fff8ef merges we-promise/sure#4028's branch down to bring its 0ca4e5360. It is a merge, not a rebase, so the branch fast-forwarded.
21e209447 is the first version's commit (64899409d), cherry-picked without conflicts and rebased unchanged. The only edits from the first version are the note's wording, its key and hook names, and one comment, because the rule for "understated" changed with the model (see below).
Closes we-promise/sure#4008
Fork pre-flight PR: jaysbeekay/sure#344 (pull/344), same commits (up/net-contributions-chart at b6b9791da)
we-promise/sure#4009 is in. The opening-day fix is on we-promise/sure#4028 (jaysbeekay/sure#382), and this chart draws that series unchanged. ecffa0d03 replaces "understated" (jaysbeekay/sure#383): an unvalued withdrawal pushes the line up, not down. The note now reads "Net contributions may be incomplete: a deposit or withdrawal could not be valued."
Summary
On an investment account, and on a Crypto exchange account, the Total value chart now draws a second, dashed line: Net contributions. That is the money put in, net of the money taken out. The gap between the two lines is how the account has actually performed, and because the line is now built from the same daily returns as the portfolio's return figures, the gap agrees with them. The tooltip adds net contributions and the signed difference, with the difference as a percentage of net contributions. A legend under the chart names both lines.
What changed
UI::Account::Chartpasses the model PR's series totime_series_chart_controlleras a new optionalcomparisonvalue. Each point carries its difference from total value. The figures are rounded the same way as the value line's points, so the three numbers in the tooltip agree.time_series_chart_controller.js:- When
comparisonis present, the controller draws a dashedtext-secondaryline on the same scales. Both lines' points set the y domain. - It adds two rows to the tooltip: Net contributions and Difference. The rows are built as DOM nodes with d3's
.text(), not as an HTML string, so no label or amount is parsed as markup. When net contributions are zero the percentage is left off rather than shown as infinity. - Without
comparison, the controller takes exactly the path it took before.
- When
- The legend follows the shape the loan chart's legend already uses: a
ulwith anaria-labelandaria-hiddenswatches. The lines differ in style (solid and dashed) as well as colour. - When a flow the line counts could not be valued (a currency with no rate at all, or a journalled position with no price that day), a note under the legend says net contributions may be incomplete, because a deposit or withdrawal could not be valued. It names no direction: an unvalued deposit leaves the line too low, an unvalued withdrawal too high.
- Four strings added to
config/locales/views/components/en.ymlunderUI.account.chart.net_contributions.
Unchanged: the Holdings, Cash and Gains views, accounts that don't hold trades, and every other caller of the controller.
Changed from the first version: the note now reads "Net contributions may be incomplete: a deposit or withdrawal could not be valued." Its key is UI.account.chart.net_contributions.incomplete and its hook data-net-contributions-incomplete. The first version's wording ("has no exchange rate for its date") no longer describes the rule: the model now carries the last known rate to a date with none, and also flags an unpriced journal. An interim wording said "understated", which is wrong for a withdrawal.
How flows are valued (from the model PR):
- A security moved in or out counts at the position's value that day.
- A flow in another currency converts at the previous day's rate, as every start-of-day flow does in the daily returns.
- A flow that cannot be valued counts as nothing, never at 1:1, and the incomplete note appears.
Demo data
No demo data change needed. From the generator's code, the demo Fidelity HSA Investment account's quarterly transfers from checking should step the line up, and the other demo investment accounts, which only record buys, should keep it flat at the opening value. I haven't checked this on a running demo instance.
Screenshots
These are the first version's screenshots. The test account has only same-currency cash flows and no journals, and for those the two valuations give the same figures. I haven't re-taken them on this branch.
The test account has these values:
- opened with $10,000
- $5,000 deposited about four months ago
- a $150 dividend
- $2,000 withdrawn
The dividend lifts only the value line. The withdrawal lowers both lines.
| Light | Dark |
|---|---|
![]() | ![]() |
| Light | Dark |
|---|---|
![]() | ![]() |
Migration notes
No migration.
Verification
Tests in test/components/UI/account/chart_test.rb, running against the daily-returns model:
- the Total value view of an investment account carries net contributions and a legend. The test checks the serialized difference: $400, +2.7% of $15,000.
- zero net contributions serialize a null percent the browser can parse. The account opens at $0, takes $5,000 in and $5,000 out, and is worth $400, so the difference's percentage is infinite. The test parses the attribute strictly (Ruby's
JSON.parserefuses a bareInfinity, as the browser's does) and asserts the percentage isnull, which the controller then leaves off. ActiveSupport writes a non-finite Float asnull, so this pins existing behaviour rather than fixing a defect. - the line isn't drawn on the Holdings, Cash or Gains views
- the line is drawn only for accounts that hold trades: an exchange Crypto account does, a wallet Crypto account and a Depository account don't
- the chart says when net contributions are incomplete. It also asserts that the note says "incomplete" and names no direction.
A system test, test/system/account_chart_net_contributions_test.rb, checks the drawing in a browser:
- an investment account draws the dashed net contributions line and its legend
- a depository account draws neither
I broke each part on purpose and reran the tests. A test caught every break:
| Breakage | Caught by |
|---|---|
Component drops the supports_trades? check | account-type test, the existing build-once test, and the depository system test |
Component drops the balance view check | views test |
| Difference computed the wrong way round | serialized-difference test |
Comparison attribute written with a bare Infinity (JSON.generate(..., allow_nan: true)) | zero-contributions test (JSON::ParserError) |
| Controller never draws the comparison line | investment system test |
| Incomplete note never shown | incomplete test |
| Incomplete note always shown | incomplete test + total value test |
| Comparison drawn from the value line's own series | total value test |
| Legend removed | total value test + incomplete test |
| Old "understated" copy restored | incomplete test |
| Component returns false | incomplete test |
The tooltip rows are not asserted in a browser: the drawn line and legend are, and the tooltip's figures come from the same serialized payload the component tests pin. The tooltip is shown in the screenshots.
Commands, on 08f400b76:
bin/rails test:11880 runs, 54663 assertions, 0 failures, 0 errors, 34 skipsDISABLE_PARALLELIZATION=true bin/rails test test/system/account_chart_net_contributions_test.rb test/system/account_chart_drag_select_test.rb: 3 runs, 0 failuresbin/rubocopon the changed Ruby: no offensesbundle exec erb_lint app/components/UI/account/chart.html.erb: no errorsbundle exec i18n-tasks unused/missing -l en: neither the old nor the new key reportedbiome linton the controller: clean.biome checkreports one formatting difference, at the_yAxisPadding/_yAxisMinRelSpancomments (lines 41-43), which aremain's own (we-promise/sure#3906) and outside this diff.bin/brakeman: no warnings
Blast radius
Who else hits these lines, and what do they pass?
-
time_series_chart_controlleris shared by the dashboard net worth chart, the sparkline partial and the onboarding preferences preview, as well as the account chart. The newcomparisonvalue is optional. When it is absent,_comparisonPointsis empty, so:- no extra line is drawn
- the tooltip has no extra rows
- the y-scale domain is computed from the same points as before (an empty array is concatenated)
Only
UI::Account::Chartpasses the value (grep -rn "comparison-value" app), and only for the Total value view of an account that holds trades. -
UI::Account::Chart: the series is still built once per render, and the existing "builds its balance series once per render" test passes. The net contributions series is a second call, made only when the line is shown.
What else reads what this changes the reading of? The incomplete note's string is read only by this template. git grep for the old method, key and hook names is empty. The model PR lists the other "net contributions" measures (InvestmentStatement#net_contributions, Goal#net_contributed_for), which this chart doesn't use.
Rebased onto main. we-promise/sure#3906 rewrote the body of _d3YScale. This PR's change, the method's first two lines, applied on top of the new scale logic without conflicts, so both lines' points set the domain.
Engine fix round merged down (2026-10-09)
up/net-contributions-model (#343), which now carries the daily returns and journal flows fix round, is merged into this branch with a --no-ff merge (9f161056d), clean, no force push. Nothing in this branch's own code changed.
- Full suite on this head: 10,714 runs, 45,742 assertions, 0 failures, 0 errors, 33 skips (local, PostgreSQL 16, 4 workers).
- Targeted tests (portfolio models, chart series builder, chartable,
UI::Account::Chart): 186 runs, 0 failures.
Updated 2026-10-13: #383 fix, new head, new parent pre-flights.
- #383, new head.
ecffa0d03, a fast-forward from21e209447, merges the model branch down (6b9fff8ef, a merge rather than a rebase, bringing0ca4e5360). On top of that it changes the note to "Net contributions may be incomplete: a deposit or withdrawal could not be valued." The key is nowUI.account.chart.net_contributions.incomplete, the hook isdata-net-contributions-incomplete, and the component method isnet_contributions_incomplete?. This answers cubic 4207601808 (reply 4259895516; cubic resolved the thread).- The chart test now asserts that the note says "incomplete" and names no direction. With the old copy it failed at
chart_test.rb:369. - Mutations caught: old copy restored, note never shown, note always shown, and the component returning false.
- The stale-name
git grepis empty, andi18n-tasks unused/missing -l enreport neither key. - Full suite on
ecffa0d03: 11,879 runs, 0 failures, 0 errors, 34 skips. Brakeman reports 0 warnings, and rubocop and erb_lint are clean.
- The chart test now asserts that the note says "incomplete" and names no direction. With the old copy it failed at
- Stack below this PR:
Updated 2026-10-14: tests for the full review 6156864341 and the nightly 6157118515. New head 08f400b76, a fast-forward from ecffa0d03, with two test-only commits. Reply: comment 6160721832.
0bfec27e4pins the zero-net-contributions case. Finding 1's defect claim is declined: ActiveSupport 8.1.3.1 writes a non-finite Float asnull, and the controller omits anullpercentage. The test can't fail first, because the code is already correct. Mutation: writing the attribute withallow_nan: truemakes it raiseJSON::ParserError.08f400b76adds the system test for finding 2. Mutations caught:_drawComparisonLinereturning early, and thesupports_trades?check dropped.- Full suite on
08f400b76: 11,880 runs, 54,663 assertions, 0 failures, 0 errors, 34 skips. The system test passed four runs in local headless Chrome. rubocop, erb_lint and Brakeman are clean.biome lintis clean;biome checkflags onlymain's own comment formatting at lines 41-43, outside this diff. - Upstream we-promise/sure#4029's body was updated on 2026-10-14 to match: head
08f400b76, the "incomplete" note, the new tests, and "stacked on" we-promise/sure#4197 and we-promise/sure#4198.



