From a1e967a2f2d9b0beb68a9ba4102a59f43104e528 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Wed, 23 Aug 2023 15:27:06 +0545 Subject: [PATCH] refactor: Fix and handle both ebsv3 and other formats #1826 --- .../helper_functions/helper_functions.dart | 39 +++++++++---------- .../view/oid4c4vc_credential_pick_page.dart | 2 +- .../cubit/qr_code_scan_cubit.dart | 2 +- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/app/shared/helper_functions/helper_functions.dart b/lib/app/shared/helper_functions/helper_functions.dart index 56e67edcc..5a9d4f08f 100644 --- a/lib/app/shared/helper_functions/helper_functions.dart +++ b/lib/app/shared/helper_functions/helper_functions.dart @@ -459,29 +459,28 @@ OIDC4VCType? getOIDC4VCTypeForIssuance(String url) { } (String, List?, String?) getCredentialData({ - required List credentials, + required dynamic credential, OIDC4VCType? oidc4vcType, }) { - late String credential; - late List credentialSupported; - late String format; - - for (final cred in credentials) { - if (cred is String) { - credential = cred; - if (oidc4vcType != null) { - credentialSupported = oidc4vcType.credentialSupported; - format = oidc4vcType.issuerVcType; - } - } else if (cred is Map) { - credentialSupported = - (cred['types'] as List).map((e) => e.toString()).toList(); - credential = credentialSupported.last; - format = cred['format'].toString(); - } else { - throw Exception(); + late String cred; + List? credentialSupported; + String? format; + + if (credential is String) { + cred = credential; + if (oidc4vcType != null) { + credentialSupported = oidc4vcType.credentialSupported; + format = oidc4vcType.issuerVcType; } + } else if (credential is Map) { + credentialSupported = (credential['types'] as List) + .map((e) => e.toString()) + .toList(); + cred = credentialSupported.last; + format = credential['format'].toString(); + } else { + throw Exception(); } - return (credential, credentialSupported, format); + return (cred, credentialSupported, format); } diff --git a/lib/dashboard/home/tab_bar/credentials/oid4c4vc_pick/oid4c4vc_credential_pick/view/oid4c4vc_credential_pick_page.dart b/lib/dashboard/home/tab_bar/credentials/oid4c4vc_pick/oid4c4vc_credential_pick/view/oid4c4vc_credential_pick_page.dart index ff9947543..7a474bb2d 100644 --- a/lib/dashboard/home/tab_bar/credentials/oid4c4vc_pick/oid4c4vc_credential_pick/view/oid4c4vc_credential_pick_page.dart +++ b/lib/dashboard/home/tab_bar/credentials/oid4c4vc_pick/oid4c4vc_credential_pick/view/oid4c4vc_credential_pick_page.dart @@ -91,7 +91,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget { credentials.length, (index) { final (credential, _, _) = getCredentialData( - credentials: credentials, + credential: credentials[index], ); final CredentialSubjectType credentialSubjectType = diff --git a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart index cd489bae8..876dacbea 100644 --- a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart +++ b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart @@ -807,7 +807,7 @@ class QRCodeScanCubit extends Cubit { emit(state.loading()); final (credential, credentialSupported, format) = getCredentialData( - credentials: credentials, + credential: credentials[i], oidc4vcType: currentOIIDC4VCTypeForIssuance, );