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

updating for compatibility walletconnect_flutter_v2 package #5

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Binary file added .DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions .idea/libraries/Dart_SDK.xml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

36 changes: 36 additions & 0 deletions .idea/workspace.xml

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

Binary file added lib/.DS_Store
Binary file not shown.
23 changes: 12 additions & 11 deletions lib/src/helpers/wallet_connect_uri_convertor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ class WalletConnectUriConvertor {
static Uri? toUri(String uri) {
if (uri.isEmpty) return null;

final u = Uri.tryParse(
uri.startsWith('wc:') ? uri.replaceFirst('wc:', 'wc://') : uri,
);

final u = Uri.tryParse(uri);
if (u == null) return null;

if ([
u.host.isNotEmpty,
u.path.isNotEmpty,
u.isScheme('wc'),
].contains(false)) return null;

Expand All @@ -22,8 +19,10 @@ class WalletConnectUriConvertor {
if (uri is WalletConnectV1Uri) {
return Uri(
scheme: uri.protocol,
userInfo: uri.topic,
host: uri.version.version.toString(),
path: [
uri.topic,
uri.version.version.toString(),
].join('@'),
queryParameters: {
'bridge': uri.bridge,
'key': uri.key,
Expand All @@ -34,12 +33,14 @@ class WalletConnectUriConvertor {
if (uri is WalletConnectV2Uri) {
return Uri(
scheme: uri.protocol,
userInfo: uri.topic,
host: uri.version.version.toString(),
path: [
uri.topic,
uri.version.version.toString(),
].join('@'),
queryParameters: {
'relayProtocol': uri.relayProtocol,
'relay-protocol': uri.relayProtocol,
'symKey': uri.symKey,
'relayData': uri.relayData,
if (uri.relayData != null) 'relayData': uri.relayData,
},
).toString();
}
Expand Down
11 changes: 7 additions & 4 deletions lib/src/wallet_connect_uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ enum WalletConnectVersion {

/// Parse [WalletConnectVersion] from [String] that contains version number
static WalletConnectVersion parse(String value) {
final s = int.tryParse(value) ?? 0;
if (s > 0) return from(s);
return unknown;
try {
final v = value.contains('@') ? value.split('@').last : value;
return from(int.parse(v));
} catch (_) {
return unknown;
}
}

/// Get [WalletConnectVersion] from [int] that contains version number
Expand Down Expand Up @@ -74,7 +77,7 @@ abstract class WalletConnectUri {
final u = WalletConnectUriConvertor.toUri(uri);
if (u == null) throw const FormatException('Invalid WalletConnect URI');

final v = WalletConnectVersion.parse(u.host);
final v = WalletConnectVersion.parse(u.path);
if (v == WalletConnectVersion.v1) return WalletConnectV1Uri.parse(uri);
if (v == WalletConnectVersion.v2) return WalletConnectV2Uri.parse(uri);

Expand Down
5 changes: 3 additions & 2 deletions lib/src/wallet_connect_v1_uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class WalletConnectV1Uri extends WalletConnectUri {
);
}

final topic = u.path.contains('@') ? u.path.split('@').first : u.path;
final params = u.queryParameters;

return WalletConnectV1Uri(
protocol: u.scheme,
topic: u.userInfo,
version: WalletConnectVersion.parse(u.host),
topic: topic,
version: WalletConnectVersion.parse(u.path),
bridge: params['bridge'] ?? '',
key: params['key'] ?? '',
);
Expand Down
5 changes: 3 additions & 2 deletions lib/src/wallet_connect_v2_uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class WalletConnectV2Uri extends WalletConnectUri {
);
}

final topic = u.path.contains('@') ? u.path.split('@').first : u.path;
final params = u.queryParameters;

return WalletConnectV2Uri(
protocol: u.scheme,
topic: u.userInfo,
version: WalletConnectVersion.parse(u.host),
topic: topic,
version: WalletConnectVersion.parse(u.path),
relayProtocol: params['relay-protocol'] ?? '',
symKey: params['symKey'] ?? '',
relayData: params['relayData'],
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 0.1.0
repository: https://github.com/SimplioOfficial/wallet-connect-uri-validator.git

environment:
sdk: '>=2.18.6 <3.0.0'
sdk: ">=3.0.0 <4.0.0"

dev_dependencies:
lints: ^2.0.0
Expand Down
Loading