Updated on 2026-08-14

This commit is contained in:
Tangem 2025-07-30 12:29:05 +05:00
parent 4c51193221
commit c8a181c829
13 changed files with 135 additions and 73 deletions

View file

@ -1,11 +1,11 @@
package com.tangem.domain.swap
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.swap.models.SwapStatusModel
import com.tangem.domain.swap.models.SwapTransactionListModel
import com.tangem.domain.swap.models.SwapTransactionModel
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import kotlinx.coroutines.flow.Flow
/**
@ -34,7 +34,7 @@ interface SwapTransactionRepository {
* @param userWallet selected user wallet
* @param cryptoCurrencyId transactions for specific crypto currency
*/
suspend fun getTransactions(
fun getTransactions(
userWallet: UserWallet,
cryptoCurrencyId: CryptoCurrency.ID,
): Flow<List<SwapTransactionListModel>?>

View file

@ -8,10 +8,7 @@ import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.swap.SwapErrorResolver
import com.tangem.domain.swap.SwapRepositoryV2
import com.tangem.domain.swap.SwapTransactionRepository
import com.tangem.domain.swap.models.SwapDataTransactionModel
import com.tangem.domain.swap.models.SwapStatus
import com.tangem.domain.swap.models.SwapStatusModel
import com.tangem.domain.swap.models.SwapTransactionModel
import com.tangem.domain.swap.models.*
@Suppress("LongParameterList")
class SwapTransactionSentUseCase(
@ -28,15 +25,8 @@ class SwapTransactionSentUseCase(
provider: ExpressProvider,
txHash: String,
timestamp: Long,
swapTxType: SwapTxType,
) = Either.catch {
swapRepositoryV2.swapTransactionSent(
userWallet = userWallet,
fromCryptoCurrencyStatus = fromCryptoCurrencyStatus,
toAddress = swapDataTransactionModel.txTo,
txId = swapDataTransactionModel.txId,
txHash = txHash,
txExtraId = swapDataTransactionModel.txExtraId,
)
if (provider.type.shouldStoreSwapTransaction()) {
swapTransactionRepository.storeTransaction(
userWalletId = userWallet.walletId,
@ -56,12 +46,22 @@ class SwapTransactionSentUseCase(
txExternalId = (swapDataTransactionModel as? SwapDataTransactionModel.CEX)?.externalTxId,
averageDuration = null,
),
swapTxType = swapTxType,
),
)
}
swapTransactionRepository.storeLastSwappedCryptoCurrencyId(
userWalletId = userWallet.walletId,
cryptoCurrencyId = toCryptoCurrencyStatus.currency.id,
)
swapRepositoryV2.swapTransactionSent(
userWallet = userWallet,
fromCryptoCurrencyStatus = fromCryptoCurrencyStatus,
toAddress = swapDataTransactionModel.txTo,
txId = swapDataTransactionModel.txId,
txHash = txHash,
txExtraId = swapDataTransactionModel.txExtraId,
)
}.mapLeft(swapErrorResolver::resolve)
}