Skip to content

Commit

Permalink
Ensure web redirect presentation gracefully handles testing cases whe…
Browse files Browse the repository at this point in the history
…re no window is present
  • Loading branch information
jnewc committed Apr 19, 2024
1 parent 5c2005d commit 3616e6b
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,23 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi
responseCode: nil
)


Analytics.Service.record(events: [presentEvent, networkEvent])

guard UIApplication.shared.windows.count > 0 else {
self.handleWebViewControllerPresentedCompletion()
seal.fulfill()
return
}

if PrimerUIManager.primerRootViewController == nil {
firstly {
PrimerUIManager.prepareRootViewController()
}
.done {
PrimerUIManager.primerRootViewController?.present(self.webViewController!, animated: true, completion: {
DispatchQueue.main.async {
self.handleWebViewControlllerPresentedCompletion()
self.handleWebViewControllerPresentedCompletion()
seal.fulfill()
}
})
Expand All @@ -215,7 +223,7 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi
} else {
PrimerUIManager.primerRootViewController?.present(self.webViewController!, animated: true, completion: {
DispatchQueue.main.async {
self.handleWebViewControlllerPresentedCompletion()
self.handleWebViewControllerPresentedCompletion()
seal.fulfill()
}
})
Expand All @@ -224,7 +232,7 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi
}
}

private func handleWebViewControlllerPresentedCompletion() {
private func handleWebViewControllerPresentedCompletion() {
DispatchQueue.main.async {
let viewEvent = Analytics.Event.ui(
action: .view,
Expand Down

0 comments on commit 3616e6b

Please sign in to comment.