diff --git a/domain/transaction/models/src/main/kotlin/com/tangem/domain/transaction/error/GetFeeError.kt b/domain/transaction/models/src/main/kotlin/com/tangem/domain/transaction/error/GetFeeError.kt index 1e8b733d5c..3c8dfbdcfb 100644 --- a/domain/transaction/models/src/main/kotlin/com/tangem/domain/transaction/error/GetFeeError.kt +++ b/domain/transaction/models/src/main/kotlin/com/tangem/domain/transaction/error/GetFeeError.kt @@ -10,6 +10,9 @@ sealed class GetFeeError { data object SuiOneCoinRequired : BlockchainErrors() } + /** + * Gasless transaction related errors, model logic uses this errors types, don't remove or change them + */ sealed class GaslessError : GetFeeError() { data object NetworkIsNotSupported : GaslessError() data object NoSupportedTokensFound : GaslessError() diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/gasless/TokenFeeCalculator.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/gasless/TokenFeeCalculator.kt index 803a21668b..41e65be9d6 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/gasless/TokenFeeCalculator.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/gasless/TokenFeeCalculator.kt @@ -20,11 +20,11 @@ import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.transaction.GaslessTransactionRepository import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.transaction.error.GetFeeError.GaslessError -import com.tangem.domain.transaction.error.mapToFeeError import com.tangem.domain.transaction.models.TransactionFeeExtended import com.tangem.domain.transaction.raiseIllegalStateError import com.tangem.domain.utils.convertToSdkAmount import com.tangem.domain.walletmanager.WalletManagersFacade +import com.tangem.utils.extensions.isZero import java.math.BigDecimal import java.math.BigInteger import java.math.RoundingMode @@ -83,7 +83,7 @@ internal class TokenFeeCalculator( when (result) { is Result.Success -> result.data - is Result.Failure -> raise(result.mapToFeeError()) + is Result.Failure -> raise(GaslessError.DataError(result.error)) null -> raise(GetFeeError.UnknownError) } } @@ -96,6 +96,11 @@ internal class TokenFeeCalculator( initialFee: Fee.Ethereum, ): Either { return either { + // fast finish to skip calculations if no funds in token + if (tokenForPayFeeStatus.value.amount?.isZero() == true) { + raise(GaslessError.NotEnoughFunds) + } + val tokenForPayFee = tokenForPayFeeStatus.currency as? CryptoCurrency.Token ?: raiseIllegalStateError("only tokens are supported") @@ -114,7 +119,7 @@ internal class TokenFeeCalculator( ) val feeTransferGasLimit = when (feeTransferGasLimitResult) { - is Result.Failure -> raise(GetFeeError.DataError(feeTransferGasLimitResult.error)) + is Result.Failure -> raise(GaslessError.DataError(feeTransferGasLimitResult.error)) is Result.Success -> feeTransferGasLimitResult.data }.increaseByPercent(PERCENT_TO_INCREASE_TRANSFER_GASLIMIT) diff --git a/domain/transaction/src/test/java/com/tangem/domain/transaction/usecase/gasless/TokenFeeCalculatorTest.kt b/domain/transaction/src/test/java/com/tangem/domain/transaction/usecase/gasless/TokenFeeCalculatorTest.kt index e3a91a642c..3c60d6efea 100644 --- a/domain/transaction/src/test/java/com/tangem/domain/transaction/usecase/gasless/TokenFeeCalculatorTest.kt +++ b/domain/transaction/src/test/java/com/tangem/domain/transaction/usecase/gasless/TokenFeeCalculatorTest.kt @@ -298,7 +298,7 @@ class TokenFeeCalculatorTest { // Then assertTrue(result.isLeft()) result.onLeft { error -> - assertTrue(error is GetFeeError.DataError) + assertTrue(error is GetFeeError.GaslessError.DataError) } }