Skip to content

Commit

Permalink
feat: Enhance presentation definition #1876
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Sep 8, 2023
1 parent b9e867c commit b819bd0
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 19 deletions.
8 changes: 1 addition & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@
"request": "launch",
"type": "dart",
"program": "lib/main_production.dart",
"args": [
"--flavor",
"production",
"--target",
"lib/main_production.dart",
"--release"
]
"args": ["--flavor", "production", "--target", "lib/main_production.dart"]
}
]
}
10 changes: 5 additions & 5 deletions lib/app/shared/enum/type/blockchain_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ extension BlockchainTypeX on BlockchainType {
Filter get filter {
switch (this) {
case BlockchainType.tezos:
return Filter('String', 'TezosAssociatedAddress');
return Filter(type: 'String', pattern: 'TezosAssociatedAddress');

case BlockchainType.ethereum:
return Filter('String', 'EthereumAssociatedAddress');
return Filter(type: 'String', pattern: 'EthereumAssociatedAddress');

case BlockchainType.fantom:
return Filter('String', 'FantomAssociatedAddress');
return Filter(type: 'String', pattern: 'FantomAssociatedAddress');

case BlockchainType.polygon:
return Filter('String', 'PolygonAssociatedAddress');
return Filter(type: 'String', pattern: 'PolygonAssociatedAddress');

case BlockchainType.binance:
return Filter('String', 'BinanceAssociatedAddress');
return Filter(type: 'String', pattern: 'BinanceAssociatedAddress');
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/credentials/cubit/credentials_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ class CredentialsCubit extends Cubit<CredentialsState> {
Field(path: [r'$..type'], filter: blockchainType.filter),
Field(
path: [r'$..associatedAddress'],
filter: Filter('String', cryptoAccountData.walletAddress),
filter: Filter(
type: 'String',
pattern: cryptoAccountData.walletAddress,
),
),
],
credentialList: oldCredentialList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ List<CredentialModel> getCredentialsFromFilterList({
/// remove unmatched credential
searchList.removeWhere(
(element) {
if (element == field.filter?.pattern ||
field.filter?.pattern == null) {
if (field.filter?.pattern != null &&
element == field.filter?.pattern) {
return false;
} else if (field.filter?.contains != null &&
element == field.filter?.contains?.containsConst) {
return false;
}

return true;
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class MissingCredentialsCubit extends Cubit<MissingCredentialsState> {
continue;
}

final credentialName = credentialField['filter']['pattern'] as String;
final Filter filter = Filter.fromJson(
credentialField['filter'] as Map<String, dynamic>);

final credentialName =
filter.pattern ?? filter.contains!.containsConst;

final isPresentable = await isCredentialPresentable(credentialName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,10 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
continue;
}

final credentialName = credentialField['filter']['pattern'] as String;
final Filter filter =
Filter.fromJson(credentialField['filter'] as Map<String, dynamic>);

final credentialName = filter.pattern ?? filter.contains!.containsConst;

final isPresentable = await isCredentialPresentable(credentialName);
if (!isPresentable) {
Expand Down
1 change: 1 addition & 0 deletions packages/credential_manifest/lib/credential_manifest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export 'src/helpers/get_credential_manifest.dart';
export 'src/helpers/get_text_from_credential.dart';
export 'src/models/color_object.dart';
export 'src/models/constraints.dart';
export 'src/models/contains.dart';
export 'src/models/display_mapping.dart';
export 'src/models/display_mapping_path.dart';
export 'src/models/display_mapping_text.dart';
Expand Down
18 changes: 18 additions & 0 deletions packages/credential_manifest/lib/src/models/contains.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:json_annotation/json_annotation.dart';

part 'contains.g.dart';

@JsonSerializable(explicitToJson: true)
class Contains {
Contains({
required this.containsConst,
});

factory Contains.fromJson(Map<String, dynamic> json) =>
_$ContainsFromJson(json);

@JsonKey(name: 'const')
String containsConst;

Map<String, dynamic> toJson() => _$ContainsToJson(this);
}
10 changes: 8 additions & 2 deletions packages/credential_manifest/lib/src/models/filter.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import 'package:credential_manifest/src/models/contains.dart';
import 'package:json_annotation/json_annotation.dart';

part 'filter.g.dart';

@JsonSerializable(explicitToJson: true)
class Filter {
Filter(this.type, this.pattern);
Filter({
required this.type,
this.pattern,
this.contains,
});
factory Filter.fromJson(Map<String, dynamic> json) => _$FilterFromJson(json);

final String type;
final String pattern;
final String? pattern;
final Contains? contains;

Map<String, dynamic> toJson() => _$FilterToJson(this);
}

0 comments on commit b819bd0

Please sign in to comment.