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

Sign up to get free protection for your applications and to get access to all the features.
@@ -109,6 +109,10 @@ dependencies {
109
109
  //noinspection GradleDynamicVersion
110
110
  implementation "com.facebook.react:react-native:+"
111
111
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
112
+ implementation 'net.java.dev.jna:jna:5.12.1@aar'
113
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0' // Latest stable version
114
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0' // For Dispatchers.Main
115
+ implementation 'com.google.code.gson:gson:2.9.0'
112
116
  }
113
117
 
114
118
  if (isNewArchitectureEnabled()) {
@@ -4,6 +4,21 @@ import com.facebook.react.bridge.ReactApplicationContext
4
4
  import com.facebook.react.bridge.ReactMethod
5
5
  import com.facebook.react.bridge.Promise
6
6
  import android.content.pm.PackageManager
7
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
8
+ import uniffi.uniffi_yttrium.ChainAbstractionClient
9
+ import kotlinx.coroutines.*
10
+ import com.facebook.react.bridge.ReadableMap
11
+ import uniffi.uniffi_yttrium.FfiAddress
12
+ import uniffi.uniffi_yttrium.FfiBytes
13
+ import uniffi.uniffi_yttrium.Ffiu64
14
+ import uniffi.uniffi_yttrium.InitTransaction
15
+ import uniffi.uniffi_yttrium.*
16
+ import uniffi.yttrium.*
17
+ import kotlin.jvm.internal.Intrinsics.Kotlin
18
+ import com.facebook.react.bridge.Arguments
19
+ import com.google.gson.Gson
20
+ import com.google.gson.JsonObject
21
+ import com.google.gson.JsonElement
7
22
 
8
23
  class RNWalletConnectModuleModule internal constructor(context: ReactApplicationContext) :
9
24
  RNWalletConnectModuleSpec(context) {
@@ -49,6 +64,147 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
49
64
  }
50
65
  }
51
66
 
67
+
68
+
69
+ // ------------------------------ Yttrium Chain Abstraction ------------------------------
70
+
71
+ @ReactMethod
72
+ override fun checkRoute(params: ReadableMap, promise: Promise){
73
+ System.out.println("checkRoute: Hello from YttriumModule")
74
+
75
+ GlobalScope.launch(Dispatchers.Main) {
76
+ try {
77
+ var projectId = params.getString("projectId") as String
78
+ val transactionMap = params.getMap("transaction")
79
+ var client = ChainAbstractionClient(projectId)
80
+
81
+ if (transactionMap != null) {
82
+ // Extract values from the nested transaction map
83
+ val chainId = transactionMap.getString("chainId") ?: ""
84
+ val txData = transactionMap.getString("data") ?: ""
85
+ val from = transactionMap.getString("from") ?: ""
86
+ val gas = transactionMap.getString("gas") ?: "0"
87
+ val gasPrice = transactionMap.getString("gasPrice") ?: "0"
88
+ val maxFeePerGas = transactionMap.getString("maxFeePerGas") ?: "0"
89
+ val maxPriorityFeePerGas = transactionMap.getString("maxPriorityFeePerGas") ?: "0"
90
+ val nonce = transactionMap.getString("nonce") ?: "0"
91
+ val to = transactionMap.getString("to") ?: ""
92
+ val value = transactionMap.getString("value") ?: "0"
93
+
94
+ val tx = InitTransaction(from, to, value, gas, gasPrice, txData, nonce, maxFeePerGas, maxPriorityFeePerGas, chainId)
95
+ val result = client.route(tx)
96
+ System.out.println("checkRoute: result: ")
97
+ System.out.println(result)
98
+ when (result) {
99
+ is RouteResponse.Success -> {
100
+ when (result.v1) {
101
+ is RouteResponseSuccess.Available -> {
102
+ val gson = Gson()
103
+ val jsonElement: JsonElement = gson.toJsonTree(result.v1.v1)
104
+ val response = JsonObject()
105
+ response.addProperty("status", "available")
106
+ response.add("data", jsonElement)
107
+ promise.resolve(gson.toJson(response))
108
+ }
109
+ is RouteResponseSuccess.NotRequired -> {
110
+ val response = JsonObject()
111
+ response.addProperty("status", "not_required")
112
+ val gson = Gson()
113
+ promise.resolve(gson.toJson(response))
114
+ }
115
+ }
116
+ }
117
+ is RouteResponse.Error -> {
118
+ System.out.println(result.v1.error.toString())
119
+ when (result.v1.error.toString()) {
120
+ "NO_ROUTES_AVAILABLE" -> {
121
+ val response = JsonObject()
122
+ response.addProperty("status", "error")
123
+ response.addProperty("reason", "noRoutesAvailable")
124
+ val gson = Gson()
125
+ promise.resolve(gson.toJson(response))
126
+ }
127
+ "INSUFFICIENT_FUNDS" -> {
128
+ val response = JsonObject()
129
+ response.addProperty("status", "error")
130
+ response.addProperty("reason", "insufficientFunds")
131
+ val gson = Gson()
132
+ promise.resolve(gson.toJson(response))
133
+ }
134
+ "INSUFFICIENT_GAS_FUNDS" -> {
135
+ val response = JsonObject()
136
+ response.addProperty("status", "error")
137
+ response.addProperty("reason", "insufficientGasFunds")
138
+ val gson = Gson()
139
+ promise.resolve(gson.toJson(response))
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ }
146
+ // Resolve the promise with the result
147
+ } catch (e: Exception) {
148
+ // In case of an error, reject the promise
149
+ promise.reject("ERROR", "Yttrium checkRoute Error:" + e.message, e)
150
+ }
151
+ }
152
+ }
153
+
154
+ @ReactMethod
155
+ override fun checkStatus(params: ReadableMap, promise: Promise){
156
+ System.out.println("checkStatus: Hello from YttriumModule address")
157
+
158
+ GlobalScope.launch(Dispatchers.Main) {
159
+ try {
160
+
161
+ var projectId = params.getString("projectId") as String
162
+ var orchestrationId = params.getString("orchestrationId") as String
163
+ var client = ChainAbstractionClient(projectId)
164
+
165
+ when (val result = client.status(orchestrationId)) {
166
+ is StatusResponse.Completed -> {
167
+ when(result.v1) {
168
+ is StatusResponseCompleted -> {
169
+ val response = JsonObject()
170
+ response.addProperty("status", "completed")
171
+ response.addProperty("createdAt", result.v1.createdAt.toString())
172
+ val gson = Gson()
173
+ promise.resolve(gson.toJson(response))
174
+ }
175
+ }
176
+ }
177
+ is StatusResponse.Error -> {
178
+ when(result.v1) {
179
+ is StatusResponseError -> {
180
+ val response = JsonObject()
181
+ response.addProperty("status", "error")
182
+ response.addProperty("createdAt", result.v1.createdAt.toString())
183
+ response.addProperty("reason", result.v1.error.toString())
184
+ val gson = Gson()
185
+ promise.resolve(gson.toJson(response))
186
+ }
187
+ }
188
+ }
189
+ is StatusResponse.Pending -> {
190
+ when(result.v1) {
191
+ is StatusResponsePending -> {
192
+ val response = JsonObject()
193
+ response.addProperty("status", "pending")
194
+ response.addProperty("createdAt", result.v1.createdAt.toString())
195
+ response.addProperty("checkIn", result.v1.checkIn.toString())
196
+ val gson = Gson()
197
+ promise.resolve(gson.toJson(response))
198
+ }
199
+ }
200
+ }
201
+ }
202
+ } catch (e: Exception) {
203
+ // In case of an error, reject the promise
204
+ promise.reject("ERROR", "Yttrium checkStatus Error:" + e.message, e)
205
+ }
206
+ }
207
+ }
52
208
  companion object {
53
209
  const val NAME = "RNWalletConnectModule"
54
210
  }