Add autowithdrawal badge in notifications (#1078)
This commit is contained in:
parent
00ca35465c
commit
796bd4dc4b
|
@ -1,7 +1,7 @@
|
||||||
import { GraphQLError } from 'graphql'
|
import { GraphQLError } from 'graphql'
|
||||||
import { decodeCursor, LIMIT, nextNoteCursorEncoded } from '@/lib/cursor'
|
import { decodeCursor, LIMIT, nextNoteCursorEncoded } from '@/lib/cursor'
|
||||||
import { getItem, filterClause, whereClause, muteClause } from './item'
|
import { getItem, filterClause, whereClause, muteClause } from './item'
|
||||||
import { getInvoice } from './wallet'
|
import { getInvoice, getWithdrawl } from './wallet'
|
||||||
import { pushSubscriptionSchema, ssValidate } from '@/lib/validate'
|
import { pushSubscriptionSchema, ssValidate } from '@/lib/validate'
|
||||||
import { replyToSubscription } from '@/lib/webPush'
|
import { replyToSubscription } from '@/lib/webPush'
|
||||||
import { getSub } from './sub'
|
import { getSub } from './sub'
|
||||||
|
@ -444,6 +444,9 @@ export default {
|
||||||
InvoicePaid: {
|
InvoicePaid: {
|
||||||
invoice: async (n, args, { me, models }) => getInvoice(n, { id: n.id }, { me, models })
|
invoice: async (n, args, { me, models }) => getInvoice(n, { id: n.id }, { me, models })
|
||||||
},
|
},
|
||||||
|
WithdrawlPaid: {
|
||||||
|
withdrawl: async (n, args, { me, models }) => getWithdrawl(n, { id: n.id }, { me, models })
|
||||||
|
},
|
||||||
Invitification: {
|
Invitification: {
|
||||||
invite: async (n, args, { models }) => {
|
invite: async (n, args, { models }) => {
|
||||||
return await models.invite.findUnique({
|
return await models.invite.findUnique({
|
||||||
|
|
|
@ -55,6 +55,31 @@ export async function getInvoice (parent, { id }, { me, models, lnd }) {
|
||||||
return inv
|
return inv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getWithdrawl (parent, { id }, { me, models }) {
|
||||||
|
if (!me) {
|
||||||
|
throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } })
|
||||||
|
}
|
||||||
|
|
||||||
|
const wdrwl = await models.withdrawl.findUnique({
|
||||||
|
where: {
|
||||||
|
id: Number(id)
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
user: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!wdrwl) {
|
||||||
|
throw new GraphQLError('withdrawal not found', { extensions: { code: 'BAD_INPUT' } })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wdrwl.user.id !== me.id) {
|
||||||
|
throw new GraphQLError('not ur withdrawal', { extensions: { code: 'FORBIDDEN' } })
|
||||||
|
}
|
||||||
|
|
||||||
|
return wdrwl
|
||||||
|
}
|
||||||
|
|
||||||
export function createHmac (hash) {
|
export function createHmac (hash) {
|
||||||
const key = Buffer.from(process.env.INVOICE_HMAC_KEY, 'hex')
|
const key = Buffer.from(process.env.INVOICE_HMAC_KEY, 'hex')
|
||||||
return crypto.createHmac('sha256', key).update(Buffer.from(hash, 'hex')).digest('hex')
|
return crypto.createHmac('sha256', key).update(Buffer.from(hash, 'hex')).digest('hex')
|
||||||
|
@ -99,30 +124,7 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
withdrawl: async (parent, { id }, { me, models }) => {
|
withdrawl: getWithdrawl,
|
||||||
if (!me) {
|
|
||||||
throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } })
|
|
||||||
}
|
|
||||||
|
|
||||||
const wdrwl = await models.withdrawl.findUnique({
|
|
||||||
where: {
|
|
||||||
id: Number(id)
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
user: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!wdrwl) {
|
|
||||||
throw new GraphQLError('withdrawal not found', { extensions: { code: 'BAD_INPUT' } })
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wdrwl.user.id !== me.id) {
|
|
||||||
throw new GraphQLError('not ur withdrawal', { extensions: { code: 'FORBIDDEN' } })
|
|
||||||
}
|
|
||||||
|
|
||||||
return wdrwl
|
|
||||||
},
|
|
||||||
numBolt11s: async (parent, args, { me, models, lnd }) => {
|
numBolt11s: async (parent, args, { me, models, lnd }) => {
|
||||||
if (!me) {
|
if (!me) {
|
||||||
throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } })
|
throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } })
|
||||||
|
|
|
@ -95,6 +95,7 @@ export default gql`
|
||||||
id: ID!
|
id: ID!
|
||||||
earnedSats: Int!
|
earnedSats: Int!
|
||||||
sortTime: Date!
|
sortTime: Date!
|
||||||
|
withdrawl: Withdrawl!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Referral {
|
type Referral {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import { LongCountdown } from './countdown'
|
||||||
import { nextBillingWithGrace } from '@/lib/territory'
|
import { nextBillingWithGrace } from '@/lib/territory'
|
||||||
import { commentSubTreeRootId } from '@/lib/item'
|
import { commentSubTreeRootId } from '@/lib/item'
|
||||||
import LinkToContext from './link-to-context'
|
import LinkToContext from './link-to-context'
|
||||||
|
import { Badge } from 'react-bootstrap'
|
||||||
|
|
||||||
function Notification ({ n, fresh }) {
|
function Notification ({ n, fresh }) {
|
||||||
const type = n.__typename
|
const type = n.__typename
|
||||||
|
@ -283,6 +284,7 @@ function WithdrawlPaid ({ n }) {
|
||||||
<div className='fw-bold text-info ms-2 py-1'>
|
<div className='fw-bold text-info ms-2 py-1'>
|
||||||
<Check className='fill-info me-1' />{numWithUnits(n.earnedSats, { abbreviate: false, unitSingular: 'sat was', unitPlural: 'sats were' })} withdrawn from your account
|
<Check className='fill-info me-1' />{numWithUnits(n.earnedSats, { abbreviate: false, unitSingular: 'sat was', unitPlural: 'sats were' })} withdrawn from your account
|
||||||
<small className='text-muted ms-1 fw-normal' suppressHydrationWarning>{timeSince(new Date(n.sortTime))}</small>
|
<small className='text-muted ms-1 fw-normal' suppressHydrationWarning>{timeSince(new Date(n.sortTime))}</small>
|
||||||
|
{n.withdrawl.autoWithdraw && <Badge className={styles.badge} bg={null}>autowithdraw</Badge>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,4 +26,11 @@
|
||||||
|
|
||||||
.subFormGroup > div {
|
.subFormGroup > div {
|
||||||
margin-right: 0 !important;
|
margin-right: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
color: var(--theme-grey) !important;
|
||||||
|
background: var(--theme-clickToContextColor) !important;
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-left: 0.5rem;
|
||||||
}
|
}
|
|
@ -137,6 +137,9 @@ export const NOTIFICATIONS = gql`
|
||||||
id
|
id
|
||||||
sortTime
|
sortTime
|
||||||
earnedSats
|
earnedSats
|
||||||
|
withdrawl {
|
||||||
|
autoWithdraw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue