Skip to content

Commit b65e95e

Browse files
author
Sterling Long
committed
Updated disconnect to disconnect even if web3App session has expired
1 parent 55b0707 commit b65e95e

5 files changed

Lines changed: 48 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.10
2+
3+
- Fixed an issue with disconnect not working properly
4+
15
## 2.1.9
26

37
- Added safe area to modal for phones with notches

lib/constants/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22

33
class WalletConnectModalConstants {
4-
static const WALLETCONNECT_MODAL_VERSION = '2.1.9';
4+
static const WALLETCONNECT_MODAL_VERSION = '2.1.10';
55

66
static const Key helpPageKey = Key('helpPageKey');
77
static const Key qrCodePageKey = Key('qrCodePageKey');

lib/services/walletconnect_modal/walletconnect_modal_service.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ class WalletConnectModalService extends ChangeNotifier
265265
Future<void> disconnect() async {
266266
checkInitialized();
267267

268+
// If we don't have a session, disconnect automatically and notify listeners
268269
if (_session == null) {
270+
_isConnected = false;
271+
_address = '';
272+
notifyListeners();
269273
return;
270274
}
271275

@@ -278,6 +282,7 @@ class WalletConnectModalService extends ChangeNotifier
278282
message: 'User disconnected',
279283
),
280284
);
285+
// Disconnecting the session will produce the onSessionDisconnect callback
281286
await web3App!.disconnectSession(
282287
topic: session!.topic,
283288
// ignore: prefer_const_constructors
@@ -286,6 +291,14 @@ class WalletConnectModalService extends ChangeNotifier
286291
message: 'User disconnected',
287292
),
288293
);
294+
295+
// As a failsafe (If the session is expired for example), set the session to null and notify listeners
296+
if (_session != null) {
297+
_isConnected = false;
298+
_address = '';
299+
_session = null;
300+
notifyListeners();
301+
}
289302
}
290303

291304
@override

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: walletconnect_modal_flutter
22
description: The WalletConnectModal for WalletConnect built using Flutter.
3-
version: 2.1.9
3+
version: 2.1.10
44
repository: https://github.com/WalletConnect/WalletConnectModalFlutter
55

66
environment:

test/walletconnect_modal_service/walletconnect_modal_service_unit_test.dart

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ void main() {
226226

227227
await service.init();
228228

229+
int count = 0;
230+
f() {
231+
count++;
232+
}
233+
234+
service.addListener(f);
235+
229236
when(
230237
web3App.disconnectSession(
231238
topic: anyNamed('topic'),
@@ -235,10 +242,28 @@ void main() {
235242

236243
await service.disconnect();
237244

238-
verify(web3App.disconnectSession(
239-
topic: testSession.topic,
240-
reason: anyNamed('reason'),
241-
)).called(1);
245+
verifyInOrder([
246+
web3App.disconnectSession(
247+
topic: testSession.pairingTopic,
248+
reason: anyNamed('reason'),
249+
),
250+
web3App.disconnectSession(
251+
topic: testSession.topic,
252+
reason: anyNamed('reason'),
253+
)
254+
]);
255+
256+
expect(service.isConnected, isFalse);
257+
expect(service.session, isNull);
258+
expect(service.address, '');
259+
expect(count, 1);
260+
261+
// Should null things out and notify listeners
262+
await service.disconnect();
263+
264+
expect(count, 2);
265+
266+
service.removeListener(f);
242267
});
243268
});
244269

0 commit comments

Comments
 (0)