Skip to content

Commit c9abc62

Browse files
authored
fix reconciliation when experimental currency support is enabled (#6824)
* fix reconcilation when using currency symbols * note * fix tests
1 parent 234f257 commit c9abc62

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

packages/desktop-client/src/components/accounts/Reconcile.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ describe('ReconcileMenu arithmetic evaluation', () => {
174174
const input = screen.getByRole('textbox');
175175
// Replace with arithmetic expression
176176
await userEvent.clear(input);
177-
await userEvent.type(input, '100+25.50-abcd-10');
177+
await userEvent.type(input, 'abcd');
178178

179179
// Submit
180180
await userEvent.click(screen.getByRole('button', { name: 'Reconcile' }));
181181

182-
// Input contains invalid characters, so it should use cleared balance for reconciliation
182+
// Input has no digits, so it should use cleared balance for reconciliation
183183
expect(onReconcile).toHaveBeenCalledWith(123456);
184184
expect(onClose).toHaveBeenCalledTimes(1);
185185
});

packages/desktop-client/src/components/accounts/Reconcile.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import { View } from '@actual-app/components/view';
1313
import { format as formatDate } from 'date-fns';
1414
import { t } from 'i18next';
1515

16-
import { evalArithmetic } from 'loot-core/shared/arithmetic';
1716
import { type Query } from 'loot-core/shared/query';
18-
import { amountToInteger, tsToRelativeTime } from 'loot-core/shared/util';
17+
import { tsToRelativeTime } from 'loot-core/shared/util';
1918
import { type AccountEntity } from 'loot-core/types/models';
2019
import { type TransObjectLiteral } from 'loot-core/types/util';
2120

@@ -160,11 +159,9 @@ export function ReconcileMenu({
160159
return;
161160
}
162161

163-
const evaluatedAmount =
164-
inputValue != null ? evalArithmetic(inputValue) : null;
165162
const amount =
166-
evaluatedAmount != null
167-
? amountToInteger(evaluatedAmount)
163+
inputValue != null
164+
? format.fromEdit(inputValue, clearedBalance)
168165
: clearedBalance;
169166

170167
onReconcile(amount);

packages/desktop-client/src/hooks/useFormat.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,14 @@ export function useFormat(): UseFormatResult {
259259
return defaultValue;
260260
}
261261

262-
let numericValue: number | null = evalArithmetic(trimmed, null);
262+
// strip directional formatting characters and letters
263+
const normalized = trimmed
264+
.replace(/[\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, '')
265+
.replace(/\p{L}+/gu, '');
266+
let numericValue: number | null = evalArithmetic(normalized, null);
263267

264268
if (numericValue === null || isNaN(numericValue)) {
265-
numericValue = currencyToAmount(trimmed);
269+
numericValue = currencyToAmount(normalized);
266270
}
267271

268272
if (numericValue !== null && !isNaN(numericValue)) {

upcoming-release-notes/6824.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Bugfixes
3+
authors: [matt-fidd]
4+
---
5+
6+
Fix reconciliation when experimental currency support is enabled

0 commit comments

Comments
 (0)