@walletconnect/react-native-compat 2.17.2-canary-rcnt-3 → 2.17.2-canary-ca-0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,14 @@ 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.ReadableMap
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 checkRoute(params: ReadableMap, promise: Promise);
13
+ abstract fun checkStatus(params: ReadableMap, promise: Promise);
11
14
  protected abstract fun getTypedExportedConstants(): Map<String, String>
12
15
 
13
16
  override fun getConstants(): Map<String, String> {
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { NativeModules } from "react-native";
1
2
  import { getApplicationModule } from "./module";
2
3
 
3
4
  // Polyfill TextEncode / TextDecode
@@ -75,3 +76,44 @@ if (typeof global?.Application === "undefined") {
75
76
  console.error("react-native-compat: Application module is not available");
76
77
  }
77
78
  }
79
+
80
+ // iOS uses Yttrium, Android uses RNWalletConnectModule
81
+ const yttrium = NativeModules.Yttrium || NativeModules.RNWalletConnectModule;
82
+
83
+ export async function checkRoute(params) {
84
+ if (!yttrium) {
85
+ throw new Error("RN Yttrium is not correctly linked");
86
+ }
87
+
88
+ const result = await yttrium?.checkRoute(params);
89
+ return parseResult(result);
90
+ }
91
+
92
+ export async function checkStatus(params) {
93
+ if (!yttrium) {
94
+ throw new Error("RN Yttrium is not correctly linked");
95
+ }
96
+
97
+ const result = await yttrium?.checkStatus(params);
98
+ return parseResult(result);
99
+ }
100
+
101
+ function parseResult(result) {
102
+ if (typeof result === "undefined") return;
103
+
104
+ // iOS returns parsed JSON object, while Android returns stringified
105
+ if (typeof result === "string") {
106
+ try {
107
+ return JSON.parse(result);
108
+ } catch (e) {}
109
+ }
110
+ return result;
111
+ }
112
+
113
+ global.yttrium = {
114
+ checkRoute,
115
+ checkStatus,
116
+ };
117
+
118
+ // eslint-disable-next-line no-console
119
+ console.log("RN yttrium", global.yttrium);
@@ -0,0 +1,2 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTViewManager.h>
package/ios/Yttrium.mm ADDED
@@ -0,0 +1,22 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(Yttrium, NSObject)
4
+
5
+ //RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
6
+ // withResolver:(RCTPromiseResolveBlock)resolve
7
+ // withRejecter:(RCTPromiseRejectBlock)reject)
8
+ //
9
+ RCT_EXTERN_METHOD(checkStatus:(id)params
10
+ resolve:(RCTPromiseResolveBlock)resolve
11
+ reject:(RCTPromiseRejectBlock)reject)
12
+
13
+ RCT_EXTERN_METHOD(checkRoute:(id)params
14
+ resolve:(RCTPromiseResolveBlock)resolve
15
+ reject:(RCTPromiseRejectBlock)reject)
16
+
17
+ + (BOOL)requiresMainQueueSetup
18
+ {
19
+ return NO;
20
+ }
21
+
22
+ @end
@@ -0,0 +1,154 @@
1
+ import YttriumWrapper
2
+
3
+
4
+ @objc(Yttrium)
5
+ class Yttrium: NSObject {
6
+
7
+ @objc
8
+ func checkStatus(_ params: Any, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
9
+ print("checkStatus called with", params )
10
+ if let dict = params as? [String: Any],
11
+ let projectId = dict["projectId"] as? String,
12
+ let orchestrationId = dict["orchestrationId"] as? String {
13
+ let client = ChainAbstractionClient.init(projectId: projectId)
14
+ Task {
15
+ do {
16
+ let statusResponse = try await client.status(orchestrationId: orchestrationId)
17
+
18
+ switch statusResponse {
19
+ case let .completed(statusResponseCompleted):
20
+ print("status response completed", statusResponseCompleted)
21
+ let responseDict: [String: Any] = [
22
+ "createdAt": statusResponseCompleted.createdAt,
23
+ "status": "completed"
24
+ ]
25
+ resolve(responseDict)
26
+ case let .error(statusResponseError):
27
+ print("status response error", statusResponseError)
28
+ let responseDict: [String: Any] = [
29
+ "createdAt": statusResponseError.createdAt,
30
+ "reason": statusResponseError.error,
31
+ "status": "error"
32
+ ]
33
+ resolve(responseDict)
34
+ case let .pending(statusResponsePending):
35
+ print("status response pending", statusResponsePending)
36
+ let responseDict: [String: Any] = [
37
+ "createdAt": statusResponsePending.createdAt,
38
+ "checkIn": statusResponsePending.checkIn,
39
+ "status": "pending"
40
+ ]
41
+ resolve(responseDict)
42
+ }
43
+ } catch {
44
+ print("Error occurred: \(error)")
45
+ print(error)
46
+ reject("checkStatus err", "checkStatus", error)
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ func availableResponseToDictionary(_ response: YttriumWrapper.RouteResponseAvailable) -> [String: Any] {
53
+ return [
54
+ "orchestrationId": response.orchestrationId,
55
+ "transactions": response.transactions.map { transaction in
56
+ return [
57
+ "from": transaction.from,
58
+ "to": transaction.to,
59
+ "value": transaction.value,
60
+ "gas": transaction.gas,
61
+ "data": transaction.data,
62
+ "nonce": transaction.nonce,
63
+ "chainId": transaction.chainId,
64
+ "gasPrice": transaction.gasPrice,
65
+ "maxFeePerGas": transaction.maxFeePerGas,
66
+ "maxPriorityFeePerGas": transaction.maxPriorityFeePerGas,
67
+ ]
68
+ },
69
+ "metadata": [
70
+ "fundingFrom": response.metadata.fundingFrom.map { funding in
71
+ return [
72
+ "chainId": funding.chainId,
73
+ "tokenContract": funding.tokenContract,
74
+ "symbol": funding.symbol,
75
+ "amount": funding.amount,
76
+ ]
77
+ }
78
+ ],
79
+ "checkIn": response.metadata.checkIn,
80
+ ]
81
+ }
82
+
83
+ @objc
84
+ func checkRoute(_ params: Any, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
85
+ print("checkRoute called with", params)
86
+ if let dict = params as? [String: Any],
87
+ let transactionData = dict["transaction"] as? [String: Any],
88
+ let from = transactionData["from"] as? FfiAddress,
89
+ let chainId = transactionData["chainId"] as? String,
90
+ let data = transactionData["data"] as? FfiBytes,
91
+ let gasPrice = transactionData["gasPrice"] as? String,
92
+ let gas = transactionData["gas"] as? Ffiu64,
93
+ let value = transactionData["value"] as? Ffiu256,
94
+ let to = transactionData["to"] as? FfiAddress,
95
+ let maxFeePerGas = transactionData["maxFeePerGas"] as? Ffiu256,
96
+ let maxPriorityFeePerGas = transactionData["maxPriorityFeePerGas"] as? Ffiu256,
97
+ let nonce = transactionData["nonce"] as? Ffiu64,
98
+ let projectId = dict["projectId"] as? String {
99
+
100
+
101
+ let client = ChainAbstractionClient.init(projectId: projectId)
102
+ print("created client, checking route...")
103
+ Task {
104
+ do {
105
+ let transaction = InitTransaction.init(from: from, to: to, value: value, gas: gas, gasPrice: gasPrice, data: data, nonce: nonce, maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: maxPriorityFeePerGas, chainId: chainId)
106
+
107
+ let routeResponseSuccess = try await client.route(transaction: transaction)
108
+ print("result", routeResponseSuccess)
109
+
110
+ switch routeResponseSuccess {
111
+ case let .success(routeResponse):
112
+ switch routeResponse {
113
+ case let .available(availableResponse):
114
+ let responseDict = availableResponseToDictionary(availableResponse)
115
+ resolve(["status": "available", "data": responseDict])
116
+ case .notRequired(_):
117
+ print("not required")
118
+ resolve(["status": "not_required"])
119
+ }
120
+ case let .error(routeResponse):
121
+ switch routeResponse.error {
122
+ case BridgingError.insufficientFunds:
123
+ let responseDict: [String: Any] = [
124
+ "status": "error",
125
+ "reason": "insufficientFunds"
126
+ ]
127
+ resolve(responseDict)
128
+ case BridgingError.insufficientGasFunds:
129
+ let responseDict: [String: Any] = [
130
+ "status": "error",
131
+ "reason": "insufficientGasFunds"
132
+ ]
133
+ resolve(responseDict)
134
+ case BridgingError.noRoutesAvailable:
135
+ let responseDict: [String: Any] = [
136
+ "status": true,
137
+ "reason": "noRoutesAvailable"
138
+ ]
139
+ resolve(responseDict)
140
+ }
141
+ print(routeResponse)
142
+ print(routeResponse.error)
143
+ }
144
+ // resolve(result)
145
+ } catch {
146
+ print("Error occurred: \(error)")
147
+ print(error)
148
+ reject("yttrium err", "yttrium_err", error)
149
+ }
150
+ }
151
+ }
152
+
153
+ }
154
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@walletconnect/react-native-compat",
3
3
  "description": "Shims for WalletConnect Protocol in React Native Projects",
4
- "version": "2.17.2-canary-rcnt-3",
4
+ "version": "2.17.2-canary-ca-0",
5
5
  "author": "WalletConnect, Inc. <walletconnect.com>",
6
6
  "homepage": "https://github.com/walletconnect/walletconnect-monorepo/",
7
7
  "license": "Apache-2.0",
@@ -14,7 +14,8 @@ Pod::Spec.new do |s|
14
14
  s.platforms = { :ios => "11.0", :visionos => "1.0" }
15
15
  s.source = { :git => "https://github.com/walletconnect/walletconnect-monorepo.git", :tag => "#{s.version}" }
16
16
 
17
- s.source_files = "ios/**/*.{h,m,mm}"
17
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
18
+ s.dependency 'YttriumWrapper' , '0.2.22'
18
19
 
19
20
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
20
21
  # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.