diff --git a/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift index 0eee33112..1df12de34 100644 --- a/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift @@ -212,6 +212,8 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol { case .skip: appSettings.hasRunIdentityConfirmationOnboarding = true stateMachine.tryEvent(.next) + case .reset: + presentResetRecoveryKeyScreen() } } .store(in: &cancellables) diff --git a/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenCoordinator.swift b/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenCoordinator.swift index 9b600cecb..4ef07ebd0 100644 --- a/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenCoordinator.swift @@ -30,6 +30,7 @@ enum IdentityConfirmationScreenCoordinatorAction { case recoveryKey /// Only possible in debug builds. case skip + case reset } final class IdentityConfirmationScreenCoordinator: CoordinatorProtocol { @@ -63,6 +64,8 @@ final class IdentityConfirmationScreenCoordinator: CoordinatorProtocol { actionsSubject.send(.recoveryKey) case .skip: actionsSubject.send(.skip) + case .reset: + actionsSubject.send(.reset) } } .store(in: &cancellables) diff --git a/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenModels.swift b/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenModels.swift index e2ca810d6..4e5e9bca8 100644 --- a/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenModels.swift +++ b/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenModels.swift @@ -21,15 +21,16 @@ enum IdentityConfirmationScreenViewModelAction { case recoveryKey /// Only possible in debug builds. case skip + case reset } struct IdentityConfirmationScreenViewState: BindableState { - enum Mode { - case recoveryOnly - case recoveryAndVerification + enum AvailableActions { + case recovery + case interactiveVerification } - var mode = Mode.recoveryOnly + var availableActions: [AvailableActions] = [] let learnMoreURL: URL } @@ -38,4 +39,5 @@ enum IdentityConfirmationScreenViewAction { case recoveryKey /// Only possible in debug builds. case skip + case reset } diff --git a/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenViewModel.swift b/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenViewModel.swift index fec622ede..29c9c38f4 100644 --- a/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenViewModel.swift +++ b/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/IdentityConfirmationScreenViewModel.swift @@ -59,6 +59,8 @@ class IdentityConfirmationScreenViewModel: IdentityConfirmationScreenViewModelTy actionsSubject.send(.recoveryKey) case .skip: actionsSubject.send(.skip) + case .reset: + actionsSubject.send(.reset) } } @@ -75,11 +77,18 @@ class IdentityConfirmationScreenViewModel: IdentityConfirmationScreenViewModelTy return } - guard case let .success(isOnlyDeviceLeft) = await userSession.clientProxy.isOnlyDeviceLeft() else { - return + var availableActions: [IdentityConfirmationScreenViewState.AvailableActions] = [] + + if case let .success(isOnlyDeviceLeft) = await userSession.clientProxy.isOnlyDeviceLeft(), + !isOnlyDeviceLeft { + availableActions.append(.interactiveVerification) } - state.mode = isOnlyDeviceLeft ? .recoveryOnly : .recoveryAndVerification + if sessionSecurityState.recoveryState == .enabled || sessionSecurityState.recoveryState == .incomplete { + availableActions.append(.recovery) + } + + state.availableActions = availableActions } private static let loadingIndicatorIdentifier = "\(IdentityConfirmationScreenViewModel.self)-Loading" diff --git a/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/View/IdentityConfirmationScreen.swift b/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/View/IdentityConfirmationScreen.swift index 5d11ee220..3e231d9f2 100644 --- a/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/View/IdentityConfirmationScreen.swift +++ b/ElementX/Sources/Screens/Onboarding/IdentityConfirmationScreen/View/IdentityConfirmationScreen.swift @@ -71,23 +71,23 @@ struct IdentityConfirmationScreen: View { @ViewBuilder private var actionButtons: some View { VStack(spacing: 32) { - switch context.viewState.mode { - case .recoveryOnly: - Button(L10n.screenSessionVerificationEnterRecoveryKey) { - context.send(viewAction: .recoveryKey) - } - .buttonStyle(.compound(.primary)) - - case .recoveryAndVerification: + if context.viewState.availableActions.contains(.interactiveVerification) { Button(L10n.actionStartVerification) { context.send(viewAction: .otherDevice) } .buttonStyle(.compound(.primary)) + if context.viewState.availableActions.contains(.recovery) { + Button(L10n.screenSessionVerificationEnterRecoveryKey) { + context.send(viewAction: .recoveryKey) + } + .buttonStyle(.compound(.plain)) + } + } else if context.viewState.availableActions.contains(.recovery) { Button(L10n.screenSessionVerificationEnterRecoveryKey) { context.send(viewAction: .recoveryKey) } - .buttonStyle(.compound(.plain)) + .buttonStyle(.compound(.primary)) } if shouldShowSkipButton { @@ -96,6 +96,11 @@ struct IdentityConfirmationScreen: View { } .buttonStyle(.compound(.plain)) } + + Button(L10n.screenRecoveryKeyConfirmLostRecoveryKey, role: .destructive) { + context.send(viewAction: .reset) + } + .buttonStyle(.compound(.plain)) } } } diff --git a/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPad-en-GB.1.png b/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPad-en-GB.1.png index 5c02ed379..99685c1f6 100644 --- a/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPad-en-GB.1.png +++ b/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPad-en-GB.1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f3ac13eb903ab6386f788382ea3362e6ef49f0aa065dd672953f1960bad44a27 -size 115060 +oid sha256:062da336508f1585f505f4cbb28885ba81f62082c8e786bd920386cc34d5ccea +size 118392 diff --git a/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPad-pseudo.1.png b/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPad-pseudo.1.png index 6532586dd..a8086ff72 100644 --- a/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPad-pseudo.1.png +++ b/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPad-pseudo.1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:783830e86a68a1aec227f6e16fc865451cdb3407e7b7967a00bf1d3920d8db92 -size 146800 +oid sha256:aed4dbdb22e4fa558b72f189a581e0930fc8d0476d7e0d7dcf9e1a8afb7d17a5 +size 156197 diff --git a/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPhone-15-en-GB.1.png b/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPhone-15-en-GB.1.png index 752e6039c..c5f30c574 100644 --- a/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPhone-15-en-GB.1.png +++ b/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPhone-15-en-GB.1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:15e443ca166ca691ac1f7ba73732e564c5ea3e18297f290337d94fc55da1a821 -size 71486 +oid sha256:7049b155c4155acf845121595c828822d51143b72cb1cc0eb5fb8309a5ee1c7a +size 75502 diff --git a/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPhone-15-pseudo.1.png b/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPhone-15-pseudo.1.png index 934c7ff3e..6399a1ae9 100644 --- a/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPhone-15-pseudo.1.png +++ b/PreviewTests/__Snapshots__/PreviewTests/test_identityConfirmationScreen-iPhone-15-pseudo.1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f44459b131c9d4a9c88547b9b58c23814919fe2311ffac7694cf19e5f584e817 -size 106764 +oid sha256:055aa831d819235c1f49b158dd329f10bd8be99d2a8b470e7786b58527d3c168 +size 117727