Skip to content

Commit

Permalink
feat: email notification endpoint for distribute-payouts events (#4298)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraeth-eth authored Apr 7, 2024
1 parent d137ddb commit 3f3ff13
Show file tree
Hide file tree
Showing 6 changed files with 673 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/components/buttons/SubscribeButton/hooks/useSubscribeButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ export const useSubscribeButton = ({ projectId }: { projectId: number }) => {
userId,
})
if (!notifications?.length) {
const { error } = await supabase.from('user_subscriptions').insert([
{
user_id: _session.user.id,
project_id: projectId,
notification_id: ProjectNotification.ProjectPaid,
},
])
const subscriptions = generateUserSubscriptions(userId, projectId)
const { error } = await supabase
.from('user_subscriptions')
.insert(subscriptions)
if (error) throw error
setIsSubscribed(true)
} else {
Expand All @@ -84,7 +81,9 @@ export const useSubscribeButton = ({ projectId }: { projectId: number }) => {
.delete()
.eq('user_id', userId)
.eq('project_id', projectId)
.eq('notification_id', ProjectNotification.ProjectPaid)
.or(
'notification_id.eq.project_paid,notification_id.eq.payouts_distributed',
)
if (error) throw error
setIsSubscribed(false)
}
Expand Down Expand Up @@ -161,3 +160,17 @@ export const useSubscribeButton = ({ projectId }: { projectId: number }) => {
onSubscribeButtonClicked,
}
}

const generateUserSubscriptions = (userId: string, projectId: number) => {
const base = {
user_id: userId,
project_id: projectId,
}
return [
ProjectNotification.ProjectPaid,
ProjectNotification.PayoutsDistributed,
].map(notification_id => ({
...base,
notification_id,
}))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
query DistributePayoutsEvents(
$where: DistributePayoutsEvent_filter
$orderBy: DistributePayoutsEvent_orderBy
$orderDirection: OrderDirection
$first: Int
$skip: Int
) {
distributePayoutsEvents(
where: $where
orderBy: $orderBy
orderDirection: $orderDirection
first: $first
skip: $skip
) {
txHash
amount
amountUSD
beneficiary
beneficiaryDistributionAmount
beneficiaryDistributionAmountUSD
caller
from
projectId
splitDistributions {
beneficiary
amount
amountUSD
allocator
caller
domain
from
group
id
lockedUntil
percent
preferAddToBalance
preferClaimed
projectId
splitProjectId
terminal
timestamp
txHash
}
distributedAmount
distributedAmountUSD
fee
feeUSD
fundingCycleConfiguration
fundingCycleNumber
id
memo
terminal
timestamp
}
}
1 change: 1 addition & 0 deletions src/models/notifications/projectNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export enum ProjectNotification {
ProjectPaid = 'project_paid',
PayoutsDistributed = 'payouts_distributed',
}
Loading

0 comments on commit 3f3ff13

Please sign in to comment.