Fixes ELEMENT-97277 - Be less aggressive on recovery key states

This commit is contained in:
Stefan Ceriu 2024-04-08 16:19:06 +03:00 committed by Stefan Ceriu
parent 1ff4c02782
commit 446aab58de
8 changed files with 67 additions and 30 deletions

View File

@ -62,6 +62,8 @@ final class SecureBackupRecoveryKeyScreenCoordinator: CoordinatorProtocol {
self.actionsSubject.send(.recoveryChanged)
case .fixRecovery:
self.actionsSubject.send(.recoveryFixed)
case .unknown:
fatalError()
}
case .showResetKeyInfo:
self.actionsSubject.send(.showResetKeyInfo)

View File

@ -26,6 +26,7 @@ enum SecureBackupRecoveryKeyScreenViewMode {
case setupRecovery
case changeRecovery
case fixRecovery
case unknown
}
struct SecureBackupRecoveryKeyScreenViewState: BindableState {
@ -47,10 +48,12 @@ struct SecureBackupRecoveryKeyScreenViewState: BindableState {
return recoveryKey == nil ? L10n.screenRecoveryKeyChangeTitle : L10n.screenRecoveryKeySaveTitle
case .fixRecovery:
return L10n.screenRecoveryKeyConfirmTitle
default:
return L10n.errorUnknown
}
}
var subtitle: String {
var subtitle: String? {
switch mode {
case .setupRecovery:
return recoveryKey == nil ? L10n.screenRecoveryKeySetupDescription : L10n.screenRecoveryKeySaveDescription
@ -58,10 +61,12 @@ struct SecureBackupRecoveryKeyScreenViewState: BindableState {
return recoveryKey == nil ? L10n.screenRecoveryKeyChangeDescription : L10n.screenRecoveryKeySaveDescription
case .fixRecovery:
return L10n.screenRecoveryKeyConfirmDescription
default:
return nil
}
}
var recoveryKeySubtitle: String {
var recoveryKeySubtitle: String? {
switch mode {
case .setupRecovery:
return recoveryKey == nil ? L10n.screenRecoveryKeySetupGenerateKeyDescription : L10n.screenRecoveryKeySaveKeyDescription
@ -69,6 +74,8 @@ struct SecureBackupRecoveryKeyScreenViewState: BindableState {
return recoveryKey == nil ? L10n.screenRecoveryKeyChangeGenerateKeyDescription : L10n.screenRecoveryKeySaveKeyDescription
case .fixRecovery:
return L10n.screenRecoveryKeyConfirmKeyDescription
default:
return nil
}
}
}

View File

@ -116,7 +116,7 @@ extension SecureBackupRecoveryState {
case .incomplete:
return .fixRecovery
default:
fatalError("Invalid recovery state")
return .unknown
}
}
}

View File

@ -54,6 +54,26 @@ struct SecureBackupRecoveryKeyScreen: View {
case .fixRecovery:
header
confirmRecoveryKeySection
case .unknown:
header
}
}
}
private var header: some View {
VStack(spacing: 16) {
HeroImage(icon: \.keySolid)
Text(context.viewState.title)
.foregroundColor(.compound.textPrimary)
.font(.compound.headingMDBold)
.multilineTextAlignment(.center)
if let subtitle = context.viewState.subtitle {
Text(subtitle)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodyMD)
.multilineTextAlignment(.center)
}
}
}
@ -65,6 +85,8 @@ struct SecureBackupRecoveryKeyScreen: View {
recoveryCreatedActionButtons
case .fixRecovery:
incompleteVerificationActionButtons
case .unknown:
EmptyView()
}
}
@ -121,22 +143,6 @@ struct SecureBackupRecoveryKeyScreen: View {
}
}
private var header: some View {
VStack(spacing: 16) {
HeroImage(icon: \.keySolid)
Text(context.viewState.title)
.foregroundColor(.compound.textPrimary)
.font(.compound.headingMDBold)
.multilineTextAlignment(.center)
Text(context.viewState.subtitle)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodyMD)
.multilineTextAlignment(.center)
}
}
private var generateRecoveryKeySection: some View {
VStack(alignment: .leading, spacing: 8) {
Text(L10n.commonRecoveryKey)
@ -172,16 +178,18 @@ struct SecureBackupRecoveryKeyScreen: View {
.background(Color.compound.bgSubtleSecondaryLevel0)
.clipShape(RoundedRectangle(cornerRadius: 8))
Label {
Text(context.viewState.recoveryKeySubtitle)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodySM)
} icon: {
if context.viewState.recoveryKey == nil {
CompoundIcon(\.infoSolid, size: .small, relativeTo: .compound.bodySM)
if let subtitle = context.viewState.recoveryKeySubtitle {
Label {
Text(subtitle)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodySM)
} icon: {
if context.viewState.recoveryKey == nil {
CompoundIcon(\.infoSolid, size: .small, relativeTo: .compound.bodySM)
}
}
.labelStyle(.custom(spacing: 8, alignment: .top))
}
.labelStyle(.custom(spacing: 8, alignment: .top))
}
}
@ -211,9 +219,11 @@ struct SecureBackupRecoveryKeyScreen: View {
context.send(viewAction: .confirmKey)
}
Text(context.viewState.recoveryKeySubtitle)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodySM)
if let subtitle = context.viewState.recoveryKeySubtitle {
Text(subtitle)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodySM)
}
}
}
}
@ -224,6 +234,7 @@ struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview
static let setupViewModel = viewModel(recoveryState: .enabled)
static let notSetUpViewModel = viewModel(recoveryState: .disabled)
static let incompleteViewModel = viewModel(recoveryState: .incomplete)
static let unknownViewModel = viewModel(recoveryState: .unknown)
static var previews: some View {
NavigationStack {
@ -240,6 +251,11 @@ struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview
SecureBackupRecoveryKeyScreen(context: incompleteViewModel.context)
}
.previewDisplayName("Incomplete")
NavigationStack {
SecureBackupRecoveryKeyScreen(context: unknownViewModel.context)
}
.previewDisplayName("Unknown")
}
static func viewModel(recoveryState: SecureBackupRecoveryState) -> SecureBackupRecoveryKeyScreenViewModelType {