-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MBL-1328] Pledge Button Active/Inactive States #2019
Changes from 2 commits
a55e91e
c928d94
0a8620c
6a49bab
5451807
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,8 +86,9 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType, | |
.skipNil() | ||
|
||
let context = initialData.map(\.context) | ||
let project = initialData.map(\.project) | ||
let checkoutId = initialData.map(\.checkoutId) | ||
let baseReward = initialData.map(\.rewards).map(\.first) | ||
let baseReward = initialData.map(\.rewards).map(\.first).skipNil() | ||
|
||
let configurePaymentMethodsData = Signal.merge( | ||
initialData, | ||
|
@@ -109,14 +110,40 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType, | |
.map { _ in AppEnvironment.current.currentUser } | ||
.map(isNotNil) | ||
|
||
let notChangingPaymentMethod = context.map { context in | ||
context.isUpdating && context != .changePaymentMethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change the payment method on a post-campaign pledge? I thought they were immutable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yes thank you! |
||
} | ||
.filter(isTrue) | ||
|
||
let paymentMethodSelected = self.creditCardSelectedProperty.signal.skipNil() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Since this gets passed into the CTA to indicate whether or not it is enabled, does the CTA disable ApplePay as well? Technically we could still run an ApplePay transaction before the payment method is selected (since in that case, you select a card via the ApplePay dialog), but I also don't think that's a big deal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I set this up so that it doesn't impact apple pay for this reason. Which, is what we want here. |
||
|
||
let paymentMethodChangedAndValid = Signal.merge( | ||
notChangingPaymentMethod.mapConst(false), | ||
Signal.combineLatest( | ||
project, | ||
baseReward, | ||
paymentMethodSelected.map { (source: PaymentSourceSelected, _, _) in source }, | ||
context | ||
) | ||
.map(paymentMethodValid) | ||
) | ||
|
||
let isEnabled = Signal.merge( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This could have a more descriptive name like |
||
self.viewDidLoadProperty.signal.mapConst(false) | ||
.take(until: paymentMethodChangedAndValid.ignoreValues()), | ||
paymentMethodChangedAndValid | ||
) | ||
.skipRepeats() | ||
|
||
self.configurePledgeViewCTAContainerView = Signal.combineLatest( | ||
isLoggedIn, | ||
isEnabled, | ||
context | ||
) | ||
.map { isLoggedIn, context in | ||
.map { isLoggedIn, isEnabled, context in | ||
PledgeViewCTAContainerViewData( | ||
isLoggedIn: isLoggedIn, | ||
isEnabled: true, // Pledge button never needs to be disabled on checkout page. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well that's a convenient comment π |
||
isEnabled: isEnabled, | ||
context: context, | ||
willRetryPaymentMethod: false // Only retry in the `fixPaymentMethod` context. | ||
) | ||
|
@@ -394,9 +421,7 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType, | |
|
||
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) | ||
(initialData.project, baseReward, nil, initialData.total) | ||
} | ||
|
||
self.checkoutComplete = thanksPageData.skipNil() | ||
|
@@ -514,3 +539,26 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType, | |
public var inputs: PostCampaignCheckoutViewModelInputs { return self } | ||
public var outputs: PostCampaignCheckoutViewModelOutputs { return self } | ||
} | ||
|
||
private func paymentMethodValid( | ||
project: Project, | ||
reward: Reward, | ||
paymentSource: PaymentSourceSelected, | ||
context: PledgeViewContext | ||
) -> Bool { | ||
guard | ||
let backedPaymentSourceId = project.personalization.backing?.paymentSource?.id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here, I thought these were immutable? |
||
context.isUpdating, | ||
userIsBacking(reward: reward, inProject: project) | ||
else { | ||
return true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this always return true if you haven't backed this project already? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh. yeah I guess that it true. I keep forgetting we won't be updating late pledges |
||
} | ||
|
||
if project.personalization.backing?.status == .errored { | ||
return true | ||
} else if backedPaymentSourceId != paymentSource.savedCreditCardId { | ||
return true | ||
} | ||
|
||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the case where the first reward is
nil
? I thought we always had at least one reward (i.e. the no-reward award.)