diff --git a/lib/connection_bridge/beacon/cubit/beacon_cubit.dart b/lib/connection_bridge/beacon/cubit/beacon_cubit.dart index 2137bcd53..cc5e8c5da 100644 --- a/lib/connection_bridge/beacon/cubit/beacon_cubit.dart +++ b/lib/connection_bridge/beacon/cubit/beacon_cubit.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:convert'; import 'package:altme/app/app.dart'; @@ -31,11 +32,14 @@ class BeaconCubit extends Cubit { } } + Timer? debounce; + void listenToBeacon() { try { log.i('listening to beacon'); + beacon.getBeaconResponse().listen( - (data) { + (data) async { final Map requestJson = jsonDecode(data) as Map; final BeaconRequest beaconRequest = @@ -43,45 +47,57 @@ class BeaconCubit extends Cubit { log.i('beacon response - $requestJson'); log.i('beaconRequest.type - ${beaconRequest.type}'); - switch (beaconRequest.type) { - case RequestType.permission: - emit( - state.copyWith( - status: BeaconStatus.permission, - beaconRequest: beaconRequest, - ), - ); - - case RequestType.signPayload: - emit( - state.copyWith( - status: BeaconStatus.signPayload, - beaconRequest: beaconRequest, - ), - ); - - case RequestType.operation: - emit( - state.copyWith( - status: BeaconStatus.operation, - beaconRequest: beaconRequest, - ), - ); - - case RequestType.broadcast: - emit( - state.copyWith( - status: BeaconStatus.broadcast, - beaconRequest: beaconRequest, - ), - ); - - // ignore: no_default_cases - default: + + /// cancel previous timer if exists + if (debounce?.isActive ?? false) { + log.w('cancelled bombarded request'); + debounce?.cancel(); } + + debounce = Timer(const Duration(seconds: 1), () { + switch (beaconRequest.type) { + case RequestType.permission: + emit( + state.copyWith( + status: BeaconStatus.permission, + beaconRequest: beaconRequest, + ), + ); + + case RequestType.signPayload: + emit( + state.copyWith( + status: BeaconStatus.signPayload, + beaconRequest: beaconRequest, + ), + ); + + case RequestType.operation: + emit( + state.copyWith( + status: BeaconStatus.operation, + beaconRequest: beaconRequest, + ), + ); + + case RequestType.broadcast: + emit( + state.copyWith( + status: BeaconStatus.broadcast, + beaconRequest: beaconRequest, + ), + ); + + // ignore: no_default_cases + default: + break; + } + debounce?.cancel(); + }); }, ); } catch (e) { + debounce?.cancel(); log.e('beacon listening error - $e'); } } diff --git a/lib/dashboard/home/tab_bar/credentials/models/credential_model/credential_model.dart b/lib/dashboard/home/tab_bar/credentials/models/credential_model/credential_model.dart index a539c4c7e..48bb41e05 100644 --- a/lib/dashboard/home/tab_bar/credentials/models/credential_model/credential_model.dart +++ b/lib/dashboard/home/tab_bar/credentials/models/credential_model/credential_model.dart @@ -244,11 +244,7 @@ class CredentialModel extends Equatable { credentialPreview.credentialSubjectModel.credentialSubjectType == CredentialSubjectType.walletCredential; - String get getFormat => format != null - ? format! - : jwt != null - ? 'jwt_vc_json-ld' - : 'ldp_vc'; + String get getFormat => format != null ? format! : 'ldp_vc'; @override List get props => [ diff --git a/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/helpers/filter_credential_list_by_format.dart b/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/helpers/filter_credential_list_by_format.dart index 16eb3abaa..ae526544c 100644 --- a/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/helpers/filter_credential_list_by_format.dart +++ b/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/helpers/filter_credential_list_by_format.dart @@ -31,22 +31,22 @@ List filterCredenialListByFormat({ (CredentialModel credentialModel) { /// remove ldpVc if (presentLdpVc) { - return credentialModel.format != VCFormatType.ldpVc.vcValue; + return credentialModel.getFormat != VCFormatType.ldpVc.vcValue; } /// remove jwtVc if (presentJwtVc) { - return credentialModel.format != VCFormatType.jwtVc.vcValue; + return credentialModel.getFormat != VCFormatType.jwtVc.vcValue; } /// remove JwtVcJson if (presentJwtVcJson) { - return credentialModel.format != VCFormatType.jwtVcJson.vcValue; + return credentialModel.getFormat != VCFormatType.jwtVcJson.vcValue; } /// remove vcSdJwt if (presentVcSdJwt) { - return credentialModel.format != VCFormatType.vcSdJWT.vcValue; + return credentialModel.getFormat != VCFormatType.vcSdJWT.vcValue; } return false;