diff --git a/app/src/components/NotificationListItem.tsx b/app/src/components/NotificationListItem.tsx index 5bcd67437..7d3c2eb07 100644 --- a/app/src/components/NotificationListItem.tsx +++ b/app/src/components/NotificationListItem.tsx @@ -326,7 +326,7 @@ const NotificationListItem: React.FC = ({ case NotificationTypeEnum.Revocation: navigation.getParent()?.navigate(Stacks.NotificationStack, { screen: Screens.CredentialDetails, - params: { credential: notification }, + params: { credential: notification.id }, }) break case NotificationTypeEnum.Custom: diff --git a/app/src/hooks/notifications.ts b/app/src/hooks/notifications.ts index d3dac6144..2e0d25fb6 100644 --- a/app/src/hooks/notifications.ts +++ b/app/src/hooks/notifications.ts @@ -9,13 +9,7 @@ import { W3cCredentialRecord, } from '@credo-ts/core' import { useCredentialByState, useProofByState, useBasicMessages, useAgent } from '@credo-ts/react-hooks' -import { BifoldAgent, TOKENS, useServices, useStore } from '@hyperledger/aries-bifold-core' -import { - CustomRecord, - HistoryCardType, - HistoryRecord, - RecordType, -} from '@hyperledger/aries-bifold-core/App/modules/history/types' +import { BifoldAgent, useStore } from '@hyperledger/aries-bifold-core' import { BasicMessageMetadata, CredentialMetadata, @@ -23,10 +17,8 @@ import { credentialCustomMetadata, } from '@hyperledger/aries-bifold-core/App/types/metadata' import { CustomNotificationRecord } from '@hyperledger/aries-bifold-core/App/types/notification' -import { parseCredDefFromId } from '@hyperledger/aries-bifold-core/App/utils/cred-def' -import { getCredentialIdentifiers } from '@hyperledger/aries-bifold-core/App/utils/credential' import { ProofCustomMetadata, ProofMetadata } from '@hyperledger/aries-bifold-verifier' -import { useCallback, useEffect, useState } from 'react' +import { useEffect, useState } from 'react' import { attestationCredDefIds } from '../constants' import { showPersonCredentialSelector } from '../helpers/BCIDHelper' @@ -79,53 +71,6 @@ export const useNotifications = ({ isHome = true }: NotificationsInputProps): No const { agent } = useAgent() const [store] = useStore() const [nonAttestationProofs, setNonAttestationProofs] = useState([]) - const [logger, historyManagerCurried, historyEnabled] = useServices([ - TOKENS.UTIL_LOGGER, - TOKENS.FN_LOAD_HISTORY, - TOKENS.HISTORY_ENABLED, - ]) - - const logHistoryRecord = useCallback( - async (credential: CredentialRecord) => { - const connection = await agent?.connections.findById(credential?.connectionId ?? '') - const correspondenceName = connection?.alias || connection?.theirLabel || credential.connectionId - try { - if (!(agent && historyEnabled)) { - logger.trace( - `[${useNotifications.name}]:[logHistoryRecord] Skipping history log, either history function disabled or agent undefined!` - ) - return - } - const historyManager = historyManagerCurried(agent) - - const type = HistoryCardType.CardRevoked - - const events = await historyManager.getHistoryItems({ type: RecordType.HistoryRecord }) - if ( - events.some( - (event: CustomRecord) => event.content.type === type && event.content.correspondenceId === credential.id - ) - ) { - return - } - const ids = getCredentialIdentifiers(credential) - const name = parseCredDefFromId(ids.credentialDefinitionId, ids.schemaId) - - /** Save history record for card accepted */ - const recordData: HistoryRecord = { - type: type, - message: name, - createdAt: new Date(), - correspondenceId: credential.id, - correspondenceName: correspondenceName, - } - await historyManager.saveHistory(recordData) - } catch (err: unknown) { - logger.error(`[${useNotifications.name}]:[logHistoryRecord] Error saving history: ${err}`) - } - }, - [agent, historyEnabled, logger, historyManagerCurried] - ) useEffect(() => { // get all unseen messages @@ -158,7 +103,6 @@ export const useNotifications = ({ isHome = true }: NotificationsInputProps): No metadata?.revoked_seen == undefined && (metadata?.seenOnHome == undefined || !isHome) ) { - logHistoryRecord(cred) return cred } }) diff --git a/app/src/navigators/TabStack.tsx b/app/src/navigators/TabStack.tsx index cf6cd9a11..f6be74765 100644 --- a/app/src/navigators/TabStack.tsx +++ b/app/src/navigators/TabStack.tsx @@ -1,3 +1,4 @@ +import { CredentialExchangeRecord as CredentialRecord } from '@credo-ts/core' import { useAgent } from '@credo-ts/react-hooks' import { AttachTourStep, @@ -13,7 +14,15 @@ import { useStore, useTheme, } from '@hyperledger/aries-bifold-core' +import { + CustomRecord, + HistoryCardType, + HistoryRecord, + RecordType, +} from '@hyperledger/aries-bifold-core/App/modules/history/types' import { TourID } from '@hyperledger/aries-bifold-core/App/types/tour' +import { parseCredDefFromId } from '@hyperledger/aries-bifold-core/App/utils/cred-def' +import { getCredentialIdentifiers } from '@hyperledger/aries-bifold-core/App/utils/credential' import { createBottomTabNavigator } from '@react-navigation/bottom-tabs' import { useNavigation } from '@react-navigation/native' import { StackNavigationProp } from '@react-navigation/stack' @@ -41,10 +50,18 @@ const TabStack: React.FC = () => { const [store, dispatch] = useStore() const navigation = useNavigation>() - const [{ useNotifications }, { enableImplicitInvitations, enableReuseConnections }, logger] = useServices([ + const [ + { useNotifications }, + { enableImplicitInvitations, enableReuseConnections }, + logger, + historyManagerCurried, + historyEnabled, + ] = useServices([ TOKENS.NOTIFICATIONS, TOKENS.CONFIG, TOKENS.UTIL_LOGGER, + TOKENS.FN_LOAD_HISTORY, + TOKENS.HISTORY_ENABLED, ]) const notifications = useNotifications({ isHome: false } as NotificationsInputProps) @@ -58,6 +75,48 @@ const TabStack: React.FC = () => { }, }) + const logHistoryRecord = useCallback( + async (credential: CredentialRecord) => { + const connection = await agent?.connections.findById(credential?.connectionId ?? '') + const correspondenceName = connection?.alias || connection?.theirLabel || credential.connectionId + try { + if (!(agent && historyEnabled)) { + logger.trace( + `[${TabStack.name}]:[logHistoryRecord] Skipping history log, either history function disabled or agent undefined!` + ) + return + } + const historyManager = historyManagerCurried(agent) + + const type = HistoryCardType.CardRevoked + + const events = await historyManager.getHistoryItems({ type: RecordType.HistoryRecord }) + if ( + events.some( + (event: CustomRecord) => event.content.type === type && event.content.correspondenceId === credential.id + ) + ) { + return + } + const ids = getCredentialIdentifiers(credential) + const name = parseCredDefFromId(ids.credentialDefinitionId, ids.schemaId) + + /** Save history record for card accepted */ + const recordData: HistoryRecord = { + type: type, + message: name, + createdAt: new Date(), + correspondenceId: credential.id, + correspondenceName: correspondenceName, + } + await historyManager.saveHistory(recordData) + } catch (err: unknown) { + logger.error(`[${TabStack.name}]:[logHistoryRecord] Error saving history: ${err}`) + } + }, + [agent, historyEnabled, logger, historyManagerCurried] + ) + const handleDeepLink = useCallback( async (deepLink: string) => { logger.info(`Handling deeplink: ${deepLink}`) @@ -158,6 +217,13 @@ const TabStack: React.FC = () => { isTempDeleted: false, } } + if ( + (n as CredentialRecord).type === 'CredentialRecord' && + (n as CredentialRecord).state === 'done' && + (n as CredentialRecord).revocationNotification + ) { + logHistoryRecord(n as CredentialRecord) + } } if (Object.keys(notificationsToAdd).length > 0) { dispatch({