From 08a5ce1a28fb2334ac3acd1fb45f9e2834013d5e Mon Sep 17 00:00:00 2001 From: ekzyis Date: Wed, 17 Jul 2024 03:19:41 +0200 Subject: [PATCH] Remove stringTypes --- lib/wallet.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/wallet.js b/lib/wallet.js index 540edd4a..700a879c 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -25,19 +25,13 @@ export function generateSchema (wallet) { let validator - const stringTypes = ['url', 'string', 'email'] - - if (stringTypes.includes(validationType)) { - validator = string() - - if (field.validate.length) validator = validator.length(field.validate.length) - } + if (validationType === 'string') validator = string() if (validationType === 'url') { validator = process.env.NODE_ENV === 'development' - ? validator + ? string() .or([string().matches(/^(http:\/\/)?localhost:\d+$/), string().url()], 'invalid url') - : validator + : string() .url() .test(async (url, context) => { if (field.validate.torAllowed && TOR_REGEXP.test(url)) { @@ -57,8 +51,6 @@ export function generateSchema (wallet) { }) } - if (validationType === 'email') validator = lightningAddressValidator - if (words) { validator = array() .transform(function (value, originalValue) { @@ -79,6 +71,8 @@ export function generateSchema (wallet) { }) } + if (validationType === 'email') validator = lightningAddressValidator + if (validationType === 'socket') validator = string().socket() if (validationType === 'hexOrBase64') validator = hexOrBase64Validator @@ -86,6 +80,8 @@ export function generateSchema (wallet) { if (min !== undefined) validator = validator.min(min) if (max !== undefined) validator = validator.max(max) + if (field.validate.length) validator = validator.length(field.validate.length) + if (!field.optional) validator = validator.required('required') if (field.validate.test) {