Skip to content

Commit

Permalink
vote form fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorizen committed Apr 4, 2024
1 parent 2d7a9ea commit d7617d8
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/components/Forms/VoteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ export default function VoteForm({
[VoteFormFieldNames.Voter]: isValidator ? address : grants?.[0]?.granter,
}

const getOptionsValidationRule = (yup: typeof Yup): Yup.ObjectShape => {
if (!isStaker && grants.length) {
return { [VoteFormFieldNames.Option]: yup.number().required() }
}
if (isStaker && grants.length) {
return { [VoteFormFieldNames.Option]: yup.number() }
}
return {}
}

const getVoterValidationRule = (yup: typeof Yup): Yup.ObjectShape => {
if (!isStaker && grants.length) {
return { [VoteFormFieldNames.Voter]: yup.string().required() }
Expand All @@ -83,8 +73,8 @@ export default function VoteForm({
getErrorMessage,
} = useForm(DEFAULT_VALUES, yup =>
yup.object({
...getOptionsValidationRule(yup),
...getVoterValidationRule(yup),
[VoteFormFieldNames.Option]: yup.number().required(),
}),
)

Expand All @@ -103,8 +93,8 @@ export default function VoteForm({
}

formData.voter === address
? await client.tx.voteProposal(address, proposalId, formData[VoteFormFieldNames.Option])
: await client.tx.execVoteProposal(address, formData.voter, proposalId, formData.option)
? await client.tx.execVoteProposal(address, formData.voter, proposalId, formData.option)
: await client.tx.voteProposal(address, proposalId, formData[VoteFormFieldNames.Option])

onSubmit({
message: t('vote-form.submitted-msg', {
Expand Down

0 comments on commit d7617d8

Please sign in to comment.