Skip to content

Commit b17b710

Browse files
committed
Clean up code
1 parent 52b1706 commit b17b710

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/items/coupons/search/WooPosCouponsSearchViewModel.kt

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import com.woocommerce.android.ui.woopos.home.items.WooPosItemSelectionViewState
1111
import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewModel
1212
import com.woocommerce.android.ui.woopos.home.items.WooPosPaginationState
1313
import com.woocommerce.android.ui.woopos.util.WooPosGetCachedStoreCurrency
14+
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent.Event.ItemAddedToCart
1415
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEventConstant
16+
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEventConstant.ItemsListSourceType
1517
import com.woocommerce.android.ui.woopos.util.format.WooPosCouponsFormatter
1618
import dagger.hilt.android.lifecycle.HiltViewModel
1719
import kotlinx.coroutines.Job
@@ -56,7 +58,7 @@ class WooPosCouponsSearchViewModel @Inject constructor(
5658
when (event) {
5759
WooPosCouponsSearchUiEvent.OnNextPageRequested -> onEndOfListReached()
5860
is WooPosCouponsSearchUiEvent.OnCouponClicked -> {
59-
handleCouponClicked(event.coupon, WooPosAnalyticsEventConstant.ItemsListSourceType.SEARCH_RESULT)
61+
handleCouponClicked(coupon = event.coupon,)
6062
}
6163

6264
WooPosCouponsSearchUiEvent.LoadingErrorRetryButtonClicked -> handleLoadingErrorRetryClick()
@@ -113,40 +115,31 @@ class WooPosCouponsSearchViewModel @Inject constructor(
113115
paginationState = WooPosPaginationState.Loading
114116
)
115117

116-
try {
117-
val result = dataSource.loadMore()
118-
if (result.isSuccess) {
119-
val coupons = dataSource.couponsFlow.stateIn(viewModelScope).value
120-
_viewState.value = coupons.toContentState(
121-
currentState.searchQuery,
122-
WooPosPaginationState.None
123-
)
124-
} else {
125-
_viewState.value = currentState.copy(
126-
paginationState = WooPosPaginationState.Error
127-
)
128-
}
129-
} catch (e: Exception) {
118+
val result = dataSource.loadMore()
119+
if (result.isSuccess) {
120+
val coupons = dataSource.couponsFlow.stateIn(viewModelScope).value
121+
_viewState.value = coupons.toContentState(
122+
currentState.searchQuery,
123+
WooPosPaginationState.None
124+
)
125+
} else {
130126
_viewState.value = currentState.copy(
131127
paginationState = WooPosPaginationState.Error
132128
)
133129
}
134130
}
135131
}
136132

137-
private fun handleCouponClicked(
138-
coupon: WooPosItemSelectionViewState.Coupon,
139-
sourceType: WooPosAnalyticsEventConstant.ItemsListSourceType
140-
) {
133+
private fun handleCouponClicked(coupon: WooPosItemSelectionViewState.Coupon) {
141134
viewModelScope.launch {
142135
val itemData = WooPosItemsViewModel.ItemClickedData.Coupon(coupon.id, coupon.name)
143136
childToParentEventSender.sendToParent(
144137
ChildToParentEvent.ItemClickedInProductSelector(
145138
itemData = itemData,
146-
eventForTracking = com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent.Event.ItemAddedToCart(
139+
eventForTracking = ItemAddedToCart(
147140
item = itemData,
148141
source = WooPosAnalyticsEventConstant.ItemsListSource.COUPON,
149-
sourceType = sourceType
142+
sourceType = ItemsListSourceType.SEARCH_RESULT
150143
)
151144
)
152145
)

0 commit comments

Comments
 (0)