diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts index 891763a0aac7fc56fbaded2d886fb44bbb4006c6..9209026d262ef5ddaeb7b485b16227a92bab1760 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 0000000000000000000000000000000000000000..d1de146fdaa64da7dc483522c636b98d78395e58 --- /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