Skip to content
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

[FC] Removes mavericks from all viewmodels and tests #8155

9 changes: 0 additions & 9 deletions example/dependencies/dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -994,15 +994,6 @@
| | | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 -> 1.9.10 (*)
| | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:{require 1.6.4; reject _} -> 1.7.3 (*)
| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 -> 1.9.10 (*)
| +--- com.airbnb.android:mavericks-compose:3.0.9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

| | +--- androidx.lifecycle:lifecycle-common-java8:{require 2.6.1; reject _} -> 2.7.0 (*)
| | +--- androidx.fragment:fragment:{require 1.5.2; reject _} -> 1.6.2 (*)
| | +--- androidx.appcompat:appcompat:{require 1.5.0; reject _} -> 1.6.1 (*)
| | +--- androidx.compose.foundation:foundation:{require 1.2.1; reject _} -> 1.5.4 (*)
| | +--- androidx.compose.ui:ui:{require 1.2.1; reject _} -> 1.5.4 (*)
| | +--- androidx.lifecycle:lifecycle-viewmodel-compose:{require 2.6.1; reject _} -> 2.7.0 (*)
| | +--- com.airbnb.android:mavericks:3.0.9 (*)
| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 -> 1.9.10 (*)
| \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 (*)
+--- com.google.accompanist:accompanist-themeadapter-material:0.32.0 (*)
+--- com.alipay.sdk:alipaysdk-android:15.8.12
Expand Down
9 changes: 0 additions & 9 deletions financial-connections-example/dependencies/dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,6 @@
| | | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 -> 1.9.10 (*)
| | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:{require 1.6.4; reject _} -> 1.7.3 (*)
| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 -> 1.9.10 (*)
| +--- com.airbnb.android:mavericks-compose:3.0.9
| | +--- androidx.lifecycle:lifecycle-common-java8:{require 2.6.1; reject _} -> 2.7.0 (*)
| | +--- androidx.fragment:fragment:{require 1.5.2; reject _} -> 1.6.2 (*)
| | +--- androidx.appcompat:appcompat:{require 1.5.0; reject _} -> 1.6.1 (*)
| | +--- androidx.compose.foundation:foundation:{require 1.2.1; reject _} -> 1.5.4 (*)
| | +--- androidx.compose.ui:ui:{require 1.2.1; reject _} -> 1.5.4 (*)
| | +--- androidx.lifecycle:lifecycle-viewmodel-compose:{require 2.6.1; reject _} -> 2.7.0 (*)
| | +--- com.airbnb.android:mavericks:3.0.9 (*)
| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 -> 1.9.10 (*)
| \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 (*)
+--- project :payments-core
| +--- project :stripe-core (*)
Expand Down
2 changes: 0 additions & 2 deletions financial-connections/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
implementation libs.kotlin.coroutinesAndroid
implementation libs.kotlin.serialization
implementation libs.mavericks
implementation libs.mavericksCompose

debugImplementation libs.compose.uiTestManifest
debugImplementation libs.compose.uiTooling
Expand All @@ -64,7 +63,6 @@ dependencies {
testImplementation testLibs.mockito.core
testImplementation testLibs.mockito.inline
testImplementation testLibs.mockito.kotlin
testImplementation testLibs.mavericks
testImplementation testLibs.robolectric
testImplementation testLibs.testParameterInjector
testImplementation testLibs.turbine
Expand Down
9 changes: 0 additions & 9 deletions financial-connections/dependencies/dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,4 @@
| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 (*)
| +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:{require 1.6.4; reject _} -> 1.7.3 (*)
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 (*)
+--- com.airbnb.android:mavericks-compose:3.0.9
| +--- androidx.lifecycle:lifecycle-common-java8:{require 2.6.1; reject _} -> 2.7.0 (*)
| +--- androidx.fragment:fragment:{require 1.5.2; reject _} -> 1.5.2 (*)
| +--- androidx.appcompat:appcompat:{require 1.5.0; reject _} -> 1.6.1 (*)
| +--- androidx.compose.foundation:foundation:{require 1.2.1; reject _} -> 1.5.4 (*)
| +--- androidx.compose.ui:ui:{require 1.2.1; reject _} -> 1.5.4 (*)
| +--- androidx.lifecycle:lifecycle-viewmodel-compose:{require 2.6.1; reject _} -> 2.7.0 (*)
| +--- com.airbnb.android:mavericks:3.0.9 (*)
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 (*)
\--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 (*)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.stripe.android.financialconnections

import android.os.Bundle
import androidx.annotation.StringRes
import com.airbnb.mvrx.MavericksState
import com.stripe.android.financialconnections.launcher.FinancialConnectionsSheetActivityArgs
import com.stripe.android.financialconnections.launcher.FinancialConnectionsSheetActivityResult
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest
Expand All @@ -17,7 +16,7 @@ internal data class FinancialConnectionsSheetState(
val manifest: FinancialConnectionsSessionManifest?,
val webAuthFlowStatus: AuthFlowStatus,
val viewEffect: FinancialConnectionsSheetViewEffect?
) : MavericksState {
) {

val sessionSecret: String
get() = initialArgs.configuration.financialConnectionsSessionClientSecret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package com.stripe.android.financialconnections.di
import android.app.Application
import com.stripe.android.core.ApiVersion
import com.stripe.android.core.Logger
import com.stripe.android.core.injection.IOContext
import com.stripe.android.core.networking.ApiRequest
import com.stripe.android.core.networking.StripeNetworkClient
import com.stripe.android.core.version.StripeSdkVersion
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsTracker
import com.stripe.android.financialconnections.domain.HandleError
import com.stripe.android.financialconnections.domain.RealHandleError
import com.stripe.android.financialconnections.features.accountpicker.AccountPickerSubcomponent
Expand Down Expand Up @@ -37,12 +35,9 @@ import com.stripe.android.uicore.image.StripeImageLoader
import dagger.Binds
import dagger.Module
import dagger.Provides
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import java.util.Locale
import javax.inject.Named
import javax.inject.Singleton
import kotlin.coroutines.CoroutineContext

@Module(
subcomponents = [
Expand Down Expand Up @@ -162,13 +157,9 @@ internal interface FinancialConnectionsSheetNativeModule {
@Singleton
@Provides
fun providesPartnerToCoreAuthsRepository(
logger: Logger,
@IOContext workContext: CoroutineContext,
analyticsTracker: FinancialConnectionsAnalyticsTracker
logger: Logger
) = CoreAuthorizationPendingNetworkingRepairRepository(
coroutineScope = CoroutineScope(SupervisorJob() + workContext),
logger = logger,
analyticsTracker = analyticsTracker
logger = logger
)

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.stripe.android.financialconnections.features.error

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.Success
import com.stripe.android.core.exception.APIException
import com.stripe.android.financialconnections.core.Async.Loading
import com.stripe.android.financialconnections.core.Async.Success
import com.stripe.android.financialconnections.exception.InstitutionPlannedDowntimeError
import com.stripe.android.financialconnections.exception.InstitutionUnplannedDowntimeError
import com.stripe.android.financialconnections.model.FinancialConnectionsInstitution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package com.stripe.android.financialconnections.features.error

import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.compose.collectAsState
import com.airbnb.mvrx.compose.mavericksViewModel
import com.stripe.android.financialconnections.core.Async
import com.stripe.android.financialconnections.core.Async.Fail
import com.stripe.android.financialconnections.core.Async.Loading
import com.stripe.android.financialconnections.core.Async.Success
import com.stripe.android.financialconnections.core.Async.Uninitialized
import com.stripe.android.financialconnections.core.paneViewModel
import com.stripe.android.financialconnections.exception.InstitutionPlannedDowntimeError
import com.stripe.android.financialconnections.exception.InstitutionUnplannedDowntimeError
import com.stripe.android.financialconnections.exception.PartnerAuthError
Expand All @@ -26,12 +27,12 @@ import com.stripe.android.financialconnections.ui.components.FinancialConnection

@Composable
internal fun ErrorScreen() {
val viewModel: ErrorViewModel = mavericksViewModel()
val viewModel: ErrorViewModel = paneViewModel(ErrorViewModel.Companion::factory)
val parentViewModel = parentViewModel()
BackHandler(true) { }
val payload = viewModel.collectAsState { it.payload }
val state by viewModel.stateFlow.collectAsState()
ErrorContent(
payload = payload.value,
payload = state.payload,
onManualEntryClick = viewModel::onManualEntryClick,
onSelectBankClick = viewModel::onSelectAnotherBank,
onCloseFromErrorClick = parentViewModel::onCloseFromErrorClick
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.stripe.android.financialconnections.features.error

import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.MavericksViewModel
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.ViewModelContext
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.stripe.android.core.Logger
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsTracker
import com.stripe.android.financialconnections.analytics.logError
import com.stripe.android.financialconnections.core.Async
import com.stripe.android.financialconnections.core.Async.Uninitialized
import com.stripe.android.financialconnections.core.FinancialConnectionsViewModel
import com.stripe.android.financialconnections.di.FinancialConnectionsSheetNativeComponent
import com.stripe.android.financialconnections.domain.GetManifest
import com.stripe.android.financialconnections.domain.NativeAuthFlowCoordinator
import com.stripe.android.financialconnections.domain.NativeAuthFlowCoordinator.Message
Expand All @@ -17,7 +19,6 @@ import com.stripe.android.financialconnections.navigation.Destination
import com.stripe.android.financialconnections.navigation.NavigationManager
import com.stripe.android.financialconnections.navigation.PopUpToBehavior
import com.stripe.android.financialconnections.repository.FinancialConnectionsErrorRepository
import com.stripe.android.financialconnections.ui.FinancialConnectionsSheetNativeActivity
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -29,7 +30,7 @@ internal class ErrorViewModel @Inject constructor(
private val eventTracker: FinancialConnectionsAnalyticsTracker,
private val navigationManager: NavigationManager,
private val logger: Logger
) : MavericksViewModel<ErrorState>(initialState) {
) : FinancialConnectionsViewModel<ErrorState>(initialState) {

init {
logErrors()
Expand Down Expand Up @@ -83,7 +84,7 @@ internal class ErrorViewModel @Inject constructor(

fun onSelectAnotherBank() = viewModelScope.launch {
kotlin.runCatching {
val payload = requireNotNull(awaitState().payload())
val payload = requireNotNull(stateFlow.value.payload())
if (payload.disableLinkMoreAccounts) {
close(payload.error)
} else {
Expand All @@ -99,27 +100,25 @@ internal class ErrorViewModel @Inject constructor(
super.onCleared()
}

companion object : MavericksViewModelFactory<ErrorViewModel, ErrorState> {
companion object {

override fun create(
viewModelContext: ViewModelContext,
state: ErrorState
): ErrorViewModel {
return viewModelContext.activity<FinancialConnectionsSheetNativeActivity>()
.viewModel
.activityRetainedComponent
.errorSubcomponent
.create(state)
.viewModel
}
fun factory(parentComponent: FinancialConnectionsSheetNativeComponent): ViewModelProvider.Factory =
viewModelFactory {
initializer {
parentComponent
.errorSubcomponent
.create(ErrorState())
.viewModel
}
}

internal val PANE = Pane.UNEXPECTED_ERROR
}
}

internal data class ErrorState(
val payload: Async<Payload> = Uninitialized
) : MavericksState {
) {
data class Payload(
val error: Throwable,
val disableLinkMoreAccounts: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavBackStackEntry
import com.airbnb.mvrx.compose.collectAsState
import com.airbnb.mvrx.compose.mavericksViewModel
import com.stripe.android.financialconnections.R
import com.stripe.android.financialconnections.core.paneViewModel
import com.stripe.android.financialconnections.features.common.ShapedIcon
import com.stripe.android.financialconnections.ui.TextResource
import com.stripe.android.financialconnections.ui.components.FinancialConnectionsButton
Expand All @@ -29,9 +29,11 @@ import com.stripe.android.financialconnections.ui.theme.Layout
internal fun ExitModal(
backStackEntry: NavBackStackEntry
) {
val viewModel: ExitViewModel = mavericksViewModel(argsFactory = { backStackEntry.arguments })
val viewModel: ExitViewModel = paneViewModel {
ExitViewModel.factory(it, backStackEntry.arguments)
}

val state by viewModel.collectAsState()
val state by viewModel.stateFlow.collectAsState()
state.payload()?.let {
ExitModalContent(
description = it.description,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.stripe.android.financialconnections.features.exit

import android.os.Bundle
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.MavericksViewModel
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.ViewModelContext
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.stripe.android.core.Logger
import com.stripe.android.financialconnections.R
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsTracker
import com.stripe.android.financialconnections.analytics.logError
import com.stripe.android.financialconnections.core.Async
import com.stripe.android.financialconnections.core.Async.Uninitialized
import com.stripe.android.financialconnections.core.FinancialConnectionsViewModel
import com.stripe.android.financialconnections.di.FinancialConnectionsSheetNativeComponent
import com.stripe.android.financialconnections.domain.GetManifest
import com.stripe.android.financialconnections.domain.NativeAuthFlowCoordinator
import com.stripe.android.financialconnections.domain.NativeAuthFlowCoordinator.Message
import com.stripe.android.financialconnections.features.common.getBusinessName
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest.Pane
import com.stripe.android.financialconnections.navigation.Destination
import com.stripe.android.financialconnections.navigation.NavigationManager
import com.stripe.android.financialconnections.ui.FinancialConnectionsSheetNativeActivity
import com.stripe.android.financialconnections.ui.TextResource
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand All @@ -30,15 +30,15 @@ internal class ExitViewModel @Inject constructor(
private val eventTracker: FinancialConnectionsAnalyticsTracker,
private val navigationManager: NavigationManager,
private val logger: Logger
) : MavericksViewModel<ExitState>(initialState) {
) : FinancialConnectionsViewModel<ExitState>(initialState) {

init {
logErrors()
suspend {
val manifest = kotlin.runCatching { getManifest() }.getOrNull()
val businessName = manifest?.getBusinessName()
val isNetworkingSignupPane =
manifest?.isNetworkingUserFlow == true && awaitState().referrer == Pane.NETWORKING_LINK_SIGNUP_PANE
manifest?.isNetworkingUserFlow == true && stateFlow.value.referrer == Pane.NETWORKING_LINK_SIGNUP_PANE
val description = when {
isNetworkingSignupPane -> when (businessName) {
null -> TextResource.StringId(R.string.stripe_close_dialog_networking_desc_no_business)
Expand Down Expand Up @@ -85,18 +85,15 @@ internal class ExitViewModel @Inject constructor(
)
}

companion object : MavericksViewModelFactory<ExitViewModel, ExitState> {
companion object {

override fun create(
viewModelContext: ViewModelContext,
state: ExitState
): ExitViewModel {
return viewModelContext.activity<FinancialConnectionsSheetNativeActivity>()
.viewModel
.activityRetainedComponent
.exitSubcomponent
.create(state)
.viewModel
fun factory(parentComponent: FinancialConnectionsSheetNativeComponent, arguments: Bundle?) = viewModelFactory {
initializer {
parentComponent
.exitSubcomponent
.create(ExitState(arguments))
.viewModel
}
}

internal val PANE = Pane.EXIT
Expand All @@ -107,7 +104,7 @@ internal data class ExitState(
val referrer: Pane?,
val payload: Async<Payload>,
val closing: Boolean
) : MavericksState {
) {
data class Payload(
val description: TextResource,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.stripe.android.financialconnections.features.linkaccountpicker

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.Success
import com.stripe.android.financialconnections.core.Async.Loading
import com.stripe.android.financialconnections.core.Async.Success
import com.stripe.android.financialconnections.features.common.MerchantDataAccessModel
import com.stripe.android.financialconnections.model.AddNewAccount
import com.stripe.android.financialconnections.model.Bullet
Expand Down
Loading
Loading