From 5054ff6c6d200e8d4d7658e001b0bcb1936d6876 Mon Sep 17 00:00:00 2001
From: Florian Dold <florian@dold.me>
Date: Wed, 13 Apr 2022 19:32:12 +0200
Subject: anastasis-webui: make TOTP work again

---
 packages/anastasis-webui/src/pages/home/index.tsx | 75 +++++++++++++++++------
 1 file changed, 57 insertions(+), 18 deletions(-)

(limited to 'packages/anastasis-webui/src/pages/home/index.tsx')

diff --git a/packages/anastasis-webui/src/pages/home/index.tsx b/packages/anastasis-webui/src/pages/home/index.tsx
index ca6da8474..7d191ae04 100644
--- a/packages/anastasis-webui/src/pages/home/index.tsx
+++ b/packages/anastasis-webui/src/pages/home/index.tsx
@@ -34,7 +34,7 @@ import { StartScreen } from "./StartScreen";
 import { TruthsPayingScreen } from "./TruthsPayingScreen";
 
 function isBackup(reducer: AnastasisReducerApi): boolean {
-  return !!reducer.currentReducerState?.backup_state;
+  return reducer.currentReducerState?.reducer_type === "backup";
 }
 
 export function withProcessLabel(
@@ -171,57 +171,96 @@ function AnastasisClientImpl(): VNode {
   console.log("state", reducer.currentReducerState);
 
   if (
-    state.backup_state === BackupStates.ContinentSelecting ||
-    state.recovery_state === RecoveryStates.ContinentSelecting ||
-    state.backup_state === BackupStates.CountrySelecting ||
-    state.recovery_state === RecoveryStates.CountrySelecting
+    (state.reducer_type === "backup" &&
+      state.backup_state === BackupStates.ContinentSelecting) ||
+    (state.reducer_type === "recovery" &&
+      state.recovery_state === RecoveryStates.ContinentSelecting) ||
+    (state.reducer_type === "backup" &&
+      state.backup_state === BackupStates.CountrySelecting) ||
+    (state.reducer_type === "recovery" &&
+      state.recovery_state === RecoveryStates.CountrySelecting)
   ) {
     return <ContinentSelectionScreen />;
   }
   if (
-    state.backup_state === BackupStates.UserAttributesCollecting ||
-    state.recovery_state === RecoveryStates.UserAttributesCollecting
+    (state.reducer_type === "backup" &&
+      state.backup_state === BackupStates.UserAttributesCollecting) ||
+    (state.reducer_type === "recovery" &&
+      state.recovery_state === RecoveryStates.UserAttributesCollecting)
   ) {
     return <AttributeEntryScreen />;
   }
-  if (state.backup_state === BackupStates.AuthenticationsEditing) {
+  if (
+    state.reducer_type === "backup" &&
+    state.backup_state === BackupStates.AuthenticationsEditing
+  ) {
     return <AuthenticationEditorScreen />;
   }
-  if (state.backup_state === BackupStates.PoliciesReviewing) {
+  if (
+    state.reducer_type === "backup" &&
+    state.backup_state === BackupStates.PoliciesReviewing
+  ) {
     return <ReviewPoliciesScreen />;
   }
-  if (state.backup_state === BackupStates.SecretEditing) {
+  if (
+    state.reducer_type === "backup" &&
+    state.backup_state === BackupStates.SecretEditing
+  ) {
     return <SecretEditorScreen />;
   }
 
-  if (state.backup_state === BackupStates.BackupFinished) {
+  if (
+    state.reducer_type === "backup" &&
+    state.backup_state === BackupStates.BackupFinished
+  ) {
     return <BackupFinishedScreen />;
   }
 
-  if (state.backup_state === BackupStates.TruthsPaying) {
+  if (
+    state.reducer_type === "backup" &&
+    state.backup_state === BackupStates.TruthsPaying
+  ) {
     return <TruthsPayingScreen />;
   }
 
-  if (state.backup_state === BackupStates.PoliciesPaying) {
+  if (
+    state.reducer_type === "backup" &&
+    state.backup_state === BackupStates.PoliciesPaying
+  ) {
     return <PoliciesPayingScreen />;
   }
 
-  if (state.recovery_state === RecoveryStates.SecretSelecting) {
+  if (
+    state.reducer_type === "recovery" &&
+    state.recovery_state === RecoveryStates.SecretSelecting
+  ) {
     return <SecretSelectionScreen />;
   }
 
-  if (state.recovery_state === RecoveryStates.ChallengeSelecting) {
+  if (
+    state.reducer_type === "recovery" &&
+    state.recovery_state === RecoveryStates.ChallengeSelecting
+  ) {
     return <ChallengeOverviewScreen />;
   }
 
-  if (state.recovery_state === RecoveryStates.ChallengeSolving) {
+  if (
+    state.reducer_type === "recovery" &&
+    state.recovery_state === RecoveryStates.ChallengeSolving
+  ) {
     return <SolveScreen />;
   }
 
-  if (state.recovery_state === RecoveryStates.RecoveryFinished) {
+  if (
+    state.reducer_type === "recovery" &&
+    state.recovery_state === RecoveryStates.RecoveryFinished
+  ) {
     return <RecoveryFinishedScreen />;
   }
-  if (state.recovery_state === RecoveryStates.ChallengePaying) {
+  if (
+    state.reducer_type === "recovery" &&
+    state.recovery_state === RecoveryStates.ChallengePaying
+  ) {
     return <ChallengePayingScreen />;
   }
   console.log("unknown state", reducer.currentReducerState);
-- 
cgit v1.2.3

