Skip to content

A local-first personal finance app

feat(currency): add currency display to schedules (#5907)

Michael Süssemilch37247395e23f
diff --git a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
index d25831aeb3..31c56f731c 100644
--- a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
+++ b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
@@ -14,7 +14,6 @@ import { View } from '@actual-app/components/view';
import { format as monthUtilFormat } from 'loot-core/shared/months';
import { getNormalisedString } from 'loot-core/shared/normalisation';
import { getScheduledAmount } from 'loot-core/shared/schedules';
-import { integerToCurrency } from 'loot-core/shared/util';
import { type ScheduleEntity } from 'loot-core/types/models';
import { StatusBadge } from './StatusBadge';
@@ -31,6 +30,7 @@ import { DisplayId } from '@desktop-client/components/util/DisplayId';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useContextMenu } from '@desktop-client/hooks/useContextMenu';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { usePayees } from '@desktop-client/hooks/usePayees';
import {
type ScheduleStatusType,
@@ -129,9 +129,10 @@ export function ScheduleAmountCell({
op: ScheduleEntity['_amountOp'];
}) {
const { t } = useTranslation();
+ const format = useFormat();
const num = getScheduledAmount(amount);
- const currencyAmount = integerToCurrency(Math.abs(num || 0));
+ const currencyAmount = format(Math.abs(num || 0), 'financial');
const isApprox = op === 'isapprox' || op === 'isbetween';
return (
@@ -192,7 +193,10 @@ function ScheduleRow({
minimal,
statuses,
dateFormat,
-}: { schedule: ScheduleEntity; dateFormat: string } & Pick<
+}: {
+ schedule: ScheduleEntity;
+ dateFormat: string;
+} & Pick<
SchedulesTableProps,
'onSelect' | 'onAction' | 'minimal' | 'statuses'
>) {
@@ -316,6 +320,7 @@ export function SchedulesTable({
tableStyle,
}: SchedulesTableProps) {
const { t } = useTranslation();
+ const format = useFormat();
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
const [showCompleted, setShowCompleted] = useState(false);
@@ -342,7 +347,7 @@ export function SchedulesTable({
? '~'
: '') +
(amount > 0 ? '+' : '') +
- integerToCurrency(Math.abs(amount || 0));
+ format(Math.abs(amount || 0), 'financial');
const dateStr = schedule.next_date
? monthUtilFormat(schedule.next_date, dateFormat)
: null;
diff --git a/packages/desktop-client/src/components/transactions/SimpleTransactionsTable.tsx b/packages/desktop-client/src/components/transactions/SimpleTransactionsTable.tsx
index 43fbb021fc..d70de5fb14 100644
--- a/packages/desktop-client/src/components/transactions/SimpleTransactionsTable.tsx
+++ b/packages/desktop-client/src/components/transactions/SimpleTransactionsTable.tsx
@@ -17,7 +17,6 @@ import {
} from 'date-fns';
import * as monthUtils from 'loot-core/shared/months';
-import { integerToCurrency } from 'loot-core/shared/util';
import { type TransactionEntity } from 'loot-core/types/models';
import {
@@ -31,6 +30,7 @@ import { DisplayId } from '@desktop-client/components/util/DisplayId';
import { useAccount } from '@desktop-client/hooks/useAccount';
import { useCategory } from '@desktop-client/hooks/useCategory';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
+import { type FormatType, useFormat } from '@desktop-client/hooks/useFormat';
import {
useSelectedItems,
useSelectedDispatch,
@@ -56,12 +56,14 @@ type TransactionRowProps = {
transaction: TransactionEntity;
fields: string[];
selected: boolean;
+ format: (value: unknown, type: FormatType) => string;
};
const TransactionRow = memo(function TransactionRow({
transaction,
fields,
selected,
+ format,
}: TransactionRowProps) {
const { t } = useTranslation();
@@ -157,7 +159,7 @@ const TransactionRow = memo(function TransactionRow({
width={75}
style={{ textAlign: 'right', ...styles.tnum }}
>
- {integerToCurrency(transaction.amount)}
+ {format(transaction.amount, 'financial')}
</Field>
);
default:
@@ -181,6 +183,7 @@ export function SimpleTransactionsTable({
fields = ['date', 'payee', 'amount'],
style,
}: SimpleTransactionsTableProps) {
+ const format = useFormat();
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
const selectedItems = useSelectedItems();
const dispatchSelected = useSelectedDispatch();
@@ -197,10 +200,11 @@ export function SimpleTransactionsTable({
transaction={item}
fields={memoFields}
selected={selectedItems && selectedItems.has(item.id)}
+ format={format}
/>
);
},
- [memoFields, selectedItems],
+ [memoFields, selectedItems, format],
);
return (
diff --git a/upcoming-release-notes/5907.md b/upcoming-release-notes/5907.md
new file mode 100644
index 0000000000..9f40fa4e02
--- /dev/null
+++ b/upcoming-release-notes/5907.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [misu-dev]
+---
+
+Adds currency display to the schedules