@walletconnect/react-native-compat 2.18.1-canary-exp-3 → 2.18.1-canary-ca-2

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.
@@ -5,15 +5,25 @@ buildscript {
5
5
  repositories {
6
6
  google()
7
7
  mavenCentral()
8
+ maven { url 'https://jitpack.io' }
8
9
  }
9
10
 
10
11
  dependencies {
11
- classpath "com.android.tools.build:gradle:7.2.1"
12
+ classpath "com.android.tools.build:gradle:8.5.1"
12
13
  // noinspection DifferentKotlinGradleVersion
13
14
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
15
  }
15
16
  }
16
17
 
18
+ allprojects {
19
+ repositories {
20
+ google()
21
+ mavenCentral()
22
+ maven { url 'https://jitpack.io' }
23
+ }
24
+ }
25
+
26
+
17
27
  def isNewArchitectureEnabled() {
18
28
  return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
29
  }
@@ -109,6 +119,11 @@ dependencies {
109
119
  //noinspection GradleDynamicVersion
110
120
  implementation "com.facebook.react:react-native:+"
111
121
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
122
+ implementation 'net.java.dev.jna:jna:5.12.1@aar'
123
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0' // Latest stable version
124
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0' // For Dispatchers.Main
125
+ implementation 'com.google.code.gson:gson:2.9.0'
126
+ implementation 'com.github.reown-com:yttrium:0.8.19'
112
127
  }
113
128
 
114
129
  if (isNewArchitectureEnabled()) {
@@ -3,7 +3,17 @@ package com.walletconnect.reactnativemodule
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
4
  import com.facebook.react.bridge.ReactMethod
5
5
  import com.facebook.react.bridge.Promise
6
+ import com.facebook.react.bridge.ReadableArray
7
+ import com.facebook.react.bridge.ReadableMap
6
8
  import android.content.pm.PackageManager
9
+ import uniffi.uniffi_yttrium.ChainAbstractionClient
10
+ import uniffi.yttrium.PrepareResponse
11
+ import kotlinx.coroutines.*
12
+ import uniffi.uniffi_yttrium.*
13
+ import uniffi.yttrium.*
14
+ import com.google.gson.Gson
15
+ import com.google.gson.JsonObject
16
+ import com.google.gson.JsonElement
7
17
 
8
18
  class RNWalletConnectModuleModule internal constructor(context: ReactApplicationContext) :
9
19
  RNWalletConnectModuleSpec(context) {
@@ -49,6 +59,242 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
49
59
  }
50
60
  }
51
61
 
62
+
63
+
64
+ // ------------------------------ Yttrium Chain Abstraction ------------------------------
65
+
66
+ private var prepareAvailableResultsMap: MutableMap<String, PrepareResponseAvailable> = mutableMapOf()
67
+ private var prepareDetailedAvailableResultsMap: MutableMap<String, UiFields> = mutableMapOf()
68
+ private lateinit var client: ChainAbstractionClient
69
+
70
+ @OptIn(DelicateCoroutinesApi::class)
71
+ @ReactMethod
72
+ override fun initialize(params: ReadableMap, promise: Promise){
73
+ GlobalScope.launch(Dispatchers.Main) {
74
+ try {
75
+ var projectId = params.getString("projectId") as String
76
+ var sdkVersion = params.getString("sdkVersion") as String
77
+ var url = params.getString("url") as String
78
+
79
+ client = ChainAbstractionClient(projectId, PulseMetadata(url= url, bundleId = "test", packageName = "test package", sdkVersion= sdkVersion, sdkPlatform = "mobile"))
80
+ promise.resolve(true)
81
+ } catch (e: Exception) {
82
+ // In case of an error, reject the promise
83
+ promise.reject("ERROR", "Yttrium initialize Error:" + e.message, e)
84
+ }
85
+ }
86
+ }
87
+
88
+ @ReactMethod
89
+ override fun prepare(params: ReadableMap, promise: Promise){
90
+ System.out.println("checkRoute: Hello from YttriumModule")
91
+ GlobalScope.launch(Dispatchers.Main) {
92
+ try {
93
+ val transactionMap = params.getMap("transaction")
94
+
95
+ if(transactionMap === null) {
96
+ throw Error("no params")
97
+ }
98
+ // Extract values from the nested transaction map
99
+ val chainId = transactionMap.getString("chainId") ?: ""
100
+ val input = transactionMap.getString("input") ?: ""
101
+ val from = transactionMap.getString("from") ?: ""
102
+ val to = transactionMap.getString("to") ?: ""
103
+ val value = transactionMap.getString("value") ?: "0"
104
+ val result = client.prepare(chainId = chainId, from = from, Call(
105
+ to= to,
106
+ value = value,
107
+ input = input
108
+ ))
109
+
110
+ when(result) {
111
+ is PrepareResponse.Success -> {
112
+ when (result.v1) {
113
+ is PrepareResponseSuccess.Available -> {
114
+ val availableResult = (result.v1 as PrepareResponseSuccess.Available).v1;
115
+ prepareAvailableResultsMap[availableResult.orchestrationId] = availableResult;
116
+ }
117
+
118
+ is PrepareResponseSuccess.NotRequired -> {
119
+ println("not required")
120
+ }
121
+ }
122
+ }
123
+ is PrepareResponse.Error -> {
124
+ println("prepare error: ")
125
+ println(result.v1.error)
126
+ }
127
+ }
128
+ println("checkRoute: result: ")
129
+ println(result)
130
+
131
+ val gson = Gson()
132
+ val jsonResult = gson.toJson(result)
133
+ promise.resolve(jsonResult)
134
+ } catch (e: Exception) {
135
+ // In case of an error, reject the promise
136
+ promise.reject("ERROR", "Yttrium checkRoute Error:" + e.message, e)
137
+ }
138
+ }
139
+ }
140
+
141
+ @ReactMethod
142
+ override fun prepareDetailed(params: ReadableMap, promise: Promise){
143
+ System.out.println("prepareDetailed: Hello from YttriumModule")
144
+ GlobalScope.launch(Dispatchers.Main) {
145
+ try {
146
+ val transactionMap = params.getMap("transaction")
147
+
148
+ if(transactionMap === null) {
149
+ throw Error("no params")
150
+ }
151
+ // Extract values from the nested transaction map
152
+ val chainId = transactionMap.getString("chainId") ?: ""
153
+ val input = transactionMap.getString("input") ?: ""
154
+ val from = transactionMap.getString("from") ?: ""
155
+ val to = transactionMap.getString("to") ?: ""
156
+ val value = transactionMap.getString("value") ?: "0"
157
+ val result = client.prepareDetailed(chainId = chainId, from = from, Call(
158
+ to= to,
159
+ value = value,
160
+ input = input
161
+ ), Currency.USD)
162
+
163
+
164
+ println("prepareDetailed: result: ")
165
+ println(result)
166
+
167
+ when(result) {
168
+ is PrepareDetailedResponse.Success -> {
169
+ when (result.v1) {
170
+ is PrepareDetailedResponseSuccess.Available -> {
171
+ val availableResult = (result.v1 as PrepareDetailedResponseSuccess.Available).v1
172
+ prepareDetailedAvailableResultsMap[availableResult.routeResponse.orchestrationId] = availableResult
173
+ }
174
+ is PrepareDetailedResponseSuccess.NotRequired -> {
175
+ println("prepareDetailed NotRequired: ")
176
+ }
177
+ }
178
+ }
179
+ is PrepareDetailedResponse.Error -> {
180
+ println("prepareDetailed error: ")
181
+ println(result.v1.error)
182
+ }
183
+ }
184
+
185
+ val gson = Gson()
186
+ val jsonResult = gson.toJson(result)
187
+ promise.resolve(jsonResult)
188
+ } catch (e: Exception) {
189
+ // In case of an error, reject the promise
190
+ promise.reject("ERROR", "Yttrium checkRoute Error:" + e.message, e)
191
+ }
192
+ }
193
+ }
194
+
195
+ @ReactMethod
196
+ override fun status(params: ReadableMap, promise: Promise){
197
+ System.out.println("checkStatus: Hello from YttriumModule address")
198
+
199
+ GlobalScope.launch(Dispatchers.Main) {
200
+ try {
201
+ var orchestrationId = params.getString("orchestrationId") as String
202
+ val result = client.status(orchestrationId)
203
+ println("checkRoute: status: ")
204
+ println(result)
205
+
206
+ val gson = Gson()
207
+ val jsonResult = gson.toJson(result)
208
+ promise.resolve(jsonResult)
209
+ } catch (e: Exception) {
210
+ // In case of an error, reject the promise
211
+ promise.reject("ERROR", "Yttrium checkStatus Error:" + e.message, e)
212
+ }
213
+ }
214
+ }
215
+
216
+ @ReactMethod
217
+ override fun getBridgeDetails(params: ReadableMap, promise: Promise){
218
+ System.out.println("getFulfilmentDetails: Hello from YttriumModule address")
219
+
220
+ GlobalScope.launch(Dispatchers.Main) {
221
+ try {
222
+ val orchestrationId = params.getString("orchestrationId") as String
223
+
224
+ val availableResult = prepareAvailableResultsMap[orchestrationId]
225
+ val uiFields = availableResult.let {
226
+ if (it != null) {
227
+ client.getUiFields(it, Currency.USD)
228
+ }
229
+ }
230
+ val gson = Gson()
231
+ val resultJson: JsonElement = gson.toJsonTree(uiFields)
232
+ promise.resolve(gson.toJson(resultJson))
233
+ } catch (e: Exception) {
234
+ // In case of an error, reject the promise
235
+ promise.reject("ERROR", "Yttrium getFulfilmentDetails Error:" + e.message, e)
236
+ }
237
+ }
238
+ }
239
+
240
+ @ReactMethod
241
+ override fun getERC20Balance(params: ReadableMap, promise: Promise){
242
+ System.out.println("getERC20Balance: Hello from YttriumModule address")
243
+
244
+ GlobalScope.launch(Dispatchers.Main) {
245
+ try {
246
+ val tokenAddress = params.getString("tokenAddress") as String
247
+ val ownerAddress = params.getString("ownerAddress") as String
248
+ val chainId = params.getString("chainId") as String
249
+ val result = client.erc20TokenBalance(chainId = chainId, token = tokenAddress, owner = ownerAddress)
250
+ val gson = Gson()
251
+ val resultJson: JsonElement = gson.toJsonTree(result)
252
+ promise.resolve(gson.toJson(resultJson))
253
+ } catch (e: Exception) {
254
+ // In case of an error, reject the promise
255
+ promise.reject("ERROR", "Yttrium getERC20Balance Error:" + e.message, e)
256
+ }
257
+ }
258
+ }
259
+
260
+ private fun getListOfStrings(params: ReadableMap, key: String): List<String> {
261
+ val readableArray: ReadableArray? = params.getArray(key)
262
+ return readableArray?.toArrayList()?.map { it as String } ?: emptyList()
263
+ }
264
+
265
+ @ReactMethod
266
+ override fun execute(params: ReadableMap, promise: Promise){
267
+ System.out.println("getERC20Balance: Hello from YttriumModule address")
268
+
269
+ GlobalScope.launch(Dispatchers.Main) {
270
+ try {
271
+ val orchestrationId = params.getString("orchestrationId") as String
272
+ val bridgeSignedTransactions = getListOfStrings(params, "bridgeSignedTransactions")
273
+ val initialSignedTransaction = params.getString("initialSignedTransaction") as String
274
+
275
+
276
+ val prepareDetailedResult = prepareDetailedAvailableResultsMap[orchestrationId]
277
+
278
+ val result =
279
+ prepareDetailedResult?.let {
280
+ client.execute(
281
+ uiFields = it,
282
+ routeTxnSigs = bridgeSignedTransactions,
283
+ initialTxnSig = initialSignedTransaction,
284
+ )
285
+ }
286
+
287
+ val gson = Gson()
288
+ val resultJson: JsonElement = gson.toJsonTree(result)
289
+ promise.resolve(gson.toJson(resultJson))
290
+ } catch (e: Exception) {
291
+ // In case of an error, reject the promise
292
+ promise.reject("ERROR", "Yttrium getERC20Balance Error:" + e.message, e)
293
+ }
294
+ }
295
+ }
296
+
297
+
52
298
  companion object {
53
299
  const val NAME = "RNWalletConnectModule"
54
300
  }
@@ -3,15 +3,25 @@ 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 initialize(params: ReadableMap, promise: Promise);
13
+ abstract fun prepare(params: ReadableMap, promise: Promise);
14
+ abstract fun prepareDetailed(params: ReadableMap, promise: Promise);
15
+ abstract fun status(params: ReadableMap, promise: Promise);
16
+ abstract fun getBridgeDetails(params: ReadableMap, promise: Promise);
17
+ abstract fun getERC20Balance(params: ReadableMap, promise: Promise);
18
+ abstract fun execute(params: ReadableMap, promise: Promise);
19
+
11
20
  protected abstract fun getTypedExportedConstants(): Map<String, String>
12
21
 
13
22
  override fun getConstants(): Map<String, String> {
14
23
  val constants: Map<String, String> = getTypedExportedConstants()
15
24
  return constants
16
25
  }
26
+
17
27
  }
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,9 @@ 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
+ global.yttrium = NativeModules.Yttrium || NativeModules.RNWalletConnectModule;
82
+
83
+ // eslint-disable-next-line no-console
84
+ 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,35 @@
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(status:(id)params
10
+ resolve:(RCTPromiseResolveBlock)resolve
11
+ reject:(RCTPromiseRejectBlock)reject)
12
+
13
+ RCT_EXTERN_METHOD(prepare:(id)params
14
+ resolve:(RCTPromiseResolveBlock)resolve
15
+ reject:(RCTPromiseRejectBlock)reject)
16
+
17
+ RCT_EXTERN_METHOD(getBridgeDetails:(id)params
18
+ resolve:(RCTPromiseResolveBlock)resolve
19
+ reject:(RCTPromiseRejectBlock)reject)
20
+
21
+ RCT_EXTERN_METHOD(getERC20Balance:(id)params
22
+ resolve:(RCTPromiseResolveBlock)resolve
23
+ reject:(RCTPromiseRejectBlock)reject)
24
+
25
+ RCT_EXTERN_METHOD(estimateFees:(id)params
26
+ resolve:(RCTPromiseResolveBlock)resolve
27
+ reject:(RCTPromiseRejectBlock)reject)
28
+
29
+
30
+ + (BOOL)requiresMainQueueSetup
31
+ {
32
+ return NO;
33
+ }
34
+
35
+ @end
@@ -0,0 +1,304 @@
1
+ import YttriumWrapper
2
+
3
+
4
+ @objc(Yttrium)
5
+ class Yttrium: NSObject {
6
+
7
+ @objc
8
+ func status(_ 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 convertRouteResponseAvailableToDictionary(_ routeResponse: RouteResponseAvailable) -> [String: Any] {
53
+ func transactionToDictionary(_ transaction: YttriumWrapper.Transaction) -> [String: Any] {
54
+ return [
55
+ "chainId": transaction.chainId,
56
+ "from": transaction.from,
57
+ "to": transaction.to,
58
+ "value": transaction.value,
59
+ "input": transaction.input,
60
+ "gasLimit": transaction.gasLimit,
61
+ "nonce": transaction.nonce
62
+ ]
63
+ }
64
+
65
+ func fundingMetadataToDictionary(_ metadata: YttriumWrapper.FundingMetadata) -> [String: Any] {
66
+ return [
67
+ "chainId": metadata.chainId,
68
+ "tokenContract": metadata.tokenContract,
69
+ "symbol": metadata.symbol,
70
+ "amount": metadata.amount,
71
+ "bridgingFee": metadata.bridgingFee,
72
+ "decimals": metadata.decimals
73
+ ]
74
+ }
75
+
76
+ func initialTransactionMetadataToDictionary(_ metadata: YttriumWrapper.InitialTransactionMetadata) -> [String: Any] {
77
+ return [
78
+ "transferTo": metadata.transferTo,
79
+ "amount": metadata.amount,
80
+ "tokenContract": metadata.tokenContract,
81
+ "symbol": metadata.symbol,
82
+ "decimals": metadata.decimals
83
+ ]
84
+ }
85
+
86
+ func metadataToDictionary(_ metadata: YttriumWrapper.Metadata) -> [String: Any] {
87
+ return [
88
+ "fundingFrom": metadata.fundingFrom.map { fundingMetadataToDictionary($0) },
89
+ "initialTransaction": initialTransactionMetadataToDictionary(metadata.initialTransaction),
90
+ "checkIn": metadata.checkIn
91
+ ]
92
+ }
93
+
94
+ return [
95
+ "orchestrationId": routeResponse.orchestrationId,
96
+ "initialTransaction": transactionToDictionary(routeResponse.initialTransaction),
97
+ "transactions": routeResponse.transactions.map { transactionToDictionary($0) },
98
+ "metadata": metadataToDictionary(routeResponse.metadata)
99
+ ]
100
+ }
101
+
102
+ private var availableResponseDictionary: [String: RouteResponseAvailable] = [:]
103
+
104
+ @objc
105
+ func prepare(_ params: Any, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
106
+ print("checkRoute called with", params)
107
+ let dict = params as? [String: Any]
108
+
109
+ if let transactionData = dict?["transaction"] as? [String: String],
110
+ let from = transactionData["from"] ?? "" as Optional,
111
+ let chainId = transactionData["chainId"] ?? "" as Optional,
112
+ let data = transactionData["data"] ?? "" as Optional,
113
+ let value = transactionData["value"] ?? "" as Optional,
114
+ let to = transactionData["to"] ?? "" as Optional,
115
+ let projectId = dict?["projectId"] as? String {
116
+
117
+ let client = ChainAbstractionClient.init(projectId: projectId)
118
+ print("created client, checking route...")
119
+ Task {
120
+ do {
121
+ let transaction = InitialTransaction.init(chainId: chainId, from: from, to: to, value: value, input: data)
122
+
123
+ let routeResponseSuccess = try await client.prepare(initialTransaction: transaction)
124
+ print("result", routeResponseSuccess)
125
+
126
+ switch routeResponseSuccess {
127
+ case let .success(routeResponse):
128
+ switch routeResponse {
129
+ case let .available(availableResponse):
130
+
131
+ availableResponseDictionary[availableResponse.orchestrationId] = availableResponse;
132
+ // let uiFields = try await client.getRouteUiFields(routeResponse: availableResponse, initialTransaction: Transaction(from: from, to: to, value: value, gas: gas, data: data, nonce: nonce, chainId: chainId, gasPrice: gasPrice, maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: maxPriorityFeePerGas), currency: Currency.usd)
133
+ //
134
+ // let routesDetails = convertRouteUiFieldsToDictionary(uiFields)
135
+ // print("available result", availableResponse)
136
+ // print("ui_fields_json", routesDetails)
137
+ let responseDict = convertRouteResponseAvailableToDictionary(availableResponse)
138
+ print("parsed result dictionary", responseDict)
139
+ resolve(["status": "available", "data": responseDict])
140
+ // "routesDetails": routesDetails
141
+
142
+ case .notRequired(_):
143
+ print("not required")
144
+ resolve(["status": "not_required"])
145
+ }
146
+ case let .error(routeResponse):
147
+ switch routeResponse.error {
148
+ case BridgingError.insufficientFunds:
149
+ let responseDict: [String: Any] = [
150
+ "status": "error",
151
+ "reason": "insufficientFunds"
152
+ ]
153
+ resolve(responseDict)
154
+ case BridgingError.insufficientGasFunds:
155
+ let responseDict: [String: Any] = [
156
+ "status": "error",
157
+ "reason": "insufficientGasFunds"
158
+ ]
159
+ resolve(responseDict)
160
+ case BridgingError.noRoutesAvailable:
161
+ let responseDict: [String: Any] = [
162
+ "status": "error",
163
+ "reason": "noRoutesAvailable"
164
+ ]
165
+ resolve(responseDict)
166
+ }
167
+ print(routeResponse)
168
+ print(routeResponse.error)
169
+ }
170
+ // resolve(result)
171
+ } catch {
172
+ print("Error occurred: \(error)")
173
+ print(error)
174
+ reject("yttrium err", "yttrium_err", error)
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ func convertUiFieldsToDictionary(_ uiFields: UiFields) -> [String: Any] {
181
+ func feeEstimatedTransactionToDictionary(_ transaction: YttriumWrapper.FeeEstimatedTransaction) -> [String: Any] {
182
+ return [
183
+ "chainId": transaction.chainId,
184
+ "from": transaction.from,
185
+ "to": transaction.to,
186
+ "value": transaction.value,
187
+ "input": transaction.input,
188
+ "gasLimit": transaction.gasLimit,
189
+ "nonce": transaction.nonce,
190
+ "maxFeePerGas": transaction.maxFeePerGas,
191
+ "maxPriorityFeePerGas": transaction.maxPriorityFeePerGas
192
+ ]
193
+ }
194
+
195
+ func amountToDictionary(_ amount: YttriumWrapper.Amount) -> [String: Any] {
196
+ return [
197
+ "symbol": amount.symbol,
198
+ "amount": amount.amount,
199
+ "unit": amount.unit,
200
+ "formatted": amount.formatted,
201
+ "formattedAlt": amount.formattedAlt
202
+ ]
203
+ }
204
+
205
+ func transactionFeeToDictionary(_ fee: YttriumWrapper.TransactionFee) -> [String: Any] {
206
+ return [
207
+ "fee": amountToDictionary(fee.fee),
208
+ "localFee": amountToDictionary(fee.localFee)
209
+ ]
210
+ }
211
+
212
+ func txnDetailsToDictionary(_ txnDetails: YttriumWrapper.TxnDetails) -> [String: Any] {
213
+ return [
214
+ "transaction": feeEstimatedTransactionToDictionary(txnDetails.transaction),
215
+ "fee": transactionFeeToDictionary(txnDetails.fee)
216
+ ]
217
+ }
218
+
219
+ return [
220
+ "route": uiFields.route.map { txnDetailsToDictionary($0) },
221
+ "localRouteTotal": amountToDictionary(uiFields.localRouteTotal),
222
+ "bridge": uiFields.bridge.map { transactionFeeToDictionary($0) },
223
+ "localBridgeTotal": amountToDictionary(uiFields.localBridgeTotal),
224
+ "initial": txnDetailsToDictionary(uiFields.initial),
225
+ "localTotal": amountToDictionary(uiFields.localTotal)
226
+ ]
227
+ }
228
+
229
+ @objc
230
+ func getBridgeDetails(_ params: Any, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
231
+ print("getBridgeDetails called with", params)
232
+ let dict = params as? [String: String]
233
+
234
+ if let orchestrationId = dict?["orchestrationId"] ?? "" as Optional,
235
+ let projectId = dict?["projectId"] as? String {
236
+
237
+ let client = ChainAbstractionClient.init(projectId: projectId)
238
+ print("created client, getting UI fields...")
239
+ Task {
240
+ do {
241
+
242
+ let availableResponse = availableResponseDictionary[orchestrationId]!
243
+ let uiFields = try await client.getUiFields(routeResponse: availableResponse, currency: Currency.usd)
244
+ let uiFIeldsDict = convertUiFieldsToDictionary(uiFields)
245
+ print("getBridgeDetails result", uiFields)
246
+ resolve(uiFIeldsDict)
247
+ } catch {
248
+ print("Error occurred: \(error)")
249
+ print(error)
250
+ reject("yttrium err", "yttrium_err getBridgeDetails", error)
251
+ }
252
+ }
253
+ }
254
+ }
255
+
256
+ @objc
257
+ func getERC20Balance(_ params: Any, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
258
+ print("getERC20Balance called with", params)
259
+ let dict = params as? [String: String]
260
+
261
+ if let tokenAddress = dict?["tokenAddress"] ?? "" as Optional,
262
+ let ownerAddress = dict?["ownerAddress"] ?? "" as Optional,
263
+ let chainId = dict?["chainId"] ?? "" as Optional,
264
+ let projectId = dict?["projectId"] as? String {
265
+
266
+ let client = ChainAbstractionClient.init(projectId: projectId)
267
+ Task {
268
+ do {
269
+ let balance = try await client.erc20TokenBalance(chainId: chainId, token: tokenAddress, owner: ownerAddress)
270
+ print("getERC20Balance result", balance)
271
+ resolve(balance)
272
+ } catch {
273
+ print("Error occurred: \(error)")
274
+ print(error)
275
+ reject("yttrium err", "yttrium_err getERC20Balance", error)
276
+ }
277
+ }
278
+ }
279
+ }
280
+
281
+ @objc
282
+ func estimateFees(_ params: Any, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
283
+ print("getERC20Balance called with", params)
284
+ let dict = params as? [String: String]
285
+
286
+ if let chainId = dict?["chainId"] ?? "" as Optional,
287
+ let projectId = dict?["projectId"] as? String {
288
+
289
+ let client = ChainAbstractionClient.init(projectId: projectId)
290
+ Task {
291
+ do {
292
+ let fees = try await client.estimateFees(chainId: chainId)
293
+ print("estimateFees result", fees)
294
+ resolve(["maxFeePerGas": fees.maxFeePerGas, "maxPriorityFeePerGas": fees.maxPriorityFeePerGas])
295
+ } catch {
296
+ print("Error occurred: \(error)")
297
+ print(error)
298
+ reject("yttrium err", "yttrium_err estimateFees", error)
299
+ }
300
+ }
301
+ }
302
+ }
303
+
304
+ }
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.18.1-canary-exp-3",
4
+ "version": "2.18.1-canary-ca-2",
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.8.35'
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.