Updated on 2026-08-14
This commit is contained in:
parent
85c6044602
commit
d470f278fc
8 changed files with 108 additions and 73 deletions
|
|
@ -19,14 +19,6 @@ sealed class UserWalletsListError(code: Int) : TangemError(code) {
|
|||
override var customMessage: String = "Encryption key invalidated"
|
||||
}
|
||||
|
||||
object BiometricsAuthenticationDisabled : UserWalletsListError(code = 60005) {
|
||||
override var customMessage: String = "Biometrics authentication disabled"
|
||||
}
|
||||
|
||||
object NoUserWalletSelected : UserWalletsListError(code = 60006) {
|
||||
override var customMessage: String = "No user wallet selected"
|
||||
}
|
||||
|
||||
data class BiometricsAuthenticationLockout(val isPermanent: Boolean) : UserWalletsListError(code = 60003) {
|
||||
override var customMessage: String = "Biometric authentication lockout, permanent: $isPermanent"
|
||||
}
|
||||
|
|
@ -35,4 +27,16 @@ sealed class UserWalletsListError(code: Int) : TangemError(code) {
|
|||
override var customMessage: String = "An error has occurred, please scan your card to log in"
|
||||
override val messageResId: Int = R.string.user_wallet_list_error_unable_to_unlock
|
||||
}
|
||||
|
||||
object BiometricsAuthenticationDisabled : UserWalletsListError(code = 60005) {
|
||||
override var customMessage: String = "Biometrics authentication disabled"
|
||||
}
|
||||
|
||||
object NoUserWalletSelected : UserWalletsListError(code = 60006) {
|
||||
override var customMessage: String = "No user wallet selected"
|
||||
}
|
||||
|
||||
object NotAllUserWalletsUnlocked : UserWalletsListError(code = 60007) {
|
||||
override var customMessage: String = "Not all user wallets was unlocked"
|
||||
}
|
||||
}
|
||||
|
|
@ -105,17 +105,13 @@ interface UserWalletsListManager {
|
|||
/**
|
||||
* Receive saved [UserWallet]s, populate [userWallets] flow with it and set [isLocked] as false.
|
||||
*
|
||||
* @param throwIfNotAllWalletsUnlocked Indicates that the function must throw
|
||||
* [UserWalletsListError.NotAllUserWalletsUnlocked] if not all user wallets are unlocked.
|
||||
*
|
||||
* @return [CompletionResult] of operation, with selected [UserWallet]
|
||||
* or null if there is no selected [UserWallet]
|
||||
*/
|
||||
suspend fun unlock(): CompletionResult<UserWallet>
|
||||
|
||||
/**
|
||||
* Unlock all [UserWallet]s and select passed [UserWalletId]
|
||||
*
|
||||
* @param selectedWalletId [UserWalletId] of [UserWallet] which must be selected
|
||||
*/
|
||||
suspend fun unlockAndSelect(selectedWalletId: UserWalletId): CompletionResult<UserWallet>
|
||||
suspend fun unlock(throwIfNotAllWalletsUnlocked: Boolean = false): CompletionResult<UserWallet>
|
||||
|
||||
/** Remove [UserWallet]s from [userWallets] and set [isLocked] as true */
|
||||
fun lock()
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
package com.tangem.domain.wallets.models
|
||||
|
||||
sealed interface UnlockWalletError {
|
||||
|
||||
object CommonError : UnlockWalletError
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.tangem.domain.wallets.models
|
||||
|
||||
sealed class UnlockWalletsError {
|
||||
|
||||
object UnableToUnlockWallets : UnlockWalletsError()
|
||||
|
||||
object NoUserWalletSelected : UnlockWalletsError()
|
||||
|
||||
object NotAllUserWalletsUnlocked : UnlockWalletsError()
|
||||
|
||||
data class DataError(val cause: Throwable) : UnlockWalletsError()
|
||||
}
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
package com.tangem.domain.wallets.usecase
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.left
|
||||
import arrow.core.right
|
||||
import arrow.core.raise.either
|
||||
import arrow.core.raise.ensureNotNull
|
||||
import com.tangem.common.doOnFailure
|
||||
import com.tangem.common.doOnSuccess
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListError
|
||||
import com.tangem.domain.wallets.legacy.WalletsStateHolder
|
||||
import com.tangem.domain.wallets.legacy.asLockable
|
||||
import com.tangem.domain.wallets.models.UnlockWalletError
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.models.UnlockWalletsError
|
||||
|
||||
/**
|
||||
* Unlock wallets use case
|
||||
|
|
@ -19,14 +18,27 @@ import com.tangem.domain.wallets.models.UserWalletId
|
|||
*/
|
||||
class UnlockWalletsUseCase(private val walletsStateHolder: WalletsStateHolder) {
|
||||
|
||||
suspend operator fun invoke(selectedWalletId: UserWalletId): Either<UnlockWalletError, Unit> {
|
||||
val userWalletsListManager = walletsStateHolder.userWalletsListManager?.asLockable()
|
||||
?: return UnlockWalletError.CommonError.left()
|
||||
suspend operator fun invoke(throwIfNotAllWalletsUnlocked: Boolean = false): Either<UnlockWalletsError, Unit> =
|
||||
either {
|
||||
val userWalletsListManager = ensureNotNull(
|
||||
value = walletsStateHolder.userWalletsListManager?.asLockable(),
|
||||
raise = {
|
||||
UnlockWalletsError.DataError(
|
||||
cause = IllegalStateException("The lockable user wallets list manager could not be found")
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
userWalletsListManager.unlockAndSelect(selectedWalletId = selectedWalletId)
|
||||
.doOnSuccess { return Unit.right() }
|
||||
.doOnFailure { return UnlockWalletError.CommonError.left() }
|
||||
userWalletsListManager.unlock(throwIfNotAllWalletsUnlocked)
|
||||
.doOnFailure { error ->
|
||||
val e = when (error) {
|
||||
is UserWalletsListError.NoUserWalletSelected -> UnlockWalletsError.NoUserWalletSelected
|
||||
is UserWalletsListError.NotAllUserWalletsUnlocked ->
|
||||
UnlockWalletsError.NotAllUserWalletsUnlocked
|
||||
else -> UnlockWalletsError.UnableToUnlockWallets
|
||||
}
|
||||
|
||||
return Unit.right()
|
||||
}
|
||||
raise(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue