Skip to content

Commit

Permalink
refactor: Solved input descriptor id issue #1888
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Sep 13, 2023
1 parent 575a4fa commit 52e4ecd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ part 'credential_manifest_pick_cubit.g.dart';
class CredentialManifestPickCubit extends Cubit<CredentialManifestPickState> {
CredentialManifestPickCubit({
required List<CredentialModel> credentialList,
required PresentationDefinition presentationDefinition,
required CredentialModel credential,
required int inputDescriptorIndex,
}) : super(const CredentialManifestPickState(filteredCredentialList: [])) {
filterList(
credentialList: credentialList,
presentationDefinition: presentationDefinition,
credential: credential,
inputDescriptorIndex: inputDescriptorIndex,
);
}

void filterList({
required List<CredentialModel> credentialList,
required PresentationDefinition presentationDefinition,
required CredentialModel credential,
required int inputDescriptorIndex,
}) {
var presentationDefinition =
credential.credentialManifest!.presentationDefinition!;

if (presentationDefinition.submissionRequirements != null) {
/// https://identity.foundation/presentation-exchange/#presentation-definition-extensions
final inputDescriptors = List.of(presentationDefinition.inputDescriptors);
Expand Down Expand Up @@ -70,7 +73,10 @@ class CredentialManifestPickCubit extends Cubit<CredentialManifestPickState> {
}
}

presentationDefinition.inputDescriptors = newInputDescriptor;
presentationDefinition = PresentationDefinition.copyWithData(
oldPresentationDefinition: presentationDefinition,
inputDescriptors: newInputDescriptor,
);
}

/// Get instruction to filter credentials of the wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ class CredentialManifestOfferPickPage extends StatelessWidget {
Widget build(BuildContext context) {
return BlocProvider(
create: (context) {
final presentationDefinition =
credential.credentialManifest!.presentationDefinition!;
return CredentialManifestPickCubit(
presentationDefinition: presentationDefinition,
credential: credential,
credentialList: context.read<CredentialsCubit>().state.credentials,
inputDescriptorIndex: inputDescriptorIndex,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ class PresentationDefinition {
factory PresentationDefinition.fromJson(Map<String, dynamic> json) =>
_$PresentationDefinitionFromJson(json);

factory PresentationDefinition.copyWithData({
required PresentationDefinition oldPresentationDefinition,
required List<InputDescriptor> inputDescriptors,
}) {
return PresentationDefinition(
inputDescriptors: inputDescriptors,
id: oldPresentationDefinition.id,
name: oldPresentationDefinition.name,
purpose: oldPresentationDefinition.purpose,
submissionRequirements: oldPresentationDefinition.submissionRequirements,
);
}

final String? id;
@JsonKey(name: 'input_descriptors')
List<InputDescriptor> inputDescriptors;
Expand Down

0 comments on commit 52e4ecd

Please sign in to comment.