Skip to content

Commit

Permalink
deal properly with json value inside selective disclosure which has a…
Browse files Browse the repository at this point in the history
… claim
  • Loading branch information
hawkbee1 committed Sep 26, 2024
1 parent 6b9e8a0 commit 4a2fdcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class SelectiveDisclosureDisplayMap {
).buildMap;
if (nestedMap.isNotEmpty) {
builtMap[title] = nestedMap;
} else {
builtMap.addAll(
claimData(mapKey, title),
);
}
} else {
builtMap.addAll(claimData(mapKey, title));
Expand Down Expand Up @@ -131,13 +135,6 @@ class SelectiveDisclosureDisplayMap {
if (claimList is List) {
if (claimList.contains(digest)) displayElement = true;
}
if (claimList == null) {
// checking if content is the nested value we want to display
final contentJson = jsonDecode(content);
if (contentJson[1] == parentKeyId) {
displayElement = true;
}
}
}
if (!displayElement) continue;
}
Expand All @@ -156,7 +153,7 @@ class SelectiveDisclosureDisplayMap {
if (!currentClaims.containsKey(element.key) ||
currentClaims[element.key].length == 0) {
if (element.value is Map) {
builtMap.addAll(MapForNestedClaimWithoutDisplay(element));
builtMap.addAll(MapForNestedClaimWithoutDisplay(element, null));
continue;
}

Expand All @@ -174,6 +171,7 @@ class SelectiveDisclosureDisplayMap {
/// can be used in recursive way to get more nested levels
Map<String, dynamic> MapForNestedClaimWithoutDisplay(
dynamic element,
String? title,
) {
final value = element.value as Map<String, dynamic>;
final builtMap = <String, dynamic>{};
Expand Down Expand Up @@ -208,7 +206,7 @@ class SelectiveDisclosureDisplayMap {
(entry) => entry.value.toString().contains(element.key.toString()),
);
if (index == -1) isDisabled = true;
builtMap[element.key.toString()] = {
builtMap[title ?? element.key.toString()] = {
'mapKey': element.key.toString(),
'claimKey': element.key.toString(),
'threeDotValue': null,
Expand Down Expand Up @@ -289,12 +287,19 @@ class SelectiveDisclosureDisplayMap {
(entry) => entry.value.toString().contains(claimKey),
);
if (indexInDisclosure == -1) isDisabled = true;

// ignore: inference_failure_on_uninitialized_variable, prefer_typing_uninitialized_variables
late final value;
try {
final json = jsonDecode(element.data);
value = json;
} catch (e) {
value = element.data;
}
final listElement = {
'mapKey': mapKey,
'claimKey': claimKey,
'threeDotValue': element.threeDotValue,
'value': element.data,
'value': value,
'hasCheckbox': !isDisabled && isPresentation,
'isCompulsary': isCompulsary,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/selective_disclosure/selective_disclosure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class SelectiveDisclosure {
value.add(
ClaimsData(
isfromDisclosureOfJWT: true,
data: data.toString(),
data: data is Map ? jsonEncode(data) : data.toString(),
),
);
} catch (e) {
Expand Down

0 comments on commit 4a2fdcf

Please sign in to comment.