Generate validation schema for LnAddr
This commit is contained in:
parent
587bfa34be
commit
4df0b460c3
|
@ -149,7 +149,7 @@ const nameValidator = string()
|
||||||
const intValidator = number().typeError('must be a number').integer('must be whole')
|
const intValidator = number().typeError('must be a number').integer('must be whole')
|
||||||
const floatValidator = number().typeError('must be a number')
|
const floatValidator = number().typeError('must be a number')
|
||||||
|
|
||||||
const lightningAddressValidator = process.env.NODE_ENV === 'development'
|
export const lightningAddressValidator = process.env.NODE_ENV === 'development'
|
||||||
? string().or(
|
? string().or(
|
||||||
[string().matches(/^[\w_]+@localhost:\d+$/), string().email()],
|
[string().matches(/^[\w_]+@localhost:\d+$/), string().email()],
|
||||||
'address is no good')
|
'address is no good')
|
||||||
|
@ -303,17 +303,6 @@ export function advSchema (args) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function lnAddrAutowithdrawSchema ({ me } = {}) {
|
|
||||||
return object({
|
|
||||||
address: lightningAddressValidator.required('required').test({
|
|
||||||
name: 'address',
|
|
||||||
test: addr => !addr.endsWith('@stacker.news'),
|
|
||||||
message: 'automated withdrawals must be external'
|
|
||||||
}),
|
|
||||||
...autowithdrawSchemaMembers
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CLNAutowithdrawSchema ({ me } = {}) {
|
export function CLNAutowithdrawSchema ({ me } = {}) {
|
||||||
return object({
|
return object({
|
||||||
socket: string().socket().required('required'),
|
socket: string().socket().required('required'),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { array, object, string } from 'yup'
|
import { array, object, string } from 'yup'
|
||||||
import { autowithdrawSchemaMembers, hexOrBase64Validator } from '@/lib/validate'
|
import { autowithdrawSchemaMembers, hexOrBase64Validator, lightningAddressValidator } from '@/lib/validate'
|
||||||
import { TOR_REGEXP } from '@/lib/url'
|
import { TOR_REGEXP } from '@/lib/url'
|
||||||
|
|
||||||
export function generateResolverName (walletField) {
|
export function generateResolverName (walletField) {
|
||||||
|
@ -25,7 +25,7 @@ export function generateSchema (wallet) {
|
||||||
|
|
||||||
let validator
|
let validator
|
||||||
|
|
||||||
const stringTypes = ['url', 'string']
|
const stringTypes = ['url', 'string', 'email']
|
||||||
|
|
||||||
if (stringTypes.includes(validationType)) {
|
if (stringTypes.includes(validationType)) {
|
||||||
validator = string()
|
validator = string()
|
||||||
|
@ -57,6 +57,8 @@ export function generateSchema (wallet) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (validationType === 'email') validator = lightningAddressValidator
|
||||||
|
|
||||||
if (words) {
|
if (words) {
|
||||||
validator = array()
|
validator = array()
|
||||||
.transform(function (value, originalValue) {
|
.transform(function (value, originalValue) {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import { lnAddrAutowithdrawSchema } from '@/lib/validate'
|
|
||||||
|
|
||||||
export const name = 'lightning-address'
|
export const name = 'lightning-address'
|
||||||
export const shortName = 'lnAddr'
|
export const shortName = 'lnAddr'
|
||||||
|
|
||||||
|
@ -8,7 +6,12 @@ export const fields = [
|
||||||
name: 'address',
|
name: 'address',
|
||||||
label: 'lightning address',
|
label: 'lightning address',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
autoComplete: 'off'
|
autoComplete: 'off',
|
||||||
|
validate: {
|
||||||
|
type: 'email',
|
||||||
|
test: addr => !addr.endsWith('@stacker.news'),
|
||||||
|
message: 'automated withdrawals must be external'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -18,8 +21,6 @@ export const card = {
|
||||||
badges: ['receive only', 'non-custodialish']
|
badges: ['receive only', 'non-custodialish']
|
||||||
}
|
}
|
||||||
|
|
||||||
export const schema = lnAddrAutowithdrawSchema
|
|
||||||
|
|
||||||
export const walletType = 'LIGHTNING_ADDRESS'
|
export const walletType = 'LIGHTNING_ADDRESS'
|
||||||
|
|
||||||
export const walletField = 'walletLightningAddress'
|
export const walletField = 'walletLightningAddress'
|
||||||
|
|
Loading…
Reference in New Issue