Updated on 2026-08-14
This commit is contained in:
parent
3a9bdb16ad
commit
aa621dd48f
10 changed files with 78 additions and 36 deletions
|
|
@ -2,11 +2,9 @@ package com.tangem.domain.tokens
|
|||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.tokens.model.FeePaidCurrency
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* Use case for checking if currency amount can be subtracted.
|
||||
|
|
@ -14,17 +12,18 @@ import kotlinx.coroutines.withContext
|
|||
*/
|
||||
class IsAmountSubtractAvailableUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) {
|
||||
suspend operator fun invoke(userWalletId: UserWalletId, currency: CryptoCurrency): Either<Throwable, Boolean> =
|
||||
Either.catch {
|
||||
withContext(dispatchers.io) {
|
||||
when (val feeCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, currency.network)) {
|
||||
is FeePaidCurrency.Coin -> currency is CryptoCurrency.Coin
|
||||
is FeePaidCurrency.SameCurrency -> true
|
||||
is FeePaidCurrency.Token -> currency.id == feeCurrency.tokenId
|
||||
is FeePaidCurrency.FeeResource -> false
|
||||
}
|
||||
}
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
currency: CryptoCurrency,
|
||||
isGaslessEthTx: Boolean = false,
|
||||
): Either<Throwable, Boolean> = Either.catch {
|
||||
if (isGaslessEthTx) return@catch true
|
||||
when (val feeCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, currency.network)) {
|
||||
is FeePaidCurrency.Coin -> currency is CryptoCurrency.Coin
|
||||
is FeePaidCurrency.SameCurrency -> true
|
||||
is FeePaidCurrency.Token -> currency.id == feeCurrency.tokenId
|
||||
is FeePaidCurrency.FeeResource -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue