Updated on 2026-08-14
This commit is contained in:
parent
eec7f2ffc0
commit
cff0f51c84
4 changed files with 30 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
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
|
||||
|
|
@ -128,25 +129,32 @@ class GetFeeForGaslessUseCase(
|
|||
} ?: raiseIllegalStateError("native currency not found for network ${network.id}")
|
||||
|
||||
val nativeBalance = nativeCurrencyStatus.value.amount ?: BigDecimal.ZERO
|
||||
return if (nativeBalance >= feeValue) {
|
||||
val nativeCoinSelectedResult =
|
||||
TransactionFeeExtended(transactionFee = initialFee, feeTokenId = nativeCurrencyStatus.currency.id)
|
||||
return if (nativeBalance >= feeValue) {
|
||||
nativeCoinSelectedResult
|
||||
} else {
|
||||
findTokensToPayFee(
|
||||
walletManager = walletManager,
|
||||
initialTxFee = initialFee,
|
||||
nativeCurrencyStatus = nativeCurrencyStatus,
|
||||
networkCurrenciesStatuses = networkCurrenciesStatuses,
|
||||
)
|
||||
).getOrElse { error ->
|
||||
when (error) {
|
||||
GaslessError.NotEnoughFunds -> nativeCoinSelectedResult
|
||||
else -> raise(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("NullableToStringCall")
|
||||
private suspend fun Raise<GetFeeError>.findTokensToPayFee(
|
||||
private suspend fun findTokensToPayFee(
|
||||
walletManager: EthereumWalletManager,
|
||||
initialTxFee: TransactionFee,
|
||||
nativeCurrencyStatus: CryptoCurrencyStatus,
|
||||
networkCurrenciesStatuses: List<CryptoCurrencyStatus>,
|
||||
): TransactionFeeExtended {
|
||||
): Either<GetFeeError, TransactionFeeExtended> = either {
|
||||
val initialFee = initialTxFee.normal as? Fee.Ethereum
|
||||
?: raiseIllegalStateError(
|
||||
error = "only Fee.Ethereum supported, but was ${initialTxFee.normal::class.qualifiedName}",
|
||||
|
|
@ -178,6 +186,6 @@ class GetFeeForGaslessUseCase(
|
|||
tokenForPayFeeStatus = tokenForPayFeeStatus,
|
||||
nativeCurrencyStatus = nativeCurrencyStatus,
|
||||
initialFee = initialFee,
|
||||
).bind()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import arrow.core.raise.either
|
|||
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
|
||||
import com.tangem.blockchain.blockchains.ethereum.tokenmethods.TransferERC20TokenCallData
|
||||
import com.tangem.blockchain.common.Amount
|
||||
import com.tangem.blockchain.common.BlockchainSdkError
|
||||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.blockchain.common.TransactionData
|
||||
import com.tangem.blockchain.common.transaction.Fee
|
||||
|
|
@ -89,6 +90,7 @@ internal class TokenFeeCalculator(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||
suspend fun calculateTokenFee(
|
||||
walletManager: EthereumWalletManager,
|
||||
tokenForPayFeeStatus: CryptoCurrencyStatus,
|
||||
|
|
@ -119,8 +121,17 @@ internal class TokenFeeCalculator(
|
|||
)
|
||||
|
||||
val feeTransferGasLimit = when (feeTransferGasLimitResult) {
|
||||
is Result.Failure -> raise(GaslessError.DataError(feeTransferGasLimitResult.error))
|
||||
is Result.Success -> feeTransferGasLimitResult.data
|
||||
is Result.Failure -> {
|
||||
// If there is a dust on the balance, the gas limit estimation will fail with code
|
||||
if (feeTransferGasLimitResult.error is BlockchainSdkError.WrappedThrowable) {
|
||||
val cause = feeTransferGasLimitResult.error.cause
|
||||
if (cause is BlockchainSdkError.Ethereum.InsufficientFundsForOperation) {
|
||||
raise(GaslessError.NotEnoughFunds)
|
||||
}
|
||||
}
|
||||
raise(GaslessError.DataError(feeTransferGasLimitResult.error))
|
||||
}
|
||||
}.increaseByPercent(PERCENT_TO_INCREASE_TRANSFER_GASLIMIT)
|
||||
|
||||
val baseGas = gaslessTransactionRepository.getBaseGasForTransaction()
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import com.tangem.features.send.v2.api.subcomponents.feeSelector.FeeSelectorRelo
|
|||
import com.tangem.features.send.v2.api.subcomponents.feeSelector.analytics.CommonSendFeeAnalyticEvents
|
||||
import com.tangem.features.send.v2.api.subcomponents.feeSelector.analytics.CommonSendFeeAnalyticEvents.GasPriceInserter
|
||||
import com.tangem.features.send.v2.feeselector.model.transformers.*
|
||||
import com.tangem.utils.coroutines.JobHolder
|
||||
import com.tangem.utils.coroutines.saveIn
|
||||
import com.tangem.utils.transformer.update
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
|
|
@ -62,6 +64,7 @@ internal class FeeSelectorLogic @AssistedInject constructor(
|
|||
) : FeeSelectorIntents {
|
||||
|
||||
private var appCurrency: AppCurrency = AppCurrency.Default
|
||||
private val loadFeeJobHolder = JobHolder()
|
||||
val uiState = MutableStateFlow(params.state)
|
||||
|
||||
val isGaslessEnabled = sendFeatureToggles.isGaslessTransactionsEnabled &&
|
||||
|
|
@ -113,7 +116,7 @@ internal class FeeSelectorLogic @AssistedInject constructor(
|
|||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}.saveIn(loadFeeJobHolder)
|
||||
}
|
||||
|
||||
private fun isFeeApproximate(amountType: AmountType): Boolean {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
# https://github.com/tangem/tangem-sdk-android/
|
||||
# https://github.com/tangem/vico
|
||||
|
||||
tangemBlockchainSdk = "releases-5.33-1413"
|
||||
tangemBlockchainSdk = "releases-5.33-1421"
|
||||
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
|
||||
tangemCardSdk = "releases-5.33-576"
|
||||
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue