Skip to content

Commit

Permalink
Merge pull request #1835 from IntersectMBO/develop
Browse files Browse the repository at this point in the history
fix: fix payment address validation
  • Loading branch information
MSzalowski authored Aug 27, 2024
2 parents c8348fe + 859dad1 commit abcc29a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
11 changes: 2 additions & 9 deletions govtool/frontend/src/consts/dRepActions/fields.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import i18n from "@/i18n";
import {
PAYMENT_ADDRESS_REGEX,
URL_REGEX,
isValidURLLength,
} from "@/utils";
import { URL_REGEX, isReceivingAddress, isValidURLLength } from "@/utils";

export const Rules = {
GIVEN_NAME: {
Expand Down Expand Up @@ -52,10 +48,7 @@ export const Rules = {
},
},
PAYMENT_ADDRESS: {
pattern: {
value: PAYMENT_ADDRESS_REGEX,
message: i18n.t("registration.fields.validations.paymentAddress"),
}
validate: isReceivingAddress,
},
QUALIFICATIONS: {
maxLength: {
Expand Down
17 changes: 11 additions & 6 deletions govtool/frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,21 +361,27 @@ export const en = {
givenName: "Given Name",
objectives: "Objectives",
objectivesPlaceholder: "Tell others what you want to achieve...",
objectivesHelpfulText: "A short description of your beliefs and goals as a DRep",
objectivesHelpfulText:
"A short description of your beliefs and goals as a DRep",
motivations: "Motivations",
motivationsPlaceholder: "Describe what motivates you...",
motivationsHelpfulText: "A short description of why you want to be a DRep, what personal and professional experiences you have had that have driven you to register",
motivationsHelpfulText:
"A short description of why you want to be a DRep, what personal and professional experiences you have had that have driven you to register",
qualifications: "Qualifications",
qualificationsPlaceholder: "List your qualifications...",
qualificationsHelpfulText: "Key qualifications you hold that are relevant to your role as a DRep",
qualificationsHelpfulText:
"Key qualifications you hold that are relevant to your role as a DRep",
paymentAddress: "Payment Address",
paymentAddressPlaceholder: "addr1vpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5eg0yu80w",
paymentAddressPlaceholder:
"addr1vpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5eg0yu80w",
doNotList: "Do not list",
doNotListHelpfulText: "Check this box if you do not want to show up in Govtool DRep Directory or in similar tools",
doNotListHelpfulText:
"Check this box if you do not want to show up in Govtool DRep Directory or in similar tools",
},
errors: {
tooLongUrl: "Url must be less than 128 bytes",
mustBeStakeAddress: "It must be reward address in bech32 format",
mustBeReceivingAddress: "Invalid payment address",
},
},
proposalDiscussion: {
Expand Down Expand Up @@ -692,7 +698,6 @@ export const en = {
maxLength: "Max {{maxLength}} characters",
required: "This field is required",
url: "Invalid URL",
paymentAddress: "Invalid payment address",
},
},
},
Expand Down
11 changes: 11 additions & 0 deletions govtool/frontend/src/utils/isValidFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ export async function isRewardAddress(address: string) {
return i18n.t("forms.errors.mustBeStakeAddress");
}
}

export async function isReceivingAddress(address: string) {
try {
const receivingAddress = Address.from_bech32(address);
return receivingAddress
? true
: i18n.t("forms.errors.mustBeReceivingAddress");
} catch (e) {
return i18n.t("forms.errors.mustBeReceivingAddress");
}
}

0 comments on commit abcc29a

Please sign in to comment.