diff --git a/app/src/main/assets/tangem-app-config b/app/src/main/assets/tangem-app-config index 64ae04d208..7f058ec409 160000 --- a/app/src/main/assets/tangem-app-config +++ b/app/src/main/assets/tangem-app-config @@ -1 +1 @@ -Subproject commit 64ae04d2086e5a605dd4da3cba4af32a60d46c79 +Subproject commit 7f058ec409b4eaaf8688ecd4bf944ef8d58d3564 diff --git a/app/src/main/java/com/tangem/tap/common/shop/TangemShopService.kt b/app/src/main/java/com/tangem/tap/common/shop/TangemShopService.kt index 3da94dc568..f5281cc796 100644 --- a/app/src/main/java/com/tangem/tap/common/shop/TangemShopService.kt +++ b/app/src/main/java/com/tangem/tap/common/shop/TangemShopService.kt @@ -5,6 +5,7 @@ import android.content.Intent import com.google.android.gms.wallet.PaymentData import com.shopify.buy3.Storefront import com.tangem.tap.common.analytics.AnalyticsHandler +import com.tangem.tap.common.extensions.filterNotNull import com.tangem.tap.common.shop.data.ProductType import com.tangem.tap.common.shop.data.TangemProduct import com.tangem.tap.common.shop.data.TotalSum @@ -21,7 +22,6 @@ class TangemShopService(application: Application, shopifyShop: ShopifyShop) { private val shopifyService = ShopifyService(application, shopifyShop) - private lateinit var product: Storefront.Product private val checkouts = mutableMapOf() private val variants = mutableMapOf() @@ -31,22 +31,19 @@ class TangemShopService(application: Application, shopifyShop: ShopifyShop) { suspend fun getProducts(): Result> { val result = shopifyService.getProducts() - result.onSuccess { - product = it.first { - val variantsSku = it.variants.edges.map { it.node.sku } - variantsSku.contains(ProductType.WALLET_2_CARDS.sku) && variantsSku.contains( - ProductType.WALLET_3_CARDS.sku - ) - } - product.variants.edges.map { it.node } - .forEach { variant -> - if (variant.sku == ProductType.WALLET_2_CARDS.sku) { - variants[ProductType.WALLET_2_CARDS] = variant - } else if (variant.sku == ProductType.WALLET_3_CARDS.sku) { - variants[ProductType.WALLET_3_CARDS] = variant - } - } + return result.mapCatching { product -> + val availableVariants = product + .flatMap { it.variants.edges.map { it.node } } + .filter { SKUS_TO_DISPLAY.contains(it.sku) } + .associateBy { ProductType.fromSku(it.sku) } + .filterNotNull() + variants.putAll(availableVariants) + if (variants.size < SKUS_TO_DISPLAY.size) { + return Result.failure(Exception( + "Shopify: products are missing, " + + "\nproducts available: ${variants.keys.map { it.sku }}")) + } val twoCardsProduct = TangemProduct( type = ProductType.WALLET_2_CARDS, @@ -65,7 +62,6 @@ class TangemShopService(application: Application, shopifyShop: ShopifyShop) { createCheckouts() return Result.success(listOf(twoCardsProduct, threeCardsProduct)) } - return Result.failure(result.exceptionOrNull()!!) } private suspend fun createCheckouts() { @@ -214,6 +210,7 @@ class TangemShopService(application: Application, shopifyShop: ShopifyShop) { companion object { const val TANGEM_WALLET_2_CARDS_SKU = "TG115x2" const val TANGEM_WALLET_3_CARDS_SKU = "TG115x3" + val SKUS_TO_DISPLAY = listOf(TANGEM_WALLET_2_CARDS_SKU, TANGEM_WALLET_3_CARDS_SKU) } } diff --git a/app/src/main/java/com/tangem/tap/common/shop/data/ProductType.kt b/app/src/main/java/com/tangem/tap/common/shop/data/ProductType.kt index 89116f8096..d8db451147 100644 --- a/app/src/main/java/com/tangem/tap/common/shop/data/ProductType.kt +++ b/app/src/main/java/com/tangem/tap/common/shop/data/ProductType.kt @@ -4,5 +4,15 @@ import com.tangem.tap.common.shop.TangemShopService enum class ProductType(val sku: String) { WALLET_2_CARDS(TangemShopService.TANGEM_WALLET_2_CARDS_SKU), - WALLET_3_CARDS(TangemShopService.TANGEM_WALLET_3_CARDS_SKU) + WALLET_3_CARDS(TangemShopService.TANGEM_WALLET_3_CARDS_SKU); + + companion object { + fun fromSku(sku: String): ProductType? { + return when (sku) { + WALLET_2_CARDS.sku -> WALLET_2_CARDS + WALLET_3_CARDS.sku -> WALLET_3_CARDS + else -> null + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/shop/redux/ShopAction.kt b/app/src/main/java/com/tangem/tap/features/shop/redux/ShopAction.kt index 500cc39285..27a4a5b9e5 100644 --- a/app/src/main/java/com/tangem/tap/features/shop/redux/ShopAction.kt +++ b/app/src/main/java/com/tangem/tap/features/shop/redux/ShopAction.kt @@ -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) : ShopAction() + object Failure : ShopAction(), NotificationAction { + override val messageResource = R.string.common_server_unavailable + } } data class ApplyPromoCode(val promoCode: String) : ShopAction() { diff --git a/app/src/main/java/com/tangem/tap/features/shop/redux/ShopMiddleware.kt b/app/src/main/java/com/tangem/tap/features/shop/redux/ShopMiddleware.kt index 464a99de96..f3734950da 100644 --- a/app/src/main/java/com/tangem/tap/features/shop/redux/ShopMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/shop/redux/ShopMiddleware.kt @@ -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 -> { diff --git a/app/src/main/java/com/tangem/tap/features/shop/redux/ShopReducer.kt b/app/src/main/java/com/tangem/tap/features/shop/redux/ShopReducer.kt index ee12f53109..001c48a46f 100644 --- a/app/src/main/java/com/tangem/tap/features/shop/redux/ShopReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/shop/redux/ShopReducer.kt @@ -65,5 +65,6 @@ private fun internalReduce(action: Action, state: ShopState): ShopState { } ShopAction.FinishSuccessfulOrder -> state ShopAction.ResetState -> ShopState() + ShopAction.LoadProducts.Failure -> state } } \ No newline at end of file diff --git a/app/src/main/res/values-de/strings_final.xml b/app/src/main/res/values-de/strings_final.xml index de09eb54fd..0e388163a0 100644 --- a/app/src/main/res/values-de/strings_final.xml +++ b/app/src/main/res/values-de/strings_final.xml @@ -45,5 +45,6 @@ If you chose the wrong network during your crypto transfer from the exchange, this guide will help you recover your funds Custom + The server is not available, please try again later \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings_final.xml b/app/src/main/res/values-fr/strings_final.xml index de09eb54fd..0e388163a0 100644 --- a/app/src/main/res/values-fr/strings_final.xml +++ b/app/src/main/res/values-fr/strings_final.xml @@ -45,5 +45,6 @@ If you chose the wrong network during your crypto transfer from the exchange, this guide will help you recover your funds Custom + The server is not available, please try again later \ No newline at end of file diff --git a/app/src/main/res/values-it/strings_final.xml b/app/src/main/res/values-it/strings_final.xml index de09eb54fd..0e388163a0 100644 --- a/app/src/main/res/values-it/strings_final.xml +++ b/app/src/main/res/values-it/strings_final.xml @@ -45,5 +45,6 @@ If you chose the wrong network during your crypto transfer from the exchange, this guide will help you recover your funds Custom + The server is not available, please try again later \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings_final.xml b/app/src/main/res/values-ru/strings_final.xml index ea424b57b6..626d6eb7d8 100644 --- a/app/src/main/res/values-ru/strings_final.xml +++ b/app/src/main/res/values-ru/strings_final.xml @@ -45,6 +45,7 @@ Если вы совершили ошибку с выбором сети при переводе средств с биржи, эта инструкция поможет вам восстановить средства Пользовательский + Сервер недоступен, повторите попытку позднее Баланс Обработка полной суммы… diff --git a/app/src/main/res/values/strings_final.xml b/app/src/main/res/values/strings_final.xml index 2478dee488..0733b14d9c 100644 --- a/app/src/main/res/values/strings_final.xml +++ b/app/src/main/res/values/strings_final.xml @@ -45,6 +45,7 @@ If you chose the wrong network during your crypto transfer from the exchange, this guide will help you recover your funds Custom + The server is not available, please try again later Total balance Some networks are unreachable