From dda9dc9dce4efb0938ba0e1e53943f93f845fe08 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Wed, 25 Oct 2023 09:37:34 +0200 Subject: [PATCH 1/2] Added bundleId/packageName into websocket handshake connection --- example/dapp/ios/Podfile.lock | 8 +++++- .../Flutter/GeneratedPluginRegistrant.swift | 2 ++ example/wallet/ios/Podfile.lock | 6 +++++ .../Flutter/GeneratedPluginRegistrant.swift | 2 ++ lib/apis/core/relay_client/relay_client.dart | 16 +++++++----- lib/apis/utils/walletconnect_utils.dart | 25 +++++++++---------- pubspec.yaml | 1 + 7 files changed, 40 insertions(+), 20 deletions(-) diff --git a/example/dapp/ios/Podfile.lock b/example/dapp/ios/Podfile.lock index 4ae7d1e5..3e05a432 100644 --- a/example/dapp/ios/Podfile.lock +++ b/example/dapp/ios/Podfile.lock @@ -1,23 +1,29 @@ PODS: - Flutter (1.0.0) + - package_info_plus (0.4.5): + - Flutter - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS DEPENDENCIES: - Flutter (from `Flutter`) + - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) EXTERNAL SOURCES: Flutter: :path: Flutter + package_info_plus: + :path: ".symlinks/plugins/package_info_plus/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" SPEC CHECKSUMS: Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85 shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 -COCOAPODS: 1.12.1 +COCOAPODS: 1.13.0 diff --git a/example/dapp/macos/Flutter/GeneratedPluginRegistrant.swift b/example/dapp/macos/Flutter/GeneratedPluginRegistrant.swift index 724bb2ac..55e04aa6 100644 --- a/example/dapp/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/dapp/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,8 +5,10 @@ import FlutterMacOS import Foundation +import package_info_plus import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/example/wallet/ios/Podfile.lock b/example/wallet/ios/Podfile.lock index fda1dc09..db6c3de3 100644 --- a/example/wallet/ios/Podfile.lock +++ b/example/wallet/ios/Podfile.lock @@ -56,6 +56,8 @@ PODS: - nanopb/encode (= 2.30909.0) - nanopb/decode (2.30909.0) - nanopb/encode (2.30909.0) + - package_info_plus (0.4.5): + - Flutter - PromisesObjC (2.2.0) - shared_preferences_foundation (0.0.1): - Flutter @@ -64,6 +66,7 @@ PODS: DEPENDENCIES: - Flutter (from `Flutter`) - mobile_scanner (from `.symlinks/plugins/mobile_scanner/ios`) + - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) SPEC REPOS: @@ -86,6 +89,8 @@ EXTERNAL SOURCES: :path: Flutter mobile_scanner: :path: ".symlinks/plugins/mobile_scanner/ios" + package_info_plus: + :path: ".symlinks/plugins/package_info_plus/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" @@ -103,6 +108,7 @@ SPEC CHECKSUMS: MLKitVision: 8baa5f46ee3352614169b85250574fde38c36f49 mobile_scanner: 47056db0c04027ea5f41a716385542da28574662 nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431 + package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85 PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 diff --git a/example/wallet/macos/Flutter/GeneratedPluginRegistrant.swift b/example/wallet/macos/Flutter/GeneratedPluginRegistrant.swift index f15c78b2..4dc19730 100644 --- a/example/wallet/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/wallet/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,9 +6,11 @@ import FlutterMacOS import Foundation import mobile_scanner +import package_info_plus import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin")) + FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/lib/apis/core/relay_client/relay_client.dart b/lib/apis/core/relay_client/relay_client.dart index 8ef1f2ac..1a6886fd 100644 --- a/lib/apis/core/relay_client/relay_client.dart +++ b/lib/apis/core/relay_client/relay_client.dart @@ -55,6 +55,8 @@ class RelayClient implements IRelayClient { @override bool get isConnected => jsonRPC != null && !jsonRPC!.isClosed; + bool get _relayIsClosed => jsonRPC != null && jsonRPC!.isClosed; + bool _initialized = false; bool _active = true; bool _connecting = false; @@ -237,13 +239,14 @@ class RelayClient implements IRelayClient { var auth = await core.crypto.signJWT(core.relayUrl); core.logger.t('Signed JWT: $auth'); try { - final String url = WalletConnectUtils.formatRelayRpcUrl( + final url = WalletConnectUtils.formatRelayRpcUrl( protocol: WalletConnectConstants.CORE_PROTOCOL, version: WalletConnectConstants.CORE_VERSION, relayUrl: core.relayUrl, sdkVersion: WalletConnectConstants.SDK_VERSION, auth: auth, projectId: core.projectId, + packageName: (await WalletConnectUtils.getPackageName()), ); if (jsonRPC != null) { @@ -324,6 +327,7 @@ class RelayClient implements IRelayClient { code == 4008 || code == 4010 || code == 1002 || + code == 10002 || code == 1005) { await connect(); } else { @@ -357,9 +361,8 @@ class RelayClient implements IRelayClient { void _heartbeatSubscription(EventArgs? args) async { core.logger.i('RelayClient heartbeat received'); - if (jsonRPC != null && jsonRPC!.isClosed) { - core.logger.t('RelayClient, WebSocket closed, reconnecting'); - await connect(); + if (_relayIsClosed) { + await _handleRelayClose(10002, null); } } @@ -400,7 +403,9 @@ class RelayClient implements IRelayClient { return params.hashCode; } - void _handleUnsubscribe(Parameters params) {} + void _handleUnsubscribe(Parameters params) { + core.logger.i('[$runtimeType] _handleUnsubscribe $params'); + } /// MESSAGE HANDLING @@ -448,7 +453,6 @@ class RelayClient implements IRelayClient { JsonRpcUtils.payloadId(entropy: 6), ); } catch (e) { - // print('onSubscribe error: $e, stack: $stacktrace'); core.logger.w('RelayClient, onSubscribe error. Topic: $topic, Error: $e'); onRelayClientError.broadcast(ErrorEvent(e)); } diff --git a/lib/apis/utils/walletconnect_utils.dart b/lib/apis/utils/walletconnect_utils.dart index 60b2abe3..0a7df483 100644 --- a/lib/apis/utils/walletconnect_utils.dart +++ b/lib/apis/utils/walletconnect_utils.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:package_info_plus/package_info_plus.dart'; import 'package:universal_io/io.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:walletconnect_flutter_v2/apis/core/relay_client/relay_client_models.dart'; @@ -34,6 +35,11 @@ class WalletConnectUtils { .join('-'); } + static Future getPackageName() async { + final packageInfo = await PackageInfo.fromPlatform(); + return packageInfo.packageName; + } + static String getId() { if (Platform.isAndroid) { return 'android'; @@ -74,19 +80,17 @@ class WalletConnectUtils { required String sdkVersion, required String auth, String? projectId, + String? packageName, }) { final Uri uri = Uri.parse(relayUrl); final Map queryParams = Uri.splitQueryString(uri.query); - String ua = formatUA( - protocol, - version, - sdkVersion, - ); + String ua = formatUA(protocol, version, sdkVersion); final Map relayParams = { 'auth': auth, - if (projectId != null && projectId.isNotEmpty) 'projectId': projectId, + if ((projectId ?? '').isNotEmpty) 'projectId': projectId!, 'ua': ua, + if ((packageName ?? '').isNotEmpty) 'origin': packageName!, }; queryParams.addAll(relayParams); return uri.replace(queryParameters: queryParams).toString(); @@ -106,13 +110,8 @@ class WalletConnectUtils { } List methods = (uri.queryParameters['methods'] ?? '') // Replace all the square brackets with empty string, split by comma - .replaceAll( - RegExp(r'[\[\]"]+'), - '', - ) - .split( - ',', - ); + .replaceAll(RegExp(r'[\[\]"]+'), '') + .split(','); if (methods.length == 1 && methods[0].isEmpty) { methods = []; } diff --git a/pubspec.yaml b/pubspec.yaml index 306dcd90..88020d2c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: web3dart: ^2.5.1 logger: ^2.0.2+1 freezed_annotation: ^2.2.0 + package_info_plus: ^4.2.0 dev_dependencies: flutter_test: From 16b2f0e165b894e35cdb05353310952c5d8d1c40 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Wed, 25 Oct 2023 09:40:50 +0200 Subject: [PATCH 2/2] bumped version --- CHANGELOG.md | 4 ++++ lib/apis/utils/constants.dart | 2 +- lib/src/version.dart | 2 +- pubspec.yaml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1aba1a4..334b3567 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.6 + +- Minor changes. + ## 2.1.5 - Added a core heartbeat to check and expire on pairing and sessions. diff --git a/lib/apis/utils/constants.dart b/lib/apis/utils/constants.dart index 3c09d31d..de7a408e 100644 --- a/lib/apis/utils/constants.dart +++ b/lib/apis/utils/constants.dart @@ -1,5 +1,5 @@ class WalletConnectConstants { - static const SDK_VERSION = '2.1.5'; + static const SDK_VERSION = '2.1.6'; static const CORE_PROTOCOL = 'wc'; static const CORE_VERSION = 2; diff --git a/lib/src/version.dart b/lib/src/version.dart index a0aa4231..88c2f9fb 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '2.1.5'; +const packageVersion = '2.1.6'; diff --git a/pubspec.yaml b/pubspec.yaml index 88020d2c..d6beb4dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: walletconnect_flutter_v2 description: This repository contains oficial implementation of WalletConnect v2 protocols for Flutter applications. The communications protocol for web3. -version: 2.1.5 +version: 2.1.6 repository: https://github.com/WalletConnect/WalletConnectFlutterV2 environment: