From 17fd06894a7bc511041d1aa772bd4271686710f1 Mon Sep 17 00:00:00 2001 From: Matt Fiddaman <github@m.fiddaman.uk> Date: Tue, 17 Sep 2024 21:10:52 +0100 Subject: [PATCH] update synced account balance in db if available (#3452) --- packages/loot-core/src/server/accounts/sync.ts | 11 ++++++++++- upcoming-release-notes/3452.md | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 upcoming-release-notes/3452.md diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts index 891763a0a..9209026d2 100644 --- a/packages/loot-core/src/server/accounts/sync.ts +++ b/packages/loot-core/src/server/accounts/sync.ts @@ -54,6 +54,13 @@ function getAccountBalance(account) { } } +async function updateAccountBalance(id, balance) { + await db.runQuery('UPDATE accounts SET balance_current = ? WHERE id = ?', [ + amountToInteger(balance), + id, + ]); +} + export async function getGoCardlessAccounts(userId, userKey, id) { const userToken = await asyncStorage.getItem('user-token'); if (!userToken) return; @@ -694,7 +701,7 @@ export async function syncAccount( ); } - const { transactions: originalTransactions } = download; + const { transactions: originalTransactions, accountBalance } = download; if (originalTransactions.length === 0) { return { added: [], updated: [] }; @@ -713,6 +720,8 @@ export async function syncAccount( useStrictIdChecking, ); + if (accountBalance) await updateAccountBalance(id, accountBalance); + return result; }); } else { diff --git a/upcoming-release-notes/3452.md b/upcoming-release-notes/3452.md new file mode 100644 index 000000000..d1de146fd --- /dev/null +++ b/upcoming-release-notes/3452.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [matt-fidd] +--- + +Update synced account balance in db if available -- GitLab