@procivis/one-react-native-components 0.3.142 → 0.3.147

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/lib/commonjs/components/proof-request/index.js +1 -12
  2. package/lib/commonjs/components/proof-request/index.js.map +1 -1
  3. package/lib/commonjs/components/proof-request/v2/share-credential-v2-group.js +6 -3
  4. package/lib/commonjs/components/proof-request/v2/share-credential-v2-group.js.map +1 -1
  5. package/lib/commonjs/components/proof-request/v2/share-credential-v2.js.map +1 -1
  6. package/lib/commonjs/ui-components/credential/card/credential-header.js +8 -38
  7. package/lib/commonjs/ui-components/credential/card/credential-header.js.map +1 -1
  8. package/lib/commonjs/ui-components/credential/card/credential-logo.js +71 -0
  9. package/lib/commonjs/ui-components/credential/card/credential-logo.js.map +1 -0
  10. package/lib/commonjs/ui-components/credential/card/index.js +7 -0
  11. package/lib/commonjs/ui-components/credential/card/index.js.map +1 -1
  12. package/lib/commonjs/ui-components/input/selection-input.js +69 -53
  13. package/lib/commonjs/ui-components/input/selection-input.js.map +1 -1
  14. package/lib/commonjs/ui-components/text/index.js +1 -9
  15. package/lib/commonjs/ui-components/text/index.js.map +1 -1
  16. package/lib/commonjs/utils/hooks/core/proofs.js +1 -1
  17. package/lib/commonjs/utils/hooks/core/proofs.js.map +1 -1
  18. package/lib/commonjs/utils/hooks/core/transaction.js +20 -0
  19. package/lib/commonjs/utils/hooks/core/transaction.js.map +1 -0
  20. package/lib/commonjs/utils/parsers/credential-sharing-v2.js +34 -3
  21. package/lib/commonjs/utils/parsers/credential-sharing-v2.js.map +1 -1
  22. package/lib/commonjs/utils/parsers/credential.js +22 -14
  23. package/lib/commonjs/utils/parsers/credential.js.map +1 -1
  24. package/lib/commonjs/utils/parsers/index.js +0 -11
  25. package/lib/commonjs/utils/parsers/index.js.map +1 -1
  26. package/lib/commonjs/utils/parsers/query.js +2 -2
  27. package/lib/commonjs/utils/parsers/query.js.map +1 -1
  28. package/lib/module/components/proof-request/index.js +0 -1
  29. package/lib/module/components/proof-request/index.js.map +1 -1
  30. package/lib/module/components/proof-request/v2/share-credential-v2-group.js +6 -3
  31. package/lib/module/components/proof-request/v2/share-credential-v2-group.js.map +1 -1
  32. package/lib/module/components/proof-request/v2/share-credential-v2.js.map +1 -1
  33. package/lib/module/ui-components/credential/card/credential-header.js +8 -38
  34. package/lib/module/ui-components/credential/card/credential-header.js.map +1 -1
  35. package/lib/module/ui-components/credential/card/credential-logo.js +64 -0
  36. package/lib/module/ui-components/credential/card/credential-logo.js.map +1 -0
  37. package/lib/module/ui-components/credential/card/index.js +2 -0
  38. package/lib/module/ui-components/credential/card/index.js.map +1 -1
  39. package/lib/module/ui-components/input/selection-input.js +70 -54
  40. package/lib/module/ui-components/input/selection-input.js.map +1 -1
  41. package/lib/module/ui-components/text/index.js +2 -2
  42. package/lib/module/ui-components/text/index.js.map +1 -1
  43. package/lib/module/utils/hooks/core/proofs.js +1 -1
  44. package/lib/module/utils/hooks/core/proofs.js.map +1 -1
  45. package/lib/module/utils/hooks/core/transaction.js +13 -0
  46. package/lib/module/utils/hooks/core/transaction.js.map +1 -0
  47. package/lib/module/utils/parsers/credential-sharing-v2.js +31 -1
  48. package/lib/module/utils/parsers/credential-sharing-v2.js.map +1 -1
  49. package/lib/module/utils/parsers/credential.js +20 -13
  50. package/lib/module/utils/parsers/credential.js.map +1 -1
  51. package/lib/module/utils/parsers/index.js +0 -1
  52. package/lib/module/utils/parsers/index.js.map +1 -1
  53. package/lib/module/utils/parsers/query.js +2 -2
  54. package/lib/module/utils/parsers/query.js.map +1 -1
  55. package/lib/typescript/components/proof-request/index.d.ts +0 -1
  56. package/lib/typescript/components/proof-request/v2/share-credential-v2-group.d.ts +8 -1
  57. package/lib/typescript/components/proof-request/v2/share-credential-v2.d.ts +1 -1
  58. package/lib/typescript/ui-components/credential/card/credential-logo.d.ts +17 -0
  59. package/lib/typescript/ui-components/credential/card/index.d.ts +3 -0
  60. package/lib/typescript/ui-components/input/selection-input.d.ts +3 -7
  61. package/lib/typescript/ui-components/text/index.d.ts +2 -1
  62. package/lib/typescript/ui-components/text/typography.d.ts +13 -13
  63. package/lib/typescript/utils/hooks/core/proofs.d.ts +2 -2
  64. package/lib/typescript/utils/hooks/core/transaction.d.ts +2 -0
  65. package/lib/typescript/utils/parsers/credential-sharing-v2.d.ts +10 -2
  66. package/lib/typescript/utils/parsers/credential.d.ts +2 -1
  67. package/lib/typescript/utils/parsers/index.d.ts +0 -1
  68. package/package.json +7 -4
  69. package/src/components/proof-request/index.ts +0 -1
  70. package/src/components/proof-request/v2/share-credential-v2-group.tsx +12 -2
  71. package/src/components/proof-request/v2/share-credential-v2.tsx +1 -1
  72. package/src/ui-components/credential/card/credential-header.tsx +9 -37
  73. package/src/ui-components/credential/card/credential-logo.stories.tsx +45 -0
  74. package/src/ui-components/credential/card/credential-logo.tsx +79 -0
  75. package/src/ui-components/credential/card/index.ts +5 -8
  76. package/src/ui-components/input/selection-input.tsx +85 -65
  77. package/src/ui-components/text/index.ts +2 -1
  78. package/src/utils/hooks/core/proofs.ts +3 -3
  79. package/src/utils/hooks/core/transaction.ts +18 -0
  80. package/src/utils/parsers/credential-sharing-v2.tsx +70 -1
  81. package/src/utils/parsers/credential.ts +27 -13
  82. package/src/utils/parsers/index.ts +0 -1
  83. package/src/utils/parsers/query.ts +1 -1
  84. package/lib/commonjs/components/proof-request/v1/group.js +0 -35
  85. package/lib/commonjs/components/proof-request/v1/group.js.map +0 -1
  86. package/lib/commonjs/components/proof-request/v1/index.js +0 -39
  87. package/lib/commonjs/components/proof-request/v1/index.js.map +0 -1
  88. package/lib/commonjs/components/proof-request/v1/select-credential.js +0 -53
  89. package/lib/commonjs/components/proof-request/v1/select-credential.js.map +0 -1
  90. package/lib/commonjs/components/proof-request/v1/share-credential.js +0 -110
  91. package/lib/commonjs/components/proof-request/v1/share-credential.js.map +0 -1
  92. package/lib/commonjs/utils/parsers/credential-sharing.js +0 -269
  93. package/lib/commonjs/utils/parsers/credential-sharing.js.map +0 -1
  94. package/lib/module/components/proof-request/v1/group.js +0 -27
  95. package/lib/module/components/proof-request/v1/group.js.map +0 -1
  96. package/lib/module/components/proof-request/v1/index.js +0 -4
  97. package/lib/module/components/proof-request/v1/index.js.map +0 -1
  98. package/lib/module/components/proof-request/v1/select-credential.js +0 -44
  99. package/lib/module/components/proof-request/v1/select-credential.js.map +0 -1
  100. package/lib/module/components/proof-request/v1/share-credential.js +0 -101
  101. package/lib/module/components/proof-request/v1/share-credential.js.map +0 -1
  102. package/lib/module/utils/parsers/credential-sharing.js +0 -256
  103. package/lib/module/utils/parsers/credential-sharing.js.map +0 -1
  104. package/lib/typescript/components/proof-request/v1/group.d.ts +0 -2
  105. package/lib/typescript/components/proof-request/v1/index.d.ts +0 -3
  106. package/lib/typescript/components/proof-request/v1/select-credential.d.ts +0 -15
  107. package/lib/typescript/components/proof-request/v1/share-credential.d.ts +0 -27
  108. package/lib/typescript/utils/parsers/credential-sharing.d.ts +0 -21
  109. package/src/components/proof-request/v1/group.tsx +0 -26
  110. package/src/components/proof-request/v1/index.ts +0 -3
  111. package/src/components/proof-request/v1/select-credential.tsx +0 -55
  112. package/src/components/proof-request/v1/share-credential.tsx +0 -159
  113. package/src/utils/parsers/credential-sharing.tsx +0 -415
@@ -1,159 +0,0 @@
1
- import {
2
- CredentialDetail,
3
- CredentialListItem,
4
- CredentialState,
5
- PresentationDefinitionField,
6
- PresentationDefinitionRequestedCredential,
7
- } from '@procivis/react-native-one-core';
8
- import React, { FunctionComponent, useMemo } from 'react';
9
- import { Dimensions, ImageSourcePropType, StyleProp, StyleSheet, ViewStyle } from 'react-native';
10
-
11
- import { CredentialDetailsCardListItem, useAppColorScheme } from '../../../ui-components';
12
- import { concatTestID } from '../../../utils';
13
- import { useCoreConfig } from '../../../utils/hooks/core/core-config';
14
- import { getValidityState, ValidityState } from '../../../utils/parsers/credential';
15
- import {
16
- shareCredentialCardFromCredential,
17
- ShareCredentialCardLabels,
18
- } from '../../../utils/parsers/credential-sharing';
19
- import { SelectShareCredentialCardNotice } from '../select-share-credential-card-notice';
20
- import { ShareCredentialCardNotice } from '../share-credential-card-notice';
21
-
22
- export type ShareCredentialLabels = ShareCredentialCardLabels & {
23
- invalidCredentialNotice: string;
24
- multipleCredentialsNotice: string;
25
- multipleCredentialsSelect: string;
26
- revokedCredentialNotice: string;
27
- suspendedCredentialNotice: string;
28
- };
29
-
30
- export const ShareCredential: FunctionComponent<{
31
- allCredentials: CredentialDetail[];
32
- expanded?: boolean;
33
- labels: ShareCredentialLabels;
34
- language?: string;
35
- lastItem?: boolean;
36
- onHeaderPress?: (_credentialId?: string) => void;
37
- onImagePreview: (title: string, image: ImageSourcePropType) => void;
38
- onSelectCredential?: () => void;
39
- onSelectField: (_id: PresentationDefinitionField['id'], _selected: boolean) => void;
40
- request: PresentationDefinitionRequestedCredential;
41
- selectedCredentialId?: CredentialListItem['id'];
42
- selectedFields?: Array<PresentationDefinitionField['id']>;
43
- style?: StyleProp<ViewStyle>;
44
- testID: string;
45
- }> = ({
46
- allCredentials,
47
- expanded,
48
- labels,
49
- language,
50
- lastItem,
51
- onHeaderPress,
52
- onImagePreview,
53
- onSelectCredential,
54
- onSelectField,
55
- request,
56
- selectedCredentialId,
57
- selectedFields,
58
- style,
59
- testID,
60
- }) => {
61
- const colorScheme = useAppColorScheme();
62
- const credential = allCredentials.find((c) => c.id === selectedCredentialId);
63
- const { data: config } = useCoreConfig();
64
- const cardWidth = useMemo(() => Dimensions.get('window').width - 32, []);
65
-
66
- const selectionOptions = useMemo(
67
- () =>
68
- request.applicableCredentials.filter((applicableCredentialId) =>
69
- allCredentials.some(({ id, state }) => id === applicableCredentialId && state === CredentialState.ACCEPTED),
70
- ),
71
- [allCredentials, request],
72
- );
73
- const multipleCredentialsAvailable = selectionOptions.length > 1;
74
-
75
- const validityState = getValidityState(
76
- credential
77
- ? {
78
- ...credential,
79
- issuer: credential?.issuer?.id,
80
- }
81
- : undefined,
82
- );
83
-
84
- const footer = useMemo(() => {
85
- if (!expanded) {
86
- return;
87
- }
88
- if (validityState === ValidityState.Revoked) {
89
- return (
90
- <ShareCredentialCardNotice
91
- testID={concatTestID(testID, 'notice.revoked')}
92
- text={labels.revokedCredentialNotice}
93
- />
94
- );
95
- }
96
- if (validityState === ValidityState.Suspended) {
97
- return (
98
- <ShareCredentialCardNotice
99
- testID={concatTestID(testID, 'notice.suspended')}
100
- text={labels.suspendedCredentialNotice}
101
- />
102
- );
103
- }
104
-
105
- if (multipleCredentialsAvailable) {
106
- return (
107
- <SelectShareCredentialCardNotice
108
- buttonTitle={labels.multipleCredentialsSelect}
109
- onPress={onSelectCredential}
110
- testID={concatTestID(testID, 'notice.multiple')}
111
- text={labels.multipleCredentialsNotice}
112
- />
113
- );
114
- }
115
- }, [expanded, labels, multipleCredentialsAvailable, onSelectCredential, testID, validityState]);
116
-
117
- if (!config) {
118
- return null;
119
- }
120
-
121
- const { card, attributes } = shareCredentialCardFromCredential(
122
- credential,
123
- Boolean(expanded),
124
- multipleCredentialsAvailable,
125
- request,
126
- selectedFields,
127
- config,
128
- testID,
129
- labels,
130
- language,
131
- );
132
-
133
- return (
134
- <CredentialDetailsCardListItem
135
- attributes={attributes}
136
- card={{
137
- ...card,
138
- credentialId: request.id,
139
- onHeaderPress,
140
- width: cardWidth,
141
- }}
142
- expanded={expanded}
143
- footer={footer}
144
- lastItem={lastItem}
145
- onAttributeSelected={onSelectField}
146
- onImagePreview={onImagePreview}
147
- style={[styles.credential, { borderColor: colorScheme.background }, style]}
148
- testID={testID}
149
- />
150
- );
151
- };
152
-
153
- const styles = StyleSheet.create({
154
- credential: {
155
- borderRadius: 10,
156
- borderWidth: 1,
157
- marginBottom: 8,
158
- },
159
- });
@@ -1,415 +0,0 @@
1
- import {
2
- Claim,
3
- CoreConfig,
4
- CredentialDetail,
5
- CredentialListItem,
6
- CredentialType,
7
- PresentationDefinitionField,
8
- PresentationDefinitionRequestedCredential,
9
- PresentationDefinitionV2Credential,
10
- } from '@procivis/react-native-one-core';
11
- import React from 'react';
12
-
13
- import {
14
- CredentialAttribute,
15
- CredentialCardProps,
16
- CredentialHeaderProps,
17
- Selector,
18
- SelectorStatus,
19
- } from '../../ui-components/credential';
20
- import { CredentialCardNotice } from '../../ui-components/credential/card/credential-card';
21
- import { CredentialNoticeWarningIcon, CredentialWarningIcon, RequiredAttributeIcon } from '../../ui-components/icons';
22
- import { concatTestID } from '../testID';
23
- import {
24
- CardLabels,
25
- credentialDetailFromPresentationV2Credential,
26
- CredentialDetailsCardPropsWithoutWidth,
27
- detailsCardAttributeFromClaim,
28
- getCredentialCardPropsFromCredential,
29
- getValidityState,
30
- nestAttributes,
31
- supportsSelectiveDisclosure,
32
- ValidityState,
33
- } from './credential';
34
-
35
- export const validityCheckedCardFromCredential = (
36
- credential: CredentialDetail | PresentationDefinitionV2Credential,
37
- expanded: boolean,
38
- selectiveDisclosureSupported: boolean | undefined,
39
- multipleCredentialsAvailable: boolean,
40
- config: CoreConfig,
41
- notice: CredentialCardNotice | undefined,
42
- testID: string,
43
- labels: ShareCredentialCardLabels,
44
- language: string | undefined,
45
- ): Omit<CredentialCardProps, 'onHeaderPress' | 'style' | 'testID' | 'width'> => {
46
- let credentialHeaderDetail:
47
- | Pick<
48
- CredentialHeaderProps,
49
- | 'credentialDetailPrimary'
50
- | 'credentialDetailSecondary'
51
- | 'credentialDetailErrorColor'
52
- | 'credentialDetailTestID'
53
- | 'statusIcon'
54
- >
55
- | undefined;
56
- if (selectiveDisclosureSupported === false) {
57
- credentialHeaderDetail = {
58
- credentialDetailPrimary: labels.selectiveDisclosure,
59
- credentialDetailTestID: concatTestID(testID, 'header.nonSelectiveDisclosure'),
60
- statusIcon: CredentialWarningIcon,
61
- };
62
- } else if ('embeddedDisclosurePolicyViolation' in credential) {
63
- credentialHeaderDetail = {
64
- credentialDetailPrimary: labels.disclosurePolicyViolation,
65
- credentialDetailTestID: concatTestID(testID, 'header.dislosurePolicyViolation'),
66
- statusIcon: CredentialWarningIcon,
67
- };
68
- } else if (!expanded && multipleCredentialsAvailable) {
69
- credentialHeaderDetail = {
70
- credentialDetailPrimary: labels.multipleCredentials,
71
- credentialDetailTestID: concatTestID(testID, 'header.multiple'),
72
- statusIcon: CredentialWarningIcon,
73
- };
74
- }
75
-
76
- const card = getCredentialCardPropsFromCredential(
77
- credentialDetailFromPresentationV2Credential(credential),
78
- credential.claims,
79
- config,
80
- notice,
81
- testID,
82
- labels,
83
- language,
84
- );
85
- return {
86
- ...card,
87
- header: {
88
- ...card.header,
89
- ...credentialHeaderDetail,
90
- },
91
- };
92
- };
93
-
94
- export const missingCredentialCardFromRequest = (
95
- request: PresentationDefinitionRequestedCredential,
96
- notice: CredentialCardNotice | undefined,
97
- testID: string,
98
- labels: ShareCredentialCardLabels,
99
- ): Omit<CredentialCardProps, 'onHeaderPress' | 'style' | 'width'> => {
100
- return {
101
- cardImage: undefined,
102
- color: undefined,
103
- testID,
104
- header: {
105
- credentialDetailErrorColor: true,
106
- credentialDetailPrimary: labels.missingCredential,
107
- credentialDetailTestID: concatTestID(testID, 'header.missing'),
108
- credentialName: request.name ?? request.id,
109
- statusIcon: CredentialWarningIcon,
110
- },
111
- ...notice,
112
- };
113
- };
114
-
115
- interface DisplayedAttribute {
116
- claim?: FlatClaim;
117
- field?: PresentationDefinitionField;
118
- id: string;
119
- selected?: boolean;
120
- status: SelectorStatus;
121
- }
122
-
123
- const getAttributeSelectorStatus = (
124
- field: PresentationDefinitionField,
125
- validityState: ValidityState,
126
- credential?: CredentialDetail,
127
- claim?: Claim,
128
- selected?: boolean,
129
- ): SelectorStatus => {
130
- if (!credential || validityState !== ValidityState.Valid) {
131
- return SelectorStatus.Rejected;
132
- }
133
- if (field.required) {
134
- if (claim) {
135
- return SelectorStatus.Required;
136
- } else {
137
- return SelectorStatus.Rejected;
138
- }
139
- }
140
- if (!claim) {
141
- return SelectorStatus.Disabled;
142
- }
143
- return selected ? SelectorStatus.SelectedCheckmark : SelectorStatus.Empty;
144
- };
145
-
146
- type FlatClaim = Claim & {
147
- isArrayElement?: boolean;
148
- };
149
-
150
- // Returns a spread list of all claims with their full JSON path as key, including all intermediate objects
151
- const spreadClaims = (claims: Claim[]): FlatClaim[] => {
152
- return claims.reduce((acc, claim) => {
153
- const result = [claim];
154
- if (claim.value.type_ === 'NESTED') {
155
- const nestedClaimsWithPath: FlatClaim[] = claim.value.value.map((c) => ({
156
- ...c,
157
- isArrayElement: claim.schema.array && claim.path.split('/').pop() !== claim.schema.key,
158
- }));
159
- result.push(...spreadClaims(nestedClaimsWithPath));
160
- }
161
- return [...acc, ...result];
162
- }, [] as FlatClaim[]);
163
- };
164
-
165
- const getDisplayedAttributes = (
166
- request: PresentationDefinitionRequestedCredential,
167
- validityState: ValidityState,
168
- credential?: CredentialDetail,
169
- selectiveDisclosureSupported?: boolean,
170
- selectedFields?: string[],
171
- ): DisplayedAttribute[] => {
172
- const claims = credential ? spreadClaims(credential.claims) : undefined;
173
- const isApplicable = credential ? request.applicableCredentials.includes(credential.id) : false;
174
-
175
- let fields = request.fields;
176
- if (credential) {
177
- const fieldsWithNoKeyMapping = request.fields
178
- .filter((field) => !(credential.id in field.keyMap))
179
- .filter((field) => !isApplicable || !field.required);
180
- const fullyNestedFields = getFullyNestedFields(request.fields, credential.id);
181
-
182
- fields = [...fieldsWithNoKeyMapping, ...fullyNestedFields];
183
- }
184
-
185
- return fields.map((field) => {
186
- const selected = !field.required && selectedFields?.includes(field.id);
187
- const claim = credential
188
- ? claims?.find(({ path }) => {
189
- return path === field.keyMap[credential.id];
190
- })
191
- : undefined;
192
- const status =
193
- selectiveDisclosureSupported === false
194
- ? SelectorStatus.Required
195
- : getAttributeSelectorStatus(field, validityState, credential, claim, selected);
196
- return { claim, field, id: field.id, selected, status };
197
- });
198
- };
199
-
200
- const getFullyNestedFields = (
201
- fields: PresentationDefinitionRequestedCredential['fields'],
202
- credentialId: CredentialDetail['id'],
203
- ) => {
204
- const allKeys = fields.filter((field) => credentialId in field.keyMap).map((field) => field.keyMap[credentialId]);
205
-
206
- return fields
207
- .map((field) => ({ field, key: field.keyMap[credentialId] }))
208
- .filter(({ key }) => key && allKeys.every((k) => !k.startsWith(`${key}/`)))
209
- .map(({ field }) => field);
210
- };
211
-
212
- export const shareCredentialCardAttributeFromClaim = (
213
- id: string,
214
- config: CoreConfig,
215
- testID: string,
216
- labels: ShareCredentialCardLabels,
217
- language: string | undefined,
218
- claim?: FlatClaim,
219
- field?: PresentationDefinitionField,
220
- ): CredentialAttribute => {
221
- if (claim) {
222
- return {
223
- ...detailsCardAttributeFromClaim(claim, config, testID, language),
224
- id,
225
- path: claim.path,
226
- listValue: claim.isArrayElement,
227
- };
228
- }
229
- return {
230
- id,
231
- name: field?.name?.split('/').pop() ?? id,
232
- path: field?.name ?? id,
233
- value: labels.missingAttribute,
234
- valueErrorColor: true,
235
- };
236
- };
237
-
238
- // Will propagate the attribute status (right accessory + selected?) for all nested attributes
239
- // Note: This function MUTATES the input attribute
240
- const setStatusForNestedObjectOrArrayFields = (
241
- attribute: CredentialAttribute,
242
- status?: SelectorStatus,
243
- disabled?: boolean,
244
- ) => {
245
- const accessory = status && <Selector status={status} />;
246
- const isObject = attribute.attributes && attribute.attributes.length > 0;
247
- const isArray = attribute.values && attribute.values.length > 0;
248
-
249
- // If the attribute is not an object or array, we update the attribute and return
250
- if (!isObject && !isArray) {
251
- attribute.rightAccessory = accessory;
252
- attribute.disabled = disabled;
253
- return attribute;
254
- }
255
-
256
- // The object can be optional (tappable radio-checkmark), or required (checkmark)
257
- if (status === SelectorStatus.SelectedCheckmark || status === SelectorStatus.Empty) {
258
- // If it's a selectable object, the accessory is rendered next to the object title,
259
- // The nested attributes have no accessory, and can not be selected
260
- attribute.rightAccessory = accessory;
261
- setStatusForNestedObjectOrArrayFields(attribute, undefined, true);
262
- } else {
263
- const nested = attribute.attributes ?? attribute.values;
264
- // If the object is required / rejected, the accessory is rendered next to each nested attribute (except other object titles)
265
- // all fields are disabled
266
- for (const nestedAttribute of nested) {
267
- setStatusForNestedObjectOrArrayFields(nestedAttribute, status, true);
268
- }
269
- }
270
- };
271
-
272
- export type ShareCredentialCardLabels = CardLabels & {
273
- selectiveDisclosure: string;
274
- missingAttribute: string;
275
- missingCredential: string;
276
- multipleCredentials: string;
277
- disclosurePolicyViolation: string;
278
- };
279
-
280
- export const shareCredentialCardFromCredential = (
281
- credential: CredentialDetail | PresentationDefinitionV2Credential | undefined,
282
- expanded: boolean,
283
- multipleCredentialsAvailable: boolean,
284
- request: PresentationDefinitionRequestedCredential,
285
- selectedFields: string[] | undefined,
286
- config: CoreConfig,
287
- testID: string,
288
- labels: ShareCredentialCardLabels,
289
- language: string | undefined,
290
- ): CredentialDetailsCardPropsWithoutWidth => {
291
- const credentialAsListItem: CredentialListItem | undefined = credential
292
- ? { type: CredentialType.SINGLE, ...credential, issuer: credential.issuer?.id }
293
- : undefined;
294
- const selectiveDisclosureSupported = supportsSelectiveDisclosure(credentialAsListItem, config);
295
- const cardTestId = concatTestID(testID, 'card');
296
- const card = credential
297
- ? validityCheckedCardFromCredential(
298
- credential,
299
- expanded,
300
- selectiveDisclosureSupported,
301
- multipleCredentialsAvailable,
302
- config,
303
- undefined,
304
- cardTestId,
305
- labels,
306
- language,
307
- )
308
- : missingCredentialCardFromRequest(request, undefined, cardTestId, labels);
309
- const validityState = getValidityState(credentialAsListItem);
310
- const displayedAttributes = getDisplayedAttributes(
311
- request,
312
- validityState,
313
- credential ? credentialDetailFromPresentationV2Credential(credential) : undefined,
314
- selectiveDisclosureSupported,
315
- selectedFields,
316
- );
317
-
318
- const attributes: CredentialAttribute[] = displayedAttributes.map(({ claim, field, id, selected, status }, index) => {
319
- const disabled = !credential || !field || field.required || !claim;
320
- const attribute: CredentialAttribute = {
321
- ...shareCredentialCardAttributeFromClaim(
322
- id,
323
- config,
324
- concatTestID(testID, 'attribute', `${index}`),
325
- labels,
326
- language,
327
- claim,
328
- field,
329
- ),
330
- selected,
331
- };
332
-
333
- setStatusForNestedObjectOrArrayFields(attribute, status, disabled);
334
- return attribute;
335
- });
336
- return {
337
- attributes: nestAttributes(attributes),
338
- card,
339
- };
340
- };
341
-
342
- export const selectCredentialCardAttributeFromClaim = (
343
- id: string,
344
- config: CoreConfig,
345
- testID: string,
346
- labels: ShareCredentialCardLabels,
347
- language: string | undefined,
348
- claim?: FlatClaim,
349
- field?: PresentationDefinitionField,
350
- ): CredentialAttribute => {
351
- const attribute = shareCredentialCardAttributeFromClaim(id, config, testID, labels, language, claim, field);
352
- if (!claim) {
353
- return attribute;
354
- }
355
- return {
356
- ...attribute,
357
- rightAccessory: RequiredAttributeIcon,
358
- };
359
- };
360
-
361
- export const selectCredentialCardFromCredential = (
362
- credential: CredentialDetail,
363
- selected: boolean,
364
- request: PresentationDefinitionRequestedCredential,
365
- config: CoreConfig,
366
- testID: string,
367
- labels: ShareCredentialCardLabels,
368
- language: string | undefined,
369
- ): CredentialDetailsCardPropsWithoutWidth => {
370
- const selectiveDisclosureSupported = supportsSelectiveDisclosure(
371
- credential ? { ...credential, issuer: credential.issuer?.id } : undefined,
372
- config,
373
- );
374
- const rightAccessory = <Selector status={selected ? SelectorStatus.SelectedRadio : SelectorStatus.Empty} />;
375
- const notice: CredentialCardNotice | undefined =
376
- selectiveDisclosureSupported === false
377
- ? {
378
- text: labels.selectiveDisclosure,
379
- noticeIcon: CredentialNoticeWarningIcon,
380
- }
381
- : undefined;
382
- const { header, ...cardProps } = getCredentialCardPropsFromCredential(
383
- credential,
384
- credential.claims,
385
- config,
386
- notice,
387
- testID,
388
- labels,
389
- language,
390
- );
391
- const card = {
392
- header: {
393
- ...header,
394
- accessory: rightAccessory,
395
- },
396
- ...cardProps,
397
- };
398
- const attributes: CredentialAttribute[] = getFullyNestedFields(request.fields, credential.id).map((field) => {
399
- const claim = spreadClaims(credential.claims).find(({ path }) => {
400
- return path === field.keyMap[credential.id];
401
- });
402
-
403
- const attribute = selectCredentialCardAttributeFromClaim(field.id, config, testID, labels, language, claim, field);
404
- return {
405
- ...attribute,
406
- rightAccessory: (
407
- <Selector status={field.required && !claim ? SelectorStatus.Rejected : SelectorStatus.Required} />
408
- ),
409
- };
410
- });
411
- return {
412
- attributes: nestAttributes(attributes),
413
- card,
414
- };
415
- };