@expensify/react-native-wallet 0.1.40 → 0.1.41
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.
- package/ios/WalletManager.swift +57 -17
- package/package.json +1 -1
package/ios/WalletManager.swift
CHANGED
|
@@ -120,16 +120,37 @@ open class WalletManager: UIViewController {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
DispatchQueue.main.async {
|
|
123
|
-
if self.addPassViewController
|
|
124
|
-
self.presentAddPaymentPassCompletionHandler = completion
|
|
125
|
-
self.addPassViewController = enrollViewController
|
|
126
|
-
RCTPresentedViewController()?.present(enrollViewController, animated: true, completion: nil)
|
|
127
|
-
} else {
|
|
123
|
+
if let enrollVC = self.addPassViewController, enrollVC.isBeingPresented || enrollVC.presentingViewController != nil {
|
|
128
124
|
self.logInfo(message: "EnrollViewController is already presented.")
|
|
129
125
|
completion(.error, [
|
|
130
126
|
"errorMessage": "EnrollViewController is already presented."
|
|
131
127
|
])
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let presentPassHandler = self.presentAddPaymentPassCompletionHandler
|
|
132
|
+
let addPaymentPassHandler = self.addPaymentPassCompletionHandler
|
|
133
|
+
self.addPassViewController = nil
|
|
134
|
+
self.presentAddPaymentPassCompletionHandler = nil
|
|
135
|
+
self.addPaymentPassCompletionHandler = nil
|
|
136
|
+
self.addPassHandler = nil
|
|
137
|
+
|
|
138
|
+
let errorResponse: NSDictionary = [
|
|
139
|
+
"errorMessage": "EnrollViewController is no longer presented."
|
|
140
|
+
]
|
|
141
|
+
presentPassHandler?(.error, errorResponse)
|
|
142
|
+
addPaymentPassHandler?(.error, errorResponse)
|
|
143
|
+
|
|
144
|
+
guard let presentingViewController = RCTPresentedViewController() else {
|
|
145
|
+
completion(.error, [
|
|
146
|
+
"errorMessage": "Presenting view controller is unavailable."
|
|
147
|
+
])
|
|
148
|
+
return
|
|
132
149
|
}
|
|
150
|
+
|
|
151
|
+
self.presentAddPaymentPassCompletionHandler = completion
|
|
152
|
+
self.addPassViewController = enrollViewController
|
|
153
|
+
presentingViewController.present(enrollViewController, animated: true, completion: nil)
|
|
133
154
|
}
|
|
134
155
|
}
|
|
135
156
|
|
|
@@ -197,12 +218,23 @@ open class WalletManager: UIViewController {
|
|
|
197
218
|
}
|
|
198
219
|
|
|
199
220
|
private func hideModal() {
|
|
221
|
+
guard let enrollVC = addPassViewController else {
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
|
|
200
225
|
DispatchQueue.main.async {
|
|
201
|
-
|
|
226
|
+
guard self.addPassViewController === enrollVC else {
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if enrollVC.isBeingPresented || enrollVC.presentingViewController != nil {
|
|
202
231
|
enrollVC.dismiss(animated: true, completion: {
|
|
203
|
-
self.addPassViewController
|
|
232
|
+
if self.addPassViewController === enrollVC {
|
|
233
|
+
self.addPassViewController = nil
|
|
234
|
+
}
|
|
204
235
|
})
|
|
205
236
|
} else {
|
|
237
|
+
self.addPassViewController = nil
|
|
206
238
|
self.logInfo(message: "EnrollViewController is not presented currently.")
|
|
207
239
|
}
|
|
208
240
|
}
|
|
@@ -220,6 +252,10 @@ extension WalletManager: PKAddPaymentPassViewControllerDelegate {
|
|
|
220
252
|
generateRequestWithCertificateChain certificates: [Data],
|
|
221
253
|
nonce: Data, nonceSignature: Data,
|
|
222
254
|
completionHandler handler: @escaping (PKAddPaymentPassRequest) -> Void) {
|
|
255
|
+
guard controller === addPassViewController else {
|
|
256
|
+
return
|
|
257
|
+
}
|
|
258
|
+
|
|
223
259
|
let stringNonce = nonce.base64EncodedString() as NSString
|
|
224
260
|
let stringNonceSignature = nonceSignature.base64EncodedString() as NSString
|
|
225
261
|
let stringCertificates = certificates.map {
|
|
@@ -230,15 +266,16 @@ extension WalletManager: PKAddPaymentPassViewControllerDelegate {
|
|
|
230
266
|
|
|
231
267
|
// Retry the JS issuer callback if the user tries again to add a payment pass
|
|
232
268
|
if let addPaymentPassHandler = addPaymentPassCompletionHandler {
|
|
233
|
-
|
|
269
|
+
// The callback can synchronously register the next completion.
|
|
234
270
|
addPaymentPassCompletionHandler = nil
|
|
271
|
+
addPaymentPassHandler(.retry, reqestCardData.toNSDictionary())
|
|
235
272
|
return
|
|
236
273
|
}
|
|
237
274
|
|
|
238
275
|
// Finish IOSPresentAddPaymentPassView function
|
|
239
276
|
if let presentPassHandler = presentAddPaymentPassCompletionHandler {
|
|
240
|
-
presentPassHandler(.completed, reqestCardData.toNSDictionary())
|
|
241
277
|
presentAddPaymentPassCompletionHandler = nil
|
|
278
|
+
presentPassHandler(.completed, reqestCardData.toNSDictionary())
|
|
242
279
|
}
|
|
243
280
|
}
|
|
244
281
|
|
|
@@ -247,10 +284,16 @@ extension WalletManager: PKAddPaymentPassViewControllerDelegate {
|
|
|
247
284
|
_ controller: PKAddPaymentPassViewController,
|
|
248
285
|
didFinishAdding pass: PKPaymentPass?,
|
|
249
286
|
error: Error?) {
|
|
250
|
-
|
|
287
|
+
guard controller === addPassViewController else {
|
|
251
288
|
return
|
|
252
289
|
}
|
|
253
|
-
|
|
290
|
+
|
|
291
|
+
let presentPassHandler = presentAddPaymentPassCompletionHandler
|
|
292
|
+
let addPaymentPassHandler = addPaymentPassCompletionHandler
|
|
293
|
+
presentAddPaymentPassCompletionHandler = nil
|
|
294
|
+
addPaymentPassCompletionHandler = nil
|
|
295
|
+
addPassHandler = nil
|
|
296
|
+
|
|
254
297
|
let errorMessage = error?.localizedDescription ?? ""
|
|
255
298
|
|
|
256
299
|
if error != nil {
|
|
@@ -261,13 +304,13 @@ extension WalletManager: PKAddPaymentPassViewControllerDelegate {
|
|
|
261
304
|
}
|
|
262
305
|
|
|
263
306
|
// Cancel the IOSPresentAddPaymentPassView function when the user cancelled the modal
|
|
264
|
-
if let handler =
|
|
307
|
+
if let handler = presentPassHandler {
|
|
265
308
|
let response = AddPassResponse(status: .canceled, nonce: nil, nonceSignature: nil, certificates: nil)
|
|
266
309
|
handler(.canceled, response.toNSDictionary())
|
|
267
310
|
}
|
|
268
311
|
|
|
269
312
|
// If the pass is returned complete the IOSHandleAddPaymentPassResponse function
|
|
270
|
-
if let addPaymentPassHandler =
|
|
313
|
+
if let addPaymentPassHandler = addPaymentPassHandler {
|
|
271
314
|
if pass != nil {
|
|
272
315
|
addPaymentPassHandler(.completed, nil)
|
|
273
316
|
} else {
|
|
@@ -276,11 +319,8 @@ extension WalletManager: PKAddPaymentPassViewControllerDelegate {
|
|
|
276
319
|
])
|
|
277
320
|
}
|
|
278
321
|
}
|
|
279
|
-
|
|
280
|
-
addPassHandler = nil
|
|
322
|
+
|
|
281
323
|
hideModal()
|
|
282
|
-
addPaymentPassCompletionHandler = nil
|
|
283
|
-
presentAddPaymentPassCompletionHandler = nil
|
|
284
324
|
}
|
|
285
325
|
}
|
|
286
326
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expensify/react-native-wallet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "A React Native module designed for seamless integration of Card Push Provisioning into Apple Wallet and Google Wallet, enabling easy and secure addition of payment cards directly from your application.",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "lib/commonjs/index",
|