Skip to content

Commit

Permalink
fix: Remove precondition on presentPaymentMethod (#1048)
Browse files Browse the repository at this point in the history
* Dont crash when tokenizationViewModel is not present

* Formatting
  • Loading branch information
NQuinn27 authored Nov 19, 2024
1 parent 7729303 commit 668f9ed
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Sources/PrimerSDK/Classes/User Interface/PrimerUIManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ internal class PrimerUIManager: PrimerUIManaging {
func presentPaymentMethod(type: String) {
let paymentMethodTokenizationViewModel = PrimerAPIConfiguration.paymentMethodConfigViewModels.filter({ $0.config.type == type }).first

precondition(paymentMethodTokenizationViewModel != nil, "PrimerUIManager should have validated that the view model exists.")
guard let paymentMethodTokenizationViewModel else {
let error = PrimerError.unableToPresentPaymentMethod(
paymentMethodType: type,
userInfo: .errorUserInfoDictionary(
additionalInfo: ["message": "paymentMethodTokenizationViewModel was not present when calling presentPaymentMethod"]
),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: error)
return
}

var imgView: UIImageView?
if let squareLogo = PrimerAPIConfiguration.paymentMethodConfigViewModels.filter({ $0.config.type == type }).first?.uiModule.icon {
Expand All @@ -101,21 +110,21 @@ internal class PrimerUIManager: PrimerUIManaging {

PrimerUIManager.primerRootViewController?.showLoadingScreenIfNeeded(imageView: imgView, message: nil)

paymentMethodTokenizationViewModel?.checkoutEventsNotifierModule.didStartTokenization = {
paymentMethodTokenizationViewModel.checkoutEventsNotifierModule.didStartTokenization = {
PrimerUIManager.primerRootViewController?.showLoadingScreenIfNeeded(imageView: imgView, message: nil)
}

paymentMethodTokenizationViewModel?.willPresentPaymentMethodUI = {
paymentMethodTokenizationViewModel.willPresentPaymentMethodUI = {
PrimerUIManager.primerRootViewController?.showLoadingScreenIfNeeded(imageView: imgView, message: nil)
}

paymentMethodTokenizationViewModel?.didPresentPaymentMethodUI = {}
paymentMethodTokenizationViewModel.didPresentPaymentMethodUI = {}

paymentMethodTokenizationViewModel?.willDismissPaymentMethodUI = {
paymentMethodTokenizationViewModel.willDismissPaymentMethodUI = {
PrimerUIManager.primerRootViewController?.showLoadingScreenIfNeeded(imageView: imgView, message: nil)
}

paymentMethodTokenizationViewModel?.start()
paymentMethodTokenizationViewModel.start()
}

func prepareRootViewController() -> Promise<Void> {
Expand Down

0 comments on commit 668f9ed

Please sign in to comment.