Skip to content

Commit

Permalink
reconnection mechanism on walletkit
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Dec 18, 2024
1 parent a4bf7d4 commit 62f6919
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/reown_walletkit/lib/walletkit_impl.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:event/event.dart';
import 'package:flutter/widgets.dart';
import 'package:reown_core/relay_client/websocket/http_client.dart';
import 'package:reown_core/relay_client/websocket/i_http_client.dart';
import 'package:reown_core/reown_core.dart';
Expand All @@ -7,7 +8,7 @@ import 'package:reown_core/store/i_generic_store.dart';
import 'package:reown_sign/reown_sign.dart';
import 'package:reown_walletkit/i_walletkit_impl.dart';

class ReownWalletKit implements IReownWalletKit {
class ReownWalletKit with WidgetsBindingObserver implements IReownWalletKit {
bool _initialized = false;

static Future<ReownWalletKit> createInstance({
Expand Down Expand Up @@ -116,6 +117,7 @@ class ReownWalletKit implements IReownWalletKit {
await core.start();
await reOwnSign.init();

WidgetsBinding.instance.addObserver(this);
_initialized = true;
}

Expand Down Expand Up @@ -483,4 +485,13 @@ class ReownWalletKit implements IReownWalletKit {

@override
IGenericStore<String> get pairingTopics => reOwnSign.pairingTopics;

@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
if (state == AppLifecycleState.resumed) {
if (!core.relayClient.isConnected) {
await core.relayClient.connect();
}
}
}
}

0 comments on commit 62f6919

Please sign in to comment.