Updated on 2026-08-14

This commit is contained in:
Tangem 2024-01-18 16:31:19 +03:00
parent 0b037f2b2d
commit 5d69093f1d

View file

@ -2,13 +2,17 @@ package com.tangem.domain.transaction.usecase
import arrow.core.Either
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.TransactionData
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.transaction.TransactionRepository
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.withContext
class CreateTransactionUseCase(
private val transactionRepository: TransactionRepository,
private val dispatchers: CoroutineDispatcherProvider,
) {
/**
@ -22,16 +26,18 @@ class CreateTransactionUseCase(
destination: String,
userWalletId: UserWalletId,
network: Network,
) = Either.catch {
requireNotNull(
transactionRepository.createTransaction(
amount = amount,
fee = fee,
memo = memo,
destination = destination,
userWalletId = userWalletId,
network = network,
),
) { "Failed to create transaction" }
): Either<Throwable, TransactionData> = withContext(dispatchers.io) {
Either.catch {
requireNotNull(
transactionRepository.createTransaction(
amount = amount,
fee = fee,
memo = memo,
destination = destination,
userWalletId = userWalletId,
network = network,
),
) { "Failed to create transaction" }
}
}
}