Skip to content

Commit

Permalink
fix: check for inactive topic at init wc2 client
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Apr 26, 2024
1 parent f3a056e commit 4ce5228
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/screen/bloc/connections/connections_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:autonomy_flutter/database/entity/connection.dart';
import 'package:autonomy_flutter/model/p2p_peer.dart';
import 'package:autonomy_flutter/service/tezos_beacon_service.dart';
import 'package:autonomy_flutter/service/wc2_service.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:collection/collection.dart';

part 'connections_state.dart';
Expand Down Expand Up @@ -158,7 +159,7 @@ class ConnectionsBloc extends AuBloc<ConnectionsEvent, ConnectionsState> {
if (topic == null) {
return;
}

log.info('SessionDeletedEvent: $topic');
add(SessionDeletedEvent(topic));
}

Expand Down
15 changes: 13 additions & 2 deletions lib/service/wc2_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class Wc2Service {
_wcClient.onSessionDelete.subscribe(_onSessionDeleted);

_registerEthRequest('${Wc2Chain.ethereum}:${Environment.web3ChainId}');
_registerEthRequest('${Wc2Chain.ethereum}:5');

_registerFeralfileRequest(
'${Wc2Chain.autonomy}:${Environment.appTestnetConfig ? 1 : 0}');
Expand Down Expand Up @@ -330,7 +329,19 @@ class Wc2Service {

Future<List<String>> _getAllConnectionKey() async {
final connections = await _cloudDB.connectionDao.getWc2Connections();
return connections.map((e) => e.key).toList();
final activeTopics = _wcClient.getActiveSessions().keys;
log.info('[Wc2Service] activeTopics: $activeTopics');
final inactiveConnections = connections
.where((element) =>
!activeTopics.any((topic) => element.key.contains(topic)))
.toList();
await _cloudDB.connectionDao.deleteConnections(inactiveConnections);
final keys = connections
.where((element) => !inactiveConnections.contains(element))
.map((e) => e.key)
.toList();
log.info('[Wc2Service] connection keys: $keys');
return keys;
}

List<SessionRequest> getPendingRequests() =>
Expand Down

0 comments on commit 4ce5228

Please sign in to comment.