Skip to content

Commit

Permalink
[#377] fix: validation of ada amount
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Mar 15, 2024
1 parent d6ecbb4 commit 88e2a2b
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 88e2a2b

Please sign in to comment.