From c26ed716b411a31546531774df4742d12ea6ba47 Mon Sep 17 00:00:00 2001 From: samiuelson Date: Thu, 14 Nov 2024 18:19:32 +0100 Subject: [PATCH] Extract `nameForTracking` from the state model --- .../controller/CardReaderPaymentController.kt | 22 +++++--- .../CardReaderPaymentOrRefundState.kt | 56 +++++-------------- 2 files changed, 27 insertions(+), 51 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentController.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentController.kt index 9576432d905..8b9526e9dad 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentController.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentController.kt @@ -1080,16 +1080,22 @@ class CardReaderPaymentController( private fun trackCancelledFlow(state: CardReaderPaymentOrRefundState) { when (state) { - is CardReaderPaymentOrRefundState.TrackableState -> { - when (state) { - is CardReaderPaymentState -> - tracker.trackPaymentCancelled(state.nameForTracking) - is CardReaderInteracRefundState -> - tracker.trackInteracRefundCancelled(state.nameForTracking) + is CardReaderPaymentState, is CardReaderInteracRefundState -> { + val nameForTracking = when (state) { + is CardReaderPaymentState.CollectingPayment -> "Collecting" + is CardReaderPaymentState.PaymentCapturing -> "Capturing" + is CardReaderPaymentState.ProcessingPayment -> "Processing" + is CardReaderInteracRefundState.CollectingInteracRefund -> "Collecting" + is CardReaderInteracRefundState.LoadingData -> "Loading" + is CardReaderInteracRefundState.ProcessingInteracRefund -> "Processing" + else -> null + } + if (nameForTracking == null) { + WooLog.e(WooLog.T.CARD_READER, "Invalid state received") + } else { + tracker.trackInteracRefundCancelled(nameForTracking) } } - - else -> WooLog.e(WooLog.T.CARD_READER, "Invalid state received") } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentOrRefundState.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentOrRefundState.kt index afe6ffd877a..47ddec3371b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentOrRefundState.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentOrRefundState.kt @@ -5,72 +5,48 @@ import com.woocommerce.android.ui.payments.cardreader.payment.InteracRefundFlowE import com.woocommerce.android.ui.payments.cardreader.payment.PaymentFlowError sealed class CardReaderPaymentOrRefundState { - interface TrackableState { - val nameForTracking: String - } - sealed class CardReaderPaymentState : CardReaderPaymentOrRefundState() { - data class LoadingData(val onCancel: () -> Unit,) : CardReaderPaymentState(), TrackableState { - override val nameForTracking: String = "Loading" - } + data class LoadingData(val onCancel: () -> Unit) : CardReaderPaymentState() data object ReFetchingOrder : CardReaderPaymentState() sealed class CollectingPayment( open val amountWithCurrencyLabel: String, @StringRes open val cardReaderHint: Int? = null, - ) : CardReaderPaymentState(), TrackableState { + ) : CardReaderPaymentState() { data class BuiltInReaderCollectPaymentState( override val amountWithCurrencyLabel: String, override val cardReaderHint: Int? = null, - ) : CollectingPayment(amountWithCurrencyLabel, cardReaderHint) { - override val nameForTracking: String - get() = "Collecting" - } + ) : CollectingPayment(amountWithCurrencyLabel, cardReaderHint) data class ExternalReaderCollectPaymentState( override val amountWithCurrencyLabel: String, override val cardReaderHint: Int? = null, val onCancel: (() -> Unit) - ) : CollectingPayment(amountWithCurrencyLabel, cardReaderHint) { - override val nameForTracking: String - get() = "Collecting" - } + ) : CollectingPayment(amountWithCurrencyLabel, cardReaderHint) } sealed class ProcessingPayment( open val amountWithCurrencyLabel: String, - ) : CardReaderPaymentState(), TrackableState { + ) : CardReaderPaymentState() { data class BuiltInReaderProcessingPayment(override val amountWithCurrencyLabel: String) : - ProcessingPayment(amountWithCurrencyLabel) { - override val nameForTracking: String - get() = "Processing" - } + ProcessingPayment(amountWithCurrencyLabel) data class ExternalReaderProcessingPayment( override val amountWithCurrencyLabel: String, val onCancel: () -> Unit - ) : ProcessingPayment(amountWithCurrencyLabel) { - override val nameForTracking: String - get() = "Processing" - } + ) : ProcessingPayment(amountWithCurrencyLabel) } data class PrintingReceipt(val amountWithCurrencyLabel: String) : CardReaderPaymentState() sealed class PaymentCapturing(open val amountWithCurrencyLabel: String) : - CardReaderPaymentState(), TrackableState { + CardReaderPaymentState() { data class BuiltInReaderPaymentCapturing(override val amountWithCurrencyLabel: String) : - PaymentCapturing(amountWithCurrencyLabel) { - override val nameForTracking: String - get() = "Capturing" - } + PaymentCapturing(amountWithCurrencyLabel) data class ExternalReaderPaymentCapturing(override val amountWithCurrencyLabel: String) : - PaymentCapturing(amountWithCurrencyLabel) { - override val nameForTracking: String - get() = "Capturing" - } + PaymentCapturing(amountWithCurrencyLabel) } sealed class PaymentSuccessful( @@ -145,23 +121,17 @@ sealed class CardReaderPaymentOrRefundState { } sealed class CardReaderInteracRefundState : CardReaderPaymentOrRefundState() { - data class LoadingData(val onCancel: () -> Unit) : CardReaderInteracRefundState(), TrackableState { - override val nameForTracking: String = "Loading" - } + data class LoadingData(val onCancel: () -> Unit) : CardReaderInteracRefundState() data class CollectingInteracRefund( val amountWithCurrencyLabel: String, val onCancel: () -> Unit, @StringRes val cardReaderHint: Int? = null, - ) : CardReaderInteracRefundState(), TrackableState { - override val nameForTracking: String = "Collecting" - } + ) : CardReaderInteracRefundState() data class ProcessingInteracRefund( val amountWithCurrencyLabel: String, - ) : CardReaderInteracRefundState(), TrackableState { - override val nameForTracking: String = "Processing" - } + ) : CardReaderInteracRefundState() data class InteracRefundFailure( val amountWithCurrencyLabel: String?,