Skip to content

Commit 57e23d5

Browse files
This commit fixes a bug that caused the Friends page to crash.
The error was a `TypeError` caused by incorrectly accessing the expenses array when calculating friend balances. This has been corrected. The client-side calculation logic is now more robust and handles cases where groups may not have any expenses.
1 parent 9011da7 commit 57e23d5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

frontend/screens/FriendsScreen.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ const FriendsScreen = () => {
1515
const balances = {}; // { friendId: { name, netBalance, groups: { groupId: { name, balance } } } }
1616

1717
groupsWithDetails.forEach(group => {
18-
const [members, expenses] = group.details;
18+
const [membersResponse, expensesResponse] = group.details;
19+
const members = membersResponse.data;
20+
const expenses = expensesResponse.data.expenses;
1921

20-
expenses.expenses.forEach(expense => {
22+
if (!expenses) return; // Guard against undefined expenses
23+
24+
expenses.forEach(expense => {
2125
const payerId = expense.createdBy;
2226
const payerIsMe = payerId === user._id;
2327

0 commit comments

Comments
 (0)