Updated on 2026-08-14
This commit is contained in:
parent
312740cd64
commit
5f95ba532e
4 changed files with 43 additions and 23 deletions
|
|
@ -57,21 +57,11 @@ internal class BiometricUserWalletsListManager(
|
|||
get() = state.value.userWallets.size
|
||||
|
||||
override suspend fun unlock(): CompletionResult<UserWallet> {
|
||||
return unlockWithBiometryInternal()
|
||||
.mapFailure { error ->
|
||||
if (error is UserWalletsListError) {
|
||||
error
|
||||
} else {
|
||||
UserWalletsListError.UnableToUnlockUserWallets(cause = error)
|
||||
}
|
||||
}
|
||||
.map {
|
||||
selectedUserWalletSync.guard {
|
||||
throw UserWalletsListError.UnableToUnlockUserWallets(
|
||||
cause = IllegalStateException("No user wallet selected"),
|
||||
)
|
||||
}
|
||||
}
|
||||
return unlockWithBiometryInternal().mapUnlockResult()
|
||||
}
|
||||
|
||||
override suspend fun unlockAndSelect(selectedWalletId: UserWalletId): CompletionResult<UserWallet> {
|
||||
return unlockWithBiometryInternal(selectedWalletId = selectedWalletId).mapUnlockResult()
|
||||
}
|
||||
|
||||
override fun lock() {
|
||||
|
|
@ -198,7 +188,7 @@ internal class BiometricUserWalletsListManager(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun unlockWithBiometryInternal(): CompletionResult<Unit> {
|
||||
private suspend fun unlockWithBiometryInternal(selectedWalletId: UserWalletId? = null): CompletionResult<Unit> {
|
||||
return keysRepository.getAll()
|
||||
.map { keys ->
|
||||
state.update { prevState ->
|
||||
|
|
@ -207,7 +197,7 @@ internal class BiometricUserWalletsListManager(
|
|||
)
|
||||
}
|
||||
}
|
||||
.flatMap { loadModels() }
|
||||
.flatMap { loadModels(selectedWalletId = selectedWalletId) }
|
||||
.map {
|
||||
state.update { prevState ->
|
||||
val hasLockedUserWallets = prevState.userWallets.any { it.isLocked }
|
||||
|
|
@ -216,6 +206,24 @@ internal class BiometricUserWalletsListManager(
|
|||
}
|
||||
}
|
||||
|
||||
private fun CompletionResult<Unit>.mapUnlockResult(): CompletionResult<UserWallet> {
|
||||
return this
|
||||
.mapFailure { error ->
|
||||
if (error is UserWalletsListError) {
|
||||
error
|
||||
} else {
|
||||
UserWalletsListError.UnableToUnlockUserWallets(cause = error)
|
||||
}
|
||||
}
|
||||
.map {
|
||||
selectedUserWalletSync.guard {
|
||||
throw UserWalletsListError.UnableToUnlockUserWallets(
|
||||
cause = IllegalStateException("No user wallet selected"),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun saveEncryptionKeyIfNotNull(userWallet: UserWallet): CompletionResult<ByteArray?> {
|
||||
val encryptionKey = userWallet.scanResponse.card.encryptionKey
|
||||
?.let { UserWalletEncryptionKey(userWallet.walletId, it) }
|
||||
|
|
@ -237,7 +245,7 @@ internal class BiometricUserWalletsListManager(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun loadModels(): CompletionResult<Unit> {
|
||||
private suspend fun loadModels(selectedWalletId: UserWalletId? = null): CompletionResult<Unit> {
|
||||
return getSavedUserWallets()
|
||||
.map { userWallets ->
|
||||
if (userWallets.isNotEmpty()) {
|
||||
|
|
@ -247,7 +255,7 @@ internal class BiometricUserWalletsListManager(
|
|||
prevState.copy(
|
||||
userWallets = wallets,
|
||||
selectedUserWalletId = findOrSetSelectedUserWalletId(
|
||||
prevSelectedWalletId = prevState.selectedUserWalletId,
|
||||
prevSelectedWalletId = selectedWalletId ?: prevState.selectedUserWalletId,
|
||||
userWallets = wallets,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue