Skip to content

Commit

Permalink
required changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vrrayz committed Nov 13, 2023
1 parent f45b419 commit 844c77c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/ui/src/mocks/helpers/asChainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const asChainData = (data: any): any => {

case 'String':
return isNaN(data) ? data : createType('u128', data)

case 'Boolean':
return createType('bool', data)
default:
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/src/proposals/modals/AddNewProposal/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const defaultProposalValues = {
},
updatePalletFrozenStatus: {
pallet: 'ProjectToken',
default: false,
},
}

Expand Down Expand Up @@ -413,7 +414,11 @@ export const schemaFactory = (api?: Api) => {
freeze: Yup.boolean()
.test(
differentFromContext(
'The ProjectToken pallet is currently ${val}, so presently this proposal would fail due to execution constraints.',
(isFrozen) =>
`The ProjectToken pallet is currently ${
isFrozen ? 'disabled' : 'enabled'
}, so presently this proposal would fail due to execution constraints.`,
'palletFrozenStatus',
'execution'
)
)
Expand Down
14 changes: 8 additions & 6 deletions packages/ui/src/proposals/model/validation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { get } from 'lodash'
import * as Yup from 'yup'
import { AnyObject } from 'yup/lib/types'

Expand All @@ -20,17 +21,18 @@ export const isValidCSV = (message: string): Yup.TestConfig<any, AnyObject> => (
return true
},
})
export const differentFromContext = (msg: string, type?: string): Yup.TestConfig<any, AnyObject> => ({
export const differentFromContext = (
msg: (value: any) => string,
contextPath: string,
type?: string
): Yup.TestConfig<any, AnyObject> => ({
name: type ?? 'differentFromContext',
exclusive: false,
test(value: boolean) {
const validationValue = !this.options.context?.palletFrozenStatus.isFalse
const validationValue = get(this.options.context, contextPath).toJSON()
if (value === validationValue) {
return this.createError({
message: msg,
params: {
val: validationValue ? 'disabled' : 'enabled',
},
message: msg(value),
})
}
return true
Expand Down

0 comments on commit 844c77c

Please sign in to comment.