Skip to content

Commit

Permalink
feat: improving parseCredDefFromId function and CredentialCard11 attr…
Browse files Browse the repository at this point in the history
…ibute value (openwallet-foundation#1155)

Signed-off-by: Caroline Lucas Calheirani <ccalheirani@gmail.com>
  • Loading branch information
CarolineLCa authored Jun 11, 2024
1 parent 37ca0a2 commit 6115b21
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
8 changes: 4 additions & 4 deletions packages/legacy/core/App/components/misc/CredentialCard11.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const CredentialCard11: React.FC<CredentialCard11Props> = ({

const parseAttribute = (item: (Attribute & Predicate) | undefined) => {
let parsedItem = item
if (item && !item.value) {
if (item && item.value != null) {
parsedItem = pTypeToText(item, t, attributeTypes) as Attribute & Predicate
}
const parsedValue = formatIfDate(
Expand All @@ -253,7 +253,7 @@ const CredentialCard11: React.FC<CredentialCard11Props> = ({
)
return {
label: item?.label ?? item?.name ?? '',
value: item?.value ? parsedValue : `${parsedItem?.pType} ${parsedValue}`,
value: item?.value !== undefined && item?.value != null ? parsedValue : `${parsedItem?.pType} ${parsedValue}`,
}
}

Expand Down Expand Up @@ -407,7 +407,7 @@ const CredentialCard11: React.FC<CredentialCard11Props> = ({
return (
item && (
<View style={{ marginTop: 15 }}>
{!(item?.value || item?.satisfied) ? (
{!(item?.value != null || item?.satisfied) ? (
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<Icon
style={{ paddingTop: 2, paddingHorizontal: 2 }}
Expand All @@ -420,7 +420,7 @@ const CredentialCard11: React.FC<CredentialCard11Props> = ({
) : (
<AttributeLabel label={label} />
)}
{!(item?.value || item?.pValue) ? null : (
{!(item?.value != null || item?.pValue) ? null : (
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
{flaggedAttributes?.includes(label) && !item.pValue && !allPI && proof && (
<Icon
Expand Down
19 changes: 8 additions & 11 deletions packages/legacy/core/App/utils/cred-def.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { AnonCredsCredentialMetadataKey } from '@credo-ts/anoncreds'
import { AnonCredsCredentialMetadataKey, parseIndyCredentialDefinitionId, parseIndySchemaId } from '@credo-ts/anoncreds'
import { CredentialExchangeRecord as CredentialRecord } from '@credo-ts/core'

import { credentialSchema, parseSchemaFromId } from './schema'
import { credentialSchema } from './schema'

export function parseCredDefFromId(credDefId?: string, schemaId?: string): string {
let name = 'Credential'
if (credDefId) {
const credDefRegex = /[^:]+/g
const credDefIdParts = credDefId.match(credDefRegex)
if (credDefIdParts?.length === 5) {
name = `${credDefIdParts?.[4].replace(/_|-/g, ' ')}`
.split(' ')
.map((credIdPart) => credIdPart.charAt(0).toUpperCase() + credIdPart.substring(1))
.join(' ')
}
const parseIndyCredDefId = parseIndyCredentialDefinitionId(credDefId)
name = parseIndyCredDefId.tag
}
if (name.toLocaleLowerCase() === 'default' || name.toLowerCase() === 'credential') {
name = parseSchemaFromId(schemaId).name
if (schemaId) {
const parseIndySchema = parseIndySchemaId(schemaId)
name = parseIndySchema.schemaName
}
}
return name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('displays a credential selection screen', () => {
const attributeBase = {
referent: '',
schemaId: '',
credentialDefinitionId: 'AAAAAAAAAAAAAAAAAAAAAA:1:AA:1234:test',
credentialDefinitionId: 'AAAAAAAAAAAAAAAAAAAAAA:3:CL:1234:test',
toJSON: jest.fn(),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('displays a proof request screen', () => {
const attributeBase = {
referent: '',
schemaId: '',
credentialDefinitionId: 'AAAAAAAAAAAAAAAAAAAAAA:1:AA:1234:test',
credentialDefinitionId: 'AAAAAAAAAAAAAAAAAAAAAA:3:CL:1234:test',
toJSON: jest.fn(),
}

Expand Down

0 comments on commit 6115b21

Please sign in to comment.