Skip to content

A local-first personal finance app

[AI] Persist bank sync status in the accounts table (#8017)

Matiss Janis Aboltins23ad162fb7b2
diff --git a/packages/desktop-client/src/accounts/syncStatus.test.ts b/packages/desktop-client/src/accounts/syncStatus.test.ts
new file mode 100644
index 0000000000..c4618aa12e
--- /dev/null
+++ b/packages/desktop-client/src/accounts/syncStatus.test.ts
@@ -0,0 +1,22 @@
+import type { AccountEntity } from '@actual-app/core/types/models';
+import { describe, expect, it } from 'vitest';
+
+import { isAccountFailedSync } from './syncStatus';
+
+function makeAccount(
+ bank_sync_status: AccountEntity['bank_sync_status'],
+): Pick<AccountEntity, 'bank_sync_status'> {
+ return { bank_sync_status };
+}
+
+describe('syncStatus', () => {
+ it('treats failed, attention-required and reauth-required as failed', () => {
+ expect(isAccountFailedSync(makeAccount('failed'))).toBe(true);
+ expect(isAccountFailedSync(makeAccount('attention-required'))).toBe(true);
+ expect(isAccountFailedSync(makeAccount('reauth-required'))).toBe(true);
+ expect(isAccountFailedSync(makeAccount('pending'))).toBe(false);
+ expect(isAccountFailedSync(makeAccount('sync-requested'))).toBe(false);
+ expect(isAccountFailedSync(makeAccount('ok'))).toBe(false);
+ expect(isAccountFailedSync(makeAccount(null))).toBe(false);
+ });
+});
diff --git a/packages/desktop-client/src/accounts/syncStatus.ts b/packages/desktop-client/src/accounts/syncStatus.ts
new file mode 100644
index 0000000000..e4ccb84500
--- /dev/null
+++ b/packages/desktop-client/src/accounts/syncStatus.ts
@@ -0,0 +1,12 @@
+import type { AccountEntity } from '@actual-app/core/types/models';
+
+export function isAccountFailedSync(
+ account: Pick<AccountEntity, 'bank_sync_status'>,
+) {
+ const status = account.bank_sync_status;
+ return (
+ status === 'failed' ||
+ status === 'attention-required' ||
+ status === 'reauth-required'
+ );
+}
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx
index dee6b9ccfa..07bd64658a 100644
--- a/packages/desktop-client/src/components/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/accounts/Account.tsx
@@ -54,7 +54,6 @@ import { useAccounts } from '#hooks/useAccounts';
import { SchedulesProvider } from '#hooks/useCachedSchedules';
import { useCategories } from '#hooks/useCategories';
import { useDateFormat } from '#hooks/useDateFormat';
-import { useFailedAccounts } from '#hooks/useFailedAccounts';
import { useLocalPref } from '#hooks/useLocalPref';
import { usePayees } from '#hooks/usePayees';
import { getSchedulesQuery } from '#hooks/useSchedules';
@@ -240,7 +239,6 @@ type AccountInternalProps = {
onBatchDelete: ReturnType<typeof useTransactionBatchActions>['onBatchDelete'];
categoryId?: string;
location: ReturnType<typeof useLocation>;
- failedAccounts: ReturnType<typeof useFailedAccounts>;
dateFormat: ReturnType<typeof useDateFormat>;
payees: PayeeEntity[];
categoryGroups: CategoryGroupEntity[];
@@ -1713,7 +1711,6 @@ class AccountInternal extends PureComponent<
dateFormat,
hideFraction,
accountsSyncing,
- failedAccounts,
showExtraBalances,
accountId,
categoryId,
@@ -1790,7 +1787,6 @@ class AccountInternal extends PureComponent<
savedFilters={this.props.savedFilters}
accountName={accountName}
accountsSyncing={accountsSyncing}
- failedAccounts={failedAccounts}
accounts={accounts}
transactions={transactions}
showBalances={showBalances ?? false}
@@ -1985,7 +1981,6 @@ export function Account() {
);
const { data: accounts = [] } = useAccounts();
const { data: payees = [] } = usePayees();
- const failedAccounts = useFailedAccounts();
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
const [hideFraction] = useSyncedPref('hideFraction');
const [expandSplits] = useLocalPref('expand-splits');
@@ -2043,7 +2038,6 @@ export function Account() {
newTransactions={newTransactions}
matchedTransactions={matchedTransactions}
accounts={accounts}
- failedAccounts={failedAccounts}
dateFormat={dateFormat}
hideFraction={String(hideFraction) === 'true'}
expandSplits={expandSplits}
diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsx
index 7b6089b357..7d18353b46 100644
--- a/packages/desktop-client/src/components/accounts/Header.tsx
+++ b/packages/desktop-client/src/components/accounts/Header.tsx
@@ -35,6 +35,7 @@ import type {
} from '@actual-app/core/types/models';
import { format as formatDate } from 'date-fns';
+import { isAccountFailedSync } from '#accounts/syncStatus';
import { AnimatedRefresh } from '#components/AnimatedRefresh';
import { Search } from '#components/common/Search';
import { FilterButton } from '#components/filters/FiltersMenu';
@@ -64,7 +65,6 @@ type AccountHeaderProps = {
filterId?: SavedFilter;
savedFilters: TransactionFilterEntity[];
accountsSyncing: string[];
- failedAccounts: AccountSyncSidebarProps['failedAccounts'];
accounts: AccountEntity[];
transactions: TransactionEntity[];
showBalances: boolean;
@@ -140,7 +140,6 @@ export function AccountHeader({
filterId,
savedFilters,
accountsSyncing,
- failedAccounts,
accounts,
transactions,
showBalances,
@@ -304,7 +303,6 @@ export function AccountHeader({
{!!account?.bank && (
<AccountSyncSidebar
account={account}
- failedAccounts={failedAccounts}
accountsSyncing={accountsSyncing}
/>
)}
@@ -592,19 +590,11 @@ export function AccountHeader({
type AccountSyncSidebarProps = {
account: AccountEntity;
- failedAccounts: Map<
- string,
- {
- type: string;
- code: string;
- }
- >;
accountsSyncing: string[];
};
function AccountSyncSidebar({
account,
- failedAccounts,
accountsSyncing,
}: AccountSyncSidebarProps) {
return (
@@ -612,7 +602,7 @@ function AccountSyncSidebar({
style={{
backgroundColor: accountsSyncing.includes(account.id)
? theme.sidebarItemBackgroundPending
- : failedAccounts.has(account.id)
+ : isAccountFailedSync(account)
? theme.sidebarItemBackgroundFailed
: theme.sidebarItemBackgroundPositive,
marginRight: '4px',
diff --git a/packages/desktop-client/src/components/mobile/accounts/AccountPage.tsx b/packages/desktop-client/src/components/mobile/accounts/AccountPage.tsx
index ef9e1375f1..04941b8bc4 100644
--- a/packages/desktop-client/src/components/mobile/accounts/AccountPage.tsx
+++ b/packages/desktop-client/src/components/mobile/accounts/AccountPage.tsx
@@ -1,4 +1,4 @@
-import React, { Fragment, useCallback, useMemo } from 'react';
+import React, { Fragment, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router';
@@ -12,11 +12,11 @@ import { send } from '@actual-app/core/platform/client/connection';
import type { AccountEntity } from '@actual-app/core/types/models';
import { useReopenAccountMutation, useUpdateAccountMutation } from '#accounts';
+import { isAccountFailedSync } from '#accounts/syncStatus';
import { MobileBackButton } from '#components/mobile/MobileBackButton';
import { AddTransactionButton } from '#components/mobile/transactions/AddTransactionButton';
import { MobilePageHeader, Page } from '#components/Page';
import { useAccount } from '#hooks/useAccount';
-import { useFailedAccounts } from '#hooks/useFailedAccounts';
import { useSyncedPref } from '#hooks/useSyncedPref';
import {
collapseModals,
@@ -92,17 +92,10 @@ export function AccountPage() {
}
function AccountHeader({ account }: { readonly account: AccountEntity }) {
- const failedAccounts = useFailedAccounts();
const { t } = useTranslation();
const syncingAccountIds = useSelector(state => state.account.accountsSyncing);
- const pending = useMemo(
- () => syncingAccountIds.includes(account.id),
- [syncingAccountIds, account.id],
- );
- const failed = useMemo(
- () => failedAccounts.has(account.id),
- [failedAccounts, account.id],
- );
+ const pending = syncingAccountIds.includes(account.id);
+ const failed = isAccountFailedSync(account);
const dispatch = useDispatch();
const { mutate: updateAccount } = useUpdateAccountMutation();
diff --git a/packages/desktop-client/src/components/mobile/accounts/AccountsPage.tsx b/packages/desktop-client/src/components/mobile/accounts/AccountsPage.tsx
index 3bb9dcff4e..00a2a00ee3 100644
--- a/packages/desktop-client/src/components/mobile/accounts/AccountsPage.tsx
+++ b/packages/desktop-client/src/components/mobile/accounts/AccountsPage.tsx
@@ -24,13 +24,13 @@ import type { AccountEntity } from '@actual-app/core/types/models';
import { css } from '@emotion/css';
import { useMoveAccountMutation, useSyncAndDownloadMutation } from '#accounts';
+import { isAccountFailedSync } from '#accounts/syncStatus';
import { makeAmountFullStyle } from '#components/budget/util';
import { MOBILE_NAV_HEIGHT } from '#components/mobile/MobileNavTabs';
import { PullToRefresh } from '#components/mobile/PullToRefresh';
import { MobilePageHeader, Page } from '#components/Page';
import { CellValue, CellValueText } from '#components/spreadsheet/CellValue';
import { useAccounts } from '#hooks/useAccounts';
-import { useFailedAccounts } from '#hooks/useFailedAccounts';
import { useLocalPref } from '#hooks/useLocalPref';
import { useNavigate } from '#hooks/useNavigate';
import { useSyncedPref } from '#hooks/useSyncedPref';
@@ -395,7 +395,6 @@ const AccountList = forwardRef<HTMLDivElement, AccountListProps>(
}: AccountListProps,
ref,
) => {
- const failedAccounts = useFailedAccounts();
const syncingAccountIds = useSelector(
state => state.account.accountsSyncing,
);
@@ -464,7 +463,7 @@ const AccountList = forwardRef<HTMLDivElement, AccountListProps>(
<ListBox
aria-label={ariaLabel}
items={accounts}
- dependencies={[syncingAccountIds, failedAccounts, updatedAccounts]}
+ dependencies={[syncingAccountIds, updatedAccounts]}
dragAndDropHooks={dragAndDropHooks}
ref={ref}
style={{
@@ -484,7 +483,7 @@ const AccountList = forwardRef<HTMLDivElement, AccountListProps>(
isUpdated={updatedAccounts && updatedAccounts.includes(account.id)}
isConnected={!!account.bank}
isPending={syncingAccountIds.includes(account.id)}
- isFailed={failedAccounts && failedAccounts.has(account.id)}
+ isFailed={isAccountFailedSync(account)}
getBalanceQuery={getBalanceBinding}
onSelect={onOpenAccount}
/>
diff --git a/packages/desktop-client/src/components/sidebar/Accounts.tsx b/packages/desktop-client/src/components/sidebar/Accounts.tsx
index 49aabbaf36..3cee526735 100644
--- a/packages/desktop-client/src/components/sidebar/Accounts.tsx
+++ b/packages/desktop-client/src/components/sidebar/Accounts.tsx
@@ -6,9 +6,9 @@ import { View } from '@actual-app/components/view';
import type { AccountEntity } from '@actual-app/core/types/models';
import { useMoveAccountMutation } from '#accounts';
+import { isAccountFailedSync } from '#accounts/syncStatus';
import { useAccounts } from '#hooks/useAccounts';
import { useClosedAccounts } from '#hooks/useClosedAccounts';
-import { useFailedAccounts } from '#hooks/useFailedAccounts';
import { useLocalPref } from '#hooks/useLocalPref';
import { useOffBudgetAccounts } from '#hooks/useOffBudgetAccounts';
import { useOnBudgetAccounts } from '#hooks/useOnBudgetAccounts';
@@ -25,7 +25,6 @@ export function Accounts() {
const { t } = useTranslation();
const [isDragging, setIsDragging] = useState(false);
const { data: accounts = [] } = useAccounts();
- const failedAccounts = useFailedAccounts();
const updatedAccounts = useUpdatedAccounts();
const { data: offbudgetAccounts = [] } = useOffBudgetAccounts();
const { data: onBudgetAccounts = [] } = useOnBudgetAccounts();
@@ -122,7 +121,7 @@ export function Accounts() {
account={account}
connected={!!account.bank}
pending={syncingAccountIds.includes(account.id)}
- failed={failedAccounts.has(account.id)}
+ failed={isAccountFailedSync(account)}
updated={updatedAccounts.includes(account.id)}
to={getAccountPath(account)}
query={bindings.accountBalance(account.id)}
@@ -154,7 +153,7 @@ export function Accounts() {
account={account}
connected={!!account.bank}
pending={syncingAccountIds.includes(account.id)}
- failed={failedAccounts.has(account.id)}
+ failed={isAccountFailedSync(account)}
updated={updatedAccounts.includes(account.id)}
to={getAccountPath(account)}
query={bindings.accountBalance(account.id)}
diff --git a/packages/loot-core/migrations/1780606215000_add_bank_sync_status.sql b/packages/loot-core/migrations/1780606215000_add_bank_sync_status.sql
new file mode 100644
index 0000000000..c7a4703864
--- /dev/null
+++ b/packages/loot-core/migrations/1780606215000_add_bank_sync_status.sql
@@ -0,0 +1,5 @@
+BEGIN TRANSACTION;
+
+ALTER TABLE accounts ADD COLUMN bank_sync_status text;
+
+COMMIT;
diff --git a/packages/loot-core/src/mocks/index.ts b/packages/loot-core/src/mocks/index.ts
index c55b617314..66cf6ca9ca 100644
--- a/packages/loot-core/src/mocks/index.ts
+++ b/packages/loot-core/src/mocks/index.ts
@@ -40,6 +40,7 @@ export function generateAccount(
balance_limit: 0,
account_sync_source: 'goCardless',
last_sync: new Date().getTime().toString(),
+ bank_sync_status: 'ok',
};
}
@@ -59,6 +60,7 @@ function emptySyncFields(): Pick<
| 'balance_limit'
| 'account_sync_source'
| 'last_sync'
+ | 'bank_sync_status'
> {
return {
account_id: null,
@@ -72,6 +74,7 @@ function emptySyncFields(): Pick<
balance_limit: null,
account_sync_source: null,
last_sync: null,
+ bank_sync_status: null,
};
}
diff --git a/packages/loot-core/src/server/accounts/app-bank-sync.test.ts b/packages/loot-core/src/server/accounts/app-bank-sync.test.ts
index 3e389efd7a..ac546364b8 100644
--- a/packages/loot-core/src/server/accounts/app-bank-sync.test.ts
+++ b/packages/loot-core/src/server/accounts/app-bank-sync.test.ts
@@ -1,4 +1,5 @@
// @ts-strict-ignore
+import * as asyncStorage from '#platform/server/asyncStorage';
import * as db from '#server/db';
import { loadMappings } from '#server/db/mappings';
@@ -12,6 +13,7 @@ vi.mock('./sync', async () => ({
}));
const simpleFinBatchSyncHandler = app.handlers['simplefin-batch-sync'];
+const accountsBankSyncHandler = app.handlers['accounts-bank-sync'];
function insertBank(bank: { id: string; bank_id: string; name: string }) {
db.runQuery(
@@ -41,6 +43,10 @@ async function setupSimpleFinAccounts(
beforeEach(async () => {
vi.resetAllMocks();
+ vi.mocked(asyncStorage.multiGet).mockResolvedValue({
+ 'user-id': 'user-1',
+ 'user-key': 'key-1',
+ });
await global.emptyDatabase()();
await loadMappings();
});
@@ -135,3 +141,82 @@ describe('simpleFinBatchSync', () => {
});
});
});
+
+describe('accountsBankSync', () => {
+ it('persists ok status after a successful sync', async () => {
+ insertBank({ id: 'bank1', bank_id: 'gc-bank', name: 'GoCardless' });
+ await db.insertAccount({
+ id: 'acct1',
+ name: 'Checking',
+ bank: 'bank1',
+ account_id: 'ext-1',
+ account_sync_source: 'goCardless',
+ });
+
+ vi.mocked(bankSync.syncAccount).mockResolvedValue({
+ added: [],
+ updated: [],
+ updatedPreview: [],
+ });
+
+ const result = await accountsBankSyncHandler({ ids: ['acct1'] });
+
+ expect(result.errors).toEqual([]);
+
+ const account = await db.first<db.DbAccount>(
+ 'SELECT * FROM accounts WHERE id = ?',
+ ['acct1'],
+ );
+ expect(account!.bank_sync_status).toBe('ok');
+ });
+
+ it('persists reauth-required status after a reauth error', async () => {
+ insertBank({ id: 'bank1', bank_id: 'gc-bank', name: 'GoCardless' });
+ await db.insertAccount({
+ id: 'acct1',
+ name: 'Checking',
+ bank: 'bank1',
+ account_id: 'ext-1',
+ account_sync_source: 'goCardless',
+ });
+
+ vi.mocked(bankSync.syncAccount).mockRejectedValue({
+ type: 'BankSyncError',
+ reason: 'login required',
+ category: 'ITEM_ERROR',
+ code: 'ITEM_LOGIN_REQUIRED',
+ message: 'login required',
+ });
+
+ await accountsBankSyncHandler({ ids: ['acct1'] });
+
+ const account = await db.first<db.DbAccount>(
+ 'SELECT * FROM accounts WHERE id = ?',
+ ['acct1'],
+ );
+ expect(account!.bank_sync_status).toBe('reauth-required');
+ });
+
+ it('persists failed status after an operational sync error', async () => {
+ insertBank({ id: 'bank1', bank_id: 'gc-bank', name: 'GoCardless' });
+ await db.insertAccount({
+ id: 'acct1',
+ name: 'Checking',
+ bank: 'bank1',
+ account_id: 'ext-1',
+ account_sync_source: 'goCardless',
+ });
+
+ vi.mocked(bankSync.syncAccount).mockRejectedValue(
+ new Error('connection timeout'),
+ );
+
+ await accountsBankSyncHandler({ ids: ['acct1'] });
+
+ const account = await db.first<db.DbAccount>(
+ 'SELECT * FROM accounts WHERE id = ?',
+ ['acct1'],
+ );
+ expect(account!.bank_sync_status).toBe('failed');
+ });
+});
diff --git a/packages/loot-core/src/server/accounts/app.ts b/packages/loot-core/src/server/accounts/app.ts
index b87e0f5107..8a59a382d8 100644
--- a/packages/loot-core/src/server/accounts/app.ts
+++ b/packages/loot-core/src/server/accounts/app.ts
@@ -25,6 +25,7 @@ import { amountToInteger } from '#shared/util';
import type { ImportTransactionsOpts } from '#types/api-handlers';
import type {
AccountEntity,
+ BankSyncStatus,
CategoryEntity,
GoCardlessToken,
ImportTransactionEntity,
@@ -121,6 +122,7 @@ async function getAccounts(): Promise<AccountEntity[]> {
balance_limit: dbAccount.balance_limit ?? null,
account_sync_source: dbAccount.account_sync_source ?? null,
last_sync: dbAccount.last_sync ?? null,
+ bank_sync_status: dbAccount.bank_sync_status ?? null,
}) satisfies AccountEntity,
);
}
@@ -218,7 +220,7 @@ async function linkGoCardlessAccount({
connection.send('sync-event', {
type: 'success',
- tables: ['transactions'],
+ tables: ['transactions', 'accounts'],
});
return 'ok';
@@ -295,7 +297,7 @@ async function linkSimpleFinAccount({
connection.send('sync-event', {
type: 'success',
- tables: ['transactions'],
+ tables: ['transactions', 'accounts'],
});
return 'ok';
@@ -372,7 +374,7 @@ async function linkPluggyAiAccount({
connection.send('sync-event', {
type: 'success',
- tables: ['transactions'],
+ tables: ['transactions', 'accounts'],
});
return 'ok';
@@ -457,7 +459,7 @@ async function linkEnableBankingAccount({
connection.send('sync-event', {
type: 'success',
- tables: ['transactions'],
+ tables: ['transactions', 'accounts'],
});
return 'ok';
@@ -1142,7 +1144,11 @@ async function handleSyncResponse(
}
const ts = new Date().getTime().toString();
- await db.update('accounts', { id: acctId, last_sync: ts });
+ await db.update('accounts', {
+ id: acctId,
+ last_sync: ts,
+ bank_sync_status: 'ok',
+ });
return {
newTransactions,
@@ -1222,6 +1228,37 @@ function handleSyncError(
};
}
+function getBankSyncStatusFromError(
+ err: Error | PostError | BankSyncError,
+): BankSyncStatus {
+ if (isBankSyncError(err)) {
+ if (
+ (err.category === 'ITEM_ERROR' && err.code === 'ITEM_LOGIN_REQUIRED') ||
+ (err.category === 'INVALID_INPUT' &&
+ err.code === 'INVALID_ACCESS_TOKEN') ||
+ err.category === 'INVALID_ACCESS_TOKEN'
+ ) {
+ return 'reauth-required';
+ }
+
+ if (err.category === 'ACCOUNT_NEEDS_ATTENTION') {
+ return 'attention-required';
+ }
+ }
+
+ return 'failed';
+}
+
+function persistBankSyncError(
+ accountId: AccountEntity['id'],
+ err: Error | PostError | BankSyncError,
+) {
+ return db.update('accounts', {
+ id: accountId,
+ bank_sync_status: getBankSyncStatusFromError(err),
+ });
+}
+
export type SyncResponseWithErrors = SyncResponse & {
errors: SyncError[];
};
@@ -1274,6 +1311,7 @@ async function accountsBankSync({
updatedAccounts.push(...syncResponseData.updatedAccounts);
} catch (err) {
const error = err as Error;
+ await persistBankSyncError(acct.id, error);
errors.push(handleSyncError(error, acct));
captureException({
...error,
@@ -1288,7 +1326,7 @@ async function accountsBankSync({
if (updatedAccounts.length > 0) {
connection.send('sync-event', {
type: 'success',
- tables: ['transactions'],
+ tables: ['transactions', 'accounts'],
});
}
@@ -1356,17 +1394,15 @@ async function simpleFinBatchSync({
const updatedAccounts: Array<AccountEntity['id']> = [];
if (syncResponse.res?.error_code) {
- errors.push(
- handleSyncError(
- {
- type: 'BankSyncError',
- reason: 'Failed syncing account "' + account.name + '."',
- category: syncResponse.res.error_type,
- code: syncResponse.res.error_code,
- } as BankSyncError,
- account,
- ),
- );
+ const bankSyncError = {
+ type: 'BankSyncError',
+ reason: 'Failed syncing account "' + account.name + '."',
+ category: syncResponse.res.error_type,
+ code: syncResponse.res.error_code,
+ } as BankSyncError;
+
+ await persistBankSyncError(account.id, bankSyncError);
+ errors.push(handleSyncError(bankSyncError, account));
} else if (syncResponse.res) {
const syncResponseData = await handleSyncResponse(
syncResponse.res,
@@ -1377,14 +1413,11 @@ async function simpleFinBatchSync({
matchedTransactions.push(...syncResponseData.matchedTransactions);
updatedAccounts.push(...syncResponseData.updatedAccounts);
} else {
- errors.push(
- handleSyncError(
- new Error(
- 'Failed syncing account "' + account.name + '": empty response',
- ),
- account,
- ),
+ const emptyResponseError = new Error(
+ 'Failed syncing account "' + account.name + '": empty response',
);
+ await persistBankSyncError(account.id, emptyResponseError);
+ errors.push(handleSyncError(emptyResponseError, account));
}
retVal.push({
@@ -1395,6 +1428,7 @@ async function simpleFinBatchSync({
} catch (err) {
for (const account of accounts) {
const error = err as Error;
+ await persistBankSyncError(account.id, error);
retVal.push({
accountId: account.id,
res: {
@@ -1410,7 +1444,7 @@ async function simpleFinBatchSync({
if (retVal.some(a => a.res.updatedAccounts.length > 0)) {
connection.send('sync-event', {
type: 'success',
- tables: ['transactions'],
+ tables: ['transactions', 'accounts'],
});
}
@@ -1497,6 +1531,7 @@ async function unlinkAccount({ id }: { id: AccountEntity['id'] }) {
balance_available: null,
balance_limit: null,
account_sync_source: null,
+ bank_sync_status: null,
});
if (isGoCardless === false) {
@@ -1582,7 +1617,7 @@ app.method('simplefin-accounts', simpleFinAccounts);
app.method('pluggyai-accounts', pluggyAiAccounts);
app.method('gocardless-get-banks', getGoCardlessBanks);
app.method('gocardless-create-web-token', createGoCardlessWebToken);
-app.method('accounts-bank-sync', accountsBankSync);
-app.method('simplefin-batch-sync', simpleFinBatchSync);
+app.method('accounts-bank-sync', mutator(accountsBankSync));
+app.method('simplefin-batch-sync', mutator(simpleFinBatchSync));
app.method('transactions-import', mutator(undoable(importTransactions)));
app.method('account-unlink', mutator(unlinkAccount));
diff --git a/packages/loot-core/src/server/aql/schema/index.ts b/packages/loot-core/src/server/aql/schema/index.ts
index 3303cc37df..746ec602a1 100644
--- a/packages/loot-core/src/server/aql/schema/index.ts
+++ b/packages/loot-core/src/server/aql/schema/index.ts
@@ -77,6 +77,7 @@ export const schema = {
account_sync_source: f('string'),
last_reconciled: f('string'),
last_sync: f('string'),
+ bank_sync_status: f('string'),
},
categories: {
id: f('id'),
diff --git a/packages/loot-core/src/server/db/types/index.ts b/packages/loot-core/src/server/db/types/index.ts
index 236c297526..e390805921 100644
--- a/packages/loot-core/src/server/db/types/index.ts
+++ b/packages/loot-core/src/server/db/types/index.ts
@@ -24,6 +24,14 @@ export type DbAccount = {
account_sync_source?: 'simpleFin' | 'goCardless' | null;
last_reconciled?: string | null;
last_sync?: string | null;
+ bank_sync_status?:
+ | 'ok'
+ | 'pending'
+ | 'sync-requested'
+ | 'failed'
+ | 'reauth-required'
+ | 'attention-required'
+ | null;
};
export type DbBank = {
diff --git a/packages/loot-core/src/types/models/account.ts b/packages/loot-core/src/types/models/account.ts
index dcf21fc190..7315be64a8 100644
--- a/packages/loot-core/src/types/models/account.ts
+++ b/packages/loot-core/src/types/models/account.ts
@@ -21,6 +21,15 @@ export type AccountEntity = {
balance_limit: number | null;
account_sync_source: AccountSyncSource | null;
last_sync: string | null;
+ bank_sync_status: BankSyncStatus | null;
};
export type AccountSyncSource = BankSyncProviders;
+
+export type BankSyncStatus =
+ | 'ok'
+ | 'pending'
+ | 'sync-requested'
+ | 'failed'
+ | 'reauth-required'
+ | 'attention-required';
diff --git a/upcoming-release-notes/8017.md b/upcoming-release-notes/8017.md
new file mode 100644
index 0000000000..2bc0aeb56f
--- /dev/null
+++ b/upcoming-release-notes/8017.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [jcam, MatissJanis]
+---
+
+Accounts with a failed bank sync now stay flagged as failed after reloading, instead of losing that status on refresh.