From 1d7e8192bd670eff263fa193bbbd846dee3e20d2 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Tue, 27 Dec 2022 16:01:04 +0545 Subject: [PATCH 1/6] print enabled --- lib/wc_client.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/wc_client.dart b/lib/wc_client.dart index b5515f1..ca1c3cb 100644 --- a/lib/wc_client.dart +++ b/lib/wc_client.dart @@ -318,7 +318,7 @@ class WCClient { switch (request.method) { case WCMethod.SESSION_REQUEST: final param = WCSessionRequest.fromJson(request.params!.first); - // print('SESSION_REQUEST $param'); + print('SESSION_REQUEST $param'); _handshakeId = request.id; _remotePeerId = param.peerId; _remotePeerMeta = param.peerMeta; @@ -333,7 +333,7 @@ class WCClient { } break; case WCMethod.ETH_SIGN: - // print('ETH_SIGN $request'); + print('ETH_SIGN $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -348,7 +348,7 @@ class WCClient { ); break; case WCMethod.ETH_PERSONAL_SIGN: - // print('ETH_PERSONAL_SIGN $request'); + print('ETH_PERSONAL_SIGN $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -363,7 +363,7 @@ class WCClient { ); break; case WCMethod.ETH_SIGN_TYPE_DATA: - // print('ETH_SIGN_TYPE_DATA $request'); + print('ETH_SIGN_TYPE_DATA $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -378,17 +378,17 @@ class WCClient { ); break; case WCMethod.ETH_SIGN_TRANSACTION: - // print('ETH_SIGN_TRANSACTION $request'); + print('ETH_SIGN_TRANSACTION $request'); final param = WCEthereumTransaction.fromJson(request.params!.first); onEthSignTransaction?.call(request.id, param); break; case WCMethod.ETH_SEND_TRANSACTION: - // print('ETH_SEND_TRANSACTION $request'); + print('ETH_SEND_TRANSACTION $request'); final param = WCEthereumTransaction.fromJson(request.params!.first); onEthSendTransaction?.call(request.id, param); break; case WCMethod.WALLET_SWITCH_NETWORK: - // print('WALLET_SWITCH_NETWORK $request'); + print('WALLET_SWITCH_NETWORK $request'); final params = WCWalletSwitchNetwork.fromJson(request.params!.first); onWalletSwitchNetwork?.call(request.id, int.parse(params.chainId)); break; From d0c1666f28aeefb5549efcad31af114dcf2fceb0 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Tue, 27 Dec 2022 16:29:26 +0545 Subject: [PATCH 2/6] return peerId on session --- lib/wc_client.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/wc_client.dart b/lib/wc_client.dart index ca1c3cb..83bb8eb 100644 --- a/lib/wc_client.dart +++ b/lib/wc_client.dart @@ -24,7 +24,8 @@ import 'package:wallet_connect/wc_session_store.dart'; import 'package:web_socket_channel/io.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; -typedef SessionRequest = void Function(int id, WCPeerMeta peerMeta); +typedef SessionRequest = void Function( + int id, String peerId, WCPeerMeta peerMeta); typedef SocketError = void Function(dynamic message); typedef SocketClose = void Function(int? code, String? reason); typedef EthSign = void Function(int id, WCEthereumSignMessage message); @@ -323,7 +324,7 @@ class WCClient { _remotePeerId = param.peerId; _remotePeerMeta = param.peerMeta; _chainId = param.chainId; - onSessionRequest?.call(request.id, param.peerMeta); + onSessionRequest?.call(request.id, param.peerId, param.peerMeta); break; case WCMethod.SESSION_UPDATE: final param = WCSessionUpdate.fromJson(request.params!.first); From 95626fa2e7b0c72cdc779306c9078e365b4de8bb Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Tue, 27 Dec 2022 18:07:27 +0545 Subject: [PATCH 3/6] hide prints --- lib/wc_client.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/wc_client.dart b/lib/wc_client.dart index 83bb8eb..2847ff3 100644 --- a/lib/wc_client.dart +++ b/lib/wc_client.dart @@ -319,7 +319,7 @@ class WCClient { switch (request.method) { case WCMethod.SESSION_REQUEST: final param = WCSessionRequest.fromJson(request.params!.first); - print('SESSION_REQUEST $param'); + //print('SESSION_REQUEST $param'); _handshakeId = request.id; _remotePeerId = param.peerId; _remotePeerMeta = param.peerMeta; @@ -334,7 +334,7 @@ class WCClient { } break; case WCMethod.ETH_SIGN: - print('ETH_SIGN $request'); + //print('ETH_SIGN $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -349,7 +349,7 @@ class WCClient { ); break; case WCMethod.ETH_PERSONAL_SIGN: - print('ETH_PERSONAL_SIGN $request'); + //print('ETH_PERSONAL_SIGN $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -364,7 +364,7 @@ class WCClient { ); break; case WCMethod.ETH_SIGN_TYPE_DATA: - print('ETH_SIGN_TYPE_DATA $request'); + //print('ETH_SIGN_TYPE_DATA $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -379,17 +379,17 @@ class WCClient { ); break; case WCMethod.ETH_SIGN_TRANSACTION: - print('ETH_SIGN_TRANSACTION $request'); + //print('ETH_SIGN_TRANSACTION $request'); final param = WCEthereumTransaction.fromJson(request.params!.first); onEthSignTransaction?.call(request.id, param); break; case WCMethod.ETH_SEND_TRANSACTION: - print('ETH_SEND_TRANSACTION $request'); + //print('ETH_SEND_TRANSACTION $request'); final param = WCEthereumTransaction.fromJson(request.params!.first); onEthSendTransaction?.call(request.id, param); break; case WCMethod.WALLET_SWITCH_NETWORK: - print('WALLET_SWITCH_NETWORK $request'); + //print('WALLET_SWITCH_NETWORK $request'); final params = WCWalletSwitchNetwork.fromJson(request.params!.first); onWalletSwitchNetwork?.call(request.id, int.parse(params.chainId)); break; From fba9b209ee2b61b62ddd643f07f6a7f64426d7b2 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Tue, 27 Dec 2022 18:08:12 +0545 Subject: [PATCH 4/6] onSeesionRequest method update in example --- example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index c217f08..84ed2d4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -283,7 +283,7 @@ class _MyHomePageState extends State { )); } - _onSessionRequest(int id, WCPeerMeta peerMeta) { + _onSessionRequest(int id, String peerId, WCPeerMeta peerMeta) { showDialog( context: context, builder: (_) => SessionRequestView( From e03188a64fc98f01bc027d9b262f520a54651083 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Tue, 27 Dec 2022 18:18:18 +0545 Subject: [PATCH 5/6] intendation for print --- lib/wc_client.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/wc_client.dart b/lib/wc_client.dart index 2847ff3..351629d 100644 --- a/lib/wc_client.dart +++ b/lib/wc_client.dart @@ -319,7 +319,7 @@ class WCClient { switch (request.method) { case WCMethod.SESSION_REQUEST: final param = WCSessionRequest.fromJson(request.params!.first); - //print('SESSION_REQUEST $param'); + // print('SESSION_REQUEST $param'); _handshakeId = request.id; _remotePeerId = param.peerId; _remotePeerMeta = param.peerMeta; @@ -334,7 +334,7 @@ class WCClient { } break; case WCMethod.ETH_SIGN: - //print('ETH_SIGN $request'); + // print('ETH_SIGN $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -349,7 +349,7 @@ class WCClient { ); break; case WCMethod.ETH_PERSONAL_SIGN: - //print('ETH_PERSONAL_SIGN $request'); + // print('ETH_PERSONAL_SIGN $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -364,7 +364,7 @@ class WCClient { ); break; case WCMethod.ETH_SIGN_TYPE_DATA: - //print('ETH_SIGN_TYPE_DATA $request'); + // print('ETH_SIGN_TYPE_DATA $request'); final params = request.params!.cast(); if (params.length < 2) { throw InvalidJsonRpcParamsException(request.id); @@ -379,17 +379,17 @@ class WCClient { ); break; case WCMethod.ETH_SIGN_TRANSACTION: - //print('ETH_SIGN_TRANSACTION $request'); + // print('ETH_SIGN_TRANSACTION $request'); final param = WCEthereumTransaction.fromJson(request.params!.first); onEthSignTransaction?.call(request.id, param); break; case WCMethod.ETH_SEND_TRANSACTION: - //print('ETH_SEND_TRANSACTION $request'); + // print('ETH_SEND_TRANSACTION $request'); final param = WCEthereumTransaction.fromJson(request.params!.first); onEthSendTransaction?.call(request.id, param); break; case WCMethod.WALLET_SWITCH_NETWORK: - //print('WALLET_SWITCH_NETWORK $request'); + // print('WALLET_SWITCH_NETWORK $request'); final params = WCWalletSwitchNetwork.fromJson(request.params!.first); onWalletSwitchNetwork?.call(request.id, int.parse(params.chainId)); break; From 5d3003d51ee5afb9911d04d15b6b2aa2f12989c8 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Thu, 22 Jun 2023 13:48:10 +0545 Subject: [PATCH 6/6] fix json rpc --- lib/models/jsonrpc/json_rpc_request.dart | 3 +++ lib/models/jsonrpc/json_rpc_request.g.dart | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/models/jsonrpc/json_rpc_request.dart b/lib/models/jsonrpc/json_rpc_request.dart index 9a52700..bd0fa69 100644 --- a/lib/models/jsonrpc/json_rpc_request.dart +++ b/lib/models/jsonrpc/json_rpc_request.dart @@ -6,6 +6,7 @@ part 'json_rpc_request.g.dart'; @JsonSerializable() class JsonRpcRequest { + @JsonKey(fromJson: _idFromValue) final int id; final String jsonrpc; @JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue) @@ -18,6 +19,8 @@ class JsonRpcRequest { required this.params, }); + static int _idFromValue(value) => int.tryParse(value.toString()) ?? 0; + factory JsonRpcRequest.fromJson(Map json) => _$JsonRpcRequestFromJson(json); Map toJson() => _$JsonRpcRequestToJson(this); diff --git a/lib/models/jsonrpc/json_rpc_request.g.dart b/lib/models/jsonrpc/json_rpc_request.g.dart index fc328fa..f1e6379 100644 --- a/lib/models/jsonrpc/json_rpc_request.g.dart +++ b/lib/models/jsonrpc/json_rpc_request.g.dart @@ -8,7 +8,7 @@ part of 'json_rpc_request.dart'; JsonRpcRequest _$JsonRpcRequestFromJson(Map json) => JsonRpcRequest( - id: json['id'] as int, + id: JsonRpcRequest._idFromValue(json['id']), jsonrpc: json['jsonrpc'] as String? ?? JSONRPC_VERSION, method: $enumDecodeNullable(_$WCMethodEnumMap, json['method'], unknownValue: JsonKey.nullForUndefinedEnumValue),