Updated on 2026-08-14
This commit is contained in:
parent
bbd1fc9ace
commit
472efdfc6b
10 changed files with 36 additions and 39 deletions
|
|
@ -13,10 +13,10 @@ import com.tangem.domain.core.lce.Lce
|
|||
import com.tangem.domain.exchange.ExpressAvailabilityState
|
||||
import com.tangem.domain.exchange.RampStateManager
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.model.ScenarioUnavailabilityReason
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
|
|
@ -37,11 +37,10 @@ internal class DefaultRampManager(
|
|||
private val cryptoCurrencyConverter = CryptoCurrencyConverter(excludedBlockchains)
|
||||
|
||||
override suspend fun availableForBuy(
|
||||
scanResponse: ScanResponse,
|
||||
userWalletId: UserWalletId,
|
||||
userWallet: UserWallet,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
): ScenarioUnavailabilityReason {
|
||||
val availabilityState = runCatching { getOnrampAvailableState(userWalletId, cryptoCurrency) }
|
||||
val availabilityState = runCatching { getOnrampAvailableState(userWallet.walletId, cryptoCurrency) }
|
||||
.getOrNull()
|
||||
?: ExpressAvailabilityState.Error
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,18 @@ import arrow.core.Either
|
|||
import com.tangem.blockchainsdk.utils.toBlockchain
|
||||
import com.tangem.domain.common.util.hasDerivation
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
|
||||
class NetworkHasDerivationUseCase {
|
||||
|
||||
operator fun invoke(scanResponse: ScanResponse, network: Network): Either<Throwable, Boolean> {
|
||||
val blockchain = network.toBlockchain()
|
||||
val derivationPath = network.derivationPath.value
|
||||
return Either.catch { derivationPath != null && scanResponse.hasDerivation(blockchain, derivationPath) }
|
||||
operator fun invoke(userWallet: UserWallet, network: Network): Either<Throwable, Boolean> = Either.catch {
|
||||
when (userWallet) {
|
||||
is UserWallet.Cold -> {
|
||||
val blockchain = network.toBlockchain()
|
||||
val derivationPath = network.derivationPath.value
|
||||
derivationPath != null && userWallet.scanResponse.hasDerivation(blockchain, derivationPath)
|
||||
}
|
||||
is UserWallet.Hot -> true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@ package com.tangem.domain.exchange
|
|||
import arrow.core.Either
|
||||
import com.tangem.domain.core.lce.Lce
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.model.ScenarioUnavailabilityReason
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
|
|
@ -14,11 +14,7 @@ import kotlinx.coroutines.flow.Flow
|
|||
*/
|
||||
interface RampStateManager {
|
||||
|
||||
suspend fun availableForBuy(
|
||||
scanResponse: ScanResponse,
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
): ScenarioUnavailabilityReason
|
||||
suspend fun availableForBuy(userWallet: UserWallet, cryptoCurrency: CryptoCurrency): ScenarioUnavailabilityReason
|
||||
|
||||
/**
|
||||
* Check if [CryptoCurrency] is available for sell
|
||||
|
|
|
|||
|
|
@ -62,8 +62,7 @@ internal open class BaseActionsFactory(
|
|||
currency: CryptoCurrency,
|
||||
): ScenarioUnavailabilityReason {
|
||||
return rampStateManager.availableForBuy(
|
||||
userWalletId = userWallet.walletId,
|
||||
scanResponse = userWallet.scanResponse,
|
||||
userWallet = userWallet,
|
||||
cryptoCurrency = currency,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,12 +204,9 @@ internal class OnboardingNoteTopUpModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun loadAvailableForBuy(cryptoCurrencyStatus: CryptoCurrencyStatus) {
|
||||
val userWalletId = userWallet?.walletId ?: return
|
||||
|
||||
modelScope.launch {
|
||||
val availableForBuy = rampStateManager.availableForBuy(
|
||||
scanResponse = scanResponse,
|
||||
userWalletId = userWalletId,
|
||||
userWallet = userWallet ?: return@launch,
|
||||
cryptoCurrency = cryptoCurrencyStatus.currency,
|
||||
)
|
||||
_uiState.update {
|
||||
|
|
|
|||
|
|
@ -83,8 +83,7 @@ internal class OnrampOperationModel @Inject constructor(
|
|||
fun onHotTokenClick(status: CryptoCurrencyStatus) {
|
||||
modelScope.launch {
|
||||
val unavailabilityReason = rampStateManager.availableForBuy(
|
||||
scanResponse = selectedUserWallet.scanResponse,
|
||||
userWalletId = params.userWalletId,
|
||||
userWallet = selectedUserWallet,
|
||||
cryptoCurrency = status.currency,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -229,8 +229,7 @@ internal class OnrampTokenListModel @Inject constructor(
|
|||
return when (params.filterOperation) {
|
||||
OnrampOperation.BUY -> {
|
||||
rampStateManager.availableForBuy(
|
||||
scanResponse = userWallet.scanResponse,
|
||||
userWalletId = params.userWalletId,
|
||||
userWallet = userWallet,
|
||||
cryptoCurrency = status.currency,
|
||||
).isAvailable()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase
|
|||
import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.models.requireColdWallet
|
||||
import com.tangem.domain.wallets.usecase.GetExploreUrlUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
|
||||
import com.tangem.feature.tokendetails.deeplink.TokenDetailsDeepLinkActionListener
|
||||
|
|
@ -442,16 +441,15 @@ internal class TokenDetailsModel @Inject constructor(
|
|||
|
||||
private fun updateTopBarMenu() {
|
||||
modelScope.launch(dispatchers.main) {
|
||||
val hasDerivations =
|
||||
networkHasDerivationUseCase(
|
||||
scanResponse = userWallet.requireColdWallet().scanResponse, // TODO [REDACTED_TASK_KEY]
|
||||
network = cryptoCurrency.network,
|
||||
).getOrElse { false }
|
||||
val hasDerivations = networkHasDerivationUseCase(
|
||||
userWallet = userWallet,
|
||||
network = cryptoCurrency.network,
|
||||
).getOrElse { false }
|
||||
|
||||
val isSupported = isXPUBSupported()
|
||||
|
||||
internalUiState.value = stateFactory.getStateWithUpdatedMenu(
|
||||
cardTypesResolver = userWallet.scanResponse.cardTypesResolver,
|
||||
userWallet = userWallet,
|
||||
hasDerivations = hasDerivations,
|
||||
isSupported = isSupported,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import com.tangem.domain.models.currency.CryptoCurrency
|
|||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.staking.GetStakingIntegrationIdUseCase
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.models.requireColdWallet
|
||||
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.*
|
||||
|
|
@ -101,7 +100,7 @@ internal class TokenDetailsSkeletonStateConverter(
|
|||
|
||||
val isBitcoin = isBitcoin(cryptoCurrency.network.rawId)
|
||||
val hasDerivations = networkHasDerivationUseCase(
|
||||
scanResponse = userWallet.requireColdWallet().scanResponse, // TODO [REDACTED_TASK_KEY]
|
||||
userWallet = userWallet,
|
||||
network = cryptoCurrency.network,
|
||||
).getOrElse { false }
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import com.tangem.core.ui.extensions.resourceReference
|
|||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.card.NetworkHasDerivationUseCase
|
||||
import com.tangem.domain.common.CardTypesResolver
|
||||
import com.tangem.domain.common.util.cardTypesResolver
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.network.NetworkAddress
|
||||
|
|
@ -29,6 +29,7 @@ import com.tangem.domain.tokens.model.TokenActionsState
|
|||
import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning
|
||||
import com.tangem.domain.txhistory.models.TxHistoryListError
|
||||
import com.tangem.domain.txhistory.models.TxHistoryStateError
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
|
||||
|
|
@ -348,7 +349,7 @@ internal class TokenDetailsStateFactory(
|
|||
}
|
||||
|
||||
fun getStateWithUpdatedMenu(
|
||||
cardTypesResolver: CardTypesResolver,
|
||||
userWallet: UserWallet,
|
||||
hasDerivations: Boolean,
|
||||
isSupported: Boolean,
|
||||
): TokenDetailsState {
|
||||
|
|
@ -356,7 +357,7 @@ internal class TokenDetailsStateFactory(
|
|||
copy(
|
||||
topAppBarConfig = topAppBarConfig.copy(
|
||||
tokenDetailsAppBarMenuConfig = topAppBarConfig.tokenDetailsAppBarMenuConfig
|
||||
?.updateMenu(cardTypesResolver, hasDerivations, isSupported),
|
||||
?.updateMenu(userWallet, hasDerivations, isSupported),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -385,11 +386,16 @@ internal class TokenDetailsStateFactory(
|
|||
}
|
||||
|
||||
private fun TokenDetailsAppBarMenuConfig.updateMenu(
|
||||
cardTypesResolver: CardTypesResolver,
|
||||
userWallet: UserWallet,
|
||||
hasDerivations: Boolean,
|
||||
isSupported: Boolean,
|
||||
): TokenDetailsAppBarMenuConfig? {
|
||||
if (cardTypesResolver.isSingleWalletWithToken()) return null
|
||||
if (userWallet is UserWallet.Cold &&
|
||||
userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
return copy(
|
||||
items = buildList {
|
||||
if (isSupported && hasDerivations) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue