-
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-1123: Refactor PledgePaymentMethodsViewModel to use PaymentSourceSelected #1992
MBL-1123: Refactor PledgePaymentMethodsViewModel to use PaymentSourceSelected #1992
Conversation
…editCard model object
787544d
to
3ed8616
Compare
3ed8616
to
67460e2
Compare
return nil | ||
} | ||
} | ||
.map { $0.selectedPaymentMethod } |
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.
All this refactoring was to get this simplification!
@@ -49,11 +49,12 @@ final class PledgePaymentMethodsViewModelTests: TestCase { | |||
.observe(self.reloadPaymentMethodsProjectCountry.observer) | |||
self.vm.outputs.reloadPaymentMethods.map { $0.1 } | |||
.observe(self.reloadPaymentSheetPaymentMethodsCards.observer) | |||
self.vm.outputs.reloadPaymentMethods.map { $0.2 }.observe(self.reloadPaymentMethodsSelectedCard.observer) | |||
self.vm.outputs.reloadPaymentMethods.map { $0.3 } | |||
self.vm.outputs.reloadPaymentMethods.map { data in data.selectedPaymentMethod?.paymentSourceId } |
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.
Instead of re-writing these tests to use the new-and-better output, just shimming the refactored code into the old test. We can make these tests prettier later, if we want.
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.
LGTM 👍
📲 What
Refactor
PledgePaymentMethodsViewModel
to usePaymentSourceSelected
, instead of managing separate values for aselectedSetupIntent
and aselectedCreditCard
.🤔 Why
For MBL-1123, I need to pass the final selected value (whether it's from a
SetupIntent
, aPaymentIntent
or an existingCreditCard
) back to the delegate of thePledgePaymentMethodsViewController
. This refactor makes that significantly easier - we'll be able to keep the declarative nature of the screen, but be explicit about what kind of payment method is selected.The alternative would be to keep some kind of state in the
PledgePaymentMethodsViewController
that indicated whether or not it should use aSetupIntent
or aPaymentIntent
, and that felt messy in a different way.