146b60278c
* wip adding cowboy credits * invite gift paid action * remove balance limit * remove p2p zap withdrawal notifications * credits typedefs * squash migrations * remove wallet limit stuff * CCs in item detail * comments with meCredits * begin including CCs in item stats/notifications * buy credits ui/mutation * fix old /settings/wallets paths * bios don't get sats * fix settings * make invites work with credits * restore migration from master * inform backend of send wallets on zap * satistics header * default receive options to true and squash migrations * fix paidAction query * add nav for credits * fix forever stacked count * ek suggested fixes * fix lint * fix freebies wrt CCs * add back disable freebies * trigger cowboy hat job on CC depletion * fix meMsats+meMcredits * Update api/paidAction/README.md Co-authored-by: ekzyis <ek@stacker.news> * remove expireBoost migration that doesn't work --------- Co-authored-by: ekzyis <ek@stacker.news>
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
import { PAID_ACTION_TERMINAL_STATES, USER_ID } from '@/lib/constants'
|
|
import { datePivot } from '@/lib/time'
|
|
|
|
const MAX_PENDING_PAID_ACTIONS_PER_USER = 100
|
|
const MAX_PENDING_DIRECT_INVOICES_PER_USER_MINUTES = 10
|
|
const MAX_PENDING_DIRECT_INVOICES_PER_USER = 100
|
|
|
|
export async function assertBelowMaxPendingInvoices (context) {
|
|
const { models, me } = context
|
|
const pendingInvoices = await models.invoice.count({
|
|
where: {
|
|
userId: me?.id ?? USER_ID.anon,
|
|
actionState: {
|
|
notIn: PAID_ACTION_TERMINAL_STATES
|
|
}
|
|
}
|
|
})
|
|
|
|
if (pendingInvoices >= MAX_PENDING_PAID_ACTIONS_PER_USER) {
|
|
throw new Error('You have too many pending paid actions, cancel some or wait for them to expire')
|
|
}
|
|
}
|
|
|
|
export async function assertBelowMaxPendingDirectPayments (userId, context) {
|
|
const { models, me } = context
|
|
|
|
if (me?.id !== userId) {
|
|
const pendingSenderInvoices = await models.directPayment.count({
|
|
where: {
|
|
senderId: me?.id ?? USER_ID.anon,
|
|
createdAt: {
|
|
gt: datePivot(new Date(), { minutes: -MAX_PENDING_DIRECT_INVOICES_PER_USER_MINUTES })
|
|
}
|
|
}
|
|
})
|
|
|
|
if (pendingSenderInvoices >= MAX_PENDING_DIRECT_INVOICES_PER_USER) {
|
|
throw new Error('You\'ve sent too many direct payments')
|
|
}
|
|
}
|
|
|
|
if (!userId) return
|
|
|
|
const pendingReceiverInvoices = await models.directPayment.count({
|
|
where: {
|
|
receiverId: userId,
|
|
createdAt: {
|
|
gt: datePivot(new Date(), { minutes: -MAX_PENDING_DIRECT_INVOICES_PER_USER_MINUTES })
|
|
}
|
|
}
|
|
})
|
|
|
|
if (pendingReceiverInvoices >= MAX_PENDING_DIRECT_INVOICES_PER_USER) {
|
|
throw new Error('Receiver has too many direct payments')
|
|
}
|
|
}
|