Skip to content

Commit

Permalink
Merge pull request #2727 from TalaoDAO/october
Browse files Browse the repository at this point in the history
October
  • Loading branch information
bibash28 authored Jun 19, 2024
2 parents 28c862b + 1e4954c commit beae895
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 45 deletions.
88 changes: 52 additions & 36 deletions lib/connection_bridge/beacon/cubit/beacon_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';

import 'package:altme/app/app.dart';
Expand Down Expand Up @@ -31,57 +32,72 @@ class BeaconCubit extends Cubit<BeaconState> {
}
}

Timer? debounce;

void listenToBeacon() {
try {
log.i('listening to beacon');

beacon.getBeaconResponse().listen(
(data) {
(data) async {
final Map<String, dynamic> requestJson =
jsonDecode(data) as Map<String, dynamic>;
final BeaconRequest beaconRequest =
BeaconRequest.fromJson(requestJson);

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');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object?> get props => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ List<CredentialModel> 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;
Expand Down

0 comments on commit beae895

Please sign in to comment.