@walletconnect/react-native-compat 2.17.2-canary-ca-7 → 2.17.2-canary-ca-9
Sign up to get free protection for your applications and to get access to all the features.
- package/ios/Yttrium.mm +15 -2
- package/ios/Yttrium.swift +223 -136
- package/package.json +1 -1
- package/react-native-compat.podspec +1 -1
package/ios/Yttrium.mm
CHANGED
@@ -6,14 +6,27 @@
|
|
6
6
|
// withResolver:(RCTPromiseResolveBlock)resolve
|
7
7
|
// withRejecter:(RCTPromiseRejectBlock)reject)
|
8
8
|
//
|
9
|
-
RCT_EXTERN_METHOD(
|
9
|
+
RCT_EXTERN_METHOD(status:(id)params
|
10
10
|
resolve:(RCTPromiseResolveBlock)resolve
|
11
11
|
reject:(RCTPromiseRejectBlock)reject)
|
12
12
|
|
13
|
-
RCT_EXTERN_METHOD(
|
13
|
+
RCT_EXTERN_METHOD(prepare:(id)params
|
14
14
|
resolve:(RCTPromiseResolveBlock)resolve
|
15
15
|
reject:(RCTPromiseRejectBlock)reject)
|
16
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
|
+
|
17
30
|
+ (BOOL)requiresMainQueueSetup
|
18
31
|
{
|
19
32
|
return NO;
|
package/ios/Yttrium.swift
CHANGED
@@ -5,7 +5,7 @@ import YttriumWrapper
|
|
5
5
|
class Yttrium: NSObject {
|
6
6
|
|
7
7
|
@objc
|
8
|
-
func
|
8
|
+
func status(_ params: Any, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
9
9
|
print("checkStatus called with", params )
|
10
10
|
if let dict = params as? [String: Any],
|
11
11
|
let projectId = dict["projectId"] as? String,
|
@@ -49,68 +49,150 @@ class Yttrium: NSObject {
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
|
52
|
-
func
|
53
|
-
|
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] {
|
52
|
+
func convertRouteResponseAvailableToDictionary(_ routeResponse: RouteResponseAvailable) -> [String: Any] {
|
53
|
+
func transactionToDictionary(_ transaction: YttriumWrapper.Transaction) -> [String: Any] {
|
85
54
|
return [
|
55
|
+
"chainId": transaction.chainId,
|
86
56
|
"from": transaction.from,
|
87
57
|
"to": transaction.to,
|
88
58
|
"value": transaction.value,
|
89
|
-
"
|
90
|
-
"
|
91
|
-
"nonce": transaction.nonce
|
92
|
-
"chainId": transaction.chainId,
|
93
|
-
"gasPrice": transaction.gasPrice,
|
94
|
-
"maxFeePerGas": transaction.maxFeePerGas,
|
95
|
-
"maxPriorityFeePerGas": transaction.maxPriorityFeePerGas
|
59
|
+
"input": transaction.input,
|
60
|
+
"gasLimit": transaction.gasLimit,
|
61
|
+
"nonce": transaction.nonce
|
96
62
|
]
|
97
63
|
}
|
98
|
-
|
99
|
-
func
|
64
|
+
|
65
|
+
func fundingMetadataToDictionary(_ metadata: YttriumWrapper.FundingMetadata) -> [String: Any] {
|
100
66
|
return [
|
101
|
-
"
|
102
|
-
"
|
67
|
+
"chainId": metadata.chainId,
|
68
|
+
"tokenContract": metadata.tokenContract,
|
69
|
+
"symbol": metadata.symbol,
|
70
|
+
"amount": metadata.amount,
|
71
|
+
"bridgingFee": metadata.bridgingFee,
|
72
|
+
"decimals": metadata.decimals
|
103
73
|
]
|
104
74
|
}
|
105
|
-
|
106
|
-
func
|
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] {
|
107
87
|
return [
|
108
|
-
"
|
109
|
-
"
|
88
|
+
"fundingFrom": metadata.fundingFrom.map { fundingMetadataToDictionary($0) },
|
89
|
+
"initialTransaction": initialTransactionMetadataToDictionary(metadata.initialTransaction),
|
90
|
+
"checkIn": metadata.checkIn
|
110
91
|
]
|
111
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]
|
112
108
|
|
113
|
-
|
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] {
|
114
196
|
return [
|
115
197
|
"symbol": amount.symbol,
|
116
198
|
"amount": amount.amount,
|
@@ -119,99 +201,104 @@ class Yttrium: NSObject {
|
|
119
201
|
"formattedAlt": amount.formattedAlt
|
120
202
|
]
|
121
203
|
}
|
122
|
-
|
123
|
-
func
|
204
|
+
|
205
|
+
func transactionFeeToDictionary(_ fee: YttriumWrapper.TransactionFee) -> [String: Any] {
|
124
206
|
return [
|
125
|
-
"
|
126
|
-
"
|
127
|
-
"fee": feeToDictionary(fee: details.fee)
|
207
|
+
"fee": amountToDictionary(fee.fee),
|
208
|
+
"localFee": amountToDictionary(fee.localFee)
|
128
209
|
]
|
129
210
|
}
|
130
|
-
|
211
|
+
|
212
|
+
func txnDetailsToDictionary(_ txnDetails: YttriumWrapper.TxnDetails) -> [String: Any] {
|
213
|
+
return [
|
214
|
+
"transaction": feeEstimatedTransactionToDictionary(txnDetails.transaction),
|
215
|
+
"fee": transactionFeeToDictionary(txnDetails.fee)
|
216
|
+
]
|
217
|
+
}
|
218
|
+
|
131
219
|
return [
|
132
|
-
"route":
|
133
|
-
"
|
134
|
-
"
|
135
|
-
"
|
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)
|
136
226
|
]
|
137
227
|
}
|
138
228
|
|
139
229
|
@objc
|
140
|
-
func
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
reject("yttrium err", "yttrium_err", error)
|
213
|
-
}
|
214
|
-
}
|
215
|
-
}
|
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
|
+
}
|
216
302
|
}
|
303
|
+
|
217
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.17.2-canary-ca-
|
4
|
+
"version": "2.17.2-canary-ca-9",
|
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.4.
|
18
|
+
s.dependency 'YttriumWrapper' , '0.4.10'
|
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.
|