Updated on 2026-08-14
This commit is contained in:
parent
94b459d7c2
commit
13fd91fc8c
11 changed files with 93 additions and 101 deletions
|
|
@ -24,10 +24,10 @@ data class SwapCurrencies(
|
|||
/**
|
||||
* Return swap group depending on [swapDirection]
|
||||
*/
|
||||
fun SwapCurrencies.getGroupWithReverse(swapDirection: SwapDirection): SwapCurrenciesGroup {
|
||||
fun SwapCurrencies.getGroupWithDirection(swapDirection: SwapDirection): SwapCurrenciesGroup {
|
||||
return when (swapDirection) {
|
||||
SwapDirection.Reverse -> fromGroup
|
||||
SwapDirection.Direct -> toGroup
|
||||
SwapDirection.Reverse -> toGroup
|
||||
SwapDirection.Direct -> fromGroup
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ import arrow.core.Either
|
|||
import com.tangem.domain.express.models.ExpressError
|
||||
import com.tangem.domain.express.models.ExpressProvider
|
||||
import com.tangem.domain.express.models.ExpressRateType
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.swap.SwapErrorResolver
|
||||
import com.tangem.domain.swap.SwapRepositoryV2
|
||||
import com.tangem.domain.swap.models.SwapDataModel
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
class GetSwapDataUseCase(
|
||||
|
|
@ -20,8 +21,8 @@ class GetSwapDataUseCase(
|
|||
userWallet: UserWallet,
|
||||
fromCryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
fromAmount: String,
|
||||
toCryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
toAddress: String?,
|
||||
toCryptoCurrency: CryptoCurrency,
|
||||
toAddress: String,
|
||||
expressProvider: ExpressProvider,
|
||||
rateType: ExpressRateType,
|
||||
): Either<ExpressError, SwapDataModel> = Either.catch {
|
||||
|
|
@ -29,7 +30,7 @@ class GetSwapDataUseCase(
|
|||
userWallet = userWallet,
|
||||
fromCryptoCurrencyStatus = fromCryptoCurrencyStatus,
|
||||
fromAmount = fromAmount,
|
||||
toCryptoCurrencyStatus = toCryptoCurrencyStatus,
|
||||
toCryptoCurrency = toCryptoCurrency,
|
||||
toAddress = toAddress,
|
||||
expressProvider = expressProvider,
|
||||
rateType = rateType,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package com.tangem.domain.swap.usecase
|
||||
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.swap.SwapTransactionRepository
|
||||
import com.tangem.domain.swap.models.SwapCurrencies
|
||||
import com.tangem.domain.swap.models.SwapCurrenciesGroup
|
||||
import com.tangem.domain.swap.models.SwapDirection
|
||||
import com.tangem.domain.swap.models.getGroupWithReverse
|
||||
import com.tangem.domain.swap.models.getGroupWithDirection
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.utils.extensions.orZero
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +31,7 @@ class SelectInitialPairUseCase(
|
|||
swapCurrencies: SwapCurrencies,
|
||||
swapDirection: SwapDirection,
|
||||
): CryptoCurrencyStatus? {
|
||||
val swapCurrenciesGroup = swapCurrencies.getGroupWithReverse(swapDirection)
|
||||
val swapCurrenciesGroup = swapCurrencies.getGroupWithDirection(swapDirection)
|
||||
return tryToGetAlreadySelectedCurrency(secondaryCryptoCurrency, swapCurrenciesGroup)
|
||||
?: tryGetFromCache(userWallet, primaryCryptoCurrency, swapCurrenciesGroup)
|
||||
?: tryGetWithMaxAmount(swapCurrenciesGroup)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue