@walletconnect/react-native-compat 2.26.1-canary-3 → 2.26.1-canary-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/walletconnect/reactnativemodule/RNWalletConnectModuleModule.kt +26 -0
- package/android/src/oldarch/RNWalletConnectModuleSpec.kt +2 -0
- package/index.js +4 -0
- package/ios/RNWalletConnectModule.mm +122 -6
- package/module/NativeRNWalletConnectModule.ts +5 -0
- package/package.json +1 -1
package/android/src/main/java/com/walletconnect/reactnativemodule/RNWalletConnectModuleModule.kt
CHANGED
|
@@ -2,8 +2,12 @@ package com.walletconnect.reactnativemodule
|
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
4
|
import com.facebook.react.bridge.ReactMethod
|
|
5
|
+
import com.facebook.react.bridge.Arguments
|
|
5
6
|
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReadableArray
|
|
8
|
+
import com.facebook.react.bridge.ReadableType
|
|
6
9
|
import android.content.pm.PackageManager
|
|
10
|
+
import android.util.Log
|
|
7
11
|
|
|
8
12
|
class RNWalletConnectModuleModule internal constructor(context: ReactApplicationContext) :
|
|
9
13
|
RNWalletConnectModuleSpec(context) {
|
|
@@ -38,6 +42,28 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
|
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
@ReactMethod
|
|
46
|
+
override fun getInstalledApps(identifiers: ReadableArray, promise: Promise) {
|
|
47
|
+
val installed = Arguments.createArray()
|
|
48
|
+
try {
|
|
49
|
+
for (i in 0 until identifiers.size()) {
|
|
50
|
+
// Check each identifier on its own so an unexpected failure on one doesn't drop the rest.
|
|
51
|
+
try {
|
|
52
|
+
if (identifiers.getType(i) != ReadableType.String) continue
|
|
53
|
+
val packageName = identifiers.getString(i)
|
|
54
|
+
if (packageName.isNullOrBlank()) continue
|
|
55
|
+
if (isPackageInstalled(packageName)) installed.pushString(packageName)
|
|
56
|
+
} catch (e: Exception) {
|
|
57
|
+
Log.w(NAME, "getInstalledApps: failed to check identifier at index $i", e)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch (e: Exception) {
|
|
61
|
+
// Never reject: return whatever was found before the failure.
|
|
62
|
+
Log.w(NAME, "getInstalledApps: failed to read identifiers", e)
|
|
63
|
+
}
|
|
64
|
+
promise.resolve(installed)
|
|
65
|
+
}
|
|
66
|
+
|
|
41
67
|
private fun isPackageInstalled(packageName: String): Boolean {
|
|
42
68
|
val manager: PackageManager = getReactApplicationContext().getPackageManager()
|
|
43
69
|
return try {
|
|
@@ -3,11 +3,13 @@ package com.walletconnect.reactnativemodule
|
|
|
3
3
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
4
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
5
|
import com.facebook.react.bridge.Promise
|
|
6
|
+
import com.facebook.react.bridge.ReadableArray
|
|
6
7
|
|
|
7
8
|
abstract class RNWalletConnectModuleSpec internal constructor(context: ReactApplicationContext) :
|
|
8
9
|
ReactContextBaseJavaModule(context) {
|
|
9
10
|
|
|
10
11
|
abstract fun isAppInstalled(packageName: String?, promise: Promise);
|
|
12
|
+
abstract fun getInstalledApps(identifiers: ReadableArray, promise: Promise);
|
|
11
13
|
protected abstract fun getTypedExportedConstants(): Map<String, String>
|
|
12
14
|
|
|
13
15
|
override fun getConstants(): Map<String, String> {
|
package/index.js
CHANGED
|
@@ -68,6 +68,10 @@ if (typeof global?.Application === "undefined") {
|
|
|
68
68
|
...module.getConstants(),
|
|
69
69
|
isAppInstalled: module.isAppInstalled,
|
|
70
70
|
};
|
|
71
|
+
// Batch lookup, only available in the WalletConnect native module (not expo-application).
|
|
72
|
+
if (typeof module.getInstalledApps === "function") {
|
|
73
|
+
global.Application.getInstalledApps = module.getInstalledApps;
|
|
74
|
+
}
|
|
71
75
|
} else {
|
|
72
76
|
global.Application = module;
|
|
73
77
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#import "RNWalletConnectModule.h"
|
|
2
2
|
|
|
3
|
+
#import <UIKit/UIKit.h>
|
|
4
|
+
|
|
3
5
|
@implementation RNWalletConnectModule
|
|
4
6
|
RCT_EXPORT_MODULE()
|
|
5
7
|
|
|
@@ -7,8 +9,84 @@ RCT_EXPORT_METHOD(isAppInstalled:(NSString *)bundleID
|
|
|
7
9
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
8
10
|
reject:(RCTPromiseRejectBlock)reject)
|
|
9
11
|
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
// Never rejects: any failure resolves NO.
|
|
13
|
+
@try {
|
|
14
|
+
NSString *scheme = [RNWalletConnectModule normalizedScheme:bundleID];
|
|
15
|
+
if (scheme == nil) {
|
|
16
|
+
resolve(@(NO));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// UIApplication is main-thread only; this module's methods run on a background queue.
|
|
20
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
21
|
+
resolve(@([RNWalletConnectModule canOpenScheme:scheme]));
|
|
22
|
+
});
|
|
23
|
+
} @catch (NSException *exception) {
|
|
24
|
+
resolve(@(NO));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
RCT_EXPORT_METHOD(getInstalledApps:(NSArray *)identifiers
|
|
29
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
30
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
31
|
+
{
|
|
32
|
+
// Never rejects: any failure resolves an empty list.
|
|
33
|
+
@try {
|
|
34
|
+
if (![identifiers isKindOfClass:[NSArray class]] || identifiers.count == 0) {
|
|
35
|
+
resolve(@[]);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// Normalize off the main thread, keeping each original identifier so callers can match
|
|
39
|
+
// results against what they passed in.
|
|
40
|
+
NSMutableArray<NSString *> *originals = [NSMutableArray arrayWithCapacity:identifiers.count];
|
|
41
|
+
NSMutableArray<NSString *> *schemes = [NSMutableArray arrayWithCapacity:identifiers.count];
|
|
42
|
+
for (id identifier in identifiers) {
|
|
43
|
+
NSString *scheme = [RNWalletConnectModule normalizedScheme:identifier];
|
|
44
|
+
if (scheme != nil) {
|
|
45
|
+
[originals addObject:identifier];
|
|
46
|
+
[schemes addObject:scheme];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (schemes.count == 0) {
|
|
50
|
+
resolve(@[]);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
[RNWalletConnectModule checkSchemes:schemes
|
|
54
|
+
originals:originals
|
|
55
|
+
start:0
|
|
56
|
+
installed:[NSMutableArray array]
|
|
57
|
+
resolve:resolve];
|
|
58
|
+
} @catch (NSException *exception) {
|
|
59
|
+
resolve(@[]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Checks schemes on the main queue in small chunks, yielding between chunks so a large list
|
|
64
|
+
// (hundreds of wallets) never blocks the UI for more than a few milliseconds at a time.
|
|
65
|
+
static const NSUInteger kSchemesPerMainQueueTurn = 16;
|
|
66
|
+
|
|
67
|
+
+ (void)checkSchemes:(NSArray<NSString *> *)schemes
|
|
68
|
+
originals:(NSArray<NSString *> *)originals
|
|
69
|
+
start:(NSUInteger)start
|
|
70
|
+
installed:(NSMutableArray<NSString *> *)installed
|
|
71
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
72
|
+
{
|
|
73
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
74
|
+
NSUInteger end = MIN(start + kSchemesPerMainQueueTurn, schemes.count);
|
|
75
|
+
for (NSUInteger i = start; i < end; i++) {
|
|
76
|
+
if ([RNWalletConnectModule canOpenScheme:schemes[i]]) {
|
|
77
|
+
[installed addObject:originals[i]];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (end >= schemes.count) {
|
|
81
|
+
resolve([installed copy]);
|
|
82
|
+
} else {
|
|
83
|
+
[RNWalletConnectModule checkSchemes:schemes
|
|
84
|
+
originals:originals
|
|
85
|
+
start:end
|
|
86
|
+
installed:installed
|
|
87
|
+
resolve:resolve];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
12
90
|
}
|
|
13
91
|
|
|
14
92
|
+ (BOOL)requiresMainQueueSetup
|
|
@@ -18,7 +96,7 @@ RCT_EXPORT_METHOD(isAppInstalled:(NSString *)bundleID
|
|
|
18
96
|
|
|
19
97
|
- (NSDictionary *)constantsToExport
|
|
20
98
|
{
|
|
21
|
-
return @{
|
|
99
|
+
return @{
|
|
22
100
|
@"applicationName": [self getAppName],
|
|
23
101
|
@"applicationId": [self getBundleId],
|
|
24
102
|
};
|
|
@@ -34,9 +112,47 @@ RCT_EXPORT_METHOD(isAppInstalled:(NSString *)bundleID
|
|
|
34
112
|
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"];
|
|
35
113
|
}
|
|
36
114
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
115
|
+
// Accepts a bare scheme ("metamask"), a scheme with separator ("metamask://") or a full URL
|
|
116
|
+
// ("metamask://wc?uri=..."), and returns only the scheme. Returns nil for nil, empty or
|
|
117
|
+
// malformed input (RFC 3986: ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )).
|
|
118
|
+
+ (nullable NSString *)normalizedScheme:(id)input {
|
|
119
|
+
if (![input isKindOfClass:[NSString class]]) {
|
|
120
|
+
return nil;
|
|
121
|
+
}
|
|
122
|
+
NSString *trimmed = [(NSString *)input stringByTrimmingCharactersInSet:
|
|
123
|
+
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
|
124
|
+
NSRange separator = [trimmed rangeOfString:@":"];
|
|
125
|
+
NSString *scheme = separator.location == NSNotFound ? trimmed : [trimmed substringToIndex:separator.location];
|
|
126
|
+
if (scheme.length == 0) {
|
|
127
|
+
return nil;
|
|
128
|
+
}
|
|
129
|
+
static NSCharacterSet *invalidCharacters;
|
|
130
|
+
static NSCharacterSet *letters;
|
|
131
|
+
static dispatch_once_t onceToken;
|
|
132
|
+
dispatch_once(&onceToken, ^{
|
|
133
|
+
NSString *ascii = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
134
|
+
letters = [NSCharacterSet characterSetWithCharactersInString:ascii];
|
|
135
|
+
invalidCharacters = [[NSCharacterSet characterSetWithCharactersInString:
|
|
136
|
+
[ascii stringByAppendingString:@"0123456789+-."]] invertedSet];
|
|
137
|
+
});
|
|
138
|
+
if (![letters characterIsMember:[scheme characterAtIndex:0]] ||
|
|
139
|
+
[scheme rangeOfCharacterFromSet:invalidCharacters].location != NSNotFound) {
|
|
140
|
+
return nil;
|
|
141
|
+
}
|
|
142
|
+
return scheme;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Must run on the main thread. Never throws: any failure counts as "not installed".
|
|
146
|
+
+ (BOOL)canOpenScheme:(NSString *)scheme {
|
|
147
|
+
@try {
|
|
148
|
+
NSURL *url = [NSURL URLWithString:[scheme stringByAppendingString:@"://"]];
|
|
149
|
+
if (url == nil) {
|
|
150
|
+
return NO;
|
|
151
|
+
}
|
|
152
|
+
return [[UIApplication sharedApplication] canOpenURL:url];
|
|
153
|
+
} @catch (NSException *exception) {
|
|
154
|
+
return NO;
|
|
155
|
+
}
|
|
40
156
|
}
|
|
41
157
|
|
|
42
158
|
- (NSDictionary *)getConstants {
|
|
@@ -3,6 +3,11 @@ import { TurboModuleRegistry } from "react-native";
|
|
|
3
3
|
|
|
4
4
|
export interface Spec extends TurboModule {
|
|
5
5
|
isAppInstalled(bundleId?: string): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* Returns the subset of `identifiers` that are installed, in a single native call.
|
|
8
|
+
* iOS: URL schemes (must be declared in LSApplicationQueriesSchemes). Android: package names.
|
|
9
|
+
*/
|
|
10
|
+
getInstalledApps(identifiers: string[]): Promise<string[]>;
|
|
6
11
|
getConstants(): {
|
|
7
12
|
applicationName: string;
|
|
8
13
|
applicationId: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walletconnect/react-native-compat",
|
|
3
3
|
"description": "Native modules and shims for WalletConnect Protocol in React Native Projects",
|
|
4
|
-
"version": "2.26.1-canary-
|
|
4
|
+
"version": "2.26.1-canary-4",
|
|
5
5
|
"author": "WalletConnect, Inc. <walletconnect.com>",
|
|
6
6
|
"homepage": "https://github.com/walletconnect/walletconnect-monorepo/",
|
|
7
7
|
"license": "SEE LICENSE IN LICENSE.md",
|