@walletconnect/react-native-compat 2.17.2-canary-ca-3 → 2.17.2-canary-ca-5
Sign up to get free protection for your applications and to get access to all the features.
package/android/src/main/java/com/walletconnect/reactnativemodule/RNWalletConnectModuleModule.kt
CHANGED
@@ -71,7 +71,7 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
|
|
71
71
|
var projectId = params.getString("projectId") as String
|
72
72
|
val transactionMap = params.getMap("transaction")
|
73
73
|
var client = ChainAbstractionClient(projectId)
|
74
|
-
|
74
|
+
|
75
75
|
if (transactionMap != null) {
|
76
76
|
// Extract values from the nested transaction map
|
77
77
|
val chainId = transactionMap.getString("chainId") ?: ""
|
@@ -93,11 +93,18 @@ class RNWalletConnectModuleModule internal constructor(context: ReactApplication
|
|
93
93
|
is RouteResponse.Success -> {
|
94
94
|
when (result.v1) {
|
95
95
|
is RouteResponseSuccess.Available -> {
|
96
|
+
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)
|
96
99
|
val gson = Gson()
|
97
|
-
val
|
100
|
+
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)
|
98
105
|
val response = JsonObject()
|
99
106
|
response.addProperty("status", "available")
|
100
|
-
response.add("data",
|
107
|
+
response.add("data", dataObject)
|
101
108
|
promise.resolve(gson.toJson(response))
|
102
109
|
}
|
103
110
|
is RouteResponseSuccess.NotRequired -> {
|
package/ios/Yttrium.swift
CHANGED
@@ -3,152 +3,215 @@ import YttriumWrapper
|
|
3
3
|
|
4
4
|
@objc(Yttrium)
|
5
5
|
class Yttrium: NSObject {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
+
func convertRouteUiFieldsToDictionary(_ routeUiFields: RouteUiFields) -> [String: Any] {
|
84
|
+
func transactionToDictionary(transaction: YttriumWrapper.Transaction) -> [String: Any] {
|
85
|
+
return [
|
86
|
+
"from": transaction.from,
|
87
|
+
"to": transaction.to,
|
88
|
+
"value": transaction.value,
|
89
|
+
"gas": transaction.gas,
|
90
|
+
"data": transaction.data,
|
91
|
+
"nonce": transaction.nonce,
|
92
|
+
"chainId": transaction.chainId,
|
93
|
+
"gasPrice": transaction.gasPrice,
|
94
|
+
"maxFeePerGas": transaction.maxFeePerGas,
|
95
|
+
"maxPriorityFeePerGas": transaction.maxPriorityFeePerGas
|
24
96
|
]
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"status": "error"
|
97
|
+
}
|
98
|
+
|
99
|
+
func estimationToDictionary(estimation: YttriumWrapper.Eip1559Estimation) -> [String: Any] {
|
100
|
+
return [
|
101
|
+
"maxFeePerGas": estimation.maxFeePerGas,
|
102
|
+
"maxPriorityFeePerGas": estimation.maxPriorityFeePerGas
|
32
103
|
]
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
"status": "pending"
|
104
|
+
}
|
105
|
+
|
106
|
+
func feeToDictionary(fee: YttriumWrapper.TransactionFee) -> [String: Any] {
|
107
|
+
return [
|
108
|
+
"fee": amountToDictionary(amount: fee.fee),
|
109
|
+
"localFee": amountToDictionary(amount: fee.localFee)
|
40
110
|
]
|
41
|
-
resolve(responseDict)
|
42
|
-
}
|
43
|
-
} catch {
|
44
|
-
print("Error occurred: \(error)")
|
45
|
-
print(error)
|
46
|
-
reject("checkStatus err", "checkStatus", error)
|
47
111
|
}
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
112
|
+
|
113
|
+
func amountToDictionary(amount: YttriumWrapper.Amount) -> [String: Any] {
|
114
|
+
return [
|
115
|
+
"symbol": amount.symbol,
|
116
|
+
"amount": amount.amount,
|
117
|
+
"unit": amount.unit,
|
118
|
+
"formatted": amount.formatted,
|
119
|
+
"formattedAlt": amount.formattedAlt
|
120
|
+
]
|
121
|
+
}
|
122
|
+
|
123
|
+
func txnDetailsToDictionary(details: YttriumWrapper.TxnDetails) -> [String: Any] {
|
124
|
+
return [
|
125
|
+
"transaction": transactionToDictionary(transaction: details.transaction),
|
126
|
+
"estimate": estimationToDictionary(estimation: details.estimate),
|
127
|
+
"fee": feeToDictionary(fee: details.fee)
|
128
|
+
]
|
129
|
+
}
|
130
|
+
|
56
131
|
return [
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
"data": transaction.data,
|
62
|
-
"nonce": transaction.nonce,
|
63
|
-
"chainId": transaction.chainId,
|
64
|
-
"gasPrice": transaction.gasPrice,
|
65
|
-
"maxFeePerGas": transaction.maxFeePerGas,
|
66
|
-
"maxPriorityFeePerGas": transaction.maxPriorityFeePerGas,
|
132
|
+
"route": routeUiFields.route.map { txnDetailsToDictionary(details: $0) },
|
133
|
+
"bridge": routeUiFields.bridge.map { feeToDictionary(fee: $0) },
|
134
|
+
"initial": txnDetailsToDictionary(details: routeUiFields.initial),
|
135
|
+
"localTotal": amountToDictionary(amount: routeUiFields.localTotal)
|
67
136
|
]
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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)
|
137
|
+
}
|
138
|
+
|
139
|
+
@objc
|
140
|
+
func checkRoute(_ params: Any, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
141
|
+
print("checkRoute called with", params)
|
142
|
+
if let dict = params as? [String: Any],
|
143
|
+
let transactionData = dict["transaction"] as? [String: Any],
|
144
|
+
let from = transactionData["from"] as? FfiAddress,
|
145
|
+
let chainId = transactionData["chainId"] as? String,
|
146
|
+
let data = transactionData["data"] as? FfiBytes,
|
147
|
+
let gasPrice = transactionData["gasPrice"] as? String,
|
148
|
+
let gas = transactionData["gas"] as? Ffiu64,
|
149
|
+
let value = transactionData["value"] as? Ffiu256,
|
150
|
+
let to = transactionData["to"] as? FfiAddress,
|
151
|
+
let maxFeePerGas = transactionData["maxFeePerGas"] as? Ffiu256,
|
152
|
+
let maxPriorityFeePerGas = transactionData["maxPriorityFeePerGas"] as? Ffiu256,
|
153
|
+
let nonce = transactionData["nonce"] as? Ffiu64,
|
154
|
+
let projectId = dict["projectId"] as? String {
|
106
155
|
|
107
|
-
let routeResponseSuccess = try await client.route(transaction: transaction)
|
108
|
-
print("result", routeResponseSuccess)
|
109
156
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
157
|
+
let client = ChainAbstractionClient.init(projectId: projectId)
|
158
|
+
print("created client, checking route...")
|
159
|
+
Task {
|
160
|
+
do {
|
161
|
+
let transaction = InitTransaction.init(from: from, to: to, value: value, gas: gas, gasPrice: gasPrice, data: data, nonce: nonce, maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: maxPriorityFeePerGas, chainId: chainId)
|
162
|
+
|
163
|
+
let routeResponseSuccess = try await client.route(transaction: transaction)
|
164
|
+
print("result", routeResponseSuccess)
|
165
|
+
|
166
|
+
switch routeResponseSuccess {
|
167
|
+
case let .success(routeResponse):
|
168
|
+
switch routeResponse {
|
169
|
+
case let .available(availableResponse):
|
170
|
+
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)
|
171
|
+
|
172
|
+
let routesDetails = convertRouteUiFieldsToDictionary(uiFields)
|
173
|
+
|
174
|
+
print("ui_fields_json", routesDetails)
|
175
|
+
let responseDict = availableResponseToDictionary(availableResponse)
|
176
|
+
resolve(["status": "available", "data": [
|
177
|
+
"routes": responseDict,
|
178
|
+
"routesDetails": routesDetails
|
179
|
+
]])
|
180
|
+
case .notRequired(_):
|
181
|
+
print("not required")
|
182
|
+
resolve(["status": "not_required"])
|
183
|
+
}
|
184
|
+
case let .error(routeResponse):
|
185
|
+
switch routeResponse.error {
|
186
|
+
case BridgingError.insufficientFunds:
|
187
|
+
let responseDict: [String: Any] = [
|
188
|
+
"status": "error",
|
189
|
+
"reason": "insufficientFunds"
|
190
|
+
]
|
191
|
+
resolve(responseDict)
|
192
|
+
case BridgingError.insufficientGasFunds:
|
193
|
+
let responseDict: [String: Any] = [
|
194
|
+
"status": "error",
|
195
|
+
"reason": "insufficientGasFunds"
|
196
|
+
]
|
197
|
+
resolve(responseDict)
|
198
|
+
case BridgingError.noRoutesAvailable:
|
199
|
+
let responseDict: [String: Any] = [
|
200
|
+
"status": "error",
|
201
|
+
"reason": "noRoutesAvailable"
|
202
|
+
]
|
203
|
+
resolve(responseDict)
|
204
|
+
}
|
205
|
+
print(routeResponse)
|
206
|
+
print(routeResponse.error)
|
207
|
+
}
|
208
|
+
// resolve(result)
|
209
|
+
} catch {
|
210
|
+
print("Error occurred: \(error)")
|
211
|
+
print(error)
|
212
|
+
reject("yttrium err", "yttrium_err", error)
|
213
|
+
}
|
143
214
|
}
|
144
|
-
// resolve(result)
|
145
|
-
} catch {
|
146
|
-
print("Error occurred: \(error)")
|
147
|
-
print(error)
|
148
|
-
reject("yttrium err", "yttrium_err", error)
|
149
|
-
}
|
150
215
|
}
|
151
216
|
}
|
152
|
-
|
153
|
-
}
|
154
217
|
}
|
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-
|
4
|
+
"version": "2.17.2-canary-ca-5",
|
5
5
|
"author": "WalletConnect, Inc. <walletconnect.com>",
|
6
6
|
"homepage": "https://github.com/walletconnect/walletconnect-monorepo/",
|
7
7
|
"license": "Apache-2.0",
|
@@ -15,7 +15,7 @@ Pod::Spec.new do |s|
|
|
15
15
|
s.source = { :git => "https://github.com/walletconnect/walletconnect-monorepo.git", :tag => "#{s.version}" }
|
16
16
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
18
|
-
s.dependency 'YttriumWrapper' , '0.
|
18
|
+
s.dependency 'YttriumWrapper' , '0.4.6'
|
19
19
|
|
20
20
|
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
21
21
|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|