-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: changing distribution type should show accurate percentage #4201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, this stuff was pretty pesky, nicely ironed out 💯
- Created the classic "let's make .33333333333 decimals" payments
- Changing to unequal leaves everything intact
A bug I've found (which probably makes no sense fixing here), but if we add values beyond the 4th decimal, it will allow creating the action
but since we round to 4 decimals, the end result is correct
kinda confusing 🤔
anyhow, this doesn't affect this PR so I'll gladly smash approve 🚢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work on this one @davecreaser 💯
Tested it and seems the values do add up to 100%
when switching from equal
to unequal
distribution type
Screen.Recording.2025-01-30.at.14.02.50.mov
Nice!
export const getUnevenSplitPaymentTotalPercentage = ( | ||
amount: number, | ||
recipients: SplitPaymentRecipientsFieldModel[], | ||
) => { | ||
if (!amount) { | ||
return 0; | ||
} | ||
|
||
const total = | ||
recipients?.reduce((acc, recipient) => { | ||
return acc + Number(recipient.amount); | ||
}, 0) || 0; | ||
|
||
const percentage = (100 * total) / amount; | ||
|
||
return Number(percentage.toFixed(4)); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! Tested both equal and unequal and changed various percentages.
Everything is acting as expected.
Very nice fix! 🎉
Description
equal
(which will always be 100%) to unequal suddenly makes the percentage not 100%.Testing
Diffs
Changes 🏗
Resolves #3856