Add autowithdrawal badge in notifications (#1078)
This commit is contained in:
parent
00ca35465c
commit
796bd4dc4b
|
@ -1,7 +1,7 @@
|
|||
import { GraphQLError } from 'graphql'
|
||||
import { decodeCursor, LIMIT, nextNoteCursorEncoded } from '@/lib/cursor'
|
||||
import { getItem, filterClause, whereClause, muteClause } from './item'
|
||||
import { getInvoice } from './wallet'
|
||||
import { getInvoice, getWithdrawl } from './wallet'
|
||||
import { pushSubscriptionSchema, ssValidate } from '@/lib/validate'
|
||||
import { replyToSubscription } from '@/lib/webPush'
|
||||
import { getSub } from './sub'
|
||||
|
@ -444,6 +444,9 @@ export default {
|
|||
InvoicePaid: {
|
||||
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: {
|
||||
invite: async (n, args, { models }) => {
|
||||
return await models.invite.findUnique({
|
||||
|
|
|
@ -55,6 +55,31 @@ export async function getInvoice (parent, { id }, { me, models, lnd }) {
|
|||
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) {
|
||||
const key = Buffer.from(process.env.INVOICE_HMAC_KEY, '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 }) => {
|
||||
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
|
||||
},
|
||||
withdrawl: getWithdrawl,
|
||||
numBolt11s: async (parent, args, { me, models, lnd }) => {
|
||||
if (!me) {
|
||||
throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } })
|
||||
|
|
|
@ -95,6 +95,7 @@ export default gql`
|
|||
id: ID!
|
||||
earnedSats: Int!
|
||||
sortTime: Date!
|
||||
withdrawl: Withdrawl!
|
||||
}
|
||||
|
||||
type Referral {
|
||||
|
|
|
@ -29,6 +29,7 @@ import { LongCountdown } from './countdown'
|
|||
import { nextBillingWithGrace } from '@/lib/territory'
|
||||
import { commentSubTreeRootId } from '@/lib/item'
|
||||
import LinkToContext from './link-to-context'
|
||||
import { Badge } from 'react-bootstrap'
|
||||
|
||||
function Notification ({ n, fresh }) {
|
||||
const type = n.__typename
|
||||
|
@ -283,6 +284,7 @@ function WithdrawlPaid ({ n }) {
|
|||
<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
|
||||
<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>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -27,3 +27,10 @@
|
|||
.subFormGroup > div {
|
||||
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
|
||||
sortTime
|
||||
earnedSats
|
||||
withdrawl {
|
||||
autoWithdraw
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue