Skip to content

Commit d7bc9dd

Browse files
committed
hide payouts create zero amount (#4517)
1 parent 0bfe8e0 commit d7bc9dd

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed

src/packages/v2v3/components/Create/components/pages/PayoutsPage/PayoutsPage.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import { useContext } from 'react'
2+
import { useAppSelector } from 'redux/hooks/useAppSelector'
23
import { useSetCreateFurthestPageReached } from 'redux/hooks/useEditingCreateFurthestPageReached'
34
import { Wizard } from '../../Wizard/Wizard'
45
import { PageContext } from '../../Wizard/contexts/PageContext'
56
import { CreateFlowPayoutsTable } from './components/CreateFlowPayoutsTable'
67
import { TreasuryOptionsRadio } from './components/TreasuryOptionsRadio'
78

89
export const PayoutsPage = () => {
10+
const treasurySelection = useAppSelector(
11+
state => state.creatingV2Project.treasurySelection,
12+
)
13+
914
useSetCreateFurthestPageReached('payouts')
1015
const { goToNextPage } = useContext(PageContext)
1116

1217
return (
1318
<CreateFlowPayoutsTable
19+
createTreasurySelection={treasurySelection}
1420
onFinish={() => {
1521
goToNextPage?.()
1622
}}

src/packages/v2v3/components/Create/components/pages/PayoutsPage/components/CreateFlowPayoutsTable.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Form } from 'antd'
22
import { CURRENCY_METADATA, CurrencyName } from 'constants/currency'
3+
import { TreasurySelection } from 'models/treasurySelection'
34
import { PayoutsTable } from 'packages/v2v3/components/shared/PayoutsTable/PayoutsTable'
45
import { Split } from 'packages/v2v3/models/splits'
56
import {
@@ -23,11 +24,15 @@ export function CreateFlowPayoutsTable({
2324
topAccessory,
2425
okButton,
2526
addPayoutsDisabled,
27+
createTreasurySelection,
2628
}: {
2729
onFinish?: VoidFunction
2830
okButton?: ReactNode
2931
topAccessory?: ReactNode
3032
addPayoutsDisabled?: boolean
33+
// TODO: Hack to allow payout recipients to be shown on review but not on create page
34+
// When zero, hides the recipients, but undefined still shows them
35+
createTreasurySelection?: TreasurySelection
3136
}) {
3237
const [
3338
editingDistributionLimit,
@@ -75,6 +80,7 @@ export function CreateFlowPayoutsTable({
7580
hideExplaination
7681
hideSettings
7782
addPayoutsDisabled={addPayoutsDisabled}
83+
createTreasurySelection={createTreasurySelection}
7884
/>
7985
{/* Empty form item just to keep AntD useWatch happy */}
8086
<Form.Item shouldUpdate name="payoutsList" className="mb-0" />

src/packages/v2v3/components/Create/components/pages/PayoutsPage/components/TreasuryOptionsRadio.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import { useModal } from 'hooks/useModal'
88
import { TreasurySelection } from 'models/treasurySelection'
99
import { ConvertAmountsModal } from 'packages/v2v3/components/shared/PayoutsTable/ConvertAmountsModal'
1010
import { usePayoutsTable } from 'packages/v2v3/components/shared/PayoutsTable/hooks/usePayoutsTable'
11-
import {
12-
V2V3_CURRENCY_ETH,
13-
V2V3_CURRENCY_USD,
14-
} from 'packages/v2v3/utils/currency'
11+
import { V4_CURRENCY_ETH, V4_CURRENCY_USD } from 'packages/v4/utils/currency'
1512
import { useCallback, useEffect, useMemo, useState } from 'react'
13+
import { useAppDispatch } from 'redux/hooks/useAppDispatch'
1614
import { useAppSelector } from 'redux/hooks/useAppSelector'
1715
import { ReduxDistributionLimit } from 'redux/hooks/v2v3/shared'
16+
import { creatingV2ProjectActions } from 'redux/slices/creatingV2Project'
1817
import { fromWad } from 'utils/format/formatNumber'
1918
import { Icons } from '../../../Icons'
2019
import { RadioCard } from './RadioCard'
@@ -29,6 +28,8 @@ export function TreasuryOptionsRadio() {
2928
const initialTreasurySelection = useAppSelector(
3029
state => state.creatingV2Project.treasurySelection,
3130
)
31+
const dispatch = useAppDispatch()
32+
3233
const [treasuryOption, setTreasuryOption] = useState<TreasurySelection>(
3334
initialTreasurySelection ?? 'zero',
3435
)
@@ -106,17 +107,19 @@ export function TreasuryOptionsRadio() {
106107
switchToZeroPayoutSelection()
107108
}
108109

110+
dispatch(creatingV2ProjectActions.setTreasurySelection(option))
109111
setTreasuryOption(option)
110112
},
111113
[
112114
treasuryOption,
113115
payoutSplits.length,
116+
dispatch,
114117
switchingToAmountsModal,
115-
switchingToUnlimitedModal,
116118
setDistributionLimit,
119+
switchingToUnlimitedModal,
120+
switchToUnlimitedPayouts,
117121
switchingToZeroAmountsModal,
118122
switchToZeroPayoutSelection,
119-
switchToUnlimitedPayouts,
120123
],
121124
)
122125

@@ -168,11 +171,11 @@ export function TreasuryOptionsRadio() {
168171
onClose={switchingToUnlimitedModal.close}
169172
/>
170173
<ConvertAmountsModal
174+
currency={currency === 'ETH' ? V4_CURRENCY_ETH : V4_CURRENCY_USD}
171175
open={switchingToAmountsModal.visible}
172176
onOk={switchToAmountsPayoutSelection}
173177
onCancel={switchingToAmountsModal.close}
174178
splits={payoutSplits}
175-
currency={currency === 'ETH' ? V2V3_CURRENCY_ETH : V2V3_CURRENCY_USD}
176179
/>
177180
</>
178181
)

src/packages/v2v3/components/shared/PayoutsTable/PayoutsTableBody.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const Row = PayoutsTableRow
1616
const Cell = PayoutsTableCell
1717

1818
export function PayoutsTableBody() {
19-
const { topAccessory, hideHeader } = usePayoutsTableContext()
19+
const { topAccessory, hideHeader, createTreasurySelection } =
20+
usePayoutsTableContext()
2021
const {
2122
payoutSplits,
2223
currency,
@@ -28,6 +29,11 @@ export function PayoutsTableBody() {
2829

2930
const hasDistributionLimit = distributionLimit && distributionLimit > 0
3031

32+
if (createTreasurySelection === 'zero') {
33+
// TODO: This feels like a hack, this should not be coupled here.
34+
return <>{topAccessory}</>
35+
}
36+
3137
return (
3238
<>
3339
{topAccessory}
@@ -59,9 +65,11 @@ export function PayoutsTableBody() {
5965
<Cell>
6066
<Trans>Address or ID</Trans>
6167
</Cell>
62-
{hasDistributionLimit ?
63-
<CurrencySwitcher />
64-
: <Trans>Percent</Trans>}
68+
{hasDistributionLimit ? (
69+
<CurrencySwitcher />
70+
) : (
71+
<Trans>Percent</Trans>
72+
)}
6573
</Row>
6674
) : null}
6775
{payoutSplits.map((payoutSplit, index) => (

src/packages/v2v3/components/shared/PayoutsTable/context/PayoutsTableContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CurrencyName } from 'constants/currency'
2+
import { TreasurySelection } from 'models/treasurySelection'
23
import { Split } from 'packages/v2v3/models/splits'
34
import { ReactNode, createContext, useContext } from 'react'
45

@@ -16,6 +17,8 @@ export interface PayoutsTableContextProps {
1617
topAccessory?: ReactNode
1718
hideSettings?: boolean
1819
addPayoutsDisabled?: boolean
20+
// TODO: Hack to allow the create payouts table to hide data if set to none.
21+
createTreasurySelection?: TreasurySelection
1922
}
2023

2124
export const PayoutsTableContext = createContext<

src/redux/slices/shared/v2ProjectDefaultState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const DEFAULT_PROJECT_METADATA_STATE: ProjectMetadata = {
120120
}
121121

122122
const DEFAULT_CREATE_STATE: CreateState = {
123-
treasurySelection: undefined,
123+
treasurySelection: 'zero',
124124
reconfigurationRuleSelection: undefined,
125125
fundingCyclesPageSelection: undefined,
126126
createFurthestPageReached: 'projectDetails',

0 commit comments

Comments
 (0)