Skip to content

Commit

Permalink
Merge pull request #93 from riccardofano/clamp-patrimony-calculation
Browse files Browse the repository at this point in the history
Debt doesn't make the total go negative
  • Loading branch information
riccardofano authored Jan 25, 2024
2 parents 3bfb3ea + 2adc602 commit 278a43d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/MoneyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function MoneyForm() {
const intDonations = toNumber(donations)

if (allValidNumbers([intTotal, intDebt, intDonations])) {
setMoney((intTotal - intDebt + intDonations).toString())
let total = intTotal - intDebt
if (total < 0) {
total = 0
}
setMoney((total + intDonations).toString())
}
}, [mode, patrimonyValues, setMoney])

Expand Down

1 comment on commit 278a43d

@vercel
Copy link

@vercel vercel bot commented on 278a43d Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.