Skip to content

Commit

Permalink
refactor: Fix and handle both ebsv3 and other formats #1826
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Aug 23, 2023
1 parent 65e886e commit a1e967a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
39 changes: 19 additions & 20 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -459,29 +459,28 @@ OIDC4VCType? getOIDC4VCTypeForIssuance(String url) {
}

(String, List<String>?, String?) getCredentialData({
required List<dynamic> credentials,
required dynamic credential,
OIDC4VCType? oidc4vcType,
}) {
late String credential;
late List<String> 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<String, dynamic>) {
credentialSupported =
(cred['types'] as List<dynamic>).map((e) => e.toString()).toList();
credential = credentialSupported.last;
format = cred['format'].toString();
} else {
throw Exception();
late String cred;
List<String>? credentialSupported;
String? format;

if (credential is String) {
cred = credential;
if (oidc4vcType != null) {
credentialSupported = oidc4vcType.credentialSupported;
format = oidc4vcType.issuerVcType;
}
} else if (credential is Map<String, dynamic>) {
credentialSupported = (credential['types'] as List<dynamic>)
.map((e) => e.toString())
.toList();
cred = credentialSupported.last;
format = credential['format'].toString();
} else {
throw Exception();
}

return (credential, credentialSupported, format);
return (cred, credentialSupported, format);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
credentials.length,
(index) {
final (credential, _, _) = getCredentialData(
credentials: credentials,
credential: credentials[index],
);

final CredentialSubjectType credentialSubjectType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
emit(state.loading());

final (credential, credentialSupported, format) = getCredentialData(
credentials: credentials,
credential: credentials[i],
oidc4vcType: currentOIIDC4VCTypeForIssuance,
);

Expand Down

0 comments on commit a1e967a

Please sign in to comment.