From 3e4cf965b064efafc5b16e27f139cfa40791f0e2 Mon Sep 17 00:00:00 2001 From: PJ Date: Sun, 31 May 2026 18:57:07 +0530 Subject: [PATCH] fix(folio): carry forward total balance across off-screen transitions AddTransactionScreen shows neither AccountCard nor LedgerBalance, so the extractor used to report 0 at the step before submit. That made every non-zero current balance look like the full delta and tripped the typed amount property on every honest submit. Remember the last-seen sum and return it whenever the current snapshot has no balance signal. --- examples/folio/sanderling/spec.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/folio/sanderling/spec.ts b/examples/folio/sanderling/spec.ts index ddd8b16..24a0e42 100644 --- a/examples/folio/sanderling/spec.ts +++ b/examples/folio/sanderling/spec.ts @@ -46,14 +46,19 @@ const accounts = extract("accounts", s => // Total balance: sum of AccountCard balances visible on Home plus the // LedgerBalance shown on Ledger. Both screens read the same DB, so summing // across whichever screen is visible gives the same authoritative number. +// Screens that show neither signal (e.g. AddTransactionScreen) carry forward +// the last-seen sum so `previous` and `current` stay on the same scale. +let lastSeenTotalBalance = 0; const totalBalance = extract("totalBalance", s => { const cards = s.ax.findAll([{ testTag: "HomeScreen" }, { testTag: "AccountCard" }]); const cardSum = cards.reduce( (sum, c) => sum + parseDollarCents(c.find({ testTag: "AccountBalance" })?.text), 0, ); - const ledgerBal = parseDollarCents(s.ax.find({ testTag: "LedgerBalance" })?.text); - return cardSum + ledgerBal; + const ledgerBalText = s.ax.find({ testTag: "LedgerBalance" })?.text; + if (cards.length === 0 && !ledgerBalText) return lastSeenTotalBalance; + lastSeenTotalBalance = cardSum + parseDollarCents(ledgerBalText); + return lastSeenTotalBalance; }); const lastAction = extract("lastAction", s => s.lastAction);