Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-17 18:53:42 +03:00
parent 9868dd2bc2
commit a3295ea181
12 changed files with 123 additions and 107 deletions

View file

@ -7,6 +7,11 @@ import kotlinx.coroutines.flow.Flow
interface UserWalletsListManager {
/**
* Indicates that the [UserWalletsListManager] is [UserWalletsListManager.Lockable]
* */
val isLockable: Boolean
/** [Flow] with all saved [UserWallet]s updates */
val userWallets: Flow<List<UserWallet>>
@ -84,11 +89,6 @@ interface UserWalletsListManager {
*/
suspend fun get(userWalletId: UserWalletId): CompletionResult<UserWallet>
/**
* Indicates that the [UserWalletsListManager] supports [UserWalletsListManager.Lockable]
* */
fun isLockable(): Boolean
interface Lockable : UserWalletsListManager {
/**

View file

@ -49,7 +49,7 @@ suspend fun UserWalletsListManager.unlockIfLockable(type: UnlockType = UnlockTyp
* [UserWalletsListManager.Lockable] otherwise
* */
fun UserWalletsListManager.asLockable(): UserWalletsListManager.Lockable? {
if (this.isLockable()) {
if (this.isLockable) {
return this as? UserWalletsListManager.Lockable
}
return null

View file

@ -1,17 +1,14 @@
package com.tangem.domain.wallets.usecase
import arrow.core.Either
import arrow.core.left
import arrow.core.raise.either
import arrow.core.right
import com.tangem.common.doOnFailure
import com.tangem.common.doOnSuccess
import com.tangem.domain.wallets.legacy.UserWalletsListManager
import com.tangem.domain.wallets.models.DeleteWalletError
import com.tangem.domain.wallets.models.UserWalletId
/**
* Use case for updating user wallet
* Use case for deleting user wallet
*
* @property userWalletsListManager user wallets list manager
*
@ -19,13 +16,21 @@ import com.tangem.domain.wallets.models.UserWalletId
*/
class DeleteWalletUseCase(private val userWalletsListManager: UserWalletsListManager) {
suspend operator fun invoke(userWalletId: UserWalletId): Either<DeleteWalletError, Unit> {
/**
* Deletes user wallet with provided ID.
*
* @param userWalletId ID of user wallet to be deleted.
*
* @return [Either] with [DeleteWalletError] or [Boolean] which indicates that there are still saved wallets.
* */
suspend operator fun invoke(userWalletId: UserWalletId): Either<DeleteWalletError, Boolean> {
return either {
userWalletsListManager.delete(userWalletIds = listOf(userWalletId))
.doOnSuccess { return Unit.right() }
.doOnFailure { return DeleteWalletError.UnableToDelete.left() }
.doOnFailure {
raise(DeleteWalletError.UnableToDelete)
}
return Unit.right()
userWalletsListManager.hasUserWallets
}
}
}