Generate validation schema for LNC
This commit is contained in:
parent
667cde6042
commit
3933a4f460
|
@ -10,7 +10,7 @@ import Info from '@/components/info'
|
||||||
import Text from '@/components/text'
|
import Text from '@/components/text'
|
||||||
import { AutowithdrawSettings } from '@/components/autowithdraw-shared'
|
import { AutowithdrawSettings } from '@/components/autowithdraw-shared'
|
||||||
import dynamic from 'next/dynamic'
|
import dynamic from 'next/dynamic'
|
||||||
import { object, string } from 'yup'
|
import { array, object, string } from 'yup'
|
||||||
import { autowithdrawSchemaMembers } from '@/lib/validate'
|
import { autowithdrawSchemaMembers } from '@/lib/validate'
|
||||||
import { useMe } from '@/components/me'
|
import { useMe } from '@/components/me'
|
||||||
import { TOR_REGEXP } from '@/lib/url'
|
import { TOR_REGEXP } from '@/lib/url'
|
||||||
|
@ -154,7 +154,7 @@ function generateSchema (wallet, { me }) {
|
||||||
return field.validate.schema
|
return field.validate.schema
|
||||||
}
|
}
|
||||||
|
|
||||||
const { type: validationType } = field.validate
|
const { type: validationType, words, min, max } = field.validate
|
||||||
|
|
||||||
let validator
|
let validator
|
||||||
|
|
||||||
|
@ -192,6 +192,29 @@ function generateSchema (wallet, { me }) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (words) {
|
||||||
|
validator = array()
|
||||||
|
.transform(function (value, originalValue) {
|
||||||
|
if (this.isType(value) && value !== null) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return originalValue ? originalValue.trim().split(/[\s]+/) : []
|
||||||
|
})
|
||||||
|
.test(async (values, context) => {
|
||||||
|
for (const v of values) {
|
||||||
|
try {
|
||||||
|
await string().oneOf(words).validate(v)
|
||||||
|
} catch {
|
||||||
|
return context.createError({ message: `'${v}' is not a valid ${field.label} word` })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (min !== undefined) validator = validator.min(min)
|
||||||
|
if (max !== undefined) validator = validator.max(max)
|
||||||
|
|
||||||
if (!field.optional) validator = validator.required('required')
|
if (!field.optional) validator = validator.required('required')
|
||||||
|
|
||||||
return validator
|
return validator
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { lncSchema } from '@/lib/validate'
|
import bip39Words from '@/lib/bip39-words'
|
||||||
|
|
||||||
export const name = 'lnc'
|
export const name = 'lnc'
|
||||||
|
|
||||||
|
@ -7,7 +7,12 @@ export const fields = [
|
||||||
name: 'pairingPhrase',
|
name: 'pairingPhrase',
|
||||||
label: 'pairing phrase',
|
label: 'pairing phrase',
|
||||||
type: 'password',
|
type: 'password',
|
||||||
help: 'We only need permissions for the uri `/lnrpc.Lightning/SendPaymentSync`\n\nCreate a budgeted account with narrow permissions:\n\n```$ litcli accounts create --balance <budget>```\n\n```$ litcli sessions add --type custom --label <your label> --account_id <account_id> --uri /lnrpc.Lightning/SendPaymentSync```\n\nGrab the `pairing_secret_mnemonic` from the output and paste it here.'
|
help: 'We only need permissions for the uri `/lnrpc.Lightning/SendPaymentSync`\n\nCreate a budgeted account with narrow permissions:\n\n```$ litcli accounts create --balance <budget>```\n\n```$ litcli sessions add --type custom --label <your label> --account_id <account_id> --uri /lnrpc.Lightning/SendPaymentSync```\n\nGrab the `pairing_secret_mnemonic` from the output and paste it here.',
|
||||||
|
validate: {
|
||||||
|
words: bip39Words,
|
||||||
|
min: 2,
|
||||||
|
max: 10
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'password',
|
name: 'password',
|
||||||
|
@ -23,5 +28,3 @@ export const card = {
|
||||||
subtitle: 'use Lightning Node Connect for LND payments',
|
subtitle: 'use Lightning Node Connect for LND payments',
|
||||||
badges: ['send only', 'non-custodialish', 'budgetable']
|
badges: ['send only', 'non-custodialish', 'budgetable']
|
||||||
}
|
}
|
||||||
|
|
||||||
export const schema = lncSchema
|
|
||||||
|
|
Loading…
Reference in New Issue