Updated on 2026-08-14
This commit is contained in:
parent
8ba59403f4
commit
18d4a01642
7 changed files with 159 additions and 0 deletions
|
|
@ -0,0 +1,35 @@
|
|||
package com.tangem.domain.common.wallets
|
||||
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
|
||||
/**
|
||||
* Sealed class representing actions that can transform the user wallets list.
|
||||
*/
|
||||
sealed class UserWalletTransformAction {
|
||||
|
||||
/**
|
||||
* The transformation block to apply to the current wallets list.
|
||||
*/
|
||||
abstract fun transform(list: List<UserWallet>): List<UserWallet>
|
||||
|
||||
/**
|
||||
* Reorders user wallets
|
||||
*
|
||||
* @param action The transformation block that takes the current list of user wallets
|
||||
* and returns a list of user wallet IDs in the desired order.
|
||||
*/
|
||||
data class Reorder(
|
||||
private val action: (List<UserWallet>) -> List<UserWalletId>,
|
||||
) : UserWalletTransformAction() {
|
||||
|
||||
override fun transform(list: List<UserWallet>): List<UserWallet> {
|
||||
val walletById = list.associateBy { it.walletId }
|
||||
val newOrderIds = action(list)
|
||||
require(walletById.keys == newOrderIds.toSet()) {
|
||||
"Reorder action must return the same set of wallet IDs as the input list"
|
||||
}
|
||||
return newOrderIds.mapNotNull { walletById[it] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -123,6 +123,14 @@ interface UserWalletsListRepository {
|
|||
*/
|
||||
suspend fun clearPersistentData()
|
||||
|
||||
/**
|
||||
* Transforms user wallets list according to the provided action.
|
||||
*
|
||||
* @param action The transformation action to apply.
|
||||
* @throws IllegalArgumentException if the transformation action is invalid (e.g. reordering with missing or extra wallet IDs).
|
||||
*/
|
||||
suspend fun transform(action: UserWalletTransformAction)
|
||||
|
||||
/**
|
||||
* Checks if there are any secured wallets (wallets that are not locked with [LockMethod.NoLock]).
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue