From 86da929bba8dd174b9e82e1690101ab2cda18e41 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Mon, 15 Jul 2024 13:00:38 +0200 Subject: [PATCH] Reconnect relay on timeout --- CHANGELOG.md | 4 +-- example/dapp/lib/main.dart | 29 ++++++++------------ lib/apis/core/relay_client/relay_client.dart | 16 +++++------ lib/src/version.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9123cd6..5853e5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ -## 2.3.0-beta04 +## 2.3.0-beta05 - One-Click Auth support -- Bug fixes +- Bug fixes and improvements ## 2.2.3 diff --git a/example/dapp/lib/main.dart b/example/dapp/lib/main.dart index 2e8398b..5270e9d 100644 --- a/example/dapp/lib/main.dart +++ b/example/dapp/lib/main.dart @@ -146,23 +146,8 @@ class _MyHomePageState extends State { void _setState(dynamic args) => setState(() {}); void _relayClientError(ErrorEvent? event) { - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - content: Text(event?.error.toString() ?? 'Relay Client error'), - actions: [ - TextButton( - onPressed: () { - _web3App!.core.relayClient.connect(); - Navigator.of(context).pop(); - }, - child: const Text('RETRY'), - ), - ], - ); - }, - ); + debugPrint('[SampleDapp] _relayClientError ${event?.error}'); + _setState(''); } @override @@ -220,6 +205,16 @@ class _MyHomePageState extends State { return Scaffold( appBar: AppBar( title: Text(_pageDatas[_selectedIndex].title), + centerTitle: true, + actions: [ + CircleAvatar( + radius: 6.0, + backgroundColor: _web3App!.core.relayClient.isConnected + ? Colors.green + : Colors.red, + ), + const SizedBox(width: 16.0), + ], ), bottomNavigationBar: MediaQuery.of(context).size.width < Constants.smallScreen diff --git a/lib/apis/core/relay_client/relay_client.dart b/lib/apis/core/relay_client/relay_client.dart index 943de87..8c3f76b 100644 --- a/lib/apis/core/relay_client/relay_client.dart +++ b/lib/apis/core/relay_client/relay_client.dart @@ -210,6 +210,7 @@ class RelayClient implements IRelayClient { core.logger.d('[$runtimeType] Connect timeout: $e'); onRelayClientError.broadcast(ErrorEvent('Connection to relay timeout')); _connecting = false; + _connect(); } catch (e) { core.logger.d('[$runtimeType] Connect error: $e'); onRelayClientError.broadcast(ErrorEvent(e)); @@ -310,13 +311,9 @@ class RelayClient implements IRelayClient { } // If the code requires reconnect, do so + final reconnectCodes = [1001, 4008, 4010, 1002, 1005, 10002]; if (code != null) { - if (code == 1001 || - code == 4008 || - code == 4010 || - code == 1002 || - code == 10002 || - code == 1005) { + if (reconnectCodes.contains(code)) { await connect(); } else { await disconnect(); @@ -324,9 +321,10 @@ class RelayClient implements IRelayClient { ? reason ?? WebSocketErrors.INVALID_PROJECT_ID_OR_JWT : ''; onRelayClientError.broadcast( - ErrorEvent( - WalletConnectError(code: code, message: errorReason), - ), + ErrorEvent(WalletConnectError( + code: code, + message: errorReason, + )), ); } } diff --git a/lib/src/version.dart b/lib/src/version.dart index 002d414..68bbe30 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '2.3.0-beta04'; +const packageVersion = '2.3.0-beta05'; diff --git a/pubspec.yaml b/pubspec.yaml index c935552..5e9a009 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: walletconnect_flutter_v2 description: WalletConnect's official Dart library v2 for WalletKit and AppKit. The communications protocol for web3. -version: 2.3.0-beta04 +version: 2.3.0-beta05 repository: https://github.com/WalletConnect/WalletConnectFlutterV2 environment: