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']) })