A local-first personal finance app
feat: add "last reconciled" timestamp to accounts (#4459)
Margarida Reis5ebbff4f87cc
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsxindex fb22b91d1d..4a66bb1d05 100644--- a/packages/desktop-client/src/components/accounts/Account.tsx+++ b/packages/desktop-client/src/components/accounts/Account.tsx@@ -1010,6 +1010,13 @@ class AccountInternal extends PureComponent<onDoneReconciling = async () => {const { accountId } = this.props;+ const account = this.props.accounts.find(+ account => account.id === accountId,+ );+ if (!account) {+ throw new Error(`Account with ID ${accountId} not found.`);+ }+const { reconcileAmount } = this.state;const { data } = await runQuery(@@ -1034,6 +1041,13 @@ class AccountInternal extends PureComponent<await this.lockTransactions();}+ const lastReconciled = new Date().getTime().toString();+ this.props.dispatch(+ updateAccount({+ account: { ...account, last_reconciled: lastReconciled },+ }),+ );+this.setState({reconcileAmount: null,showCleared: this.state.prevShowCleared,diff --git a/packages/desktop-client/src/components/accounts/Balance.tsx b/packages/desktop-client/src/components/accounts/Balance.tsxindex 136a0c0fc7..f43930488f 100644--- a/packages/desktop-client/src/components/accounts/Balance.tsx+++ b/packages/desktop-client/src/components/accounts/Balance.tsx@@ -251,6 +251,7 @@ export function Balances({}}/></Button>+{showExtraBalances && <MoreBalances balanceQuery={balanceQuery} />}{selectedItems.size > 0 && (diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsxindex 59534cab9a..4a68f224f9 100644--- a/packages/desktop-client/src/components/accounts/Header.tsx+++ b/packages/desktop-client/src/components/accounts/Header.tsx@@ -14,8 +14,10 @@ import { Menu } from '@actual-app/components/menu';import { Popover } from '@actual-app/components/popover';import { Stack } from '@actual-app/components/stack';import { styles } from '@actual-app/components/styles';+import { Tooltip } from '@actual-app/components/tooltip';import { View } from '@actual-app/components/view';+import { tsToRelativeTime } from 'loot-core/shared/util';import {type AccountEntity,type RuleConditionEntity,@@ -23,6 +25,7 @@ import {type TransactionFilterEntity,} from 'loot-core/types/models';+import { useGlobalPref } from '../../hooks/useGlobalPref';import { useLocalPref } from '../../hooks/useLocalPref';import { useSplitsExpanded } from '../../hooks/useSplitsExpanded';import { useSyncServerStatus } from '../../hooks/useSyncServerStatus';@@ -185,6 +188,8 @@ export function AccountHeader({onMakeAsNonSplitTransactions,}: AccountHeaderProps) {const { t } = useTranslation();+ const [language] = useGlobalPref('language');+const [menuOpen, setMenuOpen] = useState(false);const [reconcileOpen, setReconcileOpen] = useState(false);const searchInput = useRef<HTMLInputElement>(null);@@ -374,19 +379,33 @@ export function AccountHeader({onMakeAsNonSplitTransactions={onMakeAsNonSplitTransactions}/>)}- <View style={{ flex: '0 0 auto' }}>+ <View style={{ flex: '0 0 auto', marginLeft: 10 }}>{account && (- <>+ <Tooltip+ style={{+ ...styles.tooltip,+ marginBottom: 10,+ }}+ content={+ account?.last_reconciled+ ? `${t('Reconciled')} ${tsToRelativeTime(account.last_reconciled, language || 'en-US')}`+ : t('Not yet reconciled')+ }+ placement="top"+ triggerProps={{+ isDisabled: reconcileOpen,+ }}+ ><Buttonref={reconcileRef}variant="bare"aria-label={t('Reconcile')}- style={{ padding: 6, marginLeft: 10 }}+ style={{ padding: 6 }}onPress={() => {setReconcileOpen(true);}}>- <View title={t('Reconcile')}>+ <View><SvgLockClosed width={14} height={14} /></View></Button>@@ -403,7 +422,7 @@ export function AccountHeader({onReconcile={onReconcile}/></Popover>- </>+ </Tooltip>)}</View><Buttondiff --git a/packages/desktop-client/src/components/spreadsheet/index.ts b/packages/desktop-client/src/components/spreadsheet/index.tsindex 3394790763..c62e26f71b 100644--- a/packages/desktop-client/src/components/spreadsheet/index.ts+++ b/packages/desktop-client/src/components/spreadsheet/index.ts@@ -14,6 +14,7 @@ export type Spreadsheets = {'offbudget-accounts-balance': number;balanceCleared: number;balanceUncleared: number;+ lastReconciled: string | null;};category: {// Common fieldsdiff --git a/packages/loot-core/migrations/1740506588539_add_last_reconciled_at.sql b/packages/loot-core/migrations/1740506588539_add_last_reconciled_at.sqlnew file mode 100644index 0000000000..e895c18c2e--- /dev/null+++ b/packages/loot-core/migrations/1740506588539_add_last_reconciled_at.sql@@ -0,0 +1,5 @@+BEGIN TRANSACTION;++ALTER TABLE accounts ADD COLUMN last_reconciled text;++COMMIT;diff --git a/packages/loot-core/src/mocks/index.ts b/packages/loot-core/src/mocks/index.tsindex e008df1d7a..8e4d83d92b 100644--- a/packages/loot-core/src/mocks/index.ts+++ b/packages/loot-core/src/mocks/index.ts@@ -22,6 +22,7 @@ export function generateAccount(name,offbudget: offbudget ? 1 : 0,sort_order: 0,+ last_reconciled: null,tombstone: 0,closed: 0,...emptySyncFields(),diff --git a/packages/loot-core/src/server/accounts/app.ts b/packages/loot-core/src/server/accounts/app.tsindex b20c002b4d..fcd8187d10 100644--- a/packages/loot-core/src/server/accounts/app.ts+++ b/packages/loot-core/src/server/accounts/app.ts@@ -59,8 +59,17 @@ export type AccountHandlers = {'account-unlink': typeof unlinkAccount;};-async function updateAccount({ id, name }: Pick<AccountEntity, 'id' | 'name'>) {- await db.update('accounts', { id, name });+async function updateAccount({+ id,+ name,+ last_reconciled,+}: Pick<AccountEntity, 'id' | 'name'> &+ Partial<Pick<AccountEntity, 'last_reconciled'>>) {+ await db.update('accounts', {+ id,+ name,+ ...(last_reconciled && { last_reconciled }),+ });return {};}diff --git a/packages/loot-core/src/server/aql/schema/index.ts b/packages/loot-core/src/server/aql/schema/index.tsindex 5b85c75a65..7f271d8756 100644--- a/packages/loot-core/src/server/aql/schema/index.ts+++ b/packages/loot-core/src/server/aql/schema/index.ts@@ -74,6 +74,7 @@ export const schema = {account_id: f('string'),official_name: f('string'),account_sync_source: f('string'),+ last_reconciled: f('string'),last_sync: f('string'),},categories: {diff --git a/packages/loot-core/src/shared/util.ts b/packages/loot-core/src/shared/util.tsindex 52ff565279..39bf137bac 100644--- a/packages/loot-core/src/shared/util.ts+++ b/packages/loot-core/src/shared/util.ts@@ -1,4 +1,7 @@// @ts-strict-ignore+import { formatDistanceToNow } from 'date-fns';+import * as locales from 'date-fns/locale';+export function last<T>(arr: Array<T>) {return arr[arr.length - 1];}@@ -481,3 +484,16 @@ export function sortByKey<T>(arr: T[], key: keyof T): T[] {return 0;});}++// Date utilities++export function tsToRelativeTime(ts: string | null, language: string): string {+ if (!ts) return 'Unknown';++ const parsed = new Date(parseInt(ts, 10));+ const locale =+ locales[language.replace('-', '') as keyof typeof locales] ??+ locales['enUS'];++ return formatDistanceToNow(parsed, { addSuffix: true, locale });+}diff --git a/packages/loot-core/src/types/models/account.d.ts b/packages/loot-core/src/types/models/account.d.tsindex 74436bad58..3542fd1710 100644--- a/packages/loot-core/src/types/models/account.d.ts+++ b/packages/loot-core/src/types/models/account.d.ts@@ -4,6 +4,7 @@ export type AccountEntity = {offbudget: 0 | 1;closed: 0 | 1;sort_order: number;+ last_reconciled: string | null;tombstone: 0 | 1;} & (_SyncFields<true> | _SyncFields<false>);diff --git a/upcoming-release-notes/4459.md b/upcoming-release-notes/4459.mdnew file mode 100644index 0000000000..651b1f7d1a--- /dev/null+++ b/upcoming-release-notes/4459.md@@ -0,0 +1,6 @@+---+category: Features+authors: [tostasmistas]+---++Add "last reconciled" timestamp to accounts