Skip to content

Commit

Permalink
Better logs on core
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Oct 29, 2024
1 parent 8d4c24f commit 7901b98
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
4 changes: 4 additions & 0 deletions packages/reown_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.3

- Better logs

## 1.0.2

- Better logs
Expand Down
12 changes: 6 additions & 6 deletions packages/reown_core/lib/connectivity/connectivity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class ConnectivityState implements IConnectivity {
final isOnlineStatus = isMobileData || isWifi;

if (isOnline.value != isOnlineStatus) {
_core.logger.i('[$runtimeType] Connectivity changed $result');
isOnline.value = isOnlineStatus;
_core.logger.i('[$runtimeType] Connectivity changed $isOnlineStatus');

if (isOnline.value && !_core.relayClient.isConnected) {
await _core.relayClient.connect();
} else if (!isOnline.value && _core.relayClient.isConnected) {
await _core.relayClient.disconnect();
}
// if (isOnline.value && !_core.relayClient.isConnected) {
// await _core.relayClient.connect();
// } else if (!isOnline.value && _core.relayClient.isConnected) {
// await _core.relayClient.disconnect();
// }
}
}
}
9 changes: 8 additions & 1 deletion packages/reown_core/lib/pairing/pairing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ class Pairing implements IPairing {
Future<void> disconnect({required String topic}) async {
_checkInitialized();

core.logger.i('[$runtimeType] disconnect $topic');

await _isValidDisconnect(topic);
if (pairings.has(topic)) {
// Send the request to delete the pairing, we don't care if it fails
Expand Down Expand Up @@ -605,6 +607,7 @@ class Pairing implements IPairing {
}

Future<void> _deletePairing(String topic, bool expirerHasDeleted) async {
core.logger.d('[$runtimeType] _deletePairing $topic, $expirerHasDeleted');
await core.relayClient.unsubscribe(topic: topic);
await pairings.delete(topic);
await core.crypto.deleteSymKey(topic);
Expand All @@ -614,6 +617,7 @@ class Pairing implements IPairing {
}

Future<void> _cleanup() async {
core.logger.d('[$runtimeType] _cleanup');
final List<PairingInfo> expiredPairings = getPairings()
.where(
(PairingInfo info) => ReownCoreUtils.isExpired(info.expiry),
Expand Down Expand Up @@ -780,7 +784,9 @@ class Pairing implements IPairing {
JsonRpcRequest request, [
_,
]) async {
// print('delete');
core.logger.d(
'[$runtimeType] _onPairingDeleteRequest $topic, ${request.toJson()}',
);
final int id = request.id;
try {
await _isValidDisconnect(topic);
Expand Down Expand Up @@ -846,6 +852,7 @@ class Pairing implements IPairing {
if (event == null) {
return;
}
core.logger.d('[$runtimeType] _onExpired, ${event.toString()}');

if (pairings.has(event.target)) {
// Clean up the pairing
Expand Down
29 changes: 20 additions & 9 deletions packages/reown_core/lib/relay_client/relay_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class RelayClient implements IRelayClient {
}) async {
_checkInitialized();

core.logger.i('[$runtimeType] publish, $topic, $message');

Map<String, dynamic> data = {
'message': message,
'ttl': ttl,
Expand All @@ -128,8 +130,8 @@ class RelayClient implements IRelayClient {
data,
JsonRpcUtils.payloadId(entropy: 6),
);
} catch (e) {
// print(e);
} catch (e, s) {
core.logger.e('[$runtimeType], publish: $e', stackTrace: s);
onRelayClientError.broadcast(ErrorEvent(e));
}
}
Expand All @@ -138,6 +140,8 @@ class RelayClient implements IRelayClient {
Future<String> subscribe({required String topic}) async {
_checkInitialized();

core.logger.i('[$runtimeType] subscribe, $topic');

pendingSubscriptions[topic] = _onSubscribe(topic);

return await pendingSubscriptions[topic];
Expand All @@ -147,6 +151,8 @@ class RelayClient implements IRelayClient {
Future<void> unsubscribe({required String topic}) async {
_checkInitialized();

core.logger.i('[$runtimeType] unsubscribe, $topic');

String id = topicMap.get(topic) ?? '';

try {
Expand All @@ -158,7 +164,8 @@ class RelayClient implements IRelayClient {
},
JsonRpcUtils.payloadId(entropy: 6),
);
} catch (e) {
} catch (e, s) {
core.logger.e('[$runtimeType], unsubscribe: $e', stackTrace: s);
onRelayClientError.broadcast(ErrorEvent(e));
}

Expand Down Expand Up @@ -213,13 +220,13 @@ class RelayClient implements IRelayClient {
_connecting = false;
_subscribeToHeartbeat();
//
} on TimeoutException catch (e) {
core.logger.e('[$runtimeType]: Connect timeout: $e');
} on TimeoutException catch (e, s) {
core.logger.e('[$runtimeType], _connect timeout: $e', stackTrace: s);
onRelayClientError.broadcast(ErrorEvent('Connection to relay timeout'));
_connecting = false;
_connect();
} catch (e) {
core.logger.e('[$runtimeType]: Connect error: $e');
} catch (e, s) {
core.logger.e('[$runtimeType], _connect error: $e', stackTrace: s);
onRelayClientError.broadcast(ErrorEvent(e));
_connecting = false;
}
Expand Down Expand Up @@ -335,6 +342,7 @@ class RelayClient implements IRelayClient {
message: errorReason,
)),
);
core.logger.e('[$runtimeType], _handleRelayClose: $core, $errorReason');
}
}
}
Expand Down Expand Up @@ -466,8 +474,11 @@ class RelayClient implements IRelayClient {
{'topic': topic},
JsonRpcUtils.payloadId(entropy: 6),
);
} catch (e) {
core.logger.e('RelayClient, onSubscribe error. Topic: $topic, Error: $e');
} catch (e, s) {
core.logger.e(
'[$runtimeType], _onSubscribe: Topic, $topic, Error: $e',
stackTrace: s,
);
onRelayClientError.broadcast(ErrorEvent(e));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/reown_core/lib/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/reown_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: reown_core
description: "Reown is the onchain UX platform that provides toolkits built on top of the WalletConnect Network"
version: 1.0.2
version: 1.0.3
homepage: https://github.com/reown-com/reown_flutter
repository: https://github.com/reown-com/reown_flutter/tree/master/packages/reown_core

Expand Down

0 comments on commit 7901b98

Please sign in to comment.