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>
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
import { PAID_ACTION_PAYMENT_METHODS } from '@/lib/constants'
|
|
import { satsToMsats } from '@/lib/format'
|
|
import { notifyInvite } from '@/lib/webPush'
|
|
|
|
export const anonable = false
|
|
|
|
export const paymentMethods = [
|
|
PAID_ACTION_PAYMENT_METHODS.FEE_CREDIT,
|
|
PAID_ACTION_PAYMENT_METHODS.REWARD_SATS
|
|
]
|
|
|
|
export async function getCost ({ id }, { models, me }) {
|
|
const invite = await models.invite.findUnique({ where: { id, userId: me.id, revoked: false } })
|
|
if (!invite) {
|
|
throw new Error('invite not found')
|
|
}
|
|
return satsToMsats(invite.gift)
|
|
}
|
|
|
|
export async function perform ({ id, userId }, { me, cost, tx }) {
|
|
const invite = await tx.invite.findUnique({
|
|
where: { id, userId: me.id, revoked: false }
|
|
})
|
|
|
|
if (invite.limit && invite.giftedCount >= invite.limit) {
|
|
throw new Error('invite limit reached')
|
|
}
|
|
|
|
// check that user was created in last hour
|
|
// check that user did not already redeem an invite
|
|
await tx.user.update({
|
|
where: {
|
|
id: userId,
|
|
inviteId: null,
|
|
createdAt: {
|
|
gt: new Date(Date.now() - 1000 * 60 * 60)
|
|
}
|
|
},
|
|
data: {
|
|
mcredits: {
|
|
increment: cost
|
|
},
|
|
inviteId: id,
|
|
referrerId: me.id
|
|
}
|
|
})
|
|
|
|
return await tx.invite.update({
|
|
where: { id, userId: me.id, revoked: false, ...(invite.limit ? { giftedCount: { lt: invite.limit } } : {}) },
|
|
data: {
|
|
giftedCount: {
|
|
increment: 1
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
export async function nonCriticalSideEffects (_, { me }) {
|
|
notifyInvite(me.id)
|
|
}
|