Skip to content

Commit

Permalink
feat: Decline problem report
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Lanser <[email protected]>
  • Loading branch information
Tommylans committed Apr 11, 2024
1 parent 572538b commit 207c8a2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
30 changes: 27 additions & 3 deletions packages/agent/src/hooks/useAcceptDidCommPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function useAcceptDidCommPresentation(proofExchangeId: string) {
},
})

const { mutateAsync, status } = useMutation({
const { mutateAsync: acceptMutateAsync, status: acceptStatus } = useMutation({
mutationKey: ['acceptDidCommPresentation', proofExchangeId],
mutationFn: async () => {
const presentationDone$ = agent.events
Expand All @@ -157,9 +157,33 @@ export function useAcceptDidCommPresentation(proofExchangeId: string) {
},
})

const { mutateAsync: declineMutateAsync } = useMutation({
mutationKey: ['declineDidCommPresentation', proofExchangeId],
mutationFn: async () => {
const presentationDeclined$ = agent.events
.observable<ProofStateChangedEvent>(ProofEventTypes.ProofStateChanged)
.pipe(
// Correct record with id and state
filter(
(event) =>
event.payload.proofRecord.id === proofExchangeId &&
[ProofState.Declined].includes(event.payload.proofRecord.state)
),
// 10 seconds to complete exchange
timeout(10000),
first()
)

const presentationDeclinePromise = firstValueFrom(presentationDeclined$)
await agent.proofs.declineRequest({ proofRecordId: proofExchangeId, sendProblemReport: true })
await presentationDeclinePromise
},
})

return {
acceptPresentation: mutateAsync,
status,
acceptPresentation: acceptMutateAsync,
declinePresentation: declineMutateAsync,
status: acceptStatus,
proofExchange,
submission: data,
verifierName: connection?.theirLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ export function DidCommPresentationNotificationScreen({
const router = useRouter()
const toast = useToastController()

const { acceptPresentation, proofExchange, status, submission, verifierName } =
useAcceptDidCommPresentation(proofExchangeId)
const {
acceptPresentation,
declinePresentation,
proofExchange,
status,
submission,
verifierName,
} = useAcceptDidCommPresentation(proofExchangeId)

const pushToWallet = () => {
router.back()
Expand All @@ -44,7 +50,9 @@ export function DidCommPresentationNotificationScreen({
}

const onProofDecline = () => {
void agent.proofs.deleteById(proofExchange.id)
declinePresentation().finally(() => {
void agent.proofs.deleteById(proofExchange.id)
})

toast.show('Information request has been declined.')
pushToWallet()
Expand Down

0 comments on commit 207c8a2

Please sign in to comment.