From 19b9a2a7e19b8c92b7b60148a17029975d9d1b6d Mon Sep 17 00:00:00 2001 From: samiuelson Date: Fri, 17 Jan 2025 12:09:06 +0100 Subject: [PATCH] Switch between store management and POS variants of `PaymentsFlowTracker` in `CardReaderStatusChecker` --- .../CardReaderStatusCheckerViewModel.kt | 10 +++++++++- .../CardReaderStatusCheckerViewModelTest.kt | 15 ++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModel.kt index 936ef06809b..21a1997d145 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModel.kt @@ -7,6 +7,8 @@ import com.woocommerce.android.cardreader.CardReaderManager import com.woocommerce.android.cardreader.connection.CardReader import com.woocommerce.android.cardreader.connection.CardReaderStatus.Connected import com.woocommerce.android.cardreader.connection.ReaderType +import com.woocommerce.android.di.PointOfSaleMode +import com.woocommerce.android.di.StoreManagementMode import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderOnboardingChecker import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderOnboardingParams @@ -28,12 +30,14 @@ import javax.inject.Inject class CardReaderStatusCheckerViewModel @Inject constructor( savedState: SavedStateHandle, + @StoreManagementMode storeManagementModePaymentsFlowTracker: PaymentsFlowTracker, + @PointOfSaleMode pointOfSaleModePaymentsFlowTracker: PaymentsFlowTracker, private val cardReaderManager: CardReaderManager, private val cardReaderChecker: CardReaderOnboardingChecker, - private val paymentsFlowTracker: PaymentsFlowTracker, private val appPrefsWrapper: AppPrefsWrapper, ) : ScopedViewModel(savedState) { private val arguments: CardReaderStatusCheckerDialogFragmentArgs by savedState.navArgs() + private val paymentsFlowTracker: PaymentsFlowTracker override val _event = SingleLiveEvent() override val event: LiveData = _event @@ -42,6 +46,10 @@ class CardReaderStatusCheckerViewModel launch { checkStatus() } + paymentsFlowTracker = when (arguments.cardReaderFlowParam) { + is CardReaderFlowParam.WooPosConnection -> pointOfSaleModePaymentsFlowTracker + else -> storeManagementModePaymentsFlowTracker + } } private suspend fun checkStatus() { diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModelTest.kt index 72395e022e2..722934d20f2 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModelTest.kt @@ -511,13 +511,14 @@ class CardReaderStatusCheckerViewModelTest : BaseUnitTest() { cardReaderType: CardReaderType = CardReaderType.EXTERNAL ) = CardReaderStatusCheckerViewModel( - CardReaderStatusCheckerDialogFragmentArgs( - param, - cardReaderType + savedState = CardReaderStatusCheckerDialogFragmentArgs( + cardReaderFlowParam = param, + cardReaderType = cardReaderType ).toSavedStateHandle(), - cardReaderManager, - cardReaderChecker, - paymentsFlowTracker, - appPrefsWrapper, + storeManagementModePaymentsFlowTracker = paymentsFlowTracker, + pointOfSaleModePaymentsFlowTracker = paymentsFlowTracker, + cardReaderManager = cardReaderManager, + cardReaderChecker = cardReaderChecker, + appPrefsWrapper = appPrefsWrapper, ) }