-
Notifications
You must be signed in to change notification settings - Fork 662
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
Add FormActivityViewModel #9983
Conversation
paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/form/FormActivity.kt
Show resolved
Hide resolved
...sheet/src/main/java/com/stripe/android/paymentelement/embedded/form/FormActivityViewModel.kt
Outdated
Show resolved
Hide resolved
import com.stripe.android.model.PaymentMethodCode | ||
import javax.inject.Inject | ||
|
||
internal class FormActivityViewModel @Inject constructor( |
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.
Named FormActivityViewModel
to not conflict with existing FormViewModel
during refactors
Diffuse output:
APK
|
32ee872
to
a997c6d
Compare
paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/form/FormActivity.kt
Outdated
Show resolved
Hide resolved
...sheet/src/main/java/com/stripe/android/paymentelement/embedded/form/FormActivityViewModel.kt
Outdated
Show resolved
Hide resolved
...sheet/src/main/java/com/stripe/android/paymentelement/embedded/form/FormActivityViewModel.kt
Outdated
Show resolved
Hide resolved
hostedSurface = HOSTED_SURFACE_PAYMENT_ELEMENT, | ||
instantDebits = instantDebits, | ||
linkMode = paymentMethodMetadata.linkMode, | ||
onBehalfOf = null, |
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.
Todo as part of confirmation implementation
@@ -40,7 +47,10 @@ internal class FormActivity : AppCompatActivity() { | |||
finish() | |||
} | |||
) { | |||
Text(localArgs.selectedPaymentMethodCode) | |||
VerticalModeFormUI( |
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.
This will be moved to a FormActivityUI
composable in follow up PRs for headers/mandates
9fbebe5
to
65c4a6b
Compare
...sheet/src/main/java/com/stripe/android/paymentelement/embedded/form/FormActivityViewModel.kt
Outdated
Show resolved
Hide resolved
selectedPaymentMethodCode: PaymentMethodCode, | ||
private val selectionHolder: EmbeddedSelectionHolder, | ||
private val embeddedFormHelperFactory: EmbeddedFormHelperFactory, | ||
val eventReporter: EventReporter |
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.
I've got an idea on how to remove the need for this. I'm going to attempt it in Manage first, and can follow up here if it's successful.
paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/form/FormActivity.kt
Outdated
Show resolved
Hide resolved
...sheet/src/main/java/com/stripe/android/paymentelement/embedded/form/FormActivityViewModel.kt
Outdated
Show resolved
Hide resolved
internal class FormActivityViewModelTest { | ||
|
||
@Test | ||
fun `viewmodel initializes interactor correctly`() = runTest { |
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.
Honestly, it feels like we should remove this test, and have the test be in EmbeddedFormInteractorFactory
. But even then, I don't think that test is very valuable. It seems like we should just remove this.
This is just wiring code that'll get tested with integration tests.
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.
Removed
val eventReporter: EventReporter | ||
) : ViewModel() { | ||
|
||
val formInteractor = embeddedFormInteractorFactory.create( |
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.
I think we need to do one of 2 things:
- Inject all these things, they should already be in the dependency injection graph.
- Use this object somewhere else that can't inject these things. But even then, feels like this should live outside the view model.
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.
Update to inject all dependencies and inject interactor directly into FormActivity
formElements = formHelper.formElementsForCode(paymentMethodCode), | ||
onFormFieldValuesChanged = formHelper::onFormFieldValuesChanged, | ||
usBankAccountArguments = usBankAccountFormArguments, | ||
reportFieldInteraction = { |
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.
I think this just delegates to eventReporter
, right? Any reason not to hook it up now?
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.
It delegates to PaymentSheetAnalyticsListener
, which requires a CurrentScreen
. I'll implement in a follow up
Summary
Setup
FormActivityViewModel
andFormActivityComponent
and displayVerticalModeFormUI
Motivation
https://jira.corp.stripe.com/browse/MOBILESDK-2941
Screen.Recording.2025-01-25.at.5.59.27.PM.mov
Testing