diff --git a/packages/agent/src/hooks/useAcceptDidCommPresentation.ts b/packages/agent/src/hooks/useAcceptDidCommPresentation.ts index 886213c5..169fc34c 100644 --- a/packages/agent/src/hooks/useAcceptDidCommPresentation.ts +++ b/packages/agent/src/hooks/useAcceptDidCommPresentation.ts @@ -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 @@ -157,9 +157,33 @@ export function useAcceptDidCommPresentation(proofExchangeId: string) { }, }) + const { mutateAsync: declineMutateAsync } = useMutation({ + mutationKey: ['declineDidCommPresentation', proofExchangeId], + mutationFn: async () => { + const presentationDeclined$ = agent.events + .observable(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, diff --git a/packages/app/features/notifications/DidCommPresentationNotificationScreen.tsx b/packages/app/features/notifications/DidCommPresentationNotificationScreen.tsx index 7ef87413..f60ba45e 100644 --- a/packages/app/features/notifications/DidCommPresentationNotificationScreen.tsx +++ b/packages/app/features/notifications/DidCommPresentationNotificationScreen.tsx @@ -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() @@ -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()