Skip to content

Commit

Permalink
Merge pull request #298 from WalletConnect/chores/reconnect_on_timeout
Browse files Browse the repository at this point in the history
Reconnect relay on timeout
  • Loading branch information
quetool committed Jul 15, 2024
2 parents a9420cf + 86da929 commit 6b7b297
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
29 changes: 12 additions & 17 deletions example/dapp/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,8 @@ class _MyHomePageState extends State<MyHomePage> {
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
Expand Down Expand Up @@ -220,6 +205,16 @@ class _MyHomePageState extends State<MyHomePage> {
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
Expand Down
16 changes: 7 additions & 9 deletions lib/apis/core/relay_client/relay_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -310,23 +311,20 @@ 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();
final errorReason = code == 3000
? reason ?? WebSocketErrors.INVALID_PROJECT_ID_OR_JWT
: '';
onRelayClientError.broadcast(
ErrorEvent(
WalletConnectError(code: code, message: errorReason),
),
ErrorEvent(WalletConnectError(
code: code,
message: errorReason,
)),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/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 pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 6b7b297

Please sign in to comment.