Skip to content

Commit

Permalink
build ThanksPageData and pass to Thanks Page on successful backing
Browse files Browse the repository at this point in the history
  • Loading branch information
scottkicks committed Apr 1, 2024
1 parent cfe6054 commit f6f5f5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,9 @@ final class PostCampaignCheckoutViewController: UIViewController, MessageBannerV

self.viewModel.outputs.checkoutComplete
.observeForUI()
.observeValues { [weak self] _ in
let alert = UIAlertController(
title: "Wow!",
message: "It worked! Your checkout is done. This should push us to the Thanks page.",
preferredStyle: .alert
)
alert.addAction(UIAlertAction.init(title: "OK", style: .cancel))
self?.present(alert, animated: true)
.observeValues { [weak self] thanksPageData in
let thanksVC = ThanksViewController.configured(with: thanksPageData)
self?.navigationController?.pushViewController(thanksVC, animated: true)
}

self.viewModel.outputs.checkoutError
Expand Down
17 changes: 14 additions & 3 deletions Library/ViewModels/PostCampaignCheckoutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public protocol PostCampaignCheckoutViewModelOutputs {
var showWebHelp: Signal<HelpType, Never> { get }
var validateCheckoutSuccess: Signal<PaymentSourceValidation, Never> { get }
var goToApplePayPaymentAuthorization: Signal<PostCampaignPaymentAuthorizationData, Never> { get }
var checkoutComplete: Signal<(), Never> { get }
var checkoutComplete: Signal<ThanksPageData, Never> { get }
var checkoutError: Signal<ErrorEnvelope, Never> { get }
}

Expand All @@ -87,6 +87,7 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType,

let context = initialData.map(\.context)
let checkoutId = initialData.map(\.checkoutId)
let baseReward = initialData.map(\.rewards).map(\.first)

let configurePaymentMethodsData = Signal.merge(
initialData,
Expand Down Expand Up @@ -369,7 +370,17 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType,
AppEnvironment.current.apiService.completeOnSessionCheckout(input: input).materialize()
}

self.checkoutComplete = checkoutCompleteSignal.signal.values().ignoreValues()
let thanksPageData = Signal.combineLatest(initialData, baseReward)
.map { initialData, baseReward -> ThanksPageData? in
guard let reward = baseReward else { return nil }

return (initialData.project, reward, nil, initialData.total)
}

self.checkoutComplete = thanksPageData.skipNil()
.takeWhen(checkoutCompleteSignal.signal.values())
.map { $0 }

self.checkoutError = checkoutCompleteSignal.signal.errors()
}

Expand Down Expand Up @@ -477,7 +488,7 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType,
public let showWebHelp: Signal<HelpType, Never>
public let validateCheckoutSuccess: Signal<PaymentSourceValidation, Never>
public let goToApplePayPaymentAuthorization: Signal<PostCampaignPaymentAuthorizationData, Never>
public let checkoutComplete: Signal<(), Never>
public let checkoutComplete: Signal<ThanksPageData, Never>
public let checkoutError: Signal<ErrorEnvelope, Never>

public var inputs: PostCampaignCheckoutViewModelInputs { return self }
Expand Down

0 comments on commit f6f5f5f

Please sign in to comment.