diff --git a/govtool/frontend/src/consts/dRepActions/fields.ts b/govtool/frontend/src/consts/dRepActions/fields.ts index 4b03e79ea..d92cf229b 100644 --- a/govtool/frontend/src/consts/dRepActions/fields.ts +++ b/govtool/frontend/src/consts/dRepActions/fields.ts @@ -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: { @@ -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: { diff --git a/govtool/frontend/src/i18n/locales/en.ts b/govtool/frontend/src/i18n/locales/en.ts index a84e3b044..ba486511f 100644 --- a/govtool/frontend/src/i18n/locales/en.ts +++ b/govtool/frontend/src/i18n/locales/en.ts @@ -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: { @@ -692,7 +698,6 @@ export const en = { maxLength: "Max {{maxLength}} characters", required: "This field is required", url: "Invalid URL", - paymentAddress: "Invalid payment address", }, }, }, diff --git a/govtool/frontend/src/utils/isValidFormat.ts b/govtool/frontend/src/utils/isValidFormat.ts index d048de713..9d23b4548 100644 --- a/govtool/frontend/src/utils/isValidFormat.ts +++ b/govtool/frontend/src/utils/isValidFormat.ts @@ -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"); + } +}