Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-06 11:13:31 +04:00
parent 8ba59403f4
commit 18d4a01642
7 changed files with 159 additions and 0 deletions

View file

@ -0,0 +1,46 @@
package com.tangem.domain.wallets.usecase
import arrow.core.Either
import arrow.core.raise.catch
import arrow.core.raise.either
import arrow.core.raise.ensure
import com.tangem.domain.common.wallets.UserWalletTransformAction
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWalletId
/**
* Use case to apply a specific sorting order to a list of user wallets.
*
* @property userWalletsListRepository Repository for managing user wallets list.
*/
class ApplyUserWalletListSortingUseCase(
private val userWalletsListRepository: UserWalletsListRepository,
) {
/**
* Applies the sorting order of the provided list of user wallet IDs.
*
* @param userWalletIds List of [UserWalletId] representing the desired order.
* @return Either an [Error] or Unit on successful completion.
*/
suspend operator fun invoke(userWalletIds: List<UserWalletId>): Either<Error, Unit> = either {
ensure(userWalletIds.size > 1) { Error.UnableToSortSingleWallet }
catch(
block = {
userWalletsListRepository.transform(UserWalletTransformAction.Reorder { userWalletIds })
},
catch = { raise(Error.ReorderError) },
)
}
/**
* Sealed interface representing possible errors that can occur during the application
* of user wallet list sorting.
*/
sealed interface Error {
data object UnableToSortSingleWallet : Error
data object ReorderError : Error
}
}