From 40a42377b1900cc62be48251a309a3aff297a775 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Thu, 14 Nov 2024 16:44:22 +0545 Subject: [PATCH] feat: Update presentation definition logic - consider field.optional, one path must be satisfied, all fields should be satisfied #3012 #2882 --- .../get_credentials_from_filter_list.dart | 100 ++++++++++-------- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/helpers/get_credentials_from_filter_list.dart b/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/helpers/get_credentials_from_filter_list.dart index 896f1b10a..7018179f3 100644 --- a/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/helpers/get_credentials_from_filter_list.dart +++ b/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/helpers/get_credentials_from_filter_list.dart @@ -15,60 +15,76 @@ List getCredentialsFromFilterList({ final selectedCredential = []; for (final credential in credentialList) { + bool allConditionsSatisfied = false; fieldLoop: for (final field in filterList) { - for (final path in field.path) { - final credentialData = createJsonByDecryptingSDValues( - encryptedJson: credential.data, - selectiveDisclosure: SelectiveDisclosure(credential), - ); + /// if optional not need to compute + if (field.optional) { + allConditionsSatisfied = true; + } else { + pathLoop: + for (final path in field.path) { + final credentialData = createJsonByDecryptingSDValues( + encryptedJson: credential.data, + selectiveDisclosure: SelectiveDisclosure(credential), + ); - final searchList = getTextsFromCredential(path, credentialData); - if (searchList.isNotEmpty) { - /// remove unmatched credential - searchList.removeWhere( - (searchParameter) { - String? pattern; + final searchList = getTextsFromCredential(path, credentialData); + if (searchList.isNotEmpty) { + /// remove unmatched credential + searchList.removeWhere( + (searchParameter) { + final filter = field.filter; - if (field.filter == null) { - //ascs case - return false; - } else if (field.filter?.pattern != null) { - pattern = field.filter!.pattern; - } else if (field.filter?.contains?.containsConst != null) { - pattern = field.filter?.contains?.containsConst; - } else if (field.filter?.containsConst != null) { - pattern = field.filter?.containsConst; - } else { - /// sd-jwt vc bool case - if (searchParameter == 'true') return false; - } + /// condition matched - no further filtration needed + if (filter == null) return false; - if (pattern == null) { - return false; - } else if (pattern.endsWith(r'$')) { - final RegExp regEx = RegExp(pattern); - final Match? match = regEx.firstMatch(searchParameter); + String? pattern = filter.pattern; + if (pattern != null) { + pattern = filter.pattern; + } else if (filter.contains?.containsConst != null) { + pattern = filter.contains?.containsConst; + } else if (filter.containsConst != null) { + pattern = filter.containsConst; + } else { + /// sd-jwt vc bool case + if (searchParameter == 'true') return false; + } - if (match != null) return false; - } else { - if (searchParameter == pattern) return false; - } + if (pattern == null) { + return false; + } else if (pattern.endsWith(r'$')) { + final RegExp regEx = RegExp(pattern); + final Match? match = regEx.firstMatch(searchParameter); - return true; - }, - ); - } + if (match != null) return false; + } else { + if (searchParameter == pattern) return false; + } - /// if [searchList] is not empty we mark this credential as - /// a valid candidate - if (searchList.isNotEmpty) { - selectedCredential.add(credential); - } else { + return true; + }, + ); + } + + /// if [searchList] is not empty we mark this credential as + /// a valid candidate + if (searchList.isNotEmpty) { + allConditionsSatisfied = true; + break pathLoop; + } else { + allConditionsSatisfied = false; + } + } + // if one field is not satisfied then condition is not satisfied + if (!allConditionsSatisfied) { break fieldLoop; } } } + if (allConditionsSatisfied) { + selectedCredential.add(credential); + } } final credentials = selectedCredential.toSet().toList();