Skip to content

Commit 11a611d

Browse files
committed
Negative amount fixes
1 parent a25f964 commit 11a611d

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/components/Expense/ExpenseList.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export const ExpenseList: React.FC<{
5656
>
5757
<span className="text-[10px]">{isSettlement ? ' 🎉 ' : null}</span>
5858
{displayName(e.paidByUser, userId)}{' '}
59-
{t(`ui.expense.user.${e.amount < 0n ? 'received' : 'paid'}`, { ns: 'common' })}{' '}
59+
{t(
60+
`ui.expense.${e.paidByUser.id === userId ? 'you' : 'user'}.${e.amount < 0n ? 'received' : 'paid'}`,
61+
{ ns: 'common' },
62+
)}{' '}
6063
{toUIString(e.amount)}
6164
</p>
6265
</div>

src/components/ui/currency-input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ const CurrencyInput = React.forwardRef<
3939
value={strValue}
4040
onFocus={() => onValueChange({ strValue: parseToCleanString(strValue) })}
4141
onBlur={() => {
42-
const formattedValue = format(strValue);
42+
const formattedValue = format(strValue, allowNegative);
4343
return onValueChange({
4444
strValue: hideSymbol ? stripCurrencySymbol(formattedValue) : formattedValue,
4545
});
4646
}}
4747
onChange={(e) => {
4848
const rawValue = e.target.value;
4949
const strValue = sanitizeInput(rawValue, allowNegative);
50-
const bigIntValue = toSafeBigInt(strValue);
50+
const bigIntValue = toSafeBigInt(strValue, allowNegative);
5151
onValueChange({ strValue, bigIntValue });
5252
}}
5353
{...props}

src/pages/activity.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ function getPaymentString(
3535
);
3636
} else {
3737
return (
38-
<div className={`${user.id === paidBy ? 'text-emerald-500' : 'text-orange-500'} text-sm`}>
39-
{user.id === paidBy
40-
? `${t('ui.actors.you')} ${t('ui.expense.you.lent')} ${toUIString(BigMath.abs(expenseUserAmt))}`
41-
: `${t('ui.actors.you')} ${t('ui.expense.you.owe')} ${toUIString(expenseUserAmt)}`}
38+
<div
39+
className={`${(user.id === paidBy) !== amount < 0n ? 'text-emerald-500' : 'text-orange-500'} text-sm`}
40+
>
41+
{t(`ui.actors.you`)}{' '}
42+
{t(`ui.expense.you.${(user.id === paidBy) !== amount < 0n ? 'lent' : 'owe'}`)}{' '}
43+
{toUIString(expenseUserAmt)}
4244
</div>
4345
);
4446
}
@@ -86,7 +88,9 @@ const ActivityPage: NextPageWithUser = ({ user }) => {
8688
<span className="font-semibold text-gray-300">
8789
{displayName(e.expense.paidByUser, user.id)}
8890
</span>{' '}
89-
{t(`ui.expense.${e.expense.paidByUser.id === user.id ? 'you' : 'user'}.paid`)}{' '}
91+
{t(
92+
`ui.expense.${e.expense.paidByUser.id === user.id ? 'you' : 'user'}.${e.expense.amount > 0n ? 'paid' : 'received'}`,
93+
)}{' '}
9094
{toUIString(e.expense.amount)} {t('ui.expense.for')}{' '}
9195
<span className="font-semibold text-gray-300">{e.expense.name}</span>
9296
</p>

0 commit comments

Comments
 (0)