Updated on 2026-08-14

This commit is contained in:
Tangem 2025-09-23 20:21:48 +05:00
parent 043602ebd6
commit dd362fb32c
21 changed files with 133 additions and 184 deletions

View file

@ -317,7 +317,7 @@ internal class SendConfirmModel @Inject constructor(
null
}
val amount = receivingAmount?.convertToSdkAmount(cryptoCurrency)
val amount = receivingAmount?.convertToSdkAmount(cryptoCurrencyStatus)
saveBlockchainErrorUseCase(
error = BlockchainErrorInfo(
@ -331,7 +331,7 @@ internal class SendConfirmModel @Inject constructor(
""
},
amount = amount?.value?.stripZeroPlainString() ?: "unknown",
fee = feeValue?.convertToSdkAmount(cryptoCurrency)
fee = feeValue?.convertToSdkAmount(cryptoCurrencyStatus)
?.value?.stripZeroPlainString() ?: "unknown",
),
)
@ -424,7 +424,7 @@ internal class SendConfirmModel @Inject constructor(
modelScope.launch {
createTransferTransactionUseCase(
amount = receivingAmount.convertToSdkAmount(cryptoCurrency),
amount = receivingAmount.convertToSdkAmount(cryptoCurrencyStatus),
fee = fee,
memo = memo,
nonce = nonce,

View file

@ -260,10 +260,11 @@ internal class SendModel @Inject constructor(
suspend fun loadFee(): Either<GetFeeError, TransactionFee> {
val predefinedValues = predefinedValues
val cryptoCurrencyStatus = cryptoCurrencyStatusFlow.value
val transferTransaction = if (predefinedValues is PredefinedValues.Content.Deeplink) {
val predefinedAmount = predefinedValues.amount.parseBigDecimalOrNull()?.convertToSdkAmount(cryptoCurrency)
val predefinedAmount = predefinedValues.amount.parseBigDecimalOrNull()
createTransferTransactionUseCase(
amount = predefinedAmount ?: error("Invalid amount"),
amount = predefinedAmount?.convertToSdkAmount(cryptoCurrencyStatus) ?: error("Invalid amount"),
memo = predefinedValues.memo,
destination = predefinedValues.address,
userWalletId = userWallet.walletId,
@ -277,7 +278,7 @@ internal class SendModel @Inject constructor(
val enteredAmount = amountUM.amountTextField.cryptoAmount.value ?: error("Invalid amount")
createTransferTransactionUseCase(
amount = enteredAmount.convertToSdkAmount(cryptoCurrency),
amount = enteredAmount.convertToSdkAmount(cryptoCurrencyStatus),
memo = enteredMemo,
destination = enteredDestinationAddress,
userWalletId = userWallet.walletId,

View file

@ -287,7 +287,7 @@ internal class NotificationsModel @Inject constructor(
) {
val validationError = validateTransactionUseCase(
userWalletId = userWalletId,
amount = enteredAmount.convertToSdkAmount(currency),
amount = enteredAmount.convertToSdkAmount(cryptoCurrencyStatus),
fee = fee,
memo = memo,
destination = destinationAddress,

View file

@ -651,7 +651,7 @@ internal class StakingModel @Inject constructor(
contractAddress = tokenCryptoCurrency.contractAddress,
spenderAddress = approval.spenderAddress,
fee = fee,
cryptoCurrency = tokenCryptoCurrency,
cryptoCurrencyStatus = cryptoCurrencyStatus,
userWalletId = userWalletId,
).fold(
ifLeft = { error ->

View file

@ -189,7 +189,7 @@ internal class StakingFeeTransactionLoader @AssistedInject constructor(
val tokenCurrency = cryptoCurrencyStatus.currency as? CryptoCurrency.Token
?: return onApprovalFeeError(GetFeeError.UnknownError)
val approvalTransactionData = createApprovalTransactionUseCase(
cryptoCurrency = tokenCurrency,
cryptoCurrencyStatus = cryptoCurrencyStatus,
userWalletId = userWallet.walletId,
amount = amount,
contractAddress = tokenCurrency.contractAddress,

View file

@ -158,7 +158,7 @@ internal class StakingTransactionSender @AssistedInject constructor(
getConstructedStakingTransactionUseCase(
networkId = cryptoCurrencyStatus.currency.network.rawId,
fee = fee,
amount = amount.convertToSdkAmount(cryptoCurrencyStatus.currency),
amount = amount.convertToSdkAmount(cryptoCurrencyStatus),
transactionId = transaction.id,
).fold(
ifRight = { (constructedTransaction, transactionData) ->

View file

@ -227,7 +227,7 @@ internal class SendWithSwapConfirmModel @Inject constructor(
estimateFeeUseCase(
amount = amountValue,
userWallet = params.userWallet,
cryptoCurrency = primaryCurrencyStatus.currency,
cryptoCurrencyStatus = primaryCurrencyStatus,
).map {
it.patchTransactionFeeForSwap(INCREASE_GAS_LIMIT_FOR_CEX)
}

View file

@ -131,7 +131,7 @@ internal class SwapTransactionSender @AssistedInject constructor(
}
val txData = createTransferTransactionUseCase(
amount = fromAmount.convertToSdkAmount(fromStatus.currency),
amount = fromAmount.convertToSdkAmount(fromStatus),
fee = fee,
memo = swapTransaction.txExtraId,
destination = swapTransaction.txTo,

View file

@ -307,7 +307,7 @@ private fun SendWithSwapSuccessContent_Preview() {
fees = TransactionFee.Single(
normal = Fee.Common(
BigDecimal.ONE.convertToSdkAmount(
SwapAmountContentPreview.cryptoCurrencyStatus.currency,
SwapAmountContentPreview.cryptoCurrencyStatus,
),
),
),
@ -315,7 +315,7 @@ private fun SendWithSwapSuccessContent_Preview() {
selectedFeeItem = FeeItem.Market(
Fee.Common(
BigDecimal.ONE.convertToSdkAmount(
SwapAmountContentPreview.cryptoCurrencyStatus.currency,
SwapAmountContentPreview.cryptoCurrencyStatus,
),
),
),

View file

@ -1,6 +1,6 @@
package com.tangem.feature.swap.domain.models.domain
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.feature.swap.domain.models.ui.RequestApproveStateData
import com.tangem.feature.swap.domain.models.ui.TxFee
@ -9,14 +9,14 @@ import com.tangem.feature.swap.domain.models.ui.TxFee
*
* @param approveData tx data to give approve, it loaded from 1inch in findBestQuote if needed
* @param forTokenContractAddress token contract address for which needs permission
* @param fromToken which token will be swapping
* @param fromTokenStatus which token will be swapping
* @param approveType unlimited or tx amount approve
* @param txFee fee for tx
*/
data class PermissionOptions(
val approveData: RequestApproveStateData,
val forTokenContractAddress: String,
val fromToken: CryptoCurrency,
val fromTokenStatus: CryptoCurrencyStatus,
val spenderAddress: String,
val approveType: SwapApproveType,
val txFee: TxFee,

View file

@ -1,5 +1,6 @@
package com.tangem.feature.swap.domain
import android.util.Base64
import arrow.core.Either
import arrow.core.getOrElse
import com.tangem.blockchain.common.Amount
@ -11,6 +12,7 @@ import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.blockchainsdk.utils.fromNetworkId
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.blockchainsdk.utils.toNetworkId
import com.tangem.core.ui.format.bigdecimal.fiat
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
@ -52,8 +54,6 @@ import timber.log.Timber
import java.math.BigDecimal
import java.math.BigInteger
import java.math.RoundingMode
import android.util.Base64
import com.tangem.blockchainsdk.utils.toNetworkId
@Suppress("LargeClass", "LongParameterList")
internal class SwapInteractorImpl @AssistedInject constructor(
@ -227,7 +227,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
val approveTransaction = createApprovalTransactionUseCase(
fee = permissionOptions.txFee.fee,
userWalletId = userWalletId,
cryptoCurrency = permissionOptions.fromToken as CryptoCurrency.Token,
cryptoCurrencyStatus = permissionOptions.fromTokenStatus,
amount = amount?.value,
contractAddress = permissionOptions.forTokenContractAddress,
spenderAddress = permissionOptions.spenderAddress,
@ -239,7 +239,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
val result = sendTransactionUseCase(
txData = approveTransaction,
userWallet = userWallet,
network = permissionOptions.fromToken.network,
network = permissionOptions.fromTokenStatus.currency.network,
)
return result.fold(
ifRight = { hash ->
@ -546,7 +546,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
)
val result = validateTransactionUseCase(
amount = amount.value.convertToSdkAmount(currency),
amount = amount.value.convertToSdkAmount(fromToken),
fee = fee,
memo = null,
destination = getTokenAddress(fromToken.currency),
@ -842,7 +842,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
}
val txData = createTransferTransactionUseCase(
amount = amount.value.convertToSdkAmount(currencyToSend.currency),
amount = amount.value.convertToSdkAmount(currencyToSend),
fee = txFee.fee,
memo = exchangeDataCex.txExtraId,
destination = exchangeDataCex.txTo,
@ -1022,7 +1022,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
val txFeeResult = getUnhandledFee(
amount = amount.value,
userWallet = userWallet,
cryptoCurrency = fromToken,
cryptoCurrencyStatus = fromTokenStatus,
)
val txFee = if (provider.type == ExchangeProviderType.CEX) {
@ -1520,12 +1520,12 @@ internal class SwapInteractorImpl @AssistedInject constructor(
private suspend fun getUnhandledFee(
amount: BigDecimal,
userWallet: UserWallet,
cryptoCurrency: CryptoCurrency,
cryptoCurrencyStatus: CryptoCurrencyStatus,
): Either<GetFeeError, TransactionFee> {
return estimateFeeUseCase(
amount = amount,
userWallet = userWallet,
cryptoCurrency = cryptoCurrency,
cryptoCurrencyStatus = cryptoCurrencyStatus,
)
}
@ -1560,7 +1560,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
// setting up amount for approve with given amount for swap [SwapApproveType.Limited]
val callData = SmartContractCallDataProviderFactory.getApprovalCallData(
spenderAddress = requireNotNull(spenderAddress) { "Spender address is null" },
amount = swapAmount.value.convertToSdkAmount(fromToken),
amount = swapAmount.value.convertToSdkAmount(fromTokenStatus),
blockchain = fromToken.network.toBlockchain(),
)
val feeData = try {

View file

@ -700,9 +700,11 @@ internal class SwapModel @Inject constructor(
private fun givePermissionsToSwap() {
modelScope.launch(dispatchers.main) {
runCatching {
val fromToken = requireNotNull(dataState.fromCryptoCurrency?.currency) {
"dataState.fromCurrency might not be null"
val fromCryptoCurrency = requireNotNull(dataState.fromCryptoCurrency) {
"dataState.fromCryptoCurrency might not be null"
}
val fromToken = fromCryptoCurrency.currency
val approveDataModel = requireNotNull(dataState.approveDataModel) {
"dataState.approveDataModel.spenderAddress shouldn't be null"
}
@ -725,7 +727,7 @@ internal class SwapModel @Inject constructor(
permissionOptions = PermissionOptions(
approveData = approveDataModel,
forTokenContractAddress = (fromToken as? CryptoCurrency.Token)?.contractAddress.orEmpty(),
fromToken = fromToken,
fromTokenStatus = fromCryptoCurrency,
approveType = approveType,
txFee = feeForPermission,
spenderAddress = approveDataModel.spenderAddress,

View file

@ -144,7 +144,7 @@ internal class YieldSupplyApproveModel @Inject constructor(
).getOrNull() ?: return
val approvalTransitionData = createApprovalTransactionUseCase(
cryptoCurrency = cryptoCurrency,
cryptoCurrencyStatus = cryptoCurrencyStatus,
userWalletId = userWallet.walletId,
contractAddress = cryptoCurrency.contractAddress,
spenderAddress = contractAddress,