Skip to content

Commit

Permalink
🔧 Fix freeze pallet proposal (#4763)
Browse files Browse the repository at this point in the history
* Fix the creator token state switch input value

* Fix the execution requirement alert

* Match the design

* Improve the tests
  • Loading branch information
thesan authored Feb 6, 2024
1 parent 04cf9a8 commit f399117
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ export const SpecificParametersUpdatePalletFrozenStatus: Story = {
await createProposal(async () => {
const nextButton = getButtonByText(modal, 'Create proposal')

await userEvent.click(modal.getByTestId('crt-feature-select'))
await userEvent.click(modal.getByText('Enable'))
expect(
await modal.findByText(
/The ProjectToken pallet is currently enabled, so presently this proposal would fail due to execution constraints./
Expand All @@ -1431,7 +1431,7 @@ export const SpecificParametersUpdatePalletFrozenStatus: Story = {
expect(await modal.findByText(/Warning/))
expect(nextButton).toBeDisabled()

await userEvent.click(modal.getByTestId('crt-feature-select'))
await userEvent.click(modal.getByText('Disable'))
await waitFor(() => expect(nextButton).toBeEnabled())
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const AddNewProposalModal = () => {
})

useEffect(() => {
if (palletFrozenStatus !== undefined) form.setValue('updatePalletFrozenStatus.freeze', palletFrozenStatus.isFalse)
if (palletFrozenStatus !== undefined) form.setValue('updatePalletFrozenStatus.enable', palletFrozenStatus.isTrue)
}, [palletFrozenStatus])

const formValues = form.getValues() as AddNewProposalForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export const ExecutionRequirementsWarning = React.memo(() => {
<TextMedium bold>
<AlertSymbol /> Warning
</TextMedium>
<TextMedium inter>
<TextMedium as="div" inter>
Parameters provided here are checked across two set of constraints which are executed at different times,
creation and execution constraints. Current inputs for proposal parameters violate the execution constraints for
this proposal, meaning while you can create this proposal, if the runtime execution constraints for this
proposal remain unchanged at the time of council vote, this proposal will be automatically rejected.
<TooltipExternalLink
href="https://app.gitbook.com/o/-M-C0Rf1ILeSmMugzduG/s/-M-C0W9924TH_Qp2jnDV/governance/proposals#parameters-general-and-specific"
href="https://handbook.joystream.org/system/proposal-system#parameters-general-and-specific"
target="_blank"
>
<TextMedium>Learn more</TextMedium> <LinkSymbol />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { enhancedGetErrorMessage } from '@/common/utils/validation'
export const UpdatePalletFrozenStatus = () => {
const { watch, formState } = useFormContext()
const validationMessage = useMemo(() => {
return enhancedGetErrorMessage(formState?.errors)('updatePalletFrozenStatus.freeze') ?? ''
}, [JSON.stringify(formState?.errors), watch('updatePalletFrozenStatus.freeze')])
return enhancedGetErrorMessage(formState?.errors)('updatePalletFrozenStatus.enable') ?? ''
}, [JSON.stringify(formState?.errors), watch('updatePalletFrozenStatus.enable')])
return (
<RowGapBlock gap={24}>
<Row>
Expand All @@ -32,12 +32,7 @@ export const UpdatePalletFrozenStatus = () => {
<Row>
<InlineToggleWrap>
<Label>Creator Tokens</Label>
<ToggleCheckbox
falseLabel="Disable"
trueLabel="Enable"
name="updatePalletFrozenStatus.freeze"
id="crt-feature-select"
/>
<ToggleCheckbox falseLabel="Disable" trueLabel="Enable" name="updatePalletFrozenStatus.enable" />
<Tooltip tooltipText="You have the flexibility to enable or disable CRT feature.">
<TooltipDefault />
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const getSpecificParameters = async (
}
case 'updatePalletFrozenStatus': {
return createType('PalletProposalsCodexProposalDetails', {
SetPalletFozenStatus: [specifics.updatePalletFrozenStatus.freeze, specifics.updatePalletFrozenStatus.pallet],
SetPalletFozenStatus: [!specifics.updatePalletFrozenStatus.enable, specifics.updatePalletFrozenStatus.pallet],
})
}
default:
Expand Down
14 changes: 7 additions & 7 deletions packages/ui/src/proposals/modals/AddNewProposal/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@/common/utils/validation'
import { AccountSchema, StakingAccountSchema } from '@/memberships/model/validation'
import { Member } from '@/memberships/types'
import { differentFromContext, isValidCSV } from '@/proposals/model/validation'
import { equalToContext, isValidCSV } from '@/proposals/model/validation'
import { ProposalType } from '@/proposals/types'
import { GroupIdName } from '@/working-groups/types'

Expand Down Expand Up @@ -52,7 +52,7 @@ export const defaultProposalValues = {
},
updatePalletFrozenStatus: {
pallet: 'ProjectToken',
freeze: false,
enable: false,
},
}

Expand Down Expand Up @@ -180,7 +180,7 @@ export interface AddNewProposalForm {
}
}
updatePalletFrozenStatus: {
freeze: boolean
enable: boolean
pallet: string
}
}
Expand Down Expand Up @@ -411,12 +411,12 @@ export const schemaFactory = (api?: Api) => {
channelCashoutsEnabled: Yup.boolean(),
}),
updatePalletFrozenStatus: Yup.object().shape({
freeze: Yup.boolean()
enable: Yup.boolean()
.test(
differentFromContext(
(isFrozen) =>
equalToContext(
(enable) =>
`The ProjectToken pallet is currently ${
isFrozen ? 'disabled' : 'enabled'
enable ? 'enabled' : 'disabled'
}, so presently this proposal would fail due to execution constraints.`,
'palletFrozenStatus',
'execution'
Expand Down
12 changes: 6 additions & 6 deletions packages/ui/src/proposals/model/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ export const isValidCSV = (message: string): Yup.TestConfig<any, AnyObject> => (
},
})

export const differentFromContext = (
export const equalToContext = (
msg: (value: any) => string,
contextPath: string,
type?: string
): Yup.TestConfig<any, AnyObject> => ({
name: type ?? 'differentFromContext',
name: type ?? 'equalToContext',
exclusive: false,
test(value: boolean) {
const validationValue = get(this.options.context, contextPath).toJSON()
if (value === validationValue) {
return this.createError({
return (
value === validationValue ||
this.createError({
message: msg(value),
})
}
return true
)
},
})

0 comments on commit f399117

Please sign in to comment.