refactor: reduce boilerplate in validation schemas
This commit is contained in:
parent
8d2c23ee87
commit
6e64a341de
1 changed files with 29 additions and 30 deletions
|
|
@ -10,6 +10,15 @@ import secretTest from './helper'
|
||||||
|
|
||||||
const isDefined = it => it && it.length
|
const isDefined = it => it && it.length
|
||||||
|
|
||||||
|
const buildTestValidation = (id, passphrase) => {
|
||||||
|
return Yup.string()
|
||||||
|
.max(100, 'Too long')
|
||||||
|
.when(id, {
|
||||||
|
is: isDefined,
|
||||||
|
then: Yup.string().test(secretTest(passphrase))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
code: 'bitgo',
|
code: 'bitgo',
|
||||||
name: 'BitGo',
|
name: 'BitGo',
|
||||||
|
|
@ -93,40 +102,30 @@ export default {
|
||||||
.max(100, 'Too long')
|
.max(100, 'Too long')
|
||||||
.required(),
|
.required(),
|
||||||
BTCWalletId: Yup.string().max(100, 'Too long'),
|
BTCWalletId: Yup.string().max(100, 'Too long'),
|
||||||
BTCWalletPassphrase: Yup.string()
|
BTCWalletPassphrase: buildTestValidation(
|
||||||
.max(100, 'Too long')
|
'BTCWalletId',
|
||||||
.when('BTCWalletId', {
|
account?.BTCWalletPassphrase
|
||||||
is: isDefined,
|
),
|
||||||
then: Yup.string().test(secretTest(account?.BTCWalletPassphrase))
|
|
||||||
}),
|
|
||||||
LTCWalletId: Yup.string().max(100, 'Too long'),
|
LTCWalletId: Yup.string().max(100, 'Too long'),
|
||||||
LTCWalletPassphrase: Yup.string()
|
LTCWalletPassphrase: buildTestValidation(
|
||||||
.max(100, 'Too long')
|
'LTCWalletId',
|
||||||
.when('LTCWalletId', {
|
account?.LTCWalletPassphrase
|
||||||
is: isDefined,
|
),
|
||||||
then: Yup.string().test(secretTest(account?.LTCWalletPassphrase))
|
|
||||||
}),
|
|
||||||
ZECWalletId: Yup.string().max(100, 'Too long'),
|
ZECWalletId: Yup.string().max(100, 'Too long'),
|
||||||
ZECWalletPassphrase: Yup.string()
|
ZECWalletPassphrase: buildTestValidation(
|
||||||
.max(100, 'Too long')
|
'ZECWalletId',
|
||||||
.when('ZECWalletId', {
|
account?.ZECWalletPassphrase
|
||||||
is: isDefined,
|
),
|
||||||
then: Yup.string().test(secretTest(account?.ZECWalletPassphrase))
|
|
||||||
}),
|
|
||||||
BCHWalletId: Yup.string().max(100, 'Too long'),
|
BCHWalletId: Yup.string().max(100, 'Too long'),
|
||||||
BCHWalletPassphrase: Yup.string()
|
BCHWalletPassphrase: buildTestValidation(
|
||||||
.max(100, 'Too long')
|
'BCHWalletId',
|
||||||
.when('BCHWalletId', {
|
account?.BCHWalletPassphrase
|
||||||
is: isDefined,
|
),
|
||||||
then: Yup.string().test(secretTest(account?.BCHWalletPassphrase))
|
|
||||||
}),
|
|
||||||
DASHWalletId: Yup.string().max(100, 'Too long'),
|
DASHWalletId: Yup.string().max(100, 'Too long'),
|
||||||
DASHWalletPassphrase: Yup.string()
|
DASHWalletPassphrase: buildTestValidation(
|
||||||
.max(100, 'Too long')
|
'DASHWalletId',
|
||||||
.when('DASHWalletId', {
|
account?.DASHWalletPassphrase
|
||||||
is: isDefined,
|
),
|
||||||
then: Yup.string().test(secretTest(account?.DASHWalletPassphrase))
|
|
||||||
}),
|
|
||||||
environment: Yup.string()
|
environment: Yup.string()
|
||||||
.matches(/(prod|test)/)
|
.matches(/(prod|test)/)
|
||||||
.required()
|
.required()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue