@walletconnect/react-native-compat 2.17.2-canary-ca-5 → 2.17.2-canary-ca-7

Sign up to get free protection for your applications and to get access to all the features.
@@ -123,7 +123,7 @@ dependencies {
123
123
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0' // Latest stable version
124
124
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0' // For Dispatchers.Main
125
125
  implementation 'com.google.code.gson:gson:2.9.0'
126
- implementation 'com.github.reown-com:yttrium:0.4.2'
126
+ implementation("com.github.reown-com:yttrium:0.4.11")
127
127
  }
128
128
 
129
129
  if (isNewArchitectureEnabled()) {
@@ -7,7 +7,6 @@ import android.content.pm.PackageManager
7
7
  import uniffi.uniffi_yttrium.ChainAbstractionClient
8
8
  import kotlinx.coroutines.*
9
9
  import com.facebook.react.bridge.ReadableMap
10
- import uniffi.uniffi_yttrium.InitTransaction
11
10
  import uniffi.uniffi_yttrium.*
12
11
  import uniffi.yttrium.*
13
12
  import com.google.gson.Gson
@@ -62,10 +61,12 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
62
61
 
63
62
  // ------------------------------ Yttrium Chain Abstraction ------------------------------
64
63
 
64
+ private var availableResponseMap: MutableMap<String, RouteResponseAvailable> = mutableMapOf()
65
+
66
+
65
67
  @ReactMethod
66
- override fun checkRoute(params: ReadableMap, promise: Promise){
68
+ override fun prepare(params: ReadableMap, promise: Promise){
67
69
  System.out.println("checkRoute: Hello from YttriumModule")
68
-
69
70
  GlobalScope.launch(Dispatchers.Main) {
70
71
  try {
71
72
  var projectId = params.getString("projectId") as String
@@ -77,34 +78,23 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
77
78
  val chainId = transactionMap.getString("chainId") ?: ""
78
79
  val txData = transactionMap.getString("data") ?: ""
79
80
  val from = transactionMap.getString("from") ?: ""
80
- val gas = transactionMap.getString("gas") ?: "0"
81
- val gasPrice = transactionMap.getString("gasPrice") ?: "0"
82
- val maxFeePerGas = transactionMap.getString("maxFeePerGas") ?: "0"
83
- val maxPriorityFeePerGas = transactionMap.getString("maxPriorityFeePerGas") ?: "0"
84
- val nonce = transactionMap.getString("nonce") ?: "0"
85
81
  val to = transactionMap.getString("to") ?: ""
86
82
  val value = transactionMap.getString("value") ?: "0"
87
-
88
- val tx = InitTransaction(from, to, value, gas, gasPrice, txData, nonce, maxFeePerGas, maxPriorityFeePerGas, chainId)
89
- val result = client.route(tx)
83
+ val tx = InitialTransaction(chainId, from, to, value, txData)
84
+ val result = client.prepare(tx)
90
85
  System.out.println("checkRoute: result: ")
91
86
  System.out.println(result)
92
87
  when (result) {
93
- is RouteResponse.Success -> {
88
+ is PrepareResponse.Success -> {
94
89
  when (result.v1) {
95
90
  is RouteResponseSuccess.Available -> {
96
91
  val availableResult = (result.v1 as RouteResponseSuccess.Available).v1
97
- val transaction = Transaction(from, to, value, gas, txData, nonce, chainId, gasPrice, maxFeePerGas, maxPriorityFeePerGas)
98
- val uiFields = client.getRouteUiFields(availableResult, transaction, Currency.USD)
92
+ availableResponseMap[availableResult.orchestrationId] = availableResult
99
93
  val gson = Gson()
100
94
  val routesJson: JsonElement = gson.toJsonTree(availableResult)
101
- val routesDetailsJson: JsonElement = gson.toJsonTree(uiFields)
102
- val dataObject = JsonObject()
103
- dataObject.add("routes", routesJson)
104
- dataObject.add("routesDetails", routesDetailsJson)
105
95
  val response = JsonObject()
106
96
  response.addProperty("status", "available")
107
- response.add("data", dataObject)
97
+ response.add("data", routesJson)
108
98
  promise.resolve(gson.toJson(response))
109
99
  }
110
100
  is RouteResponseSuccess.NotRequired -> {
@@ -115,7 +105,7 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
115
105
  }
116
106
  }
117
107
  }
118
- is RouteResponse.Error -> {
108
+ is PrepareResponse.Error -> {
119
109
  System.out.println(result.v1.error.toString())
120
110
  when (result.v1.error.toString()) {
121
111
  "NO_ROUTES_AVAILABLE" -> {
@@ -153,7 +143,7 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
153
143
  }
154
144
 
155
145
  @ReactMethod
156
- override fun checkStatus(params: ReadableMap, promise: Promise){
146
+ override fun status(params: ReadableMap, promise: Promise){
157
147
  System.out.println("checkStatus: Hello from YttriumModule address")
158
148
 
159
149
  GlobalScope.launch(Dispatchers.Main) {
@@ -164,48 +154,118 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
164
154
  var client = ChainAbstractionClient(projectId)
165
155
 
166
156
  when (val result = client.status(orchestrationId)) {
167
- is StatusResponse.Completed -> {
168
- when(result.v1) {
169
- is StatusResponseCompleted -> {
170
- val response = JsonObject()
171
- response.addProperty("status", "completed")
172
- response.addProperty("createdAt", result.v1.createdAt.toString())
173
- val gson = Gson()
174
- promise.resolve(gson.toJson(response))
175
- }
176
- }
157
+ is StatusResponse.Completed -> {
158
+ when (result.v1) {
159
+ is StatusResponseCompleted -> {
160
+ val response = JsonObject()
161
+ response.addProperty("status", "completed")
162
+ response.addProperty("createdAt", result.v1.createdAt.toString())
163
+ val gson = Gson()
164
+ promise.resolve(gson.toJson(response))
165
+ }
177
166
  }
178
- is StatusResponse.Error -> {
179
- when(result.v1) {
180
- is StatusResponseError -> {
181
- val response = JsonObject()
182
- response.addProperty("status", "error")
183
- response.addProperty("createdAt", result.v1.createdAt.toString())
184
- response.addProperty("reason", result.v1.error.toString())
185
- val gson = Gson()
186
- promise.resolve(gson.toJson(response))
187
- }
167
+ }
168
+
169
+ is StatusResponse.Error -> {
170
+ when (result.v1) {
171
+ is StatusResponseError -> {
172
+ val response = JsonObject()
173
+ response.addProperty("status", "error")
174
+ response.addProperty("createdAt", result.v1.createdAt.toString())
175
+ response.addProperty("reason", result.v1.error.toString())
176
+ val gson = Gson()
177
+ promise.resolve(gson.toJson(response))
188
178
  }
189
179
  }
190
- is StatusResponse.Pending -> {
191
- when(result.v1) {
192
- is StatusResponsePending -> {
193
- val response = JsonObject()
194
- response.addProperty("status", "pending")
195
- response.addProperty("createdAt", result.v1.createdAt.toString())
196
- response.addProperty("checkIn", result.v1.checkIn.toString())
197
- val gson = Gson()
198
- promise.resolve(gson.toJson(response))
199
- }
180
+ }
181
+
182
+ is StatusResponse.Pending -> {
183
+ when (result.v1) {
184
+ is StatusResponsePending -> {
185
+ val response = JsonObject()
186
+ response.addProperty("status", "pending")
187
+ response.addProperty("createdAt", result.v1.createdAt.toString())
188
+ response.addProperty("checkIn", result.v1.checkIn.toString())
189
+ val gson = Gson()
190
+ promise.resolve(gson.toJson(response))
200
191
  }
201
192
  }
202
193
  }
194
+ }
203
195
  } catch (e: Exception) {
204
196
  // In case of an error, reject the promise
205
197
  promise.reject("ERROR", "Yttrium checkStatus Error:" + e.message, e)
206
198
  }
207
199
  }
208
200
  }
201
+
202
+ @ReactMethod
203
+ override fun getBridgeDetails(params: ReadableMap, promise: Promise){
204
+ System.out.println("getFulfilmentDetails: Hello from YttriumModule address")
205
+
206
+ GlobalScope.launch(Dispatchers.Main) {
207
+ try {
208
+
209
+ val projectId = params.getString("projectId") as String
210
+ val orchestrationId = params.getString("orchestrationId") as String
211
+ val client = ChainAbstractionClient(projectId)
212
+
213
+ val availableResult = availableResponseMap[orchestrationId] as RouteResponseAvailable
214
+ val uiFields = client.getUiFields(availableResult, Currency.USD)
215
+ val gson = Gson()
216
+ val resultJson: JsonElement = gson.toJsonTree(uiFields)
217
+ promise.resolve(gson.toJson(resultJson))
218
+ } catch (e: Exception) {
219
+ // In case of an error, reject the promise
220
+ promise.reject("ERROR", "Yttrium getFulfilmentDetails Error:" + e.message, e)
221
+ }
222
+ }
223
+ }
224
+
225
+ @ReactMethod
226
+ override fun getERC20Balance(params: ReadableMap, promise: Promise){
227
+ System.out.println("getERC20Balance: Hello from YttriumModule address")
228
+
229
+ GlobalScope.launch(Dispatchers.Main) {
230
+ try {
231
+
232
+ val projectId = params.getString("projectId") as String
233
+ val tokenAddress = params.getString("tokenAddress") as String
234
+ val ownerAddress = params.getString("ownerAddress") as String
235
+ val chainId = params.getString("chainId") as String
236
+ val client = ChainAbstractionClient(projectId)
237
+ val result = client.erc20TokenBalance(chainId, tokenAddress, ownerAddress)
238
+ val gson = Gson()
239
+ val resultJson: JsonElement = gson.toJsonTree(result)
240
+ promise.resolve(gson.toJson(resultJson))
241
+ } catch (e: Exception) {
242
+ // In case of an error, reject the promise
243
+ promise.reject("ERROR", "Yttrium getERC20Balance Error:" + e.message, e)
244
+ }
245
+ }
246
+ }
247
+
248
+ @ReactMethod
249
+ override fun estimateFees(params: ReadableMap, promise: Promise){
250
+ System.out.println("estimateFees: Hello from YttriumModule address")
251
+
252
+ GlobalScope.launch(Dispatchers.Main) {
253
+ try {
254
+
255
+ val projectId = params.getString("projectId") as String
256
+ val chainId = params.getString("chainId") as String
257
+ val client = ChainAbstractionClient(projectId)
258
+ val result = client.estimateFees(chainId)
259
+ val gson = Gson()
260
+ val resultJson: JsonElement = gson.toJsonTree(result)
261
+ promise.resolve(gson.toJson(resultJson))
262
+ } catch (e: Exception) {
263
+ // In case of an error, reject the promise
264
+ promise.reject("ERROR", "Yttrium estimateFees Error:" + e.message, e)
265
+ }
266
+ }
267
+ }
268
+
209
269
  companion object {
210
270
  const val NAME = "RNWalletConnectModule"
211
271
  }
@@ -9,8 +9,12 @@ abstract class RNWalletConnectModuleSpec internal constructor(context: ReactAppl
9
9
  ReactContextBaseJavaModule(context) {
10
10
 
11
11
  abstract fun isAppInstalled(packageName: String?, promise: Promise);
12
- abstract fun checkRoute(params: ReadableMap, promise: Promise);
13
- abstract fun checkStatus(params: ReadableMap, promise: Promise);
12
+ abstract fun prepare(params: ReadableMap, promise: Promise);
13
+ abstract fun status(params: ReadableMap, promise: Promise);
14
+ abstract fun getBridgeDetails(params: ReadableMap, promise: Promise);
15
+ abstract fun estimateFees(params: ReadableMap, promise: Promise);
16
+ abstract fun getERC20Balance(params: ReadableMap, promise: Promise);
17
+
14
18
  protected abstract fun getTypedExportedConstants(): Map<String, String>
15
19
 
16
20
  override fun getConstants(): Map<String, String> {
package/index.js CHANGED
@@ -78,42 +78,7 @@ if (typeof global?.Application === "undefined") {
78
78
  }
79
79
 
80
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
- };
81
+ global.yttrium = NativeModules.Yttrium || NativeModules.RNWalletConnectModule;
117
82
 
118
83
  // eslint-disable-next-line no-console
119
84
  console.log("RN yttrium", global.yttrium);
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-ca-5",
4
+ "version": "2.17.2-canary-ca-7",
5
5
  "author": "WalletConnect, Inc. <walletconnect.com>",
6
6
  "homepage": "https://github.com/walletconnect/walletconnect-monorepo/",
7
7
  "license": "Apache-2.0",