From d17929f2c57a5a61c9ee1ea8dec94844d12d5dff Mon Sep 17 00:00:00 2001 From: k00b Date: Thu, 19 Sep 2024 13:38:13 -0500 Subject: [PATCH] ss validate boost acts --- lib/validate.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/validate.js b/lib/validate.js index a5d930b9..cb52cdb4 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -585,17 +585,25 @@ export const amountSchema = object({ amount: intValidator.required('required').positive('must be positive') }) +export const boostValidator = intValidator + .min(BOOST_MULT, `must be at least ${BOOST_MULT}`).test({ + name: 'boost', + test: async boost => boost % BOOST_MULT === 0, + message: `must be divisble be ${BOOST_MULT}` + }) + export const boostSchema = object({ - amount: intValidator - .min(BOOST_MULT, `must be at least ${BOOST_MULT}`).test({ - name: 'boost', - test: async boost => boost % BOOST_MULT === 0, - message: `must be divisble be ${BOOST_MULT}` - }) + amount: boostValidator.required('required').positive('must be positive') }) export const actSchema = object({ - sats: intValidator.required('required').positive('must be positive'), + sats: intValidator.required('required').positive('must be positive') + .when(['act'], ([act], schema) => { + if (act === 'BOOST') { + return boostValidator + } + return schema + }), act: string().required('required').oneOf(['TIP', 'DONT_LIKE_THIS', 'BOOST']) })