@@ -70,6 +70,9 @@ class WalletConnectModalService extends ChangeNotifier
7070 @override
7171 Map <String , RequiredNamespace > get optionalNamespaces => _optionalNamespaces;
7272
73+ @override
74+ final Event <EventArgs > onPairingExpire = Event ();
75+
7376 ConnectResponse ? connectResponse;
7477 Future <SessionData >? get sessionFuture => connectResponse? .session.future;
7578 BuildContext ? context;
@@ -142,6 +145,8 @@ class WalletConnectModalService extends ChangeNotifier
142145 await WalletConnectModalServices .init ();
143146 } catch (_) {}
144147
148+ await clearPreviousInactivePairings ();
149+
145150 if (_web3App! .sessions.getAll ().isNotEmpty) {
146151 _isConnected = true ;
147152 _session = _web3App! .sessions.getAll ().first;
@@ -155,6 +160,15 @@ class WalletConnectModalService extends ChangeNotifier
155160 notifyListeners ();
156161 }
157162
163+ @override
164+ Future <void > clearPreviousInactivePairings () async {
165+ for (var pairing in _web3App! .pairings.getAll ()) {
166+ if (! pairing.active) {
167+ await _web3App! .core.expirer.expire (pairing.topic);
168+ }
169+ }
170+ }
171+
158172 @override
159173 // ignore: prefer_void_to_null
160174 Future <Null > onDispose () async {
@@ -176,12 +190,8 @@ class WalletConnectModalService extends ChangeNotifier
176190
177191 _isOpen = true ;
178192
179- rebuildConnectionUri ();
180-
181193 // Reset the explorer
182- explorerService.instance! .filterList (
183- query: '' ,
184- );
194+ explorerService.instance! .filterList (query: '' );
185195 widgetStack.instance.clear ();
186196
187197 this .context = context;
@@ -341,17 +351,22 @@ class WalletConnectModalService extends ChangeNotifier
341351 }
342352 }
343353
354+ _web3App! .core.pairing.onPairingExpire.subscribe (_onPairingExpire);
344355 connectResponse = await web3App! .connect (
345356 requiredNamespaces: requiredNamespaces,
346357 optionalNamespaces: optionalNamespaces,
347358 );
348359
349360 notifyListeners ();
350-
351361 awaitConnectResponse ();
352362 }
353363 }
354364
365+ void _onPairingExpire (PairingEvent ? args) async {
366+ _web3App! .core.pairing.onPairingExpire.unsubscribe (_onPairingExpire);
367+ onPairingExpire.broadcast ();
368+ }
369+
355370 bool _connectingWallet = false ;
356371
357372 @override
0 commit comments