Skip to content

Commit

Permalink
Merge pull request #490 from IntersectMBO/fix/377/fix-validation-of-a…
Browse files Browse the repository at this point in the history
…da-amount

[#377] fix: validation of ada amount
  • Loading branch information
MSzalowski authored Mar 15, 2024
2 parents d6ecbb4 + 88e2a2b commit 59d7704
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions govtool/frontend/src/consts/governanceAction/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,21 @@ export const GOVERNANCE_ACTION_FIELDS: GovernanceActionFields = {
value: true,
message: I18n.t("createGovernanceAction.fields.validations.required"),
},
validate: (value) =>
Number.isInteger(Number(value)) ||
I18n.t("createGovernanceAction.fields.validations.number"),
validate: (value) => {
const parsedValue = Number(
value.includes(",") ? value.replace(",", ".") : value
);

if (isNaN(parsedValue)) {
return I18n.t("createGovernanceAction.fields.validations.number");
}

if (parsedValue < 0) {
return I18n.t("createGovernanceAction.fields.validations.positive");
}

return true;
},
},
},
},
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const en = {
number: "Only number is allowed",
required: "This field is required",
url: "Invalid URL",
positive: "Only positive number is allowed",
},
},
formTitle: "Governance Action details",
Expand Down

0 comments on commit 59d7704

Please sign in to comment.