Skip to content

Commit

Permalink
fix: improve credential handling with metaOverlay support in history (#…
Browse files Browse the repository at this point in the history
…1445)

Signed-off-by: Jean-Christophe Drouin <[email protected]>
  • Loading branch information
jcdrouin21 authored Feb 19, 2025
1 parent ebfc6a7 commit e6e87e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/legacy/core/App/screens/CredentialDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const CredentialDetails: React.FC<CredentialDetailsProps> = ({ navigation, route
const historyManager = historyManagerCurried(agent)

const ids = getCredentialIdentifiers(credential)
const name = parseCredDefFromId(ids.credentialDefinitionId, ids.schemaId)
const name = overlay.metaOverlay?.name ?? parseCredDefFromId(ids.credentialDefinitionId, ids.schemaId)

/** Save history record for credential removed */
const recordData: HistoryRecord = {
Expand All @@ -209,7 +209,7 @@ const CredentialDetails: React.FC<CredentialDetailsProps> = ({ navigation, route
} catch (err: unknown) {
logger.error(`[${CredentialDetails.name}]:[logHistoryRecord] Error saving history: ${err}`)
}
}, [agent, historyEnabled, logger, historyManagerCurried, credential, credentialConnectionLabel, credentialId])
}, [agent, historyEnabled, logger, historyManagerCurried, credential, credentialConnectionLabel, credentialId, overlay])

const callSubmitRemove = useCallback(async () => {
try {
Expand Down
16 changes: 9 additions & 7 deletions packages/legacy/core/App/screens/CredentialOffer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AnonCredsCredentialMetadataKey } from '@credo-ts/anoncreds'
import { CredentialPreviewAttribute } from '@credo-ts/core'
import { useCredentialById } from '@credo-ts/react-hooks'
import { BrandingOverlay } from '@hyperledger/aries-oca'
import { BrandingOverlay, MetaOverlay } from '@hyperledger/aries-oca'
import { Attribute, CredentialOverlay } from '@hyperledger/aries-oca/build/legacy'
import { useIsFocused } from '@react-navigation/native'
import React, { useCallback, useEffect, useState } from 'react'
Expand Down Expand Up @@ -148,9 +148,11 @@ const CredentialOffer: React.FC<CredentialOfferProps> = ({ navigation, credentia
const resolvePresentationFields = async () => {
const identifiers = getCredentialIdentifiers(credential)
const attributes = buildFieldsFromAnonCredsCredential(credential)
const fields = await bundleResolver.presentationFields({ identifiers, attributes, language: i18n.language })
const bundle = await bundleResolver.resolveAllBundles({ identifiers, attributes, language: i18n.language })
const fields = bundle?.presentationFields ?? []
const metaOverlay = bundle?.metaOverlay ?? {}

return { fields }
return { fields, metaOverlay }
}

/**
Expand All @@ -162,8 +164,8 @@ const CredentialOffer: React.FC<CredentialOfferProps> = ({ navigation, credentia
setLoading(true)
updateCredentialPreview()
.then(() => resolvePresentationFields())
.then(({ fields }) => {
setOverlay((o) => ({ ...o, presentationFields: (fields as Attribute[]).filter((field) => field.value) }))
.then(({ fields, metaOverlay }) => {
setOverlay({metaOverlay: (metaOverlay as MetaOverlay), presentationFields: (fields as Attribute[]).filter((field) => field.value) })
setLoading(false)
})
}, [credential, agent, bundleResolver, i18n.language])
Expand All @@ -186,7 +188,7 @@ const CredentialOffer: React.FC<CredentialOfferProps> = ({ navigation, credentia
return
}
const ids = getCredentialIdentifiers(credential)
const name = parseCredDefFromId(ids.credentialDefinitionId, ids.schemaId)
const name = overlay.metaOverlay?.name ?? parseCredDefFromId(ids.credentialDefinitionId, ids.schemaId)

/** Save history record for card accepted */
const recordData: HistoryRecord = {
Expand All @@ -201,7 +203,7 @@ const CredentialOffer: React.FC<CredentialOfferProps> = ({ navigation, credentia
logger.error(`[${CredentialOffer.name}]:[logHistoryRecord] Error saving history: ${err}`)
}
},
[agent, historyEnabled, logger, historyManagerCurried, credential, credentialId, credentialConnectionLabel]
[agent, historyEnabled, logger, historyManagerCurried, credential, credentialId, credentialConnectionLabel, overlay]
)

const handleAcceptTouched = useCallback(async () => {
Expand Down

0 comments on commit e6e87e3

Please sign in to comment.