1
- import React from 'react' ;
2
- import { ClassName } from 'wallet-common-helpers' ;
1
+ import React , { useMemo } from 'react' ;
2
+ import { ClassName , TimeStampUnit , dateFromTimestamp } from 'wallet-common-helpers' ;
3
3
import { AttributeType } from '@concordium/web-sdk' ;
4
4
import clsx from 'clsx' ;
5
5
import { useTranslation } from 'react-i18next' ;
@@ -13,15 +13,18 @@ import {
13
13
VerifiableCredentialSchema ,
14
14
VerifiableCredentialStatus ,
15
15
} from '@shared/storage/types' ;
16
-
16
+ import { parseCredentialDID } from '@shared/utils/verifiable-credential-helpers' ;
17
17
import Img from '@popup/shared/Img' ;
18
+
18
19
import {
19
20
defaultFormatAttribute ,
21
+ useCredentialEntry ,
20
22
useCredentialLocalization ,
21
23
useCredentialMetadata ,
22
24
useCredentialSchema ,
23
25
useCredentialStatus ,
24
26
} from '../utils/verifiable-credentials' ;
27
+ import { withDateAndTime } from '@shared/utils/time-helpers' ;
25
28
26
29
/**
27
30
* Component for displaying the status of a verifiable credential.
@@ -147,14 +150,16 @@ function applySchemaAndLocalization(
147
150
148
151
type Props = Pick < ViewProps , 'className' > & {
149
152
credential : VerifiableCredential ;
153
+ showInfo ?: boolean ;
150
154
} ;
151
155
152
- export default function Web3IdCard ( { credential, ...viewProps } : Props ) {
153
- const { t } = useTranslation ( 'x' , { keyPrefix : 'sharedX.web3IdCard.warning ' } ) ;
156
+ export default function Web3IdCard ( { credential, showInfo = false , ...viewProps } : Props ) {
157
+ const { t } = useTranslation ( 'x' , { keyPrefix : 'sharedX.web3IdCard' } ) ;
154
158
const status = useCredentialStatus ( credential ) ;
155
159
const schema = useCredentialSchema ( credential ) ;
156
160
const metadata = useCredentialMetadata ( credential ) ;
157
161
const localization = useCredentialLocalization ( credential ) ;
162
+ const entry = useCredentialEntry ( credential ) ;
158
163
159
164
// Render nothing until all the required data is available.
160
165
if ( ! schema || ! metadata || localization . loading || status === undefined ) {
@@ -165,15 +170,38 @@ export default function Web3IdCard({ credential, ...viewProps }: Props) {
165
170
schema ,
166
171
credential . credentialSubject . attributes
167
172
) ;
168
- const attributes = Object . entries ( credential . credentialSubject . attributes ) . map (
169
- applySchemaAndLocalization ( schema , localization . result )
170
- ) ;
173
+
174
+ let attributes : AttributeView [ ] = [ ] ;
175
+ if ( showInfo && entry !== undefined ) {
176
+ const [ contract , id ] = parseCredentialDID ( credential . id ) ;
177
+ if ( ! entry ) {
178
+ return null ;
179
+ }
180
+
181
+ const validFrom = dateFromTimestamp ( entry . credentialInfo . validFrom , TimeStampUnit . milliSeconds ) ;
182
+ const validFromFormatted = withDateAndTime ( validFrom ) ;
183
+ attributes = [
184
+ { title : t ( 'details.id' ) , value : id } ,
185
+ { title : t ( 'details.contract' ) , value : contract . toString ( ) } ,
186
+ { title : t ( 'details.validFrom' ) , value : validFromFormatted } ,
187
+ ] ;
188
+
189
+ if ( entry . credentialInfo . validUntil !== undefined ) {
190
+ const validUntil = dateFromTimestamp ( entry . credentialInfo . validUntil , TimeStampUnit . milliSeconds ) ;
191
+ const validUntilFormatted = withDateAndTime ( validUntil ) ;
192
+ attributes . push ( { title : t ( 'details.validUntil' ) , value : validUntilFormatted } ) ;
193
+ }
194
+ } else if ( ! showInfo ) {
195
+ attributes = Object . entries ( credential . credentialSubject . attributes ) . map (
196
+ applySchemaAndLocalization ( schema , localization . result )
197
+ ) ;
198
+ }
171
199
172
200
let warning : string | undefined ;
173
201
if ( ! schemaMatchesCredentialAttributes ) {
174
- warning = t ( 'schemaMismatch' ) ;
202
+ warning = t ( 'warning. schemaMismatch' ) ;
175
203
} else if ( schema . usingFallback ) {
176
- warning = t ( 'fallback' ) ;
204
+ warning = t ( 'warning. fallback' ) ;
177
205
}
178
206
179
207
return (
0 commit comments