Skip to content

Commit

Permalink
update synced account balance in db if available (#3452)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd authored Sep 17, 2024
1 parent 4e6a3bb commit 17fd068
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -694,7 +701,7 @@ export async function syncAccount(
);
}

const { transactions: originalTransactions } = download;
const { transactions: originalTransactions, accountBalance } = download;

if (originalTransactions.length === 0) {
return { added: [], updated: [] };
Expand All @@ -713,6 +720,8 @@ export async function syncAccount(
useStrictIdChecking,
);

if (accountBalance) await updateAccountBalance(id, accountBalance);

return result;
});
} else {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3452.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [matt-fidd]
---

Update synced account balance in db if available

0 comments on commit 17fd068

Please sign in to comment.