Updated on 2026-08-14
This commit is contained in:
parent
02e44033c9
commit
9b506f8b25
6 changed files with 107 additions and 19 deletions
|
|
@ -9,6 +9,14 @@ import com.tangem.domain.models.wallet.UserWalletId
|
|||
import com.tangem.domain.models.wallet.isLocked
|
||||
import com.tangem.domain.wallets.repository.WalletsRepository
|
||||
|
||||
/**
|
||||
* Use case for unlocking a wallet using non-biometric methods.
|
||||
* If the wallet is already unlocked, it does nothing.
|
||||
*
|
||||
* **Does not** return [UnlockWalletError.AlreadyUnlocked] as an error, since the wallet is already unlocked.
|
||||
*
|
||||
* @see UnlockWalletUseCase
|
||||
*/
|
||||
class NonBiometricUnlockWalletUseCase(
|
||||
private val userWalletsListRepository: UserWalletsListRepository,
|
||||
private val walletsRepository: WalletsRepository,
|
||||
|
|
|
|||
|
|
@ -6,13 +6,26 @@ import com.tangem.domain.common.wallets.UserWalletsListRepository
|
|||
import com.tangem.domain.common.wallets.error.UnlockWalletError
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
|
||||
/**
|
||||
* Use case for unlocking a wallet using biometric authentication.
|
||||
* If biometric unlock fails, it falls back to non-biometric unlock methods.
|
||||
*
|
||||
* ** Does not** return [UnlockWalletError.AlreadyUnlocked] as an error, since the wallet is already unlocked.
|
||||
*
|
||||
* @see NonBiometricUnlockWalletUseCase
|
||||
*/
|
||||
class UnlockWalletUseCase(
|
||||
private val userWalletsListRepository: UserWalletsListRepository,
|
||||
private val nonBiometricUnlockWalletUseCase: NonBiometricUnlockWalletUseCase,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId): Either<UnlockWalletError, Unit> = either {
|
||||
userWalletsListRepository.unlockAllWallets()
|
||||
.mapLeft { nonBiometricUnlockWalletUseCase(userWalletId).bind() }
|
||||
userWalletsListRepository.unlock(userWalletId, UserWalletsListRepository.UnlockMethod.Biometric)
|
||||
.mapLeft { error ->
|
||||
when (error) {
|
||||
UnlockWalletError.AlreadyUnlocked -> Unit
|
||||
else -> nonBiometricUnlockWalletUseCase(userWalletId).bind()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue