Skip to content

Commit 8bd8bf8

Browse files
robcohenclaude
andcommitted
fix(account-tree): preserve accounts on validation errors
Cache the last successful account query result and use it when validation errors occur. This prevents the account tree from showing "No accounts found" when the ledger has balance assertion or other validation errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b3924c6 commit 8bd8bf8

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/account-tree.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ let treeVersion = 0;
2222
/** @type {Map<string, boolean>} Track expanded state across updates */
2323
const expandedState = new Map();
2424

25+
/** @type {Array<{account: string, balance: {amount: number, currency: string}}>} Cache last successful account data */
26+
let cachedAccounts = [];
27+
2528
// Account type colors matching charts.js
2629
const accountColors = {
2730
Assets: '#22d3ee', // cyan
@@ -365,12 +368,14 @@ function triggerRerender(container) {
365368
* @returns {Promise<Array<{account: string, balance: {amount: number, currency: string}}>>}
366369
*/
367370
async function queryAccountBalances(source) {
368-
if (!isWasmReady()) return [];
371+
if (!isWasmReady()) return cachedAccounts;
369372

370373
try {
371374
const result = await executeQuery(source, 'BALANCES');
372-
if (!result || result.error || !result.rows || result.rows.length === 0) {
373-
return [];
375+
if (!result || !result.rows || result.rows.length === 0) {
376+
// Query returned no rows - return cached data if available
377+
// This handles cases where validation errors prevent querying
378+
return cachedAccounts;
374379
}
375380

376381
// BALANCES returns: account, balance (or similar columns)
@@ -408,10 +413,13 @@ async function queryAccountBalances(source) {
408413
}
409414
}
410415

416+
// Cache successful result
417+
cachedAccounts = accounts;
411418
return accounts;
412419
} catch (err) {
413420
console.error('Account tree query error:', err);
414-
return [];
421+
// Return cached data on error
422+
return cachedAccounts;
415423
}
416424
}
417425

@@ -468,6 +476,7 @@ export function clearAccountTree() {
468476
}
469477
treeVersion = 0;
470478
currentGetSource = null;
479+
cachedAccounts = [];
471480
// Don't clear expandedState to preserve user preferences across sessions
472481
}
473482

0 commit comments

Comments
 (0)