From 866b4d6cd40ede273d2bda0c0cb01ac1179308f2 Mon Sep 17 00:00:00 2001
From: Matiss Janis Aboltins <matiss@mja.lv>
Date: Wed, 3 Jul 2024 17:15:36 +0100
Subject: [PATCH] :bug: (bank-sync) fix account highlight dissapearing (#2898)

---
 packages/loot-core/src/client/reducers/queries.ts | 12 +++++++++---
 packages/loot-core/src/server/main.ts             |  3 ++-
 upcoming-release-notes/2898.md                    |  6 ++++++
 3 files changed, 17 insertions(+), 4 deletions(-)
 create mode 100644 upcoming-release-notes/2898.md

diff --git a/packages/loot-core/src/client/reducers/queries.ts b/packages/loot-core/src/client/reducers/queries.ts
index b0c38817a..84528cc12 100644
--- a/packages/loot-core/src/client/reducers/queries.ts
+++ b/packages/loot-core/src/client/reducers/queries.ts
@@ -29,9 +29,15 @@ export function update(state = initialState, action: Action): QueriesState {
     case constants.SET_NEW_TRANSACTIONS:
       return {
         ...state,
-        newTransactions: action.newTransactions || [],
-        matchedTransactions: action.matchedTransactions || [],
-        updatedAccounts: action.updatedAccounts || [],
+        newTransactions: action.newTransactions
+          ? [...state.newTransactions, ...action.newTransactions]
+          : state.newTransactions,
+        matchedTransactions: action.matchedTransactions
+          ? [...state.matchedTransactions, ...action.matchedTransactions]
+          : state.matchedTransactions,
+        updatedAccounts: action.updatedAccounts
+          ? [...state.updatedAccounts, ...action.updatedAccounts]
+          : state.updatedAccounts,
       };
     case constants.UPDATE_NEW_TRANSACTIONS:
       return {
diff --git a/packages/loot-core/src/server/main.ts b/packages/loot-core/src/server/main.ts
index 3c1be8ef4..44738736f 100644
--- a/packages/loot-core/src/server/main.ts
+++ b/packages/loot-core/src/server/main.ts
@@ -1075,7 +1075,6 @@ handlers['accounts-bank-sync'] = async function ({ id }) {
           acct.account_id,
           acct.bankId,
         );
-        console.groupEnd();
 
         const { added, updated } = res;
 
@@ -1113,6 +1112,8 @@ handlers['accounts-bank-sync'] = async function ({ id }) {
 
           captureException(err);
         }
+      } finally {
+        console.groupEnd();
       }
     }
   }
diff --git a/upcoming-release-notes/2898.md b/upcoming-release-notes/2898.md
new file mode 100644
index 000000000..fc60b2551
--- /dev/null
+++ b/upcoming-release-notes/2898.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [MatissJanis]
+---
+
+Bank sync: fix account with new transactions highlight disappearing if multiple consecutive accounts are synced.
-- 
GitLab