From e08145c5596645928faf024868976de3c9d649c1 Mon Sep 17 00:00:00 2001 From: wadeking98 Date: Mon, 16 Oct 2023 12:34:54 -0700 Subject: [PATCH] delete conn from rejected proof Signed-off-by: wadeking98 --- .../legacy/core/App/navigators/RootStack.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/legacy/core/App/navigators/RootStack.tsx b/packages/legacy/core/App/navigators/RootStack.tsx index ab7e73649b..bd01380bf3 100644 --- a/packages/legacy/core/App/navigators/RootStack.tsx +++ b/packages/legacy/core/App/navigators/RootStack.tsx @@ -1,4 +1,5 @@ -import { useAgent } from '@aries-framework/react-hooks' +import { ProofState } from '@aries-framework/core' +import { useAgent, useProofByState } from '@aries-framework/react-hooks' import { useNavigation } from '@react-navigation/core' import { createStackNavigator, StackCardStyleInterpolator, StackNavigationProp } from '@react-navigation/stack' import { parseUrl } from 'query-string' @@ -6,6 +7,7 @@ import React, { useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { AppState, DeviceEventEmitter } from 'react-native' +import { ProofCustomMetadata, ProofMetadata } from '../../verifier' import HeaderButton, { ButtonLocation } from '../components/buttons/HeaderButton' import { EventTypes, walletTimeout } from '../constants' import { useAuth } from '../contexts/auth' @@ -51,6 +53,18 @@ const RootStack: React.FC = () => { const { pages, terms, splash, useBiometry, developer } = useConfiguration() useDeepLinks() + // remove connection on mobile verifier proofs if proof is rejected regardless of if it has been opened + const declinedProofs = useProofByState([ProofState.Declined, ProofState.Abandoned]) + useEffect(() => { + declinedProofs.forEach((proof) => { + const meta = proof?.metadata?.get(ProofMetadata.customMetadata) as ProofCustomMetadata + if (meta?.delete_conn_after_seen) { + agent?.connections.deleteById(proof?.connectionId ?? '').catch(() => {}) + proof?.metadata.set(ProofMetadata.customMetadata, { ...meta, delete_conn_after_seen: false }) + } + }) + }, [declinedProofs, state.preferences.useDataRetention]) + const lockoutUser = async () => { if (agent && state.authentication.didAuthenticate) { // make sure agent is shutdown so wallet isn't still open