Updated on 2026-08-14
This commit is contained in:
parent
0af5b06cbb
commit
09cb780a4f
10 changed files with 122 additions and 0 deletions
|
|
@ -0,0 +1,6 @@
|
|||
package com.tangem.domain.wallets.models
|
||||
|
||||
sealed interface DeleteWalletError {
|
||||
|
||||
object DataError : DeleteWalletError
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package com.tangem.domain.wallets.models
|
||||
|
||||
sealed interface UpdateWalletError {
|
||||
|
||||
object DataError : UpdateWalletError
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.tangem.domain.wallets.usecase
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.left
|
||||
import arrow.core.right
|
||||
import com.tangem.common.doOnFailure
|
||||
import com.tangem.common.doOnSuccess
|
||||
import com.tangem.domain.wallets.legacy.WalletsStateHolder
|
||||
import com.tangem.domain.wallets.models.DeleteWalletError
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
/**
|
||||
* Use case for updating user wallet
|
||||
*
|
||||
* @property walletsStateHolder state holder for getting static initialized 'userWalletsListManager'
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class DeleteWalletUseCase(private val walletsStateHolder: WalletsStateHolder) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId): Either<DeleteWalletError, Unit> {
|
||||
val userWalletsListManager = walletsStateHolder.userWalletsListManager
|
||||
?: return DeleteWalletError.DataError.left()
|
||||
|
||||
userWalletsListManager.delete(userWalletIds = listOf(userWalletId))
|
||||
.doOnSuccess { return Unit.right() }
|
||||
.doOnFailure { return DeleteWalletError.DataError.left() }
|
||||
|
||||
return Unit.right()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.tangem.domain.wallets.usecase
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.left
|
||||
import arrow.core.right
|
||||
import com.tangem.common.doOnFailure
|
||||
import com.tangem.common.doOnSuccess
|
||||
import com.tangem.domain.wallets.legacy.WalletsStateHolder
|
||||
import com.tangem.domain.wallets.models.UpdateWalletError
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
/**
|
||||
* Use case for updating user wallet
|
||||
*
|
||||
* @property walletsStateHolder state holder for getting static initialized 'userWalletsListManager'
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class UpdateWalletUseCase(private val walletsStateHolder: WalletsStateHolder) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
update: suspend (UserWallet) -> UserWallet,
|
||||
): Either<UpdateWalletError, Unit> {
|
||||
val userWalletsListManager = walletsStateHolder.userWalletsListManager
|
||||
?: return UpdateWalletError.DataError.left()
|
||||
|
||||
userWalletsListManager.update(userWalletId, update)
|
||||
.doOnSuccess { return Unit.right() }
|
||||
.doOnFailure { return UpdateWalletError.DataError.left() }
|
||||
|
||||
return Unit.right()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue