Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-23 12:37:05 +05:00
parent 736ef3e45e
commit 55a740c941
5 changed files with 42 additions and 16 deletions

View file

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

View file

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

View file

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

View file

@ -33,7 +33,7 @@ class GetFeeUseCase(
walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWallet.walletId,
network = network,
) as? TransactionSender
)
}
val result = transactionSender?.getFee(transactionData = transactionData)
?: 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.transaction.ActionParams
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.staking.getCurrentToken
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.IsFeeApproximateUseCase
import com.tangem.domain.wallets.models.UserWallet
@ -40,6 +42,7 @@ internal class StakingFeeTransactionLoader @AssistedInject constructor(
private val getFeeUseCase: GetFeeUseCase,
private val estimateGasUseCase: EstimateGasUseCase,
private val isFeeApproximateUseCase: IsFeeApproximateUseCase,
private val createApprovalTransactionUseCase: CreateApprovalTransactionUseCase,
@Assisted private val cryptoCurrencyStatus: CryptoCurrencyStatus,
@Assisted private val userWallet: UserWallet,
@Assisted private val yield: Yield,
@ -183,11 +186,22 @@ internal class StakingFeeTransactionLoader @AssistedInject constructor(
onApprovalFee: (TransactionFee) -> 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,
destination = validatorAddress,
fee = null,
contractAddress = tokenCurrency.contractAddress,
spenderAddress = validatorAddress,
).getOrElse {
return onApprovalFeeError(GetFeeError.DataError(it))
}
getFeeUseCase(
userWallet = userWallet,
cryptoCurrency = cryptoCurrencyStatus.currency,
network = tokenCurrency.network,
transactionData = approvalTransactionData,
).fold(
ifRight = { fee ->
onApprovalFee(fee)