Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor UI issues for OpenID cards #1465

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/legacy/core/App/components/misc/CredentialCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const CredentialCard: React.FC<CredentialCardProps> = ({
const { ColorPallet } = useTheme()
const [overlay, setOverlay] = useState<CredentialOverlay<BrandingOverlay>>({})
const { resolveBundleForCredential } = useOpenIDCredentials()
const [extraOverlayAttribute, setExtraOverlayAttribute] = useState<string | number | null | undefined>()
const [extraOverlayAttribute, setExtraOverlayAttribute] = useState<Attribute | undefined>()

useEffect(() => {
if (brandingOverlay) {
Expand All @@ -70,10 +70,7 @@ const CredentialCard: React.FC<CredentialCardProps> = ({
resolveOverlay(credential)
const credentialDisplay = getCredentialForDisplay(credential)
if (credentialDisplay.display.primary_overlay_attribute) {
const attributeValue = getAttributeField(
credentialDisplay,
credentialDisplay.display.primary_overlay_attribute
)?.value
const attributeValue = getAttributeField(credentialDisplay, credentialDisplay.display.primary_overlay_attribute)
setExtraOverlayAttribute(attributeValue)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface CredentialCard11Props {
handleAltCredChange?: () => void
brandingOverlay?: CredentialOverlay<BrandingOverlay>
hideSlice?: boolean
extraOverlayParameter?: string | number | null | undefined
extraOverlayParameter?: Attribute | undefined
brandingOverlayType?: BrandingOverlayType
}

Expand Down Expand Up @@ -451,7 +451,8 @@ const CredentialCard11: React.FC<CredentialCard11Props> = ({
},
]}
>
{extraOverlayParameter}
{extraOverlayParameter.label ?? startCase(extraOverlayParameter.name || '')}:{' '}
{extraOverlayParameter.value}
</Text>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { getCredentialForDisplay } from '../display'
import { BifoldError } from '../../../types/error'
import { EventTypes } from '../../../constants'
import { getAttributeField } from '../utils/utils'
import { Attribute } from '@hyperledger/aries-oca/build/legacy'
import startCase from 'lodash.startcase'

interface CredentialCardProps {
credentialDisplay?: W3cCredentialDisplay
Expand Down Expand Up @@ -62,9 +64,9 @@ const OpenIDCredentialCard: React.FC<CredentialCardProps> = ({
return result.display
}, [credentialDisplay, credentialRecord, t])

const overlayAttribute = useMemo((): string | number | null | undefined => {
const overlayAttributeField = useMemo((): Attribute | undefined => {
if (!display?.primary_overlay_attribute || !credentialDisplay) return undefined
return getAttributeField(credentialDisplay, display.primary_overlay_attribute)?.value
return getAttributeField(credentialDisplay, display.primary_overlay_attribute)
}, [display, credentialDisplay])

const { width } = useWindowDimensions()
Expand Down Expand Up @@ -213,7 +215,7 @@ const OpenIDCredentialCard: React.FC<CredentialCardProps> = ({
}

const CardFooter: React.FC = () => {
if (!overlayAttribute) return null
if (!overlayAttributeField) return null
return (
<View testID={testIdWithKey('CredentialCardFooter')} style={styles.footerContainer}>
<Text
Expand All @@ -226,7 +228,7 @@ const OpenIDCredentialCard: React.FC<CredentialCardProps> = ({
testID={testIdWithKey('CredentialIssued')}
maxFontSizeMultiplier={1}
>
{overlayAttribute}
{overlayAttributeField.label ?? startCase(overlayAttributeField.name || '')}: {overlayAttributeField.value}
</Text>
</View>
)
Expand Down
4 changes: 2 additions & 2 deletions packages/legacy/core/App/modules/openid/hooks/openid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export const useOpenID = ({
} catch (err: unknown) {
//TODO: Sppecify different error
const error = new BifoldError(
t('Error.Title1043'),
t('Error.Message1043'),
t('Error.Title1024'),
t('Error.Message1024'),
(err as Error)?.message ?? err,
1043
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ const OpenIDProofPresentation: React.FC<OpenIDProofPresentationProps> = ({
)
}

const selectAltCredentail = () => {}

const renderCard = (
sub: FormattedSubmissionEntry,
selectedCredential: FormattedSelectedCredentialEntry,
//TODO: Support multiplae credentials
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hasMultipleCreds: boolean
) => {
const credential = credentialsRequested.find((c) => c.id === selectedCredential.id)
Expand All @@ -216,8 +216,9 @@ const OpenIDProofPresentation: React.FC<OpenIDProofPresentationProps> = ({
<CredentialCard
credential={credential}
displayItems={fieldsMapped as Attribute[]}
hasAltCredentials={hasMultipleCreds}
handleAltCredChange={selectAltCredentail}
//TODO: Support multiplae credentials
// hasAltCredentials={hasMultipleCreds}
// handleAltCredChange={selectAltCredentail}
/>
)
}
Expand Down