Updated on 2026-08-14
This commit is contained in:
parent
73aaae287d
commit
e592b59734
1 changed files with 30 additions and 12 deletions
|
|
@ -9,6 +9,7 @@ import com.tangem.domain.staking.repositories.StakingErrorResolver
|
|||
import com.tangem.domain.staking.repositories.StakingPendingTransactionRepository
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import org.joda.time.DateTime
|
||||
import java.math.BigDecimal
|
||||
import java.util.UUID
|
||||
|
||||
class InvalidatePendingTransactionsUseCase(
|
||||
|
|
@ -41,12 +42,13 @@ class InvalidatePendingTransactionsUseCase(
|
|||
newBalancesId: Int,
|
||||
pendingData: List<Pair<PendingTransaction, BalanceItem>>,
|
||||
): Pair<List<BalanceItem>, List<PendingTransaction>> {
|
||||
val balances = realData.associateBy { Pair(it.groupId to it.type, it.amount to it.date) }.toMutableMap()
|
||||
val balances = realData.associateBy { BalanceIdentity(it.groupId, it.type, it.amount, it.date) }
|
||||
.toMutableMap()
|
||||
|
||||
val transactionsToRemove = mutableListOf<PendingTransaction>()
|
||||
|
||||
pendingData.forEach { (pendingTransaction, balanceItem) ->
|
||||
val key = Pair(balanceItem.groupId to balanceItem.type, balanceItem.amount to balanceItem.date)
|
||||
val key = BalanceIdentity(balanceItem.groupId, balanceItem.type, balanceItem.amount, balanceItem.date)
|
||||
val oldBalancesId = pendingTransaction.balancesId
|
||||
|
||||
when {
|
||||
|
|
@ -59,20 +61,36 @@ class InvalidatePendingTransactionsUseCase(
|
|||
else -> {
|
||||
val groupId = UUID.randomUUID().toString()
|
||||
val now = DateTime.now()
|
||||
balances[Pair(groupId to BalanceType.STAKED, pendingTransaction.amount to now)] = BalanceItem(
|
||||
groupId = groupId,
|
||||
type = pendingTransaction.type,
|
||||
amount = pendingTransaction.amount,
|
||||
rawCurrencyId = pendingTransaction.rawCurrencyId,
|
||||
validatorAddress = pendingTransaction.validator?.address,
|
||||
date = null,
|
||||
pendingActions = emptyList(),
|
||||
isPending = true,
|
||||
)
|
||||
balances[BalanceIdentity(groupId, BalanceType.STAKED, pendingTransaction.amount, now)] =
|
||||
BalanceItem(
|
||||
groupId = groupId,
|
||||
type = pendingTransaction.type,
|
||||
amount = pendingTransaction.amount,
|
||||
rawCurrencyId = pendingTransaction.rawCurrencyId,
|
||||
validatorAddress = pendingTransaction.validator?.address,
|
||||
date = null,
|
||||
pendingActions = emptyList(),
|
||||
isPending = true,
|
||||
)
|
||||
|
||||
balances.entries.find {
|
||||
it.key.type == BalanceType.STAKED &&
|
||||
it.key.amount == pendingTransaction.amount &&
|
||||
!it.value.isPending
|
||||
}
|
||||
?.key
|
||||
?.let { balances.remove(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return balances.values.toList() to transactionsToRemove
|
||||
}
|
||||
|
||||
private data class BalanceIdentity(
|
||||
val groupId: String,
|
||||
val type: BalanceType,
|
||||
val amount: BigDecimal,
|
||||
val date: DateTime?,
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue