whisper-money/resources/js/hooks
Víctor Falcón 1a62b8f42e
fix(dashboard): stop negative asset balances inflating net worth (#660)
## Problem

An account of type `checking`/`savings` with a genuinely **negative**
balance was:
- displayed as **positive** on the dashboard account card, and
- **added** to the net worth chart instead of subtracted,

while the **accounts page** rendered the same balance correctly as
negative.

## Root cause

The dashboard used `getAccountSign(type) * Math.abs(value)`. Liabilities
(`credit_card`/`loan`) are stored as positive magnitudes, so `-abs()`
was
correct for them — but for an **asset** holding a negative balance,
`+abs()`
flipped the sign to positive and summed it into net worth. The accounts
page
was correct because it uses the raw signed balance from
`AccountMetricsService`
with no sign transform.

## Fix

- Add `netWorthContribution(type, balance)` in `chart-calculations.ts`:
liabilities subtract their magnitude, assets keep their real sign (so an
  overdrawn asset correctly reduces net worth).
- Dashboard account card (`use-dashboard-data.ts`) now shows the raw
signed
  balance, matching the accounts page.
- Net worth headline total, short/long trend indicators and the
stacked-asset
total (`net-worth-chart.tsx`) use the raw signed value instead of
`Math.abs`.

## Tests

- 3 new unit tests in `chart-calculations.test.ts`, including a
regression case
  for a negative asset balance. Full suite: 37 passing.
2026-07-08 15:22:16 +00:00
..
use-admin.tsx
…
use-appearance.tsx fix(appearance): support MediaQueryList change events on legacy Safari (PHP-LARAVEL-41) (#646) 2026-07-05 17:03:35 +00:00
use-cashflow-data.ts
…
use-categorize-transactions.ts
…
use-chart-color-scheme.tsx
…
use-chart-views.ts
…
use-clipboard.ts
…
use-connect-flow.ts
…
use-count-up.ts
…
use-dashboard-data.test.ts
…
use-dashboard-data.ts fix(dashboard): stop negative asset balances inflating net worth (#660) 2026-07-08 15:22:16 +00:00
use-decrypt-account-names.ts
…
use-decrypt-transactions.test.tsx
…
use-decrypt-transactions.ts
…
use-expandable-categories.ts
…
use-initials.tsx
…
use-locale.ts
…
use-mobile-navigation.ts
…
use-mobile.tsx fix(appearance): support MediaQueryList change events on legacy Safari (PHP-LARAVEL-41) (#646) 2026-07-05 17:03:35 +00:00
use-onboarding-state.test.tsx
…
use-onboarding-state.ts
…
use-online-status.ts
…
use-poll-job-status.ts
…
use-pwa-install.ts
…
use-re-evaluate-all-transactions.tsx
…
use-two-factor-auth.ts
…
use-web-haptics.test.tsx
…
use-web-haptics.ts
…