Updated on 2026-08-14
This commit is contained in:
parent
df1c81ae0c
commit
2bcc9da473
11 changed files with 45 additions and 23 deletions
|
|
@ -1,15 +1,20 @@
|
|||
package com.tangem.tap.features.shop.redux
|
||||
|
||||
import android.content.Intent
|
||||
import com.tangem.tap.common.redux.NotificationAction
|
||||
import com.tangem.tap.common.shop.GooglePayService
|
||||
import com.tangem.tap.common.shop.data.ProductType
|
||||
import com.tangem.tap.common.shop.data.TangemProduct
|
||||
import com.tangem.wallet.R
|
||||
import org.rekotlin.Action
|
||||
|
||||
sealed class ShopAction : Action {
|
||||
|
||||
object LoadProducts : ShopAction() {
|
||||
data class Success(val products: List<TangemProduct>) : ShopAction()
|
||||
object Failure : ShopAction(), NotificationAction {
|
||||
override val messageResource = R.string.common_server_unavailable
|
||||
}
|
||||
}
|
||||
|
||||
data class ApplyPromoCode(val promoCode: String) : ShopAction() {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.tangem.tap.store
|
|||
import kotlinx.coroutines.launch
|
||||
import org.rekotlin.Action
|
||||
import org.rekotlin.Middleware
|
||||
import timber.log.Timber
|
||||
|
||||
class ShopMiddleware {
|
||||
|
||||
|
|
@ -88,10 +89,13 @@ private fun handle(action: Action) {
|
|||
}
|
||||
ShopAction.LoadProducts -> {
|
||||
scope.launch {
|
||||
val result = shopService.getProducts()
|
||||
result.onSuccess {
|
||||
store.dispatchOnMain(ShopAction.LoadProducts.Success(it))
|
||||
}
|
||||
shopService.getProducts().fold(
|
||||
onSuccess = { store.dispatchOnMain(ShopAction.LoadProducts.Success(it)) },
|
||||
onFailure = {
|
||||
Timber.e(it)
|
||||
store.dispatchOnMain(ShopAction.LoadProducts.Failure)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
is ShopAction.CheckIfGooglePayAvailable -> {
|
||||
|
|
|
|||
|
|
@ -65,5 +65,6 @@ private fun internalReduce(action: Action, state: ShopState): ShopState {
|
|||
}
|
||||
ShopAction.FinishSuccessfulOrder -> state
|
||||
ShopAction.ResetState -> ShopState()
|
||||
ShopAction.LoadProducts.Failure -> state
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue