Show what each scheduled payment is made of in the loan chart tooltip

Closed
JA
2mo ago
+480-38

Part of #21 (fork pre-flight). Upstream issue: we-promise/sure#3958. Upstream PR: we-promise/sure#4006 (draft), same branch, same commit (8effde2).

This targets mirror/upstream-main, not main. The change is to upstream's account-page chart (Loan::PayoffChart, from we-promise/sure#3474), which fork main does not use; the fork already shows the split on its Schedule-tab chart (#209). The upstream PR, we-promise/sure#4006, is this branch at the same commit.

Before: hovering the loan balance chart shows the scheduled balance for a date, but not how that month's payment divides between principal and interest.

After: on a scheduled payment, the tooltip adds a line under the scheduled balance, e.g. "Principal: $497.75 · Interest: $2,500.00" for the first payment on a $500,000, 6%, 30-year mortgage. The split is shown at the currency's own precision, as the Schedule tab shows it; the balance rows stay in whole units. The opening point (the amount borrowed) and the projected and recorded lines show no split.

How: Loan::PayoffChart#scheduled_series now carries principal and interest from the schedule's own Payment rows, the same rows it already read for the balance. The labels reuse loans.tabs.schedule.principal / .interest, the Schedule table's column names. The payload also carries currency_precision (Money::Currency.new(currency).default_precision || 2), because Intl's default can differ from the app's. The controller renders the row only when a point has both fields. No new query, model or component.

Blast radius

payload[:scheduled] is read only by loan_payoff_chart_controller.js (series points and keyboard stops). #series is shared with the projection and is left unchanged, so the projection carries no split; a test pins that. currency_precision is a new key read only by the split formatter.

Tests

Written first. Each new model test that checks for the split or the precision failed before the change for the expected reason (nil); the negative test is the guard.

  • each scheduled payment point carries the payment's principal and interest: matches the schedule rows and adds up to the payment.
  • the split on a long loan is interest-heavy at the start and principal-heavy at the end
  • the opening point, the projection and the recorded balance carry no split
  • the payload labels the split with the schedule table's own words
  • the payload carries the loan currency's precision for the split (USD 2, JPY 0), added for the CodeRabbit finding.
  • System: the tooltip splits a scheduled payment into principal and interest (no split at origination, the first payment's figures to the cent, balance still in whole units).

Deliberate breakages, each caught:

BreakageCaught by
Tooltip never renders the split rowsystem test
toPoint drops principalsystem test
Opening point carries a splitnegative model test
Projection carries a splitnegative model test
Principal and interest swapped2 model tests
Split uses the whole-unit balance formattersystem test
Split formatter drops the minimum fraction digitssystem test
Precision hard-coded to 2precision model test

Checks (local, Ruby 3.3.6 since 3.4.9 is not installed)

  • On cb7ef2e (now 8effde2): test/models/loan/payoff_chart_test.rb 28 runs, 0 failures; test/system/loan_payoff_chart_test.rb 7 runs, 0 failures. RuboCop clean on the changed files.
  • Full suite on 3071cee (now 69ae6b0, before the precision change): 10,504 runs, 4 failures, 1 error. All five (Provider::OpenaiTest extra_headers, Provider::RegistryTest Anthropic ENV, three Anthropic tests in Settings::HostingsControllerTest) fail identically on the base without this change.
  • Brakeman 0 warnings, npm run lint clean. biome format reports one pre-existing line (161) in the controller that is outside this diff.
  • Checked against upstream AGENTS.md: no new dependency, strings through t(), no ERB or CSS changes, no preview gate needed (no new entry point).

Commit history

On 2026-10-05 both commits were re-authored to the repository owner, with the owner's go-ahead, under the no-AI-attribution rule. The trees are identical. 3071cee → 69ae6b0, cb7ef2e → 8effde2. Reviews and comments that cite the old SHAs refer to the same code.

Screenshots of the tooltip at 8effde2, light and dark, are in we-promise/sure#4006's description.

  • Add principal and interest amounts to scheduled payment points in the loan payoff chart.
  • Show localized principal and interest values in the tooltip when both amounts are present. Keep the opening, projected, and recorded points without a payment split.
  • Add model and system test coverage for payment amounts, labels, and tooltip display.