Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-25 13:11:35 +05:00
commit 56733bbf0b
5 changed files with 42 additions and 16 deletions

View file

@ -38,7 +38,7 @@ internal class DefaultTransactionRepository(
override suspend fun createTransaction( override suspend fun createTransaction(
amount: Amount, amount: Amount,
fee: Fee, fee: Fee?,
memo: String?, memo: String?,
destination: String, destination: String,
userWalletId: UserWalletId, userWalletId: UserWalletId,
@ -52,13 +52,25 @@ internal class DefaultTransactionRepository(
derivationPath = network.derivationPath.value, derivationPath = network.derivationPath.value,
) ?: error("Wallet manager not found") ) ?: error("Wallet manager not found")
return@withContext walletManager.createTransaction( val extras = txExtras ?: getMemoExtras(networkId = network.id.value, memo)
amount = amount,
fee = fee, return@withContext if (fee != null) {
destination = destination, walletManager.createTransaction(
).copy( amount = amount,
extras = txExtras ?: getMemoExtras(networkId = network.id.value, memo), fee = fee,
) destination = destination,
).copy(
extras = extras,
)
} else {
TransactionData.Uncompiled(
amount = amount,
sourceAddress = walletManager.wallet.address,
destinationAddress = destination,
extras = extras,
fee = null,
)
}
} }
override suspend fun createTransferTransaction( override suspend fun createTransferTransaction(
@ -102,7 +114,7 @@ internal class DefaultTransactionRepository(
override suspend fun createApprovalTransaction( override suspend fun createApprovalTransaction(
amount: Amount, amount: Amount,
approvalAmount: Amount?, approvalAmount: Amount?,
fee: Fee, fee: Fee?,
contractAddress: String, contractAddress: String,
spenderAddress: String, spenderAddress: String,
userWalletId: UserWalletId, userWalletId: UserWalletId,

View file

@ -16,7 +16,7 @@ interface TransactionRepository {
@Suppress("LongParameterList") @Suppress("LongParameterList")
suspend fun createTransaction( suspend fun createTransaction(
amount: Amount, amount: Amount,
fee: Fee, fee: Fee?,
memo: String?, memo: String?,
destination: String, destination: String,
userWalletId: UserWalletId, userWalletId: UserWalletId,
@ -38,7 +38,7 @@ interface TransactionRepository {
suspend fun createApprovalTransaction( suspend fun createApprovalTransaction(
amount: Amount, amount: Amount,
approvalAmount: Amount?, approvalAmount: Amount?,
fee: Fee, fee: Fee?,
contractAddress: String, contractAddress: String,
spenderAddress: String, spenderAddress: String,
userWalletId: UserWalletId, userWalletId: UserWalletId,

View file

@ -20,7 +20,7 @@ class CreateApprovalTransactionUseCase(
cryptoCurrency: CryptoCurrency.Token, cryptoCurrency: CryptoCurrency.Token,
userWalletId: UserWalletId, userWalletId: UserWalletId,
amount: BigDecimal?, amount: BigDecimal?,
fee: Fee, fee: Fee?,
contractAddress: String, contractAddress: String,
spenderAddress: String, spenderAddress: String,
) = Either.catch { ) = Either.catch {

View file

@ -33,7 +33,7 @@ class GetFeeUseCase(
walletManagersFacade.getOrCreateWalletManager( walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWallet.walletId, userWalletId = userWallet.walletId,
network = network, network = network,
) as? TransactionSender )
} }
val result = transactionSender?.getFee(transactionData = transactionData) val result = transactionSender?.getFee(transactionData = transactionData)
?: error("Fee is null") ?: error("Fee is null")

View file

@ -14,9 +14,11 @@ import com.tangem.domain.staking.model.stakekit.Yield
import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType
import com.tangem.domain.staking.model.stakekit.transaction.ActionParams import com.tangem.domain.staking.model.stakekit.transaction.ActionParams
import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.staking.getCurrentToken import com.tangem.domain.tokens.model.staking.getCurrentToken
import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.domain.transaction.usecase.CreateApprovalTransactionUseCase
import com.tangem.domain.transaction.usecase.GetFeeUseCase import com.tangem.domain.transaction.usecase.GetFeeUseCase
import com.tangem.domain.transaction.usecase.IsFeeApproximateUseCase import com.tangem.domain.transaction.usecase.IsFeeApproximateUseCase
import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWallet
@ -40,6 +42,7 @@ internal class StakingFeeTransactionLoader @AssistedInject constructor(
private val getFeeUseCase: GetFeeUseCase, private val getFeeUseCase: GetFeeUseCase,
private val estimateGasUseCase: EstimateGasUseCase, private val estimateGasUseCase: EstimateGasUseCase,
private val isFeeApproximateUseCase: IsFeeApproximateUseCase, private val isFeeApproximateUseCase: IsFeeApproximateUseCase,
private val createApprovalTransactionUseCase: CreateApprovalTransactionUseCase,
@Assisted private val cryptoCurrencyStatus: CryptoCurrencyStatus, @Assisted private val cryptoCurrencyStatus: CryptoCurrencyStatus,
@Assisted private val userWallet: UserWallet, @Assisted private val userWallet: UserWallet,
@Assisted private val yield: Yield, @Assisted private val yield: Yield,
@ -183,11 +186,22 @@ internal class StakingFeeTransactionLoader @AssistedInject constructor(
onApprovalFee: (TransactionFee) -> Unit, onApprovalFee: (TransactionFee) -> Unit,
onApprovalFeeError: (GetFeeError) -> Unit, onApprovalFeeError: (GetFeeError) -> Unit,
) { ) {
getFeeUseCase( val tokenCurrency = cryptoCurrencyStatus.currency as? CryptoCurrency.Token
?: return onApprovalFeeError(GetFeeError.UnknownError)
val approvalTransactionData = createApprovalTransactionUseCase(
cryptoCurrency = tokenCurrency,
userWalletId = userWallet.walletId,
amount = amount, amount = amount,
destination = validatorAddress, fee = null,
contractAddress = tokenCurrency.contractAddress,
spenderAddress = validatorAddress,
).getOrElse {
return onApprovalFeeError(GetFeeError.DataError(it))
}
getFeeUseCase(
userWallet = userWallet, userWallet = userWallet,
cryptoCurrency = cryptoCurrencyStatus.currency, network = tokenCurrency.network,
transactionData = approvalTransactionData,
).fold( ).fold(
ifRight = { fee -> ifRight = { fee ->
onApprovalFee(fee) onApprovalFee(fee)