Skip to content

fix killSession() method #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/dapp/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ packages:
name: cryptography
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.5"
dio:
dependency: transitive
description:
Expand Down Expand Up @@ -406,7 +406,7 @@ packages:
path: "../.."
relative: true
source: path
version: "0.0.6"
version: "0.0.11"
watcher:
dependency: transitive
description:
Expand Down
20 changes: 10 additions & 10 deletions example/mobile/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -196,7 +196,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -253,7 +253,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
version: "0.6.4"
json_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -288,7 +288,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -316,7 +316,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
plugin_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -370,7 +370,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -412,7 +412,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
version: "0.4.9"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -475,14 +475,14 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
walletconnect_dart:
dependency: "direct main"
description:
path: "../.."
relative: true
source: path
version: "0.0.7"
version: "0.0.11"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -512,5 +512,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.5.0"
2 changes: 1 addition & 1 deletion example/wallet/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ packages:
path: "../.."
relative: true
source: path
version: "0.0.7"
version: "0.0.11"
watcher:
dependency: transitive
description:
Expand Down
35 changes: 14 additions & 21 deletions lib/src/walletconnect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,11 @@ class WalletConnect {
/// https://docs.walletconnect.com/client-api#register-event-subscription
/// Supported events: connect, disconnect, session_request, session_update
void on<T>(String eventName, OnEvent<T> callback) {
_eventBus
.on<Event<T>>()
.where((event) => event.name == eventName)
.listen((event) => callback(event.data));
_eventBus.on<Event<T>>().where((event) => event.name == eventName).listen((event) => callback(event.data));
}

/// Creates a new session calling [createSession] if it doesnt exists, or returns the instantiated one.
Future<SessionStatus> connect(
{int? chainId, OnDisplayUriCallback? onDisplayUri}) async {
Future<SessionStatus> connect({int? chainId, OnDisplayUriCallback? onDisplayUri}) async {
if (connected) {
onDisplayUri?.call(session.toUri());
return SessionStatus(
Expand Down Expand Up @@ -244,6 +240,8 @@ class WalletConnect {

await _sendResponse(response);
session.connected = true;
session.chainId = chainId;
session.accounts = accounts;

// Notify listeners
_eventBus.fire(Event<SessionStatus>(
Expand Down Expand Up @@ -378,20 +376,16 @@ class WalletConnect {
Future killSession({String? sessionError}) async {
final message = sessionError ?? 'Session disconnected';

final request = JsonRpcRequest(
id: payloadId,
method: 'wc_sessionUpdate',
params: [
{
'approved': false,
'chainId': null,
'networkId': null,
'accounts': null,
}
],
final request = JsonRpcResponse(
id: session.handshakeId,
result: {
'approved': false,
'chainId': null,
'networkId': null,
'accounts': null,
},
);

unawaited(_sendRequest(request));
await _sendResponse(request);

await _handleSessionDisconnect(errorMessage: message, forceClose: true);
}
Expand Down Expand Up @@ -436,8 +430,7 @@ class WalletConnect {
OnDisconnect? onDisconnect,
}) {
on<SessionStatus>('connect', (data) => onConnect?.call(data));
on<WCSessionUpdateResponse>(
'session_update', (data) => onSessionUpdate?.call(data));
on<WCSessionUpdateResponse>('session_update', (data) => onSessionUpdate?.call(data));
on('disconnect', (data) => onDisconnect?.call());
}

Expand Down