Skip to content

Commit dafe026

Browse files
committed
Fix typecheck errors
1 parent f2e3da4 commit dafe026

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

packages/desktop-client/src/hooks/useDisplayPayee.tsx renamed to packages/desktop-client/src/hooks/useDisplayPayee.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useMemo } from 'react';
22

33
import { useTransactions } from 'loot-core/client/data-hooks/transactions';
4-
import { getPayeesById } from 'loot-core/client/queries/queriesSlice';
54
import { q } from 'loot-core/shared/query';
65
import {
76
type AccountEntity,
@@ -20,7 +19,7 @@ type Counts = {
2019
};
2120

2221
type UseDisplayPayeeProps = {
23-
transaction: TransactionEntity;
22+
transaction?: TransactionEntity | undefined;
2423
};
2524

2625
export function useDisplayPayee({ transaction }: UseDisplayPayeeProps) {
@@ -44,7 +43,7 @@ export function useDisplayPayee({ transaction }: UseDisplayPayeeProps) {
4443
transferAccount: accounts.find(
4544
a =>
4645
a.id ===
47-
payees.find(p => p.id === transaction.payee)?.transfer_acct,
46+
payees.find(p => p.id === transaction?.payee)?.transfer_acct,
4847
),
4948
});
5049
}
@@ -71,8 +70,13 @@ export function useDisplayPayee({ transaction }: UseDisplayPayeeProps) {
7170
return 'Split (no payee)';
7271
}
7372

74-
const mostCommonPayee =
75-
getPayeesById(payees)[mostCommonPayeeTransaction.payee];
73+
const mostCommonPayee = payees.find(
74+
p => p.id === mostCommonPayeeTransaction.payee,
75+
);
76+
77+
if (!mostCommonPayee) {
78+
return 'Split (no payee)';
79+
}
7680

7781
const numDistinctPayees = Object.keys(counts).length;
7882

@@ -87,14 +91,14 @@ export function useDisplayPayee({ transaction }: UseDisplayPayeeProps) {
8791
),
8892
numHiddenPayees: numDistinctPayees - 1,
8993
});
90-
}, [subtransactions, payees]);
94+
}, [subtransactions, payees, accounts, transaction, payee]);
9195
}
9296

9397
type GetPrettyPayeeProps = {
94-
transaction: TransactionEntity;
95-
payee: PayeeEntity;
96-
transferAccount: AccountEntity | null;
97-
numHiddenPayees?: number;
98+
transaction?: TransactionEntity | undefined;
99+
payee?: PayeeEntity | undefined;
100+
transferAccount?: AccountEntity | undefined;
101+
numHiddenPayees?: number | undefined;
98102
};
99103

100104
function getPrettyPayee({
@@ -103,6 +107,10 @@ function getPrettyPayee({
103107
transferAccount,
104108
numHiddenPayees = 0,
105109
}: GetPrettyPayeeProps) {
110+
if (!transaction) {
111+
return '';
112+
}
113+
106114
const formatPayeeName = (payeeName: string) =>
107115
numHiddenPayees > 0 ? `${payeeName} (+${numHiddenPayees} more)` : payeeName;
108116

0 commit comments

Comments
 (0)