Skip to content

Commit

Permalink
AND-8864 [Actions] Add filter by availability in TokenList
Browse files Browse the repository at this point in the history
Signed-off-by: Mama1emon <[email protected]>
  • Loading branch information
Mama1emon committed Oct 29, 2024
1 parent 9dafcce commit 3bf7552
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions features/onramp/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, OnrampSelectTokenComponent>

/**
* 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<TokenListUM> = tokenListUMController.state

private val params: OnrampTokenListComponent.Params = paramsContainer.require()
private val scanResponse by lazy {
getWalletsUseCase.invokeSync().first { it.walletId == params.userWalletId }.scanResponse
}

init {
subscribeOnUpdateState()
Expand Down Expand Up @@ -98,8 +106,14 @@ internal class OnrampTokenListModel @Inject constructor(
}
}

// TODO: https://tangem.atlassian.net/browse/AND-8864
private fun List<CryptoCurrencyStatus>.filterByAvailability(): List<CryptoCurrencyStatus> {
return this
return filter {
when (params.operation) {
OnrampOperation.BUY -> {
rampStateManager.availableForBuy(scanResponse = scanResponse, cryptoCurrency = it.currency)
}
OnrampOperation.SELL -> rampStateManager.availableForSell(cryptoCurrency = it.currency)
}
}
}
}

0 comments on commit 3bf7552

Please sign in to comment.