Skip to content

Commit

Permalink
Switch between store management and POS variants of `PaymentsFlowTrac…
Browse files Browse the repository at this point in the history
…ker` in `CardReaderStatusChecker`
  • Loading branch information
samiuelson committed Jan 17, 2025
1 parent 8c926ef commit 19b9a2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<MultiLiveEvent.Event>()
override val event: LiveData<MultiLiveEvent.Event> = _event
Expand All @@ -42,6 +46,10 @@ class CardReaderStatusCheckerViewModel
launch {
checkStatus()
}
paymentsFlowTracker = when (arguments.cardReaderFlowParam) {
is CardReaderFlowParam.WooPosConnection -> pointOfSaleModePaymentsFlowTracker
else -> storeManagementModePaymentsFlowTracker
}
}

private suspend fun checkStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}

0 comments on commit 19b9a2a

Please sign in to comment.