Skip to content

Commit

Permalink
added open funding switch to create and update reward distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Sep 23, 2024
1 parent f6972f2 commit 9df9b9d
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@
"onlyMembersExecuteDescription": "If enabled, only members may execute passed proposals.",
"onlyMembersExecuteTitle": "Only members execute",
"openDate": "Open date",
"openFunding": "Open funding",
"optional": "optional",
"options": "Options",
"orUploadOne": "...or upload one below.",
Expand Down Expand Up @@ -1258,6 +1259,7 @@
"numSubmissions_one": "{{count}} submission",
"numSubmissions_other": "{{count}} submissions",
"onlyMembers": "Only members",
"openFundingDescription": "If enabled, anyone is allowed to fund this distribution. Otherwise, only the DAO can distribute funds.",
"openMobileWalletAndAcceptConnection": "<0>Open your mobile wallet</0> and accept the connection request.",
"openProfileSidebarTooltip": "Click to open profile sidebar.",
"opensAtDate": "Opens at {{date}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SegmentedControls,
SelectInput,
StatusCard,
SwitchCard,
TokenAmountDisplay,
TokenInput,
useActionOptions,
Expand Down Expand Up @@ -42,6 +43,7 @@ export type CreateRewardDistributionData = {
duration: DurationWithUnits
}
initialFunds: number
openFunding: boolean
}

export type CreateRewardDistributionOptions = {
Expand Down Expand Up @@ -76,6 +78,7 @@ export const CreateRewardDistributionComponent: ActionComponent<
const initialFunds = watch(
(fieldNamePrefix + 'initialFunds') as 'initialFunds'
)
const openFunding = watch((fieldNamePrefix + 'openFunding') as 'openFunding')

const selectedToken =
tokens.loading || token.loading || token.errored || token.updating
Expand Down Expand Up @@ -334,6 +337,25 @@ export const CreateRewardDistributionComponent: ActionComponent<
style="warning"
/>
)}

<div className="flex flex-col gap-2 max-w-prose items-start">
<InputLabel name={t('form.openFunding')} primary />
<p className="body-text text-text-secondary max-w-prose -mt-1">
{t('info.openFundingDescription')}
</p>

<SwitchCard
enabled={openFunding}
onClick={() =>
setValue(
(fieldNamePrefix + 'openFunding') as 'openFunding',
!openFunding
)
}
readOnly={!isCreating}
sizing="md"
/>
</div>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ guide](https://github.com/DA0-DA0/dao-dao-ui/wiki/Bulk-importing-actions).
"amount": <AMOUNT>,
"unit": "<seconds | minutes | hours | days | weeks | months | years | blocks>"
},
"initialFunds": <AMOUNT>
"initialFunds": <AMOUNT>,
"openFunding": <true | false>
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class CreateRewardDistributionAction extends ActionBase<CreateRewardDistr
},
},
initialFunds: 0,
openFunding: true,
}
}

Expand All @@ -146,6 +147,7 @@ export class CreateRewardDistributionAction extends ActionBase<CreateRewardDistr
immediate,
rate,
initialFunds,
openFunding,
}: CreateRewardDistributionData): Promise<UnifiedCosmosMsg[]> {
if (this.options.context.type !== ActionContextType.Dao) {
throw new Error('Only DAOs can create reward distributions')
Expand Down Expand Up @@ -252,6 +254,7 @@ export class CreateRewardDistributionAction extends ActionBase<CreateRewardDistr
},
hook_caller: hookCaller,
vp_contract: votingModule.address,
open_funding: openFunding,
} as CreateMsg,
},
})
Expand Down Expand Up @@ -609,6 +612,7 @@ export class CreateRewardDistributionAction extends ActionBase<CreateRewardDistr
initialFunds === '0'
? 0
: convertMicroDenomToDenomWithDecimals(initialFunds, token.decimals),
openFunding: !!createMsg.open_funding,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SegmentedControls,
SelectInput,
StatusCard,
SwitchCard,
} from '@dao-dao/stateless'
import {
DaoRewardDistribution,
Expand All @@ -37,6 +38,7 @@ export type UpdateRewardDistributionData = {
amount: number
duration: DurationWithUnits
}
openFunding?: boolean | null
}

export type UpdateRewardDistributionOptions = {
Expand All @@ -59,6 +61,7 @@ export const UpdateRewardDistributionComponent: ActionComponent<
const rateDuration = watch(
(fieldNamePrefix + 'rate.duration') as 'rate.duration'
)
const openFunding = watch((fieldNamePrefix + 'openFunding') as 'openFunding')

const selectedDistribution = distributions.find(
(distribution) => distribution.address === address && distribution.id === id
Expand Down Expand Up @@ -102,7 +105,7 @@ export const UpdateRewardDistributionComponent: ActionComponent<
label: getHumanReadableRewardDistributionLabel(t, distribution),
...distribution,
}))}
onSelect={({ address, id, active_epoch, token }) => {
onSelect={({ address, id, active_epoch, token, open_funding }) => {
setValue((fieldNamePrefix + 'address') as 'address', address)
setValue((fieldNamePrefix + 'id') as 'id', id)
setValue(
Expand All @@ -124,6 +127,10 @@ export const UpdateRewardDistributionComponent: ActionComponent<
)
)
}
setValue(
(fieldNamePrefix + 'openFunding') as 'openFunding',
open_funding
)
}}
trigger={{
type: 'button',
Expand Down Expand Up @@ -249,6 +256,28 @@ export const UpdateRewardDistributionComponent: ActionComponent<
</div>
</div>
)}

{/* Only show open funding switch if a defined boolean. Backwards compatibility for update actions that didn't have the field. */}
{typeof openFunding === 'boolean' && (
<div className="flex flex-col gap-2 max-w-prose items-start">
<InputLabel name={t('form.openFunding')} primary />
<p className="body-text text-text-secondary max-w-prose -mt-1">
{t('info.openFundingDescription')}
</p>

<SwitchCard
enabled={openFunding}
onClick={() =>
setValue(
(fieldNamePrefix + 'openFunding') as 'openFunding',
!openFunding
)
}
readOnly={!isCreating}
sizing="md"
/>
</div>
)}
</div>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ guide](https://github.com/DA0-DA0/dao-dao-ui/wiki/Bulk-importing-actions).
"rate": {
"amount": <AMOUNT>,
"unit": "<seconds | minutes | hours | days | weeks | months | years | blocks>"
}
},
"openFunding": <true | false>
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class UpdateRewardDistributionAction extends ActionBase<UpdateRewardDistr
units: DurationUnits.Hours,
},
},
openFunding: this.distributions[0]?.open_funding || false,
}
}

Expand All @@ -122,6 +123,7 @@ export class UpdateRewardDistributionAction extends ActionBase<UpdateRewardDistr
id,
immediate,
rate,
openFunding,
}: UpdateRewardDistributionData): UnifiedCosmosMsg {
const distribution = this.distributions.find(
(d) => d.address === address && d.id === id
Expand Down Expand Up @@ -151,6 +153,7 @@ export class UpdateRewardDistributionAction extends ActionBase<UpdateRewardDistr
continuous: false,
},
},
open_funding: openFunding,
},
},
})
Expand Down Expand Up @@ -218,6 +221,7 @@ export class UpdateRewardDistributionAction extends ActionBase<UpdateRewardDistr
units: DurationUnits.Hours,
},
},
openFunding: updateMsg.open_funding,
}
}
}

0 comments on commit 9df9b9d

Please sign in to comment.