Skip to content
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

[Core] Added bundleId/packageName as param during websocket handshake #208

Merged
merged 2 commits into from
Oct 26, 2023
Merged
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.6

- Minor changes.

## 2.1.5

- Added a core heartbeat to check and expire on pairing and sessions.
Expand Down
8 changes: 7 additions & 1 deletion example/dapp/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions example/dapp/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
6 changes: 6 additions & 0 deletions example/wallet/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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"

Expand All @@ -103,6 +108,7 @@ SPEC CHECKSUMS:
MLKitVision: 8baa5f46ee3352614169b85250574fde38c36f49
mobile_scanner: 47056db0c04027ea5f41a716385542da28574662
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126

Expand Down
2 changes: 2 additions & 0 deletions example/wallet/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
16 changes: 10 additions & 6 deletions lib/apis/core/relay_client/relay_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -324,6 +327,7 @@ class RelayClient implements IRelayClient {
code == 4008 ||
code == 4010 ||
code == 1002 ||
code == 10002 ||
code == 1005) {
await connect();
} else {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/apis/utils/constants.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
25 changes: 12 additions & 13 deletions lib/apis/utils/walletconnect_utils.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -34,6 +35,11 @@ class WalletConnectUtils {
.join('-');
}

static Future<String> getPackageName() async {
final packageInfo = await PackageInfo.fromPlatform();
return packageInfo.packageName;
}

static String getId() {
if (Platform.isAndroid) {
return 'android';
Expand Down Expand Up @@ -74,19 +80,17 @@ class WalletConnectUtils {
required String sdkVersion,
required String auth,
String? projectId,
String? packageName,
}) {
final Uri uri = Uri.parse(relayUrl);
final Map<String, String> queryParams = Uri.splitQueryString(uri.query);
String ua = formatUA(
protocol,
version,
sdkVersion,
);
String ua = formatUA(protocol, version, sdkVersion);

final Map<String, String> 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();
Expand All @@ -106,13 +110,8 @@ class WalletConnectUtils {
}
List<String> 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 = [];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down
Loading