Show recovery instead of verification if this is the last session and recovery is set up
* Show recovery instead of verification if this is the last session and recovery is set up * Rename `recoveryKeyState` to `recoveryState` * Remove duplicates on session security state changes. * Fix missing "Save recovery key" button * Fix unit tests * Rename `isLastDevice` to `isOnlyDeviceLeft` * Address PR comments
This commit is contained in:
@@ -32,9 +32,9 @@ class SecureBackupRecoveryKeyScreenViewModel: SecureBackupRecoveryKeyScreenViewM
|
||||
self.secureBackupController = secureBackupController
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
super.init(initialViewState: .init(mode: secureBackupController.recoveryKeyState.value.viewMode, bindings: .init()))
|
||||
super.init(initialViewState: .init(mode: secureBackupController.recoveryState.value.viewMode, bindings: .init()))
|
||||
|
||||
secureBackupController.recoveryKeyState
|
||||
secureBackupController.recoveryState
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(receiveValue: { [weak userIndicatorController] state in
|
||||
let loadingIndicatorIdentifier = "SecureBackupRecoveryKeyScreenLoading"
|
||||
@@ -100,7 +100,7 @@ class SecureBackupRecoveryKeyScreenViewModel: SecureBackupRecoveryKeyScreenViewM
|
||||
}
|
||||
}
|
||||
|
||||
extension SecureBackupRecoveryKeyState {
|
||||
extension SecureBackupRecoveryState {
|
||||
var viewMode: SecureBackupRecoveryKeyScreenViewMode {
|
||||
switch self {
|
||||
case .disabled:
|
||||
|
||||
@@ -65,6 +65,20 @@ struct SecureBackupRecoveryKeyScreen: View {
|
||||
private var footer: some View {
|
||||
switch context.viewState.mode {
|
||||
case .setupRecovery, .changeRecovery:
|
||||
recoveryCreatedActionButtons
|
||||
case .fixRecovery:
|
||||
Button {
|
||||
context.send(viewAction: .confirmKey)
|
||||
} label: {
|
||||
Text(L10n.actionConfirm)
|
||||
}
|
||||
.buttonStyle(.compound(.primary))
|
||||
.disabled(context.confirmationRecoveryKey.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
private var recoveryCreatedActionButtons: some View {
|
||||
VStack(spacing: 8.0) {
|
||||
if let recoveryKey = context.viewState.recoveryKey {
|
||||
ShareLink(item: recoveryKey) {
|
||||
Label(L10n.screenRecoveryKeySaveAction, icon: \.download)
|
||||
@@ -82,14 +96,6 @@ struct SecureBackupRecoveryKeyScreen: View {
|
||||
}
|
||||
.buttonStyle(.compound(.primary))
|
||||
.disabled(context.viewState.recoveryKey == nil || context.viewState.doneButtonEnabled == false)
|
||||
case .fixRecovery:
|
||||
Button {
|
||||
context.send(viewAction: .confirmKey)
|
||||
} label: {
|
||||
Text(L10n.actionConfirm)
|
||||
}
|
||||
.buttonStyle(.compound(.primary))
|
||||
.disabled(context.confirmationRecoveryKey.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,9 +210,9 @@ struct SecureBackupRecoveryKeyScreen: View {
|
||||
// MARK: - Previews
|
||||
|
||||
struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let setupViewModel = viewModel(recoveryKeyState: .enabled)
|
||||
static let notSetUpViewModel = viewModel(recoveryKeyState: .disabled)
|
||||
static let incompleteViewModel = viewModel(recoveryKeyState: .incomplete)
|
||||
static let setupViewModel = viewModel(recoveryState: .enabled)
|
||||
static let notSetUpViewModel = viewModel(recoveryState: .disabled)
|
||||
static let incompleteViewModel = viewModel(recoveryState: .incomplete)
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
@@ -225,9 +231,9 @@ struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview
|
||||
.previewDisplayName("Incomplete")
|
||||
}
|
||||
|
||||
static func viewModel(recoveryKeyState: SecureBackupRecoveryKeyState) -> SecureBackupRecoveryKeyScreenViewModelType {
|
||||
static func viewModel(recoveryState: SecureBackupRecoveryState) -> SecureBackupRecoveryKeyScreenViewModelType {
|
||||
let backupController = SecureBackupControllerMock()
|
||||
backupController.underlyingRecoveryKeyState = CurrentValueSubject<SecureBackupRecoveryKeyState, Never>(recoveryKeyState).asCurrentValuePublisher()
|
||||
backupController.underlyingRecoveryState = CurrentValueSubject<SecureBackupRecoveryState, Never>(recoveryState).asCurrentValuePublisher()
|
||||
|
||||
return SecureBackupRecoveryKeyScreenViewModel(secureBackupController: backupController, userIndicatorController: UserIndicatorControllerMock())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user