Skip to content

Commit

Permalink
fix: pid display fixes (#193)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan <[email protected]>
  • Loading branch information
janrtvld authored Oct 30, 2024
1 parent 108ebb1 commit ad65e46
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 70 deletions.
53 changes: 41 additions & 12 deletions apps/easypid/src/features/activity/FunkeActivityDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Circle, FlexPage, Heading, Paragraph, ScrollView, Stack, YStack } from
import React from 'react'
import { createParam } from 'solito'

import type { ClaimFormat } from '@credo-ts/core'
import { getPidDisclosedAttributeNames, isPidCredential, usePidCredential } from '@easypid/hooks'
import { getPidAttributesForDisplay } from '@easypid/hooks'
import { useCredentialsWithCustomDisplay } from '@easypid/hooks/useCredentialsWithCustomDisplay'
import { CardWithAttributes, TextBackButton, activityInteractions } from '@package/app'
import { useScrollViewPosition } from '@package/app/src/hooks'
Expand All @@ -18,6 +21,7 @@ export function FunkeActivityDetailScreen() {
const { params } = useParams()
const router = useRouter()
const { bottom } = useSafeAreaInsets()
const { credential: pidCredential } = usePidCredential()

const { activities } = useActivities()
const { credentials } = useCredentialsWithCustomDisplay()
Expand Down Expand Up @@ -74,6 +78,43 @@ export function FunkeActivityDetailScreen() {
{activity.request.credentials && activity.request.credentials.length > 0 ? (
activity.request.credentials.map((activityCredential) => {
const credential = credentials.find((credential) => credential.id.includes(activityCredential.id))

if (!credential)
return (
<CardWithAttributes
key={activityCredential.id}
id={activityCredential.id}
name="Deleted credential"
textColor="$grey-100"
backgroundColor="$primary-500"
disclosedAttributes={activityCredential.disclosedAttributes ?? []}
disclosedPayload={activityCredential.disclosedPayload ?? {}}
disableNavigation={true}
/>
)

if (isPidCredential(credential.metadata.type)) {
return (
<CardWithAttributes
key={pidCredential?.id}
id={pidCredential?.id as string}
name={pidCredential?.display.name as string}
issuerImage={pidCredential?.display.issuer.logo}
backgroundImage={pidCredential?.display.backgroundImage}
backgroundColor={pidCredential?.display.backgroundColor}
textColor={pidCredential?.display.textColor}
disclosedAttributes={getPidDisclosedAttributeNames(
activityCredential?.disclosedPayload ?? {},
credential?.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
)}
disclosedPayload={getPidAttributesForDisplay(
activityCredential?.disclosedPayload ?? {},
credential?.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
)}
/>
)
}

if (credential)
return (
<CardWithAttributes
Expand All @@ -89,18 +130,6 @@ export function FunkeActivityDetailScreen() {
disableNavigation={activity.status !== 'success'}
/>
)
return (
<CardWithAttributes
key={activityCredential.id}
id={activityCredential.id}
name="Deleted credential"
textColor="$grey-100"
backgroundColor="$primary-500"
disclosedAttributes={activityCredential.disclosedAttributes ?? []}
disclosedPayload={activityCredential.disclosedPayload ?? {}}
disableNavigation={true}
/>
)
})
) : (
<FailedReasonContainer reason={activity.request.failureReason ?? 'unknown'} />
Expand Down
11 changes: 4 additions & 7 deletions apps/easypid/src/features/activity/activityRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ export const useActivities = ({ filters }: { filters?: { host?: string } } = {})
export const addReceivedActivity = async (
agent: EasyPIDAppAgent,
input: {
did: string
name: string
domain?: string
host?: string
logo?: DisplayImage
backgroundColor?: string
credentialIds: string[]
Expand All @@ -100,9 +99,8 @@ export const addReceivedActivity = async (
type: 'received',
status: 'success',
entity: {
did: input.did,
name: input.name,
host: input.domain ? input.domain : (getHostNameFromUrl(input.did) as string),
host: input.host,
logo: input.logo,
backgroundColor: input.backgroundColor,
},
Expand All @@ -115,7 +113,7 @@ export const addSharedActivity = async (
input: {
status: ActivityStatus
entity: {
did: string
host: string
name?: string
logo?: DisplayImage
}
Expand All @@ -137,9 +135,8 @@ export const addSharedActivity = async (
type: 'shared',
status: input.status,
entity: {
did: input.entity.did,
name: input.entity.name,
host: getHostNameFromUrl(input.entity.did) as string,
host: input.entity.host,
logo: input.entity.logo,
},
request: {
Expand Down
4 changes: 2 additions & 2 deletions apps/easypid/src/features/onboarding/onboardingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@package/agent'
import { secureWalletKey } from '@package/secure-store/secureUnlock'
import { useToastController } from '@package/ui'
import { capitalizeFirstLetter, sleep } from '@package/utils'
import { capitalizeFirstLetter, getHostNameFromUrl, sleep } from '@package/utils'
import { useRouter } from 'expo-router'
import type React from 'react'
import { type PropsWithChildren, createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'
Expand Down Expand Up @@ -701,7 +701,7 @@ export function OnboardingContextProvider({
)

await addReceivedActivity(secureUnlock.context.agent, {
did: parsed.prettyClaims.iss,
host: getHostNameFromUrl(parsed.prettyClaims.iss) as string,
name: pidDisplay?.issuer.name,
logo: pidDisplay?.issuer.logo,
backgroundColor: '#ffffff', // PID Logo needs white background
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function OnboardingIdCardRequestedAttributes({
<CardWithAttributes
id="pid-display"
name="eID card"
issuerImage={display?.issuer.logo}
backgroundImage={display?.backgroundImage}
backgroundColor={display?.backgroundColor}
disclosedAttributes={requestedAttributes.map((a) => sanitizeString(a))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function FunkeOpenIdCredentialNotificationScreen() {
)

const lastInteractionDate = useMemo(() => {
const activity = activities.find((activity) => activity.entity.did === credential?.metadata.issuer)
const activity = activities.find((activity) => activity.entity.host === credential?.display.issuer.domain)
return activity?.date
}, [activities, credential])

Expand All @@ -76,11 +76,10 @@ export function FunkeOpenIdCredentialNotificationScreen() {
setIsStoring(true)
await storeCredential(agent, credentialRecord)
.then(async () => {
const { metadata, display } = getCredentialForDisplay(credentialRecord)
const { display } = getCredentialForDisplay(credentialRecord)

await addReceivedActivity(agent, {
did: metadata.issuer,
domain: display.issuer.domain,
host: display.issuer.domain,
name: display.issuer.name,
logo: display.issuer.logo ? display.issuer.logo : undefined,
backgroundColor: display.backgroundColor, // Might not be accurate for issuer image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
BiometricAuthenticationCancelledError,
type CredentialMetadata,
type EasyPIDAppAgent,
formatDifPexCredentialsForRequest,
getCredentialsForProofRequest,
Expand All @@ -20,7 +19,7 @@ import {
import { useSeedCredentialPidData } from '@easypid/storage'
import { getOpenIdFedIssuerMetadata } from '@easypid/utils/issuer'
import { usePushToWallet } from '@package/app/src/hooks/usePushToWallet'
import { getPidAttributesForDisplay, usePidCredential } from '../../hooks'
import { usePidCredential } from '../../hooks'
import { addSharedActivity, useActivities } from '../activity/activityRecord'
import { FunkePresentationNotificationScreen } from './FunkePresentationNotificationScreen'

Expand Down Expand Up @@ -53,9 +52,7 @@ export function FunkeOpenIdPresentationNotificationScreen() {
[credentialsForRequest]
)
const lastInteractionDate = useMemo(() => {
const activity = activities.find(
(activity) => activity.entity.did === credentialsForRequest?.authorizationRequest.issuer
)
const activity = activities.find((activity) => activity.entity.host === credentialsForRequest?.verifierHostName)
return activity?.date
}, [activities, credentialsForRequest])

Expand Down Expand Up @@ -92,22 +89,14 @@ export function FunkeOpenIdPresentationNotificationScreen() {
() =>
submission?.entries.flatMap((entry) => {
return entry.credentials.map((credential) => {
const disclosedPayload =
credential.metadata?.type === pidCredential?.type
? getPidAttributesForDisplay(
credential.disclosedPayload ?? {},
credential.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
)
: credential.disclosedPayload

return {
id: credential.id,
disclosedAttributes: credential.requestedAttributes ?? [],
disclosedPayload,
disclosedPayload: credential.disclosedPayload ?? {},
}
})
}),
[submission, pidCredential]
[submission]
)

const usePin = useMemo(() => {
Expand Down Expand Up @@ -164,8 +153,8 @@ export function FunkeOpenIdPresentationNotificationScreen() {
status: 'success',
entity: {
name: fedDisplayData ? fedDisplayData.display.name : credentialsForRequest.verifierHostName,
did: credentialsForRequest.authorizationRequest.issuer as string,
logo: fedDisplayData ? fedDisplayData.display.logo : undefined,
host: credentialsForRequest.verifierHostName as string,
},
request: {
name: submission.name,
Expand Down Expand Up @@ -264,7 +253,7 @@ export function FunkeOpenIdPresentationNotificationScreen() {
const onProofDecline = async () => {
const activityData = {
entity: {
did: credentialsForRequest?.authorizationRequest.issuer as string,
host: credentialsForRequest?.verifierHostName as string,
name: fedDisplayData ? fedDisplayData.display.name : credentialsForRequest?.verifierHostName,
logo: fedDisplayData ? fedDisplayData.display.logo : undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export function FunkePresentationNotificationScreen({
onAccept={usePin ? undefined : onAccept}
onDecline={onDecline}
logo={logo}
verifierName={verifierName}
submission={submission}
isAccepting={isAccepting}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { ClaimFormat } from '@credo-ts/core'
import { getPidAttributesForDisplay, getPidDisclosedAttributeNames, usePidCredential } from '@easypid/hooks'
import {
getPidAttributesForDisplay,
getPidDisclosedAttributeNames,
isPidCredential,
usePidCredential,
} from '@easypid/hooks'
import type { FormattedSubmission } from '@package/agent/src'
import { Heading, Paragraph, YStack } from '@package/ui'
import { CardWithAttributes } from 'packages/app/src'
Expand All @@ -18,34 +23,30 @@ export function RequestedAttributesSection({ submission }: RequestedAttributesSe
<YStack gap="$4">
<Paragraph>
{submission.areAllSatisfied
? 'Onsly the following attributes will be shared. Nothing more.'
? 'Only the following attributes will be shared. Nothing more.'
: `You don't have the requested credential(s).`}
</Paragraph>
{submission.entries.map((entry) => (
<YStack gap="$4" key={entry.inputDescriptorId}>
{entry.credentials.map((credential) => {
if (credential.metadata?.type === pidCredential?.type) {
const disclosedAttributes = getPidDisclosedAttributeNames(
credential?.disclosedPayload ?? {},
credential?.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
)

const disclosedPayload = getPidAttributesForDisplay(
credential?.disclosedPayload ?? {},
credential?.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
)

if (isPidCredential(credential.metadata?.type)) {
return (
<CardWithAttributes
key={credential.id as string}
id={credential.id as string}
key={pidCredential?.id}
id={pidCredential?.id as string}
name={pidCredential?.display.name as string}
issuerImage={pidCredential?.display.issuer.logo}
backgroundImage={pidCredential?.display.backgroundImage}
backgroundColor={pidCredential?.display.backgroundColor}
textColor={pidCredential?.display.textColor}
disclosedAttributes={disclosedAttributes}
disclosedPayload={disclosedPayload}
disclosedAttributes={getPidDisclosedAttributeNames(
credential?.disclosedPayload ?? {},
credential?.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
)}
disclosedPayload={getPidAttributesForDisplay(
credential?.disclosedPayload ?? {},
credential?.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
)}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface ShareCredentialsSlideProps {
onAccept?: () => Promise<PresentationRequestResult>
submission?: FormattedSubmission
onDecline: () => void
verifierName?: string
isAccepting: boolean
}

Expand All @@ -37,7 +36,6 @@ export const ShareCredentialsSlide = ({
submission,
onAccept,
onDecline,
verifierName,
isAccepting,
}: ShareCredentialsSlideProps) => {
const { onNext } = useWizard()
Expand All @@ -54,7 +52,12 @@ export const ShareCredentialsSlide = ({

const handleAccept = async () => {
if (onAccept) {
await onAccept()
const result = await onAccept()
if (result.status === 'error') {
toast.show(result.result.title, { message: result.result.message, customData: { preset: 'danger' } })
pushToWallet()
return
}
}
onNext()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export function FunkeCredentialDetailScreen() {
router.push({
pathname: '/credentials/[id]/attributes',
params: {
attributes: JSON.stringify(credential.attributes),
metadata: JSON.stringify(credential.metadata),
attributes: JSON.stringify(credential.attributesForDisplay ?? credential.attributes),
metadata: JSON.stringify(credential.metadataForDisplay ?? credential.metadata),
},
})
})
Expand Down
12 changes: 10 additions & 2 deletions apps/easypid/src/hooks/useCredentialsWithCustomDisplay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { type CredentialForDisplay, useCredentialsForDisplay } from 'packages/agent/src'
import { usePidCredential } from './usePidCredential'
import { type PidSdJwtVcAttributes, usePidCredential } from './usePidCredential'

type CustomCredentialForDisplay = CredentialForDisplay & {
attributesForDisplay: PidSdJwtVcAttributes
metadataForDisplay: Record<string, unknown>
}

export const useCredentialsWithCustomDisplay = () => {
const credentials = useCredentialsForDisplay()
Expand All @@ -13,5 +18,8 @@ export const useCredentialsWithCustomDisplay = () => {
credentials.credentials[index] = pidCredential.credential as CredentialForDisplay
}

return credentials
return credentials as {
credentials: CustomCredentialForDisplay[]
isLoading: boolean
}
}
Loading

0 comments on commit ad65e46

Please sign in to comment.