Skip to content

Commit

Permalink
feat: send notification for the result of the report that users adjud…
Browse files Browse the repository at this point in the history
…icate
  • Loading branch information
Xiawpohr committed Jan 14, 2025
1 parent 1220e8e commit 020745c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import { useNotificationConfig } from '../../config/NotificationConfig'
import {
useNotificationById,
markAsRead,
useNotificationById,
} from '../../stores/useNotificationStore'

interface NotificationItemProps {
Expand All @@ -20,20 +20,20 @@ const NotificationItem: React.FC<NotificationItemProps> = ({ id }) => {
const actions = config.actions

return (
<div className="relative flex items-center p-3 rounded-2xl shadow-md mb-4 bg-gray-100">
<div className="relative flex items-center p-3 mb-4 bg-gray-100 shadow-md rounded-2xl">
{isRead && (
<div className="absolute inset-0 bg-black bg-opacity-40 rounded-2xl z-20 pointer-events-none"></div>
<div className="absolute inset-0 z-10 bg-black pointer-events-none bg-opacity-40 rounded-2xl"></div>
)}

<div className="flex items-center w-full z-10">
<div className="mr-4 flex-shrink-0 flex items-center justify-center h-full">
<div className="flex items-center w-full">
<div className="flex items-center justify-center flex-shrink-0 h-full mr-4">
{IconComponent ? (
<IconComponent className="w-8 h-8" />
) : null}
</div>

<div className="flex-grow">
<p className="text-xs mb-1 text-gray-500">{time}</p>
<p className="mb-1 text-xs text-gray-500">{time}</p>
<p
className={`text-sm ${
isRead ? 'text-gray-500' : 'text-black'
Expand All @@ -42,7 +42,7 @@ const NotificationItem: React.FC<NotificationItemProps> = ({ id }) => {
{message}
</p>

<div className="flex justify-end space-x-4 mt-2">
<div className="flex justify-end mt-2 space-x-4">
{actions?.map((action, index) => (
<button
key={index}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export function useBackgroundReputationClaim() {
await claimAdjucatorReputation(report.reportId)
}
}
}, [reports, userState, claimEpochKeyReputation, claimAdjucatorReputation])
}, [claimAdjucatorReputation, claimEpochKeyReputation, reports, userState])

useEffect(() => {
claimReputation()
}, [reports, claimReputation])
}, [claimReputation])
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
useWeb3Provider,
} from '@/features/core'
import { genReportNullifierProof } from '@/features/core/utils/genReportNullifierProof'
import { RepUserType } from '@/types/Report'
import { useSendNotification } from '@/features/notification/stores/useNotificationStore'
import { NotificationType } from '@/types/Notifications'
import { RepUserType, ReputationType } from '@/types/Report'
import { relayClaimReputation } from '@/utils/api'
import { getEpochKeyNonce } from '@/utils/helpers/getEpochKeyNonce'
import { useMutation, useQueryClient } from '@tanstack/react-query'
Expand All @@ -17,6 +19,7 @@ export function useReportAdjudicatorReputation() {
const actionCount = useActionCount()
const { getGuaranteedProvider } = useWeb3Provider()
const queryClient = useQueryClient()
const sendNotification = useSendNotification()

return useMutation({
mutationKey: [MutationKeys.ClaimAdjudicatorReputation],
Expand All @@ -40,10 +43,31 @@ export function useReportAdjudicatorReputation() {

return result
},
onSuccess: () => {
onSuccess: (result) => {
queryClient.invalidateQueries({
queryKey: [QueryKeys.ReputationScore],
})
const reportId = result.message.reportId
const isPassed = result.message.isPassed
switch (result.message.type) {
case ReputationType.BE_REPORTED:
sendNotification(NotificationType.BE_REPORTED, reportId)
break
case ReputationType.REPORT_SUCCESS:
sendNotification(NotificationType.REPORT_PASSED, reportId)
break
case ReputationType.REPORT_FAILURE:
sendNotification(NotificationType.REPORT_REJECTED, reportId)
break
case ReputationType.ADJUDICATE:
sendNotification(
isPassed
? NotificationType.ADJUDICATE_RESULT_PASSED
: NotificationType.ADJUDICATE_RESULT_REJECTED,
reportId,
)
break
}
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import {
useWeb3Provider,
} from '@/features/core'
import { genReportNonNullifierProof } from '@/features/core/utils/genReportNonNullifierProof'
import { RepUserType } from '@/types/Report'
import { useSendNotification } from '@/features/notification/stores/useNotificationStore'
import { NotificationType } from '@/types/Notifications'
import { RepUserType, ReputationType } from '@/types/Report'
import { relayClaimReputation } from '@/utils/api'
import { getEpochKeyNonce } from '@/utils/helpers/getEpochKeyNonce'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { ReputationType } from '@/types/Report'
import { useSendNotification } from '@/features/notification/stores/useNotificationStore'
import { NotificationType } from '@/types/Notifications'

export function useReportEpochKeyReputation() {
const { stateTransition } = useUserStateTransition()
Expand Down
8 changes: 8 additions & 0 deletions packages/frontend/src/types/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export enum RepUserType {
ADJUDICATOR,
}

export enum RepChangeType {
REPORTER_REP = 3,
RESPONDENT_REP = 5,
FAILED_REPORTER_REP = 1,
ADJUDICATOR_REP = 1,
CHECK_IN_REP = 1,
}

export enum ReputationType {
REPORT_SUCCESS,
REPORT_FAILURE,
Expand Down
18 changes: 17 additions & 1 deletion packages/frontend/src/types/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { RelayRawComment } from './Comments'
import { RelayRawPost } from './Post'
import { RelayRawReputationHistory } from './Report'
import {
RelayRawReputationHistory,
RepChangeType,
ReputationType,
} from './Report'
import { RelayRawVote } from './Vote'

export enum Directions {
Expand Down Expand Up @@ -86,3 +90,15 @@ export interface RelayCreateVoteResponse {
export interface RelayCreateReportResponse {
reportId: string
}

export interface RelayClaimReputationResponse {
message: {
txHash: string
reportId: string
epoch: number
epochKey: string
type: ReputationType
score: RepChangeType
isPassed: true
}
}
3 changes: 2 additions & 1 deletion packages/frontend/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
FetchReputationHistoryResponse,
FetchVotesByEpochKeysParams,
FetchVotesByEpochKeysResponse,
RelayClaimReputationResponse,
RelayCreateCommentResponse,
RelayCreatePostResponse,
RelayRemoveCommentResponse,
Expand Down Expand Up @@ -346,7 +347,7 @@ export async function relayClaimReputation(
repUserType: RepUserType,
publicSignals: bigint[],
proof: bigint[],
) {
): Promise<RelayClaimReputationResponse> {
const response = await fetch(`${SERVER}/api/reputation/claim`, {
method: 'POST',
headers: {
Expand Down

0 comments on commit 020745c

Please sign in to comment.