From 4ce5228a0f255f54b8bbf34273aa5cade0b815dd Mon Sep 17 00:00:00 2001 From: phuoc Date: Fri, 26 Apr 2024 10:11:19 +0700 Subject: [PATCH] fix: check for inactive topic at init wc2 client Signed-off-by: phuoc --- lib/screen/bloc/connections/connections_bloc.dart | 3 ++- lib/service/wc2_service.dart | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/screen/bloc/connections/connections_bloc.dart b/lib/screen/bloc/connections/connections_bloc.dart index e67ed689f..3691d15de 100644 --- a/lib/screen/bloc/connections/connections_bloc.dart +++ b/lib/screen/bloc/connections/connections_bloc.dart @@ -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'; @@ -158,7 +159,7 @@ class ConnectionsBloc extends AuBloc { if (topic == null) { return; } - + log.info('SessionDeletedEvent: $topic'); add(SessionDeletedEvent(topic)); } diff --git a/lib/service/wc2_service.dart b/lib/service/wc2_service.dart index da92b1771..0bf9f2233 100644 --- a/lib/service/wc2_service.dart +++ b/lib/service/wc2_service.dart @@ -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}'); @@ -330,7 +329,19 @@ class Wc2Service { Future> _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 getPendingRequests() =>