Make clear that message belongs to test

* validate.message was used in tandem with validate.test
* it might be confused as the message if the validation for validate.type failed
* now validate.test can be a function or an object of { test, message } shape which matches Yup.test
This commit is contained in:
ekzyis 2024-07-17 03:26:50 +02:00
parent c8d91bf42d
commit 6a5713034b
3 changed files with 9 additions and 6 deletions

View File

@ -90,8 +90,7 @@ export function generateSchema (wallet) {
if (field.validate.test) {
validator = validator.test({
name: field.name,
test: field.validate.test,
message: field.validate.message
...(typeof field.validate.test === 'function' ? { test: field.validate.test } : field.validate.test)
})
}

View File

@ -9,8 +9,10 @@ export const fields = [
autoComplete: 'off',
validate: {
type: 'email',
test: addr => !addr.endsWith('@stacker.news'),
message: 'automated withdrawals must be external'
test: {
test: addr => !addr.endsWith('@stacker.news'),
message: 'automated withdrawals must be external'
}
}
}
]

View File

@ -27,8 +27,10 @@ export const fields = [
clear: true,
validate: {
type: 'hexOrBase64',
test: v => isInvoiceMacaroon(v) || isInvoicableMacaroon(v),
message: 'not an invoice macaroon or an invoicable macaroon'
test: {
test: v => isInvoiceMacaroon(v) || isInvoicableMacaroon(v),
message: 'not an invoice macaroon or an invoicable macaroon'
}
}
},
{