Skip to content

Commit

Permalink
use default card for polygonId credential #1740
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Jul 20, 2023
1 parent 4bb8c83 commit 3f260c5
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 59 deletions.
Binary file added assets/image/default_polygon_card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions lib/app/shared/constants/image_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class ImageStrings {
static const String kycCountryOfResidenceCard =
'$imagePath/kyc_country_of_residence_card.png';
static const String civicPassCard = '$imagePath/civic_pass_card.png';
static const String defaultPolygonCard =
'$imagePath/default_polygon_card.png';
static const String euDiplomaCard = '$imagePath/eu_diploma_card.png';
static const String defiComplianceCard =
'$imagePath/defi-compliance-card.png';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ extension CredentialSubjectTypeExtension on CredentialSubjectType {
case CredentialSubjectType.proofOfTwitterStats:
return 'ProofOfTwitterStats';
case CredentialSubjectType.civicPassCredential:
return 'CivicPassCredentials';
return 'CivicPassCredential';
case CredentialSubjectType.defaultCredential:
return '';
}
Expand Down
6 changes: 6 additions & 0 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ bool isVerifiableDiplomaType(CredentialModel credentialModel) {
return credentialModel.credentialPreview.type.contains('VerifiableDiploma');
}

bool isPolygonIdCard(CredentialModel credentialModel) {
return credentialModel.credentialPreview.credentialSubjectModel.id
?.contains('did:polygonid:polygon:') ??
false;
}

Map<String, dynamic> decodePayload({
required JWTDecode jwtDecode,
required String token,
Expand Down
55 changes: 53 additions & 2 deletions lib/credentials/cubit/credentials_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,45 @@ class CredentialsCubit extends Cubit<CredentialsState> {
emit(state.copyWith(status: CredentialsStatus.loading));
final savedCredentials = await credentialsRepository.findAll(/* filters */);
final dummies = _getAvalaibleDummyCredentials(savedCredentials);

final List<CredentialModel> updatedCredentials = <CredentialModel>[];

/// manually categorizing default credential
for (final credential in savedCredentials) {
final isDefaultCredential = credential
.credentialPreview.credentialSubjectModel.credentialSubjectType ==
CredentialSubjectType.defaultCredential;

if (isDefaultCredential && isVerifiableDiplomaType(credential)) {
final updatedCredential = credential.copyWith(
credentialPreview: credential.credentialPreview.copyWith(
credentialSubjectModel:
credential.credentialPreview.credentialSubjectModel.copyWith(
credentialCategory: CredentialCategory.educationCards,
),
),
);
updatedCredentials.add(updatedCredential);
} else if (isDefaultCredential && isPolygonIdCard(credential)) {
final updatedCredential = credential.copyWith(
credentialPreview: credential.credentialPreview.copyWith(
credentialSubjectModel:
credential.credentialPreview.credentialSubjectModel.copyWith(
credentialCategory: CredentialCategory.polygonidCards,
),
),
);

updatedCredentials.add(updatedCredential);
} else {
updatedCredentials.add(credential);
}
}

emit(
state.copyWith(
status: CredentialsStatus.populate,
credentials: savedCredentials,
credentials: updatedCredentials,
dummyCredentials: dummies,
),
);
Expand Down Expand Up @@ -171,7 +206,11 @@ class CredentialsCubit extends Cubit<CredentialsState> {
}) async {
late final List<CredentialModel> credentials;

if (isVerifiableDiplomaType(credential)) {
final isDefaultCredential = credential
.credentialPreview.credentialSubjectModel.credentialSubjectType ==
CredentialSubjectType.defaultCredential;

if (isDefaultCredential && isVerifiableDiplomaType(credential)) {
final updatedCredential = credential.copyWith(
credentialPreview: credential.credentialPreview.copyWith(
credentialSubjectModel:
Expand All @@ -183,6 +222,18 @@ class CredentialsCubit extends Cubit<CredentialsState> {
await replaceCredential(credential: updatedCredential);
await credentialsRepository.insert(updatedCredential);
credentials = List.of(state.credentials)..add(updatedCredential);
} else if (isDefaultCredential && isPolygonIdCard(credential)) {
final updatedCredential = credential.copyWith(
credentialPreview: credential.credentialPreview.copyWith(
credentialSubjectModel:
credential.credentialPreview.credentialSubjectModel.copyWith(
credentialCategory: CredentialCategory.polygonidCards,
),
),
);
await replaceCredential(credential: updatedCredential);
await credentialsRepository.insert(updatedCredential);
credentials = List.of(state.credentials)..add(updatedCredential);
} else {
await replaceCredential(credential: credential);
await credentialsRepository.insert(credential);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ class PolygonIdCredentialOfferPage extends StatelessWidget {
final jsonCredential = polygonIdCubitState.claims![i].info;
final credentialPreview = Credential.fromJson(jsonCredential);

final DisplayMapping? titleDisplayMapping = polygonIdCubitState
.credentialManifests![i]
.outputDescriptors
?.first
.display
?.title;

var title = '';

if (titleDisplayMapping is DisplayMappingText) {
title = titleDisplayMapping.text;
}

if (titleDisplayMapping is DisplayMappingPath) {
title = titleDisplayMapping.fallback ?? '';
}

final DisplayMapping? subTitleDisplayMapping =
polygonIdCubitState.credentialManifests![i]
.outputDescriptors?.first.display?.subtitle;

var subTitle = '';

if (subTitleDisplayMapping is DisplayMappingText) {
subTitle = subTitleDisplayMapping.text;
}

if (subTitleDisplayMapping is DisplayMappingPath) {
subTitle = subTitleDisplayMapping.fallback ?? '';
}

Widget widget;

final credentialSubjectType = credentialPreview
Expand Down Expand Up @@ -78,59 +109,24 @@ class PolygonIdCredentialOfferPage extends StatelessWidget {
);
} else if (credentialSubjectType ==
CredentialSubjectType.civicPassCredential) {
final polygonIdCubitState =
context.read<PolygonIdCubit>().state;
final DisplayMapping? titleDisplayMapping =
polygonIdCubitState.credentialManifests![i]
.outputDescriptors?.first.display?.title;

var title = '';

if (titleDisplayMapping is DisplayMappingText) {
title = titleDisplayMapping.text;
}

if (titleDisplayMapping is DisplayMappingPath) {
title = titleDisplayMapping.fallback ?? '';
}

final DisplayMapping? subTitleDisplayMapping =
polygonIdCubitState.credentialManifests![i]
.outputDescriptors?.first.display?.subtitle;

var subTitle = '';

if (subTitleDisplayMapping is DisplayMappingText) {
subTitle = subTitleDisplayMapping.text;
}

if (subTitleDisplayMapping is DisplayMappingPath) {
subTitle = subTitleDisplayMapping.fallback ?? '';
}
widget = CredentialBaseWidget(
title: title,
cardBackgroundImagePath: ImageStrings.civicPassCard,
issuerName: 'CIVIC',
value: subTitle,
);
} else {
widget = DefaultCredentialListWidget(
credentialModel: CredentialModel(
id: credentialPreview.id,
image: 'image',
credentialPreview: credentialPreview,
shareLink: '',
display: const Display(
'',
'',
'',
'',
),
data: const <String, dynamic>{},
),
widget = CredentialBaseWidget(
title: title,
cardBackgroundImagePath: ImageStrings.defaultPolygonCard,
issuerName: 'ALTME',
value: subTitle,
);
}

print(credentialPreview
.credentialSubjectModel.credentialSubjectType);

return Padding(
padding: const EdgeInsets.only(bottom: 15),
child: widget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,22 @@ class CredentialDisplay extends StatelessWidget {
}

case CredentialSubjectType.defaultCredential:
switch (credDisplayType) {
case CredDisplayType.List:
return DefaultCredentialListWidget(
credentialModel: credentialModel,
showBgDecoration: false,
);
case CredDisplayType.Detail:
return DefaultCredentialDetailWidget(
credentialModel: credentialModel,
showBgDecoration: false,
fromCredentialOffer: fromCredentialOffer!,
);
if (isPolygonIdCard(credentialModel)) {
return DefaultPolygonIdCardWidget(credentialModel: credentialModel);
} else {
switch (credDisplayType) {
case CredDisplayType.List:
return DefaultCredentialListWidget(
credentialModel: credentialModel,
showBgDecoration: false,
);
case CredDisplayType.Detail:
return DefaultCredentialDetailWidget(
credentialModel: credentialModel,
showBgDecoration: false,
fromCredentialOffer: fromCredentialOffer!,
);
}
}

case CredentialSubjectType.ecole42LearningAchievement:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CredentialBaseWidget extends StatelessWidget {
LayoutId(
id: 'title',
child: FractionallySizedBox(
widthFactor: 0.75,
widthFactor: 0.7,
heightFactor: 0.19,
child: Container(
alignment: Alignment.centerLeft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export 'civic_pass_credential_widget.dart';
export 'credential_base_widget.dart';
export 'default_credential_detail_widget.dart';
export 'default_credential_list_widget.dart';
export 'default_polygonid_card.dart';
export 'defi_complinace_credential_widget.dart';
export 'diploma_card_widget.dart';
export 'dogami_pass_widget.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:altme/app/app.dart';
import 'package:altme/dashboard/dashboard.dart';
import 'package:credential_manifest/credential_manifest.dart';
import 'package:flutter/material.dart';

class DefaultPolygonIdCardWidget extends StatelessWidget {
const DefaultPolygonIdCardWidget({
super.key,
required this.credentialModel,
});

final CredentialModel credentialModel;

@override
Widget build(BuildContext context) {
final DisplayMapping? titleDisplayMapping = credentialModel
.credentialManifest!.outputDescriptors?.first.display?.title;

var title = '';

if (titleDisplayMapping is DisplayMappingText) {
title = titleDisplayMapping.text;
}

if (titleDisplayMapping is DisplayMappingPath) {
title = titleDisplayMapping.fallback ?? '';
}

final DisplayMapping? subTitleDisplayMapping = credentialModel
.credentialManifest!.outputDescriptors?.first.display?.subtitle;

var subTitle = '';

if (subTitleDisplayMapping is DisplayMappingText) {
subTitle = subTitleDisplayMapping.text;
}

if (subTitleDisplayMapping is DisplayMappingPath) {
subTitle = subTitleDisplayMapping.fallback ?? '';
}

return CredentialBaseWidget(
title: title,
cardBackgroundImagePath: ImageStrings.defaultPolygonCard,
issuerName: 'ALTME',
value: subTitle,
issuanceDate: UiDate.formatDateForCredentialCard(
credentialModel.credentialPreview.issuanceDate,
),
expirationDate: credentialModel.expirationDate == null
? '--'
: UiDate.formatDateForCredentialCard(credentialModel.expirationDate!),
);
}
}

0 comments on commit 3f260c5

Please sign in to comment.