fix(folio): guard newAccountBalanceIsZero against navigation false positives

Scoped selectors return [] when not on HomeScreen so accounts vanish and
reappear as apparently-new on each visit. Skip the check when prev was empty.
This commit is contained in:
pj committed 2026-04-25 19:55:19 +07:00
1 parent 0708655ec1
commit 57df510b70
1 file changed
+8 -2
+8 -2
View File
@@ -74,10 +74,16 @@ const accountCards = extract(s => s.ax.findAll("desc:HomeScreen > descPrefix:acc
const backButton = extract(s => s.ax.find("desc:Back")); const backButton = extract(s => s.ax.find("desc:Back"));
// Property 1: every new account starts with balance === 0 // Property 1: every new account starts with balance === 0
// Guard: only check when accounts were visible in the previous step too.
// Without this, navigating away from HomeScreen (accounts=[]) then back
// makes every account look "new", causing false positives on pre-existing balances.
const newAccountBalanceIsZero = always( const newAccountBalanceIsZero = always(
next(() => { next(() => {
const prevIds = new Set((accounts.previous ?? []).map(a => a.id)); const prev = accounts.previous ?? [];
const newAccounts = accounts.current.filter(a => !prevIds.has(a.id)); const curr = accounts.current;
if (prev.length === 0 || curr.length === 0) return true;
const prevIds = new Set(prev.map(a => a.id));
const newAccounts = curr.filter(a => !prevIds.has(a.id));
return newAccounts.every(a => a.balance === 0); return newAccounts.every(a => a.balance === 0);
}) })
); );