mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 12:07:09 +00:00
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.
This commit is contained in:
1 parent
7ef448987f
commit
3e4cf965b0
1 file changed
+7
-2
@@ -46,14 +46,19 @@ const accounts = extract<Account[]>("accounts", s =>
|
|||||||
// Total balance: sum of AccountCard balances visible on Home plus the
|
// Total balance: sum of AccountCard balances visible on Home plus the
|
||||||
// LedgerBalance shown on Ledger. Both screens read the same DB, so summing
|
// LedgerBalance shown on Ledger. Both screens read the same DB, so summing
|
||||||
// across whichever screen is visible gives the same authoritative number.
|
// 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 totalBalance = extract("totalBalance", s => {
|
||||||
const cards = s.ax.findAll([{ testTag: "HomeScreen" }, { testTag: "AccountCard" }]);
|
const cards = s.ax.findAll([{ testTag: "HomeScreen" }, { testTag: "AccountCard" }]);
|
||||||
const cardSum = cards.reduce(
|
const cardSum = cards.reduce(
|
||||||
(sum, c) => sum + parseDollarCents(c.find({ testTag: "AccountBalance" })?.text),
|
(sum, c) => sum + parseDollarCents(c.find({ testTag: "AccountBalance" })?.text),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
const ledgerBal = parseDollarCents(s.ax.find({ testTag: "LedgerBalance" })?.text);
|
const ledgerBalText = s.ax.find({ testTag: "LedgerBalance" })?.text;
|
||||||
return cardSum + ledgerBal;
|
if (cards.length === 0 && !ledgerBalText) return lastSeenTotalBalance;
|
||||||
|
lastSeenTotalBalance = cardSum + parseDollarCents(ledgerBalText);
|
||||||
|
return lastSeenTotalBalance;
|
||||||
});
|
});
|
||||||
|
|
||||||
const lastAction = extract("lastAction", s => s.lastAction);
|
const lastAction = extract("lastAction", s => s.lastAction);
|
||||||
|
|||||||
Reference in new issue
Block a user