From 3bf7552caba466e216d3500338cde1297d449a9e Mon Sep 17 00:00:00 2001 From: Mama1emon Date: Tue, 29 Oct 2024 17:08:44 +0400 Subject: [PATCH] AND-8864 [Actions] Add filter by availability in TokenList Signed-off-by: Mama1emon --- features/onramp/impl/build.gradle.kts | 1 + .../onramp/buy/DefaultBuyCryptoComponent.kt | 2 ++ .../features/onramp/entity/OnrampOperation.kt | 12 ++++++++++++ .../DefaultOnrampSelectTokenComponent.kt | 1 + .../selecttoken/OnrampSelectTokenComponent.kt | 5 ++++- .../tokenlist/OnrampTokenListComponent.kt | 9 ++++++--- .../tokenlist/model/OnrampTokenListModel.kt | 18 ++++++++++++++++-- 7 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/entity/OnrampOperation.kt diff --git a/features/onramp/impl/build.gradle.kts b/features/onramp/impl/build.gradle.kts index f1e5987c2c..72d8342dbc 100644 --- a/features/onramp/impl/build.gradle.kts +++ b/features/onramp/impl/build.gradle.kts @@ -29,6 +29,7 @@ dependencies { implementation(projects.domain.balanceHiding) implementation(projects.domain.balanceHiding.models) implementation(projects.domain.legacy) + implementation(projects.domain.models) implementation(projects.domain.tokens) implementation(projects.domain.tokens.models) implementation(projects.domain.wallets) diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/buy/DefaultBuyCryptoComponent.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/buy/DefaultBuyCryptoComponent.kt index 6cc07cf9fb..b1ef0cbb1c 100644 --- a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/buy/DefaultBuyCryptoComponent.kt +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/buy/DefaultBuyCryptoComponent.kt @@ -12,6 +12,7 @@ import com.tangem.domain.tokens.legacy.TradeCryptoAction import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.usecase.GetWalletsUseCase import com.tangem.features.onramp.component.BuyCryptoComponent +import com.tangem.features.onramp.entity.OnrampOperation import com.tangem.features.onramp.impl.R import com.tangem.features.onramp.selecttoken.OnrampSelectTokenComponent import dagger.assisted.Assisted @@ -32,6 +33,7 @@ internal class DefaultBuyCryptoComponent @AssistedInject constructor( private val selectTokenComponent: OnrampSelectTokenComponent = onrampSelectTokenComponentFactory.create( context = appComponentContext, params = OnrampSelectTokenComponent.Params( + operation = OnrampOperation.BUY, hasSearchBar = true, userWalletId = params.userWalletId, titleResId = R.string.common_buy, diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/entity/OnrampOperation.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/entity/OnrampOperation.kt new file mode 100644 index 0000000000..9aee71731c --- /dev/null +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/entity/OnrampOperation.kt @@ -0,0 +1,12 @@ +package com.tangem.features.onramp.entity + +/** + * Onramp operation + * + * @author Andrew Khokhlov on 29/10/2024 + */ +internal enum class OnrampOperation { + BUY, + SELL, + ; +} diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/selecttoken/DefaultOnrampSelectTokenComponent.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/selecttoken/DefaultOnrampSelectTokenComponent.kt index a5c5634ec4..23cf9537ba 100644 --- a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/selecttoken/DefaultOnrampSelectTokenComponent.kt +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/selecttoken/DefaultOnrampSelectTokenComponent.kt @@ -19,6 +19,7 @@ internal class DefaultOnrampSelectTokenComponent @AssistedInject constructor( private val onrampTokenListComponent: OnrampTokenListComponent = onrampTokenListComponentFactory.create( context = child(key = "token_list"), params = OnrampTokenListComponent.Params( + operation = params.operation, hasSearchBar = params.hasSearchBar, userWalletId = params.userWalletId, onTokenClick = params.onTokenClick, diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/selecttoken/OnrampSelectTokenComponent.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/selecttoken/OnrampSelectTokenComponent.kt index 18d09e5c08..d35f3983fd 100644 --- a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/selecttoken/OnrampSelectTokenComponent.kt +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/selecttoken/OnrampSelectTokenComponent.kt @@ -5,25 +5,28 @@ import com.tangem.core.decompose.factory.ComponentFactory import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.features.onramp.entity.OnrampOperation /** * Select token component * * @author Andrew Khokhlov on 22/10/2024 */ -interface OnrampSelectTokenComponent : ComposableContentComponent { +internal interface OnrampSelectTokenComponent : ComposableContentComponent { interface Factory : ComponentFactory /** * Params * + * @property operation operation * @property hasSearchBar flag that indicates if search bar should be shown * @property userWalletId id of multi-currency wallet * @property titleResId resource id of title * @property onTokenClick callback for token click */ data class Params( + val operation: OnrampOperation, val hasSearchBar: Boolean, val userWalletId: UserWalletId, @StringRes val titleResId: Int, diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/OnrampTokenListComponent.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/OnrampTokenListComponent.kt index 9044cc1fab..7b1bd228f9 100644 --- a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/OnrampTokenListComponent.kt +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/OnrampTokenListComponent.kt @@ -7,6 +7,7 @@ import androidx.compose.ui.Modifier import com.tangem.core.decompose.factory.ComponentFactory import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.features.onramp.entity.OnrampOperation /** Token list component that present list of token for multi-currency wallet */ @Stable @@ -21,11 +22,13 @@ internal interface OnrampTokenListComponent { /** * Params * - * @property hasSearchBar flag that indicates if search bar should be shown - * @property userWalletId id of multi-currency wallet - * @property onTokenClick callback for token click + * @property operation onramp operation + * @property hasSearchBar flag that indicates if search bar should be shown + * @property userWalletId id of multi-currency wallet + * @property onTokenClick callback for token click */ data class Params( + val operation: OnrampOperation, val hasSearchBar: Boolean, val userWalletId: UserWalletId, val onTokenClick: (CryptoCurrencyStatus) -> Unit, diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/model/OnrampTokenListModel.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/model/OnrampTokenListModel.kt index 737a354ce0..aa0bc6064d 100644 --- a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/model/OnrampTokenListModel.kt +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/model/OnrampTokenListModel.kt @@ -8,9 +8,12 @@ import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase import com.tangem.domain.core.utils.getOrElse +import com.tangem.domain.exchange.RampStateManager import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.wallets.usecase.GetWalletsUseCase +import com.tangem.features.onramp.entity.OnrampOperation import com.tangem.features.onramp.tokenlist.OnrampTokenListComponent import com.tangem.features.onramp.tokenlist.entity.TokenListUM import com.tangem.features.onramp.tokenlist.entity.TokenListUMController @@ -32,11 +35,16 @@ internal class OnrampTokenListModel @Inject constructor( private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, private val getTokenListUseCase: GetTokenListUseCase, + private val getWalletsUseCase: GetWalletsUseCase, + private val rampStateManager: RampStateManager, ) : Model() { val state: StateFlow = tokenListUMController.state private val params: OnrampTokenListComponent.Params = paramsContainer.require() + private val scanResponse by lazy { + getWalletsUseCase.invokeSync().first { it.walletId == params.userWalletId }.scanResponse + } init { subscribeOnUpdateState() @@ -98,8 +106,14 @@ internal class OnrampTokenListModel @Inject constructor( } } - // TODO: https://tangem.atlassian.net/browse/AND-8864 private fun List.filterByAvailability(): List { - return this + return filter { + when (params.operation) { + OnrampOperation.BUY -> { + rampStateManager.availableForBuy(scanResponse = scanResponse, cryptoCurrency = it.currency) + } + OnrampOperation.SELL -> rampStateManager.availableForSell(cryptoCurrency = it.currency) + } + } } }