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

@ -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)
}

View file

@ -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,

View file

@ -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,
}