Updated on 2026-08-14
This commit is contained in:
parent
4c51193221
commit
c8a181c829
13 changed files with 135 additions and 73 deletions
|
|
@ -9,6 +9,7 @@ import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
|||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.swap.models.SwapDataModel
|
||||
import com.tangem.domain.swap.models.SwapDataTransactionModel
|
||||
import com.tangem.domain.swap.models.SwapTxType
|
||||
import com.tangem.domain.swap.usecase.GetSwapDataUseCase
|
||||
import com.tangem.domain.swap.usecase.SwapTransactionSentUseCase
|
||||
import com.tangem.domain.transaction.error.SendTransactionError
|
||||
|
|
@ -158,6 +159,7 @@ internal class SwapTransactionSender @AssistedInject constructor(
|
|||
provider = provider,
|
||||
txHash = txHash,
|
||||
timestamp = timestamp,
|
||||
swapTxType = SwapTxType.SendWithSwap,
|
||||
)
|
||||
onSendSuccess(txHash, timestamp, swapData)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -92,21 +92,37 @@ internal class DefaultSwapTransactionRepository(
|
|||
key = PreferencesKeys.SWAP_TRANSACTIONS_STATUSES_KEY,
|
||||
),
|
||||
) { savedTransactions, txStatuses ->
|
||||
val currencyTxs = savedTransactions?.filter {
|
||||
it.userWalletId == userWallet.walletId.stringValue &&
|
||||
(
|
||||
it.toCryptoCurrencyId == cryptoCurrencyId.value ||
|
||||
it.fromCryptoCurrencyId == cryptoCurrencyId.value
|
||||
)
|
||||
|
||||
val currencyToTxs = savedTransactions?.filter {
|
||||
val isUserWallet = it.userWalletId == userWallet.walletId.stringValue
|
||||
val toCurrency = it.toCryptoCurrencyId == cryptoCurrencyId.value
|
||||
isUserWallet && toCurrency
|
||||
}
|
||||
|
||||
currencyTxs?.mapNotNull {
|
||||
val currencyFromTxs = savedTransactions?.filter {
|
||||
val isUserWallet = it.userWalletId == userWallet.walletId.stringValue
|
||||
val fromCurrency = it.fromCryptoCurrencyId == cryptoCurrencyId.value
|
||||
isUserWallet && fromCurrency
|
||||
}
|
||||
|
||||
val toTxs = currencyToTxs?.mapNotNull {
|
||||
converter.convertBack(
|
||||
value = it,
|
||||
userWallet = userWallet,
|
||||
txStatuses = txStatuses,
|
||||
onFilter = { it.swapTxTypeDTO == SwapTxTypeDTO.Swap },
|
||||
)
|
||||
}.orEmpty()
|
||||
|
||||
val fromTxs = currencyFromTxs?.mapNotNull {
|
||||
converter.convertBack(
|
||||
value = it,
|
||||
userWallet = userWallet,
|
||||
txStatuses = txStatuses,
|
||||
)
|
||||
}
|
||||
}.orEmpty()
|
||||
|
||||
fromTxs + toTxs
|
||||
}
|
||||
.flowOn(dispatchers.default)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ internal class SavedSwapTransactionListConverter(
|
|||
value: SavedSwapTransactionListModelInner,
|
||||
userWallet: UserWallet,
|
||||
txStatuses: Map<String, ExchangeStatusModel>,
|
||||
onFilter: (SavedSwapTransactionModel) -> Boolean = { true },
|
||||
): SavedSwapTransactionListModel? {
|
||||
val fromToken = value.fromTokensResponse
|
||||
val toToken = value.toTokensResponse
|
||||
|
|
@ -50,17 +51,19 @@ internal class SavedSwapTransactionListConverter(
|
|||
) ?: return null
|
||||
|
||||
return SavedSwapTransactionListModel(
|
||||
transactions = value.transactions.map { tx ->
|
||||
val status = txStatuses[tx.txId]
|
||||
val refundCurrency = status?.refundTokensResponse?.let { id ->
|
||||
responseCryptoCurrenciesFactory.createCurrency(
|
||||
responseToken = id,
|
||||
userWallet = userWallet,
|
||||
)
|
||||
}
|
||||
val statusWithRefundCurrency = status?.copy(refundCurrency = refundCurrency)
|
||||
tx.copy(status = statusWithRefundCurrency)
|
||||
},
|
||||
transactions = value.transactions
|
||||
.filter(onFilter)
|
||||
.map { tx ->
|
||||
val status = txStatuses[tx.txId]
|
||||
val refundCurrency = status?.refundTokensResponse?.let { id ->
|
||||
responseCryptoCurrenciesFactory.createCurrency(
|
||||
responseToken = id,
|
||||
userWallet = userWallet,
|
||||
)
|
||||
}
|
||||
val statusWithRefundCurrency = status?.copy(refundCurrency = refundCurrency)
|
||||
tx.copy(status = statusWithRefundCurrency)
|
||||
},
|
||||
userWalletId = value.userWalletId,
|
||||
fromCryptoCurrencyId = value.fromCryptoCurrencyId,
|
||||
toCryptoCurrencyId = value.toCryptoCurrencyId,
|
||||
|
|
|
|||
|
|
@ -50,4 +50,16 @@ data class SavedSwapTransactionModel(
|
|||
val provider: SwapProvider,
|
||||
@Json(name = "status")
|
||||
val status: ExchangeStatusModel? = null,
|
||||
)
|
||||
@Json(name = "swapTxType")
|
||||
val swapTxTypeDTO: SwapTxTypeDTO? = SwapTxTypeDTO.Swap,
|
||||
)
|
||||
|
||||
// TODO refactor to use separate models to store
|
||||
@JsonClass(generateAdapter = false)
|
||||
enum class SwapTxTypeDTO {
|
||||
@Json(name = "Swap")
|
||||
Swap,
|
||||
|
||||
@Json(name = "SendWithSwap")
|
||||
SendWithSwap,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue