@walletconnect/react-native-compat 2.10.5-rc-60b8e52 → 2.10.5-rc-57761a66

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,120 @@
1
+ buildscript {
2
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["RNWalletConnectModule_kotlinVersion"]
4
+
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+
10
+ dependencies {
11
+ classpath "com.android.tools.build:gradle:7.2.1"
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ }
15
+ }
16
+
17
+ def isNewArchitectureEnabled() {
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
+ }
20
+
21
+ apply plugin: "com.android.library"
22
+ apply plugin: "kotlin-android"
23
+
24
+ if (isNewArchitectureEnabled()) {
25
+ apply plugin: "com.facebook.react"
26
+ }
27
+
28
+ def getExtOrDefault(name) {
29
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["RNWalletConnectModule_" + name]
30
+ }
31
+
32
+ def getExtOrIntegerDefault(name) {
33
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["RNWalletConnectModule_" + name]).toInteger()
34
+ }
35
+
36
+ def supportsNamespace() {
37
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
38
+ def major = parsed[0].toInteger()
39
+ def minor = parsed[1].toInteger()
40
+
41
+ // Namespace support was added in 7.3.0
42
+ return (major == 7 && minor >= 3) || major >= 8
43
+ }
44
+
45
+ android {
46
+ if (supportsNamespace()) {
47
+ namespace "com.walletconnect.reactnativemodule"
48
+
49
+ sourceSets {
50
+ main {
51
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
52
+ }
53
+ }
54
+ }
55
+
56
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
57
+
58
+ defaultConfig {
59
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
60
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
61
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
62
+
63
+ }
64
+
65
+ buildFeatures {
66
+ buildConfig true
67
+ }
68
+
69
+ buildTypes {
70
+ release {
71
+ minifyEnabled false
72
+ }
73
+ }
74
+
75
+ lintOptions {
76
+ disable "GradleCompatible"
77
+ }
78
+
79
+ compileOptions {
80
+ sourceCompatibility JavaVersion.VERSION_1_8
81
+ targetCompatibility JavaVersion.VERSION_1_8
82
+ }
83
+
84
+ sourceSets {
85
+ main {
86
+ if (isNewArchitectureEnabled()) {
87
+ java.srcDirs += [
88
+ "src/newarch",
89
+ // This is needed to build Kotlin project with NewArch enabled
90
+ "${project.buildDir}/generated/source/codegen/java"
91
+ ]
92
+ } else {
93
+ java.srcDirs += ["src/oldarch"]
94
+ }
95
+ }
96
+ }
97
+ }
98
+
99
+ repositories {
100
+ mavenCentral()
101
+ google()
102
+ }
103
+
104
+ def kotlin_version = getExtOrDefault("kotlinVersion")
105
+
106
+ dependencies {
107
+ // For < 0.71, this will be from the local maven repo
108
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
109
+ //noinspection GradleDynamicVersion
110
+ implementation "com.facebook.react:react-native:+"
111
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
112
+ }
113
+
114
+ if (isNewArchitectureEnabled()) {
115
+ react {
116
+ jsRootDir = file("../src/")
117
+ libraryName = "RNWalletConnectModule"
118
+ codegenJavaPackageName = "com.walletconnect.reactnativemodule"
119
+ }
120
+ }
@@ -0,0 +1,5 @@
1
+ RNWalletConnectModule_kotlinVersion=1.7.0
2
+ RNWalletConnectModule_minSdkVersion=21
3
+ RNWalletConnectModule_targetSdkVersion=31
4
+ RNWalletConnectModule_compileSdkVersion=31
5
+ RNWalletConnectModule_ndkversion=21.4.7075529
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.walletconnect.reactnativemodule">
3
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,55 @@
1
+ package com.walletconnect.reactnativemodule
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactMethod
5
+ import com.facebook.react.bridge.Promise
6
+ import android.content.pm.PackageManager
7
+
8
+ class RNWalletConnectModuleModule internal constructor(context: ReactApplicationContext) :
9
+ RNWalletConnectModuleSpec(context) {
10
+
11
+ override fun getName(): String {
12
+ return NAME
13
+ }
14
+
15
+ override protected fun getTypedExportedConstants(): Map<String, String> {
16
+ var appName: String
17
+
18
+ try {
19
+ appName = getReactApplicationContext().getApplicationInfo()
20
+ .loadLabel(getReactApplicationContext().getPackageManager()).toString()
21
+ } catch (e: Exception) {
22
+ appName = "unknown"
23
+ }
24
+
25
+ val constants: MutableMap<String, String> = HashMap()
26
+ constants.put("applicationId", getReactApplicationContext().getPackageName());
27
+ constants.put("applicationName", appName);
28
+ return constants
29
+ }
30
+
31
+ @ReactMethod
32
+ override fun isAppInstalled(packageName: String?, promise: Promise) {
33
+ try {
34
+ val installed = packageName?.let { isPackageInstalled(it) } ?: false
35
+ promise.resolve(installed)
36
+ } catch (e: Exception) {
37
+ promise.resolve(false)
38
+ }
39
+ }
40
+
41
+ private fun isPackageInstalled(packageName: String): Boolean {
42
+ val manager: PackageManager = getReactApplicationContext().getPackageManager()
43
+ return try {
44
+ @Suppress("DEPRECATION")
45
+ manager.getPackageInfo(packageName, 0)
46
+ true
47
+ } catch (e: PackageManager.NameNotFoundException) {
48
+ false
49
+ }
50
+ }
51
+
52
+ companion object {
53
+ const val NAME = "RNWalletConnectModule"
54
+ }
55
+ }
@@ -0,0 +1,35 @@
1
+ package com.walletconnect.reactnativemodule
2
+
3
+ import com.facebook.react.TurboReactPackage
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.NativeModule
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+ import com.facebook.react.module.model.ReactModuleInfo
8
+ import java.util.HashMap
9
+
10
+ class RNWalletConnectModulePackage : TurboReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return if (name == RNWalletConnectModuleModule.NAME) {
13
+ RNWalletConnectModuleModule(reactContext)
14
+ } else {
15
+ null
16
+ }
17
+ }
18
+
19
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
+ return ReactModuleInfoProvider {
21
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
+ val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
23
+ moduleInfos[RNWalletConnectModuleModule.NAME] = ReactModuleInfo(
24
+ RNWalletConnectModuleModule.NAME,
25
+ RNWalletConnectModuleModule.NAME,
26
+ false, // canOverrideExistingModule
27
+ false, // needsEagerInit
28
+ true, // hasConstants
29
+ false, // isCxxModule
30
+ isTurboModule // isTurboModule
31
+ )
32
+ moduleInfos
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,7 @@
1
+ package com.walletconnect.reactnativemodule
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+
5
+ abstract class RNWalletConnectModuleSpec internal constructor(context: ReactApplicationContext) :
6
+ NativeRNWalletConnectModuleSpec(context) {
7
+ }
@@ -0,0 +1,17 @@
1
+ package com.walletconnect.reactnativemodule
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
5
+ import com.facebook.react.bridge.Promise
6
+
7
+ abstract class RNWalletConnectModuleSpec internal constructor(context: ReactApplicationContext) :
8
+ ReactContextBaseJavaModule(context) {
9
+
10
+ abstract fun isAppInstalled(packageName: String?, promise: Promise);
11
+ protected abstract fun getTypedExportedConstants(): Map<String, String>
12
+
13
+ override fun getConstants(): Map<String, String> {
14
+ val constants: Map<String, String> = getTypedExportedConstants()
15
+ return constants
16
+ }
17
+ }
package/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { getApplicationModule } from "./module";
2
+
1
3
  // Polyfill TextEncode / TextDecode
2
4
  import "fast-text-encoding";
3
5
 
@@ -35,6 +37,23 @@ if (typeof global?.NetInfo === "undefined") {
35
37
  global.NetInfo = require("@react-native-community/netinfo");
36
38
  } catch (e) {
37
39
  // eslint-disable-next-line no-console
38
- console.error("react-native-compat: react-native.NetInfo is not available", e);
40
+ console.error("react-native-compat: @react-native-community/netinfo is not available");
41
+ }
42
+ }
43
+
44
+ if (typeof global?.Application === "undefined") {
45
+ try {
46
+ const module = getApplicationModule();
47
+ if (typeof module.getConstants === "function") {
48
+ global.Application = {
49
+ ...module.getConstants(),
50
+ isAppInstalled: module.isAppInstalled,
51
+ };
52
+ } else {
53
+ global.Application = module;
54
+ }
55
+ } catch (e) {
56
+ // eslint-disable-next-line no-console
57
+ console.error("react-native-compat: Application module is not available");
39
58
  }
40
59
  }
@@ -0,0 +1,12 @@
1
+
2
+ #ifdef RCT_NEW_ARCH_ENABLED
3
+ #import "RNRNWalletConnectModuleSpec.h"
4
+
5
+ @interface RNWalletConnectModule : NSObject <NativeRNWalletConnectModuleSpec>
6
+ #else
7
+ #import <React/RCTBridgeModule.h>
8
+
9
+ @interface RNWalletConnectModule : NSObject <RCTBridgeModule>
10
+ #endif
11
+
12
+ @end
@@ -0,0 +1,55 @@
1
+ #import "RNWalletConnectModule.h"
2
+
3
+ @implementation RNWalletConnectModule
4
+ RCT_EXPORT_MODULE()
5
+
6
+ RCT_EXPORT_METHOD(isAppInstalled:(NSString *)bundleID
7
+ resolve:(RCTPromiseResolveBlock)resolve
8
+ reject:(RCTPromiseRejectBlock)reject)
9
+ {
10
+ BOOL result = [self checkAppInstalled:bundleID];
11
+ resolve(@(result));
12
+ }
13
+
14
+ + (BOOL)requiresMainQueueSetup
15
+ {
16
+ return NO;
17
+ }
18
+
19
+ - (NSDictionary *)constantsToExport
20
+ {
21
+ return @{
22
+ @"applicationName": [self getAppName],
23
+ @"applicationId": [self getBundleId],
24
+ };
25
+ }
26
+
27
+ - (NSString *) getAppName {
28
+ NSString *displayName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
29
+ NSString *bundleName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
30
+ return displayName ? displayName : bundleName;
31
+ }
32
+
33
+ - (NSString *) getBundleId {
34
+ return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"];
35
+ }
36
+
37
+ - (BOOL)checkAppInstalled:(NSString *)bundleID {
38
+ NSURL *appURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://", bundleID]];
39
+ return [[UIApplication sharedApplication] canOpenURL:appURL];
40
+ }
41
+
42
+ - (NSDictionary *)getConstants {
43
+ return [self constantsToExport];
44
+ }
45
+
46
+ // Don't compile this code when we build for the old architecture.
47
+ #ifdef RCT_NEW_ARCH_ENABLED
48
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
49
+ (const facebook::react::ObjCTurboModule::InitParams &)params
50
+ {
51
+ return std::make_shared<facebook::react::NativeRNWalletConnectModuleSpecJSI>(params);
52
+ }
53
+ #endif
54
+
55
+ @end
@@ -0,0 +1,12 @@
1
+ import type { TurboModule } from "react-native";
2
+ import { TurboModuleRegistry } from "react-native";
3
+
4
+ export interface Spec extends TurboModule {
5
+ isAppInstalled(bundleId?: string): Promise<boolean>;
6
+ getConstants(): {
7
+ applicationName: string;
8
+ applicationId: string;
9
+ };
10
+ }
11
+
12
+ export default TurboModuleRegistry.getEnforcing<Spec>("RNWalletConnectModule");
@@ -0,0 +1,47 @@
1
+ import { NativeModules } from "react-native";
2
+
3
+ const LINKING_ERROR =
4
+ `The package to get the RNWalletConnectModule doesn't seem to be linked. Make sure: \n\n` +
5
+ "- You rebuilt the app after installing the package\n" +
6
+ "- If you are using Expo: install expo-application \n";
7
+
8
+ // @ts-expect-error
9
+ const isTurboModuleEnabled = global.__turboModuleProxy != null;
10
+
11
+ const RNWalletConnectModule = isTurboModuleEnabled
12
+ ? require("../module/NativeRNWalletConnectModule").default
13
+ : NativeModules.RNWalletConnectModule;
14
+
15
+ function getExpoModule(): any | undefined {
16
+ try {
17
+ const ExpoApplication = require("expo-application");
18
+
19
+ if (!ExpoApplication) throw new Error();
20
+
21
+ return ExpoApplication;
22
+ } catch {
23
+ throw new Error();
24
+ }
25
+ }
26
+
27
+ function getRNModule(): any | undefined {
28
+ try {
29
+ if (!RNWalletConnectModule) throw new Error();
30
+ return RNWalletConnectModule;
31
+ } catch {
32
+ throw new Error();
33
+ }
34
+ }
35
+
36
+ // Public
37
+ export function getApplicationModule(): any | undefined {
38
+ try {
39
+ return getRNModule();
40
+ } catch (error) {
41
+ try {
42
+ return getExpoModule();
43
+ } catch (error) {
44
+ throw new Error(LINKING_ERROR);
45
+ }
46
+ }
47
+ }
package/package.json CHANGED
@@ -1,13 +1,28 @@
1
1
  {
2
2
  "name": "@walletconnect/react-native-compat",
3
3
  "description": "Shims for WalletConnect Protocol in React Native Projects",
4
- "version": "2.10.5-rc-60b8e52",
4
+ "version": "2.10.5-rc-57761a66",
5
5
  "author": "WalletConnect, Inc. <walletconnect.com>",
6
6
  "homepage": "https://github.com/walletconnect/walletconnect-monorepo/",
7
7
  "license": "Apache-2.0",
8
8
  "main": "index.js",
9
9
  "files": [
10
- "dist"
10
+ "dist",
11
+ "android",
12
+ "ios",
13
+ "module",
14
+ "cpp",
15
+ "*.podspec",
16
+ "!ios/build",
17
+ "!android/build",
18
+ "!android/gradle",
19
+ "!android/gradlew",
20
+ "!android/gradlew.bat",
21
+ "!android/local.properties",
22
+ "!**/__tests__",
23
+ "!**/__fixtures__",
24
+ "!**/__mocks__",
25
+ "!**/.*"
11
26
  ],
12
27
  "keywords": [
13
28
  "wallet",
@@ -28,6 +43,17 @@
28
43
  "peerDependencies": {
29
44
  "@react-native-async-storage/async-storage": "*",
30
45
  "@react-native-community/netinfo": "*",
46
+ "expo-application": "*",
31
47
  "react-native-get-random-values": "*"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "expo-application": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "codegenConfig": {
55
+ "name": "RNRNWalletConnectModuleSpec",
56
+ "type": "modules",
57
+ "jsSrcsDir": "."
32
58
  }
33
59
  }
@@ -0,0 +1,41 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-compat"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => "11.0" }
15
+ s.source = { :git => "https://github.com/walletconnect/walletconnect-monorepo.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm}"
18
+
19
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
20
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
21
+ if respond_to?(:install_modules_dependencies, true)
22
+ install_modules_dependencies(s)
23
+ else
24
+ s.dependency "React-Core"
25
+
26
+ # Don't install the dependencies when we run `pod install` in the old architecture.
27
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
28
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
29
+ s.pod_target_xcconfig = {
30
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
31
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
32
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
33
+ }
34
+ s.dependency "React-Codegen"
35
+ s.dependency "RCT-Folly"
36
+ s.dependency "RCTRequired"
37
+ s.dependency "RCTTypeSafety"
38
+ s.dependency "ReactCommon/turbomodule/core"
39
+ end
40
+ end
41
+ end