merchant-backoffice

ZZZ: Inactive/Deprecated
Log | Files | Refs | Submodules | README

commit 4577c84b9f552315f131b58631490d0e76e8559a
parent 5010f9ab3fab13a47b4be0441a76664cc2cec1a9
Author: Sebastian <sebasjm@gmail.com>
Date:   Fri, 12 Feb 2021 01:36:36 -0300

payto regex

Diffstat:
Asrc/constants.ts | 2++
Msrc/i18n/index.ts | 6++++--
Msrc/routes/instances/UpdateModal.tsx | 4+++-
Atests/functions/regex.test.ts | 25+++++++++++++++++++++++++
4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/constants.ts b/src/constants.ts @@ -0,0 +1,2 @@ +export const PAYTO_REGEX=/^payto:\/\/[a-zA-Z][a-zA-Z0-9-.]*(\/[a-zA-Z0-9\-\.\~\(\)@_%:!$&'*+,;=]*)*\??((amount|receiver-name|sender-name|instruction|message)=[a-zA-Z0-9\-\.\~\(\)@_%:!$'*+,;=]*&?)*$/ + diff --git a/src/i18n/index.ts b/src/i18n/index.ts @@ -70,7 +70,8 @@ export default { }, validation: { required: '{{label}} es obligatorio', - typeError: '{{label}} ' + typeError: '{{label}}', + payto: 'la dirección de pago no es valida', }, text: { instances: 'Instancias', @@ -152,7 +153,8 @@ export default { }, validation: { required: '{{label}} is required', - typeError: '{{label}} ' + typeError: '{{label}}', + payto: 'the pay address is not valid', }, text: { instances: 'Instances', diff --git a/src/routes/instances/UpdateModal.tsx b/src/routes/instances/UpdateModal.tsx @@ -4,6 +4,7 @@ import { MerchantBackend } from "../../declaration"; import * as yup from 'yup'; import ConfirmModal from '../../components/modal' import YupInput from "../../components/yup/YupInput"; +import { PAYTO_REGEX } from "../../constants"; function stringToArray(this: yup.AnySchema, current: any, original: string): string[] { if (this.isType(current)) return current; @@ -12,7 +13,8 @@ function stringToArray(this: yup.AnySchema, current: any, original: string): str const schema = yup.object().shape({ name: yup.string().required(), - payto_uris: yup.array().of(yup.string()).min(1).transform(stringToArray), + payto_uris: yup.array().of(yup.string()).min(1) + .transform(stringToArray).test('payto','{path} is not valid', (values): boolean => !!values && values.filter( v => v && PAYTO_REGEX.test(v) ).length > 0 ), default_max_deposit_fee: yup.string().required(), default_max_wire_fee: yup.string().required(), default_wire_fee_amortization: yup.number().required(), diff --git a/tests/functions/regex.test.ts b/tests/functions/regex.test.ts @@ -0,0 +1,25 @@ +import { PAYTO_REGEX } from "../../src/constants"; + +const valids = [ + 'payto://iban/DE75512108001245126199?amount=EUR:200.0&message=hello', + 'payto://ach/122000661/1234', + 'payto://upi/alice@example.com?receiver-name=Alice&amount=INR:200', + 'payto://void/?amount=EUR:10.5', + 'payto://ilp/g.acme.bob' +] + +test('should be valid', () => { + valids.forEach(v => expect(v).toMatch(PAYTO_REGEX)) +}); + +const invalids = [ + 'payto://iban/DE75?512108001245126199?amount=EUR:200.0&message=hello', + 'payto://ach/122000661 /1234', + 'payto://upi/alice@ example.com?receiver-name=Alice&amount=INR:200', + 'payto://void/?mount=EUR:10.5', + 'payto: //ilp/g.acme.bob' +] + +test('should not be valid', () => { + invalids.forEach(v => expect(v).not.toMatch(PAYTO_REGEX)) +});