disable self sends in autowithdraw

This commit is contained in:
keyan 2024-01-12 09:37:50 -06:00
parent 1d388942e9
commit b530b611f5
3 changed files with 10 additions and 4 deletions

View File

@ -522,7 +522,7 @@ export default {
throw new GraphQLError('you must be logged in', { extensions: { code: 'UNAUTHENTICATED' } })
}
await ssValidate(lnAddrAutowithdrawSchema, data, { models })
await ssValidate(lnAddrAutowithdrawSchema, data, { me, models })
await models.user.update({
where: { id: me.id },

View File

@ -204,9 +204,15 @@ export function advSchema (args) {
})
}
export function lnAddrAutowithdrawSchema (args) {
export function lnAddrAutowithdrawSchema ({ me } = {}) {
return object({
lnAddr: lightningAddressValidator.required('required'),
lnAddr: lightningAddressValidator.required('required').test({
name: 'lnAddr',
test: async addr => {
return addr !== `${me.name}@stacker.news` && !addr.startsWith(`${me.name}@localhost`)
},
message: 'cannot send to yourself'
}),
autoWithdrawThreshold: intValidator.required('required').min(0, 'must be at least 0').max(msatsToSats(BALANCE_LIMIT_MSATS), `must be at most ${abbrNum(msatsToSats(BALANCE_LIMIT_MSATS))}`),
autoWithdrawMaxFeePercent: floatValidator.required('required').min(0, 'must be at least 0').max(50, 'must not exceed 50')
})

View File

@ -42,7 +42,7 @@ export default function LightningAddress () {
autoWithdrawThreshold: isNaN(me?.privates?.autoWithdrawThreshold) ? 10000 : me?.privates?.autoWithdrawThreshold,
autoWithdrawMaxFeePercent: isNaN(me?.privantes?.autoWithdrawMaxFeePercent) ? 1 : me?.privantes?.autoWithdrawMaxFeePercent
}}
schema={lnAddrAutowithdrawSchema}
schema={lnAddrAutowithdrawSchema({ me })}
onSubmit={async ({ autoWithdrawThreshold, autoWithdrawMaxFeePercent, ...values }) => {
try {
await setAutoWithdraw({