diff --git a/lib/validate.js b/lib/validate.js index 77615b86..14794de9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -149,7 +149,7 @@ const nameValidator = string() const intValidator = number().typeError('must be a number').integer('must be whole') 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().matches(/^[\w_]+@localhost:\d+$/), string().email()], '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 } = {}) { return object({ socket: string().socket().required('required'), diff --git a/lib/wallet.js b/lib/wallet.js index 1882e110..540edd4a 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -1,5 +1,5 @@ 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' export function generateResolverName (walletField) { @@ -25,7 +25,7 @@ export function generateSchema (wallet) { let validator - const stringTypes = ['url', 'string'] + const stringTypes = ['url', 'string', 'email'] if (stringTypes.includes(validationType)) { validator = string() @@ -57,6 +57,8 @@ export function generateSchema (wallet) { }) } + if (validationType === 'email') validator = lightningAddressValidator + if (words) { validator = array() .transform(function (value, originalValue) { diff --git a/wallets/lightning-address/index.js b/wallets/lightning-address/index.js index 8df1fa91..31618258 100644 --- a/wallets/lightning-address/index.js +++ b/wallets/lightning-address/index.js @@ -1,5 +1,3 @@ -import { lnAddrAutowithdrawSchema } from '@/lib/validate' - export const name = 'lightning-address' export const shortName = 'lnAddr' @@ -8,7 +6,12 @@ export const fields = [ name: 'address', label: 'lightning address', 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'] } -export const schema = lnAddrAutowithdrawSchema - export const walletType = 'LIGHTNING_ADDRESS' export const walletField = 'walletLightningAddress'