Skip to content

Commit b46be03

Browse files
This commit fixes a bug in the settlement summary on the Group Details page.
The previous implementation did not correctly display the scenario where you are owed money. This has been corrected. The summary now shows: - What you owe to others. - What others owe to you. - A "settled up" message when there are no outstanding debts.
1 parent 7211eba commit b46be03

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

frontend/screens/GroupDetailsScreen.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,30 @@ const GroupDetailsScreen = ({ route, navigation }) => {
8080
);
8181

8282
const renderSettlementSummary = () => {
83-
const userSettlements = settlements.filter(s => s.fromUserId === user._id);
84-
const totalOwed = userSettlements.reduce((sum, s) => sum + s.amount, 0);
83+
const userOwes = settlements.filter(s => s.fromUserId === user._id);
84+
const userIsOwed = settlements.filter(s => s.toUserId === user._id);
85+
const totalOwed = userOwes.reduce((sum, s) => sum + s.amount, 0);
86+
const totalToReceive = userIsOwed.reduce((sum, s) => sum + s.amount, 0);
8587

86-
if (userSettlements.length === 0) {
88+
if (userOwes.length === 0 && userIsOwed.length === 0) {
8789
return <Paragraph>You are all settled up in this group!</Paragraph>;
8890
}
8991

9092
return (
9193
<>
92-
<Title>You owe ${totalOwed.toFixed(2)} overall</Title>
93-
{userSettlements.map((s, index) => (
94-
<Paragraph key={index}>
94+
<Title style={{color: 'red'}}>You need to pay: ${totalOwed.toFixed(2)}</Title>
95+
{userOwes.map((s, index) => (
96+
<Paragraph key={`owes-${index}`}>
9597
- You owe {getMemberName(s.toUserId)} ${s.amount.toFixed(2)}
9698
</Paragraph>
9799
))}
100+
101+
<Title style={{color: 'green', marginTop: 16}}>You will receive: ${totalToReceive.toFixed(2)}</Title>
102+
{userIsOwed.map((s, index) => (
103+
<Paragraph key={`is-owed-${index}`}>
104+
- {getMemberName(s.fromUserId)} pays you ${s.amount.toFixed(2)}
105+
</Paragraph>
106+
))}
98107
</>
99108
);
100109
};

0 commit comments

Comments
 (0)