Skip to content

Commit 94ceca4

Browse files
committed
Set state properties required for calculating shares, before doing so
1 parent aab581e commit 94ceca4

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/pages/add.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ const AddPage: NextPageWithUser<{
9191
}
9292

9393
expenseQuery.data.group && setGroup(expenseQuery.data.group);
94+
setPaidBy(expenseQuery.data.paidByUser);
95+
setCurrency(expenseQuery.data.currency as CurrencyCode);
96+
setAmountStr((Number(expenseQuery.data.amount) / 100).toString());
97+
setDescription(expenseQuery.data.name);
98+
setAmount(expenseQuery.data.amount);
9499
setParticipants(
95100
expenseQuery.data.expenseParticipants.map((ep) => ({
96101
...ep.user,
97102
amount: ep.amount,
98103
})),
99104
expenseQuery.data.splitType,
100105
);
101-
setCurrency(expenseQuery.data.currency as CurrencyCode);
102-
setAmountStr((Number(expenseQuery.data.amount) / 100).toString());
103-
setDescription(expenseQuery.data.name);
104-
setPaidBy(expenseQuery.data.paidByUser);
105-
setAmount(expenseQuery.data.amount);
106106
useAddExpenseStore.setState({ showFriends: false });
107107
setExpenseDate(expenseQuery.data.expenseDate);
108108
// eslint-disable-next-line react-hooks/exhaustive-deps

src/store/addStore.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export function calculateSplitShareBasedOnAmount(
389389
Math.round(
390390
(Math.abs(
391391
paidBy?.id !== p.id
392-
? Number(p.amount) ?? 0
392+
? (Number(p.amount) ?? 0)
393393
: amountNum - (Number(p.amount) ?? 0),
394394
) /
395395
amountNum) *
@@ -403,7 +403,9 @@ export function calculateSplitShareBasedOnAmount(
403403
case SplitType.EXACT:
404404
participants.forEach((p) => {
405405
splitShares[p.id]![splitType] =
406-
paidBy?.id !== p.id ? BigMath.abs(p.amount ?? 0n) : amount - BigMath.abs(p.amount ?? 0n);
406+
paidBy?.id !== p.id
407+
? BigMath.abs(p.amount ?? 0n)
408+
: BigMath.abs(amount - (p.amount ?? 0n));
407409
});
408410

409411
break;

0 commit comments

Comments
 (0)