A local-first personal finance app
fix reconciliation when experimental currency support is enabled (#6824)
Matt Fiddamanc9abc62b3a53
diff --git a/packages/desktop-client/src/components/accounts/Reconcile.test.tsx b/packages/desktop-client/src/components/accounts/Reconcile.test.tsxindex ed16a5fd3f..cc89c20563 100644--- a/packages/desktop-client/src/components/accounts/Reconcile.test.tsx+++ b/packages/desktop-client/src/components/accounts/Reconcile.test.tsx@@ -174,12 +174,12 @@ describe('ReconcileMenu arithmetic evaluation', () => {const input = screen.getByRole('textbox');// Replace with arithmetic expressionawait userEvent.clear(input);- await userEvent.type(input, '100+25.50-abcd-10');+ await userEvent.type(input, 'abcd');// Submitawait userEvent.click(screen.getByRole('button', { name: 'Reconcile' }));- // Input contains invalid characters, so it should use cleared balance for reconciliation+ // Input has no digits, so it should use cleared balance for reconciliationexpect(onReconcile).toHaveBeenCalledWith(123456);expect(onClose).toHaveBeenCalledTimes(1);});diff --git a/packages/desktop-client/src/components/accounts/Reconcile.tsx b/packages/desktop-client/src/components/accounts/Reconcile.tsxindex 1301bca8d6..c65c1b77bd 100644--- a/packages/desktop-client/src/components/accounts/Reconcile.tsx+++ b/packages/desktop-client/src/components/accounts/Reconcile.tsx@@ -13,9 +13,8 @@ import { View } from '@actual-app/components/view';import { format as formatDate } from 'date-fns';import { t } from 'i18next';-import { evalArithmetic } from 'loot-core/shared/arithmetic';import { type Query } from 'loot-core/shared/query';-import { amountToInteger, tsToRelativeTime } from 'loot-core/shared/util';+import { tsToRelativeTime } from 'loot-core/shared/util';import { type AccountEntity } from 'loot-core/types/models';import { type TransObjectLiteral } from 'loot-core/types/util';@@ -160,11 +159,9 @@ export function ReconcileMenu({return;}- const evaluatedAmount =- inputValue != null ? evalArithmetic(inputValue) : null;const amount =- evaluatedAmount != null- ? amountToInteger(evaluatedAmount)+ inputValue != null+ ? format.fromEdit(inputValue, clearedBalance): clearedBalance;onReconcile(amount);diff --git a/packages/desktop-client/src/hooks/useFormat.ts b/packages/desktop-client/src/hooks/useFormat.tsindex 562c8011b0..e0e585c8b0 100644--- a/packages/desktop-client/src/hooks/useFormat.ts+++ b/packages/desktop-client/src/hooks/useFormat.ts@@ -259,10 +259,14 @@ export function useFormat(): UseFormatResult {return defaultValue;}- let numericValue: number | null = evalArithmetic(trimmed, null);+ // strip directional formatting characters and letters+ const normalized = trimmed+ .replace(/[\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, '')+ .replace(/\p{L}+/gu, '');+ let numericValue: number | null = evalArithmetic(normalized, null);if (numericValue === null || isNaN(numericValue)) {- numericValue = currencyToAmount(trimmed);+ numericValue = currencyToAmount(normalized);}if (numericValue !== null && !isNaN(numericValue)) {diff --git a/upcoming-release-notes/6824.md b/upcoming-release-notes/6824.mdnew file mode 100644index 0000000000..effdb8cdcb--- /dev/null+++ b/upcoming-release-notes/6824.md@@ -0,0 +1,6 @@+---+category: Bugfixes+authors: [matt-fidd]+---++Fix reconciliation when experimental currency support is enabled