Updated on 2026-08-14

This commit is contained in:
Tangem 2026-03-12 10:41:39 +04:00
parent 86af90fd92
commit d31d3f8a9b
8 changed files with 82 additions and 172 deletions

View file

@ -1,16 +1,15 @@
package com.tangem.tap.di.domain
import com.tangem.data.wallets.hot.TangemHotWalletSigner
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.supplier.SingleAccountListSupplier
import com.tangem.domain.card.repository.CardSdkConfigRepository
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.networks.single.SingleNetworkStatusFetcher
import com.tangem.domain.networks.single.SingleNetworkStatusSupplier
import com.tangem.domain.notifications.repository.PushNotificationsRepository
import com.tangem.domain.tokens.GetMultiCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.GetViewedTokenReceiveWarningUseCase
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.CurrencyChecksRepository
import com.tangem.domain.transaction.FeeRepository
import com.tangem.domain.transaction.GaslessTransactionRepository
@ -279,14 +278,12 @@ internal object TransactionDomainModule {
@Singleton
fun provideGetAvailableFeeTokensUseCase(
gaslessTransactionRepository: GaslessTransactionRepository,
currenciesRepository: CurrenciesRepository,
getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
currencyChecksRepository: CurrencyChecksRepository,
): GetAvailableFeeTokensUseCase {
return GetAvailableFeeTokensUseCase(
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
gaslessTransactionRepository = gaslessTransactionRepository,
currenciesRepository = currenciesRepository,
getMultiCryptoCurrencyStatusUseCase = getMultiCryptoCurrencyStatusUseCase,
currencyChecksRepository = currencyChecksRepository,
)
}
@ -296,17 +293,15 @@ internal object TransactionDomainModule {
fun provideGetFeeForGaslessUseCase(
walletManagersFacade: WalletManagersFacade,
gaslessTransactionRepository: GaslessTransactionRepository,
currenciesRepository: CurrenciesRepository,
getFeeUseCase: GetFeeUseCase,
getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
currencyChecksRepository: CurrencyChecksRepository,
): GetFeeForGaslessUseCase {
return GetFeeForGaslessUseCase(
walletManagersFacade = walletManagersFacade,
demoConfig = DemoConfig,
gaslessTransactionRepository = gaslessTransactionRepository,
currenciesRepository = currenciesRepository,
getMultiCryptoCurrencyStatusUseCase = getMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
getFeeUseCase = getFeeUseCase,
currencyChecksRepository = currencyChecksRepository,
)
@ -317,16 +312,14 @@ internal object TransactionDomainModule {
fun provideGetFeeForTokenUseCase(
walletManagersFacade: WalletManagersFacade,
gaslessTransactionRepository: GaslessTransactionRepository,
currenciesRepository: CurrenciesRepository,
getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
currencyChecksRepository: CurrencyChecksRepository,
): GetFeeForTokenUseCase {
return GetFeeForTokenUseCase(
gaslessTransactionRepository = gaslessTransactionRepository,
walletManagersFacade = walletManagersFacade,
demoConfig = DemoConfig,
currenciesRepository = currenciesRepository,
getMultiCryptoCurrencyStatusUseCase = getMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
currencyChecksRepository = currencyChecksRepository,
)
}
@ -362,16 +355,14 @@ internal object TransactionDomainModule {
fun provideEstimateFeeForTokenUseCase(
walletManagersFacade: WalletManagersFacade,
gaslessTransactionRepository: GaslessTransactionRepository,
currenciesRepository: CurrenciesRepository,
getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
currencyChecksRepository: CurrencyChecksRepository,
): EstimateFeeForTokenUseCase {
return EstimateFeeForTokenUseCase(
gaslessTransactionRepository = gaslessTransactionRepository,
walletManagersFacade = walletManagersFacade,
demoConfig = DemoConfig,
currenciesRepository = currenciesRepository,
getMultiCryptoCurrencyStatusUseCase = getMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
currencyChecksRepository = currencyChecksRepository,
)
}
@ -381,8 +372,7 @@ internal object TransactionDomainModule {
fun provideEstimateFeeForGaslessTxUseCase(
walletManagersFacade: WalletManagersFacade,
gaslessTransactionRepository: GaslessTransactionRepository,
currenciesRepository: CurrenciesRepository,
getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
estimateFeeUseCase: EstimateFeeUseCase,
currencyChecksRepository: CurrencyChecksRepository,
): EstimateFeeForGaslessTxUseCase {
@ -390,8 +380,7 @@ internal object TransactionDomainModule {
gaslessTransactionRepository = gaslessTransactionRepository,
walletManagersFacade = walletManagersFacade,
demoConfig = DemoConfig,
currenciesRepository = currenciesRepository,
getMultiCryptoCurrencyStatusUseCase = getMultiCryptoCurrencyStatusUseCase,
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
estimateFeeUseCase = estimateFeeUseCase,
currencyChecksRepository = currencyChecksRepository,
)

View file

@ -1,26 +0,0 @@
package com.tangem.domain.tokens
import arrow.core.Either
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.tokens.error.CurrencyStatusError
import com.tangem.domain.tokens.error.TokenListError
import com.tangem.domain.tokens.error.mapper.mapToTokenListError
import com.tangem.domain.tokens.operations.BaseCurrencyStatusOperations
import kotlinx.coroutines.flow.Flow
class GetMultiCryptoCurrencyStatusUseCase(
private val currencyStatusOperations: BaseCurrencyStatusOperations,
) {
/**
* Returns synchronously list of cryptocurrency statuses for Multi-Currency wallet
*
* @param userWalletId The unique identifier of the user's wallet.
* @return A [Flow] emitting either a [CurrencyStatusError] or a [CryptoCurrencyStatus], indicating the result of the fetch operation.
*/
suspend fun invokeMultiWalletSync(userWalletId: UserWalletId): Either<TokenListError, List<CryptoCurrencyStatus>> {
return currencyStatusOperations.getCurrenciesStatusesSync(userWalletId)
.mapLeft { error -> error.mapToTokenListError() }
}
}

View file

@ -1,19 +1,21 @@
package com.tangem.domain.transaction.usecase.gasless
import arrow.core.Either
import arrow.core.getOrElse
import arrow.core.raise.Raise
import arrow.core.raise.catch
import arrow.core.raise.either
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCoinStatus
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.tokens.GetMultiCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.CurrencyChecksRepository
import com.tangem.domain.transaction.GaslessTransactionRepository
import com.tangem.domain.transaction.error.GetFeeError
@ -29,8 +31,7 @@ class EstimateFeeForGaslessTxUseCase(
private val walletManagersFacade: WalletManagersFacade,
private val demoConfig: DemoConfig,
private val gaslessTransactionRepository: GaslessTransactionRepository,
private val currenciesRepository: CurrenciesRepository,
private val getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val estimateFeeUseCase: EstimateFeeUseCase,
private val currencyChecksRepository: CurrencyChecksRepository,
) {
@ -50,11 +51,13 @@ class EstimateFeeForGaslessTxUseCase(
catch(
block = {
val network = sendingTokenCurrencyStatus.currency.network
val nativeCurrency = currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
networkId = network.id,
derivationPath = network.derivationPath,
)
val accountStatusList = singleAccountStatusListSupplier.getSyncOrNull(userWallet.walletId)
?: raiseIllegalStateError("AccountStatusList is null for ${userWallet.walletId}")
val nativeCurrencyStatus = accountStatusList.getCoinStatus(network).getOrElse {
raiseIllegalStateError("No native currency found: ${network.id}")
}
if (!currencyChecksRepository.isNetworkSupportedForGaslessTx(network)) {
estimateFeeUseCase.invoke(
@ -66,7 +69,7 @@ class EstimateFeeForGaslessTxUseCase(
ifRight = { fee ->
return@either TransactionFeeExtended(
transactionFee = fee,
feeTokenId = nativeCurrency.id,
feeTokenId = nativeCurrencyStatus.currency.id,
)
},
)
@ -81,9 +84,9 @@ class EstimateFeeForGaslessTxUseCase(
).bind()
selectFeePaymentStrategy(
userWallet = userWallet,
accountStatusList = accountStatusList,
walletManager = walletManager,
nativeCurrency = nativeCurrency,
nativeCurrencyStatus = nativeCurrencyStatus,
network = network,
initialFee = initialFee,
)
@ -110,25 +113,17 @@ class EstimateFeeForGaslessTxUseCase(
}
private suspend fun Raise<GetFeeError>.selectFeePaymentStrategy(
userWallet: UserWallet,
accountStatusList: AccountStatusList,
walletManager: EthereumWalletManager,
nativeCurrency: CryptoCurrency,
nativeCurrencyStatus: CryptoCurrencyStatus,
network: Network,
initialFee: TransactionFee,
): TransactionFeeExtended {
val feeValue = initialFee.normal.amount.value ?: raise(GetFeeError.UnknownError)
val userCurrenciesStatuses = getMultiCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWallet.walletId,
).getOrNull() ?: raiseIllegalStateError("currencies list is null for userWalletId=${userWallet.walletId}")
val networkCurrenciesStatuses = userCurrenciesStatuses.filter {
it.currency.network.id == network.id
}
val nativeCurrencyStatus = networkCurrenciesStatuses.find {
it.currency.id == nativeCurrency.id
} ?: raiseIllegalStateError("native currency not found for network ${network.id}")
val networkCurrenciesStatuses = accountStatusList
.flattenCurrencies()
.filter { it.currency.network.id == network.id }
val nativeBalance = nativeCurrencyStatus.value.amount ?: BigDecimal.ZERO
return if (nativeBalance >= feeValue) {

View file

@ -1,17 +1,18 @@
package com.tangem.domain.transaction.usecase.gasless
import arrow.core.Either
import arrow.core.getOrElse
import arrow.core.raise.Raise
import arrow.core.raise.catch
import arrow.core.raise.either
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCoinStatus
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.tokens.GetMultiCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.CurrencyChecksRepository
import com.tangem.domain.transaction.GaslessTransactionRepository
import com.tangem.domain.transaction.error.GetFeeError
@ -25,8 +26,7 @@ class EstimateFeeForTokenUseCase(
private val gaslessTransactionRepository: GaslessTransactionRepository,
private val walletManagersFacade: WalletManagersFacade,
private val demoConfig: DemoConfig,
private val currenciesRepository: CurrenciesRepository,
private val getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val currencyChecksRepository: CurrencyChecksRepository,
) {
@ -61,21 +61,12 @@ class EstimateFeeForTokenUseCase(
error = "only Fee.Ethereum supported, but was different",
)
val nativeCurrency = currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
networkId = token.network.id,
derivationPath = token.network.derivationPath,
)
val accountStatusList = singleAccountStatusListSupplier.getSyncOrNull(userWallet.walletId)
?: raiseIllegalStateError("AccountStatusList is null for ${userWallet.walletId}")
val userCurrenciesStatusesByNetwork = getMultiCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWallet.walletId,
).getOrNull()?.filter {
it.currency.network.id == token.network.id
} ?: raiseIllegalStateError("currencies list is null for userWalletId=${userWallet.walletId}")
val nativeCurrencyStatus = userCurrenciesStatusesByNetwork.find {
it.currency.id == nativeCurrency.id
} ?: raiseIllegalStateError("native currency not found for network ${token.network.id}")
val nativeCurrencyStatus = accountStatusList.getCoinStatus(token.network).getOrElse {
raiseIllegalStateError("No native currency found: ${token.network.id}")
}
val walletManager = prepareWalletManager(userWallet, token.network)

View file

@ -1,24 +1,23 @@
package com.tangem.domain.transaction.usecase.gasless
import arrow.core.Either
import arrow.core.raise.Raise
import arrow.core.getOrElse
import arrow.core.raise.catch
import arrow.core.raise.either
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCoinStatus
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.tokens.GetMultiCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.CurrencyChecksRepository
import com.tangem.domain.transaction.GaslessTransactionRepository
import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.domain.transaction.raiseIllegalStateError
class GetAvailableFeeTokensUseCase(
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val gaslessTransactionRepository: GaslessTransactionRepository,
private val currenciesRepository: CurrenciesRepository,
private val getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
private val currencyChecksRepository: CurrencyChecksRepository,
) {
@ -34,12 +33,14 @@ class GetAvailableFeeTokensUseCase(
return either {
catch(
block = {
val userCurrenciesStatuses = getMultiCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWallet.walletId,
).getOrNull()
?: raiseIllegalStateError("currencies list is null for userWalletId=${userWallet.walletId}")
val accountStatusList = singleAccountStatusListSupplier.getSyncOrNull(userWallet.walletId)
?: raiseIllegalStateError("AccountStatusList is null for ${userWallet.walletId}")
val nativeCurrencyStatus = getNativeCurrencyStatus(userWallet, network, userCurrenciesStatuses)
val userCurrenciesStatuses = accountStatusList.flattenCurrencies()
val nativeCurrencyStatus = accountStatusList.getCoinStatus(network).getOrElse {
raiseIllegalStateError("No native currency found: ${network.id}")
}
if (!currencyChecksRepository.isNetworkSupportedForGaslessTx(network)) {
return@either listOf(nativeCurrencyStatus)
@ -58,21 +59,6 @@ class GetAvailableFeeTokensUseCase(
}
}
private suspend fun Raise<GetFeeError>.getNativeCurrencyStatus(
userWallet: UserWallet,
network: Network,
userCurrenciesStatuses: List<CryptoCurrencyStatus>,
): CryptoCurrencyStatus {
val nativeCurrency = currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
networkId = network.id,
derivationPath = network.derivationPath,
)
return userCurrenciesStatuses.find {
it.currency.id == nativeCurrency.id
} ?: raiseIllegalStateError("no native currency found")
}
private suspend fun getGaslessTokens(
network: Network,
userCurrenciesStatuses: List<CryptoCurrencyStatus>,

View file

@ -9,13 +9,14 @@ import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.common.TransactionData
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCoinStatus
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.tokens.GetMultiCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.CurrencyChecksRepository
import com.tangem.domain.transaction.GaslessTransactionRepository
import com.tangem.domain.transaction.error.GetFeeError
@ -31,8 +32,7 @@ class GetFeeForGaslessUseCase(
private val walletManagersFacade: WalletManagersFacade,
private val demoConfig: DemoConfig,
private val gaslessTransactionRepository: GaslessTransactionRepository,
private val currenciesRepository: CurrenciesRepository,
private val getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getFeeUseCase: GetFeeUseCase,
private val currencyChecksRepository: CurrencyChecksRepository,
) {
@ -51,11 +51,12 @@ class GetFeeForGaslessUseCase(
return either {
catch(
block = {
val nativeCurrency = currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
networkId = network.id,
derivationPath = network.derivationPath,
)
val accountStatusList = singleAccountStatusListSupplier.getSyncOrNull(userWallet.walletId)
?: raiseIllegalStateError("AccountStatusList is null for ${userWallet.walletId}")
val nativeCurrencyStatus = accountStatusList.getCoinStatus(network).getOrElse {
raiseIllegalStateError("No native currency found: ${network.id}")
}
if (!currencyChecksRepository.isNetworkSupportedForGaslessTx(network)) {
getFeeUseCase.invoke(userWallet, network, transactionData).fold(
@ -63,7 +64,7 @@ class GetFeeForGaslessUseCase(
ifRight = { fee ->
return@either TransactionFeeExtended(
transactionFee = fee,
feeTokenId = nativeCurrency.id,
feeTokenId = nativeCurrencyStatus.currency.id,
)
},
)
@ -79,9 +80,9 @@ class GetFeeForGaslessUseCase(
).bind()
selectFeePaymentStrategy(
userWallet = userWallet,
accountStatusList = accountStatusList,
walletManager = walletManager,
nativeCurrency = nativeCurrency,
nativeCurrencyStatus = nativeCurrencyStatus,
network = network,
initialFee = initialFee,
)
@ -108,25 +109,17 @@ class GetFeeForGaslessUseCase(
}
private suspend fun Raise<GetFeeError>.selectFeePaymentStrategy(
userWallet: UserWallet,
accountStatusList: AccountStatusList,
walletManager: EthereumWalletManager,
nativeCurrency: CryptoCurrency,
nativeCurrencyStatus: CryptoCurrencyStatus,
network: Network,
initialFee: TransactionFee,
): TransactionFeeExtended {
val feeValue = initialFee.normal.amount.value ?: raise(GetFeeError.UnknownError)
val userCurrenciesStatuses = getMultiCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWallet.walletId,
).getOrNull() ?: raiseIllegalStateError("currencies list is null for userWalletId=${userWallet.walletId}")
val networkCurrenciesStatuses = userCurrenciesStatuses.filter {
it.currency.network.id == network.id
}
val nativeCurrencyStatus = networkCurrenciesStatuses.find {
it.currency.id == nativeCurrency.id
} ?: raiseIllegalStateError("native currency not found for network ${network.id}")
val networkCurrenciesStatuses = accountStatusList
.flattenCurrencies()
.filter { it.currency.network.id == network.id }
val nativeBalance = nativeCurrencyStatus.value.amount ?: BigDecimal.ZERO
val nativeCoinSelectedResult =

View file

@ -1,18 +1,20 @@
package com.tangem.domain.transaction.usecase.gasless
import arrow.core.Either
import arrow.core.getOrElse
import arrow.core.raise.Raise
import arrow.core.raise.catch
import arrow.core.raise.either
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.common.TransactionData
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCoinStatus
import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.tokens.GetMultiCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.CurrencyChecksRepository
import com.tangem.domain.transaction.GaslessTransactionRepository
import com.tangem.domain.transaction.error.GetFeeError
@ -25,8 +27,7 @@ class GetFeeForTokenUseCase(
private val gaslessTransactionRepository: GaslessTransactionRepository,
private val walletManagersFacade: WalletManagersFacade,
private val demoConfig: DemoConfig,
private val currenciesRepository: CurrenciesRepository,
private val getMultiCryptoCurrencyStatusUseCase: GetMultiCryptoCurrencyStatusUseCase,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val currencyChecksRepository: CurrencyChecksRepository,
) {
@ -62,25 +63,16 @@ class GetFeeForTokenUseCase(
error = "only Fee.Ethereum supported, but was different",
)
val nativeCurrency = currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
networkId = token.network.id,
derivationPath = token.network.derivationPath,
)
val accountStatusList = singleAccountStatusListSupplier.getSyncOrNull(userWallet.walletId)
?: raiseIllegalStateError("AccountStatusList is null for ${userWallet.walletId}")
val userCurrenciesStatusesByNetwork = getMultiCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWallet.walletId,
).getOrNull()?.filter {
it.currency.network.id == token.network.id
} ?: raiseIllegalStateError("currencies list is null for userWalletId=${userWallet.walletId}")
val nativeCurrencyStatus = accountStatusList.getCoinStatus(token.network).getOrElse {
raiseIllegalStateError("Native currency not found for network ${token.network.id}")
}
val nativeCurrencyStatus = userCurrenciesStatusesByNetwork.find {
it.currency.id == nativeCurrency.id
} ?: raiseIllegalStateError("native currency not found for network ${token.network.id}")
val tokenCurrencyStatus = userCurrenciesStatusesByNetwork.find {
it.currency.id == token.id
} ?: raiseIllegalStateError("token currency not found for network ${token.network.id}")
val tokenCurrencyStatus = accountStatusList.getCryptoCurrencyStatus(currency = token).getOrElse {
raiseIllegalStateError("Token currency not found for network ${token.network.id}")
}
tokenFeeCalculator.calculateTokenFee(
walletManager = walletManager,

View file

@ -1,7 +1,5 @@
package com.tangem.feature.swap.domain.di
import com.tangem.domain.tokens.GetMultiCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.operations.BaseCurrencyStatusOperations
import com.tangem.feature.swap.domain.*
import dagger.Module
import dagger.Provides
@ -24,14 +22,6 @@ internal class SwapDomainModule {
return factory
}
@Provides
@Singleton
fun providesGetCryptoCurrencyStatusUseCase(
currencyStatusOperations: BaseCurrencyStatusOperations,
): GetMultiCryptoCurrencyStatusUseCase {
return GetMultiCryptoCurrencyStatusUseCase(currencyStatusOperations)
}
@Provides
@Singleton
fun provideInitialToCurrencyResolver(