Skip to content
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

New edit cycle: Fix payout splits recipient not changing #4064

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Trans } from '@lingui/macro'
import { Modal } from 'antd'
import { ExternalLinkWithIcon } from 'components/ProjectDashboard/components/ui/ExternalLinkWithIcon'
import { helpPagePath } from 'utils/routes'
import { ensureSplitsSumTo100Percent } from 'utils/v2v3/distributions'
import { useEditCycleFormContext } from '../../../EditCycleFormContext'
import { usePayoutsTable } from '../../hooks/usePayoutsTable'

export function SwitchToUnlimitedModal({
open,
Expand All @@ -12,10 +14,12 @@ export function SwitchToUnlimitedModal({
onClose: VoidFunction
}) {
const { editCycleForm } = useEditCycleFormContext()
const { payoutSplits } = usePayoutsTable()

const onOk = () => {
editCycleForm?.setFieldsValue({
distributionLimit: undefined,
payoutSplits: ensureSplitsSumTo100Percent({ splits: payoutSplits }),
Copy link
Contributor Author

@johnnyd-eth johnnyd-eth Sep 12, 2023

Choose a reason for hiding this comment

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

Also noticed a weird bug when switching to unlimited sometimes. Should always be exactly 100% in that case - this fixes

Copy link
Contributor

Choose a reason for hiding this comment

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

nice, fair lol

})
onClose()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export const usePayoutsTable = () => {
handlePayoutSplitAmountChanged({
editingPayoutSplit: newSplit,
newAmount: parseFloat(newPayoutSplit.amount.value),
newSplits,
})
}
}
Expand All @@ -308,13 +309,16 @@ export const usePayoutsTable = () => {
* - Changed the % of other splits based on the new DL keep their amount the same
* @param editingPayoutSplit - Split that has had its amount changed
* @param newAmount - The new amount of the @editingPayoutSplit
* @param newSplits - (optional) pass new splits to adjust. If undefined, uses current @payoutSplits state
*/
function handlePayoutSplitAmountChanged({
editingPayoutSplit,
newAmount,
newSplits,
}: {
editingPayoutSplit: Split
newAmount: number
newSplits?: Split[]
}) {
const isNaN = Number.isNaN(newAmount)
const _amount = isNaN
Expand All @@ -335,9 +339,7 @@ export const usePayoutsTable = () => {
const newSplitPercentPPB = round(
(_amount / (newDistributionLimit ?? 0)) * ONE_BILLION,
)

let adjustedSplits: Split[] = payoutSplits

let adjustedSplits: Split[] = newSplits ?? payoutSplits
// recalculate all split percents based on newly added split amount
if (newDistributionLimit && !distributionLimitIsInfinite) {
adjustedSplits = adjustedSplitPercents({
Expand Down