summaryrefslogtreecommitdiff
path: root/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx')
-rw-r--r--packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx37
1 files changed, 29 insertions, 8 deletions
diff --git a/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx b/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx
index 7cb7fdf20..903f57868 100644
--- a/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx
+++ b/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx
@@ -1,17 +1,29 @@
/* eslint-disable @typescript-eslint/camelcase */
import { h, VNode } from "preact";
import { useState } from "preact/hooks";
-import { RecoveryReducerProps, AnastasisClientFrame } from "./index";
+import { useAnastasisContext } from "../../context/anastasis";
+import { AnastasisClientFrame } from "./index";
-export function SecretSelectionScreen(props: RecoveryReducerProps): VNode {
- const { reducer, recoveryState } = props;
+export function SecretSelectionScreen(): VNode {
const [selectingVersion, setSelectingVersion] = useState<boolean>(false);
- const [otherVersion, setOtherVersion] = useState<number>(
- recoveryState.recovery_document?.version ?? 0
- );
- const recoveryDocument = recoveryState.recovery_document!;
const [otherProvider, setOtherProvider] = useState<string>("");
+ const reducer = useAnastasisContext()
+
+ const currentVersion = reducer?.currentReducerState
+ && ("recovery_document" in reducer.currentReducerState)
+ && reducer.currentReducerState.recovery_document?.version;
+
+ const [otherVersion, setOtherVersion] = useState<number>(currentVersion || 0);
+
+ if (!reducer) {
+ return <div>no reducer in context</div>
+ }
+ if (!reducer.currentReducerState || reducer.currentReducerState.recovery_state === undefined) {
+ return <div>invalid state</div>
+ }
+
function selectVersion(p: string, n: number): void {
+ if (!reducer) return;
reducer.runTransaction(async (tx) => {
await tx.transition("change_version", {
version: n,
@@ -20,12 +32,21 @@ export function SecretSelectionScreen(props: RecoveryReducerProps): VNode {
setSelectingVersion(false);
});
}
+
+ const recoveryDocument = reducer.currentReducerState.recovery_document
+ if (!recoveryDocument) {
+ return (
+ <AnastasisClientFrame hideNav title="Recovery: Problem">
+ <p>No recovery document found</p>
+ </AnastasisClientFrame>
+ )
+ }
if (selectingVersion) {
return (
<AnastasisClientFrame hideNav title="Recovery: Select secret">
<p>Select a different version of the secret</p>
<select onChange={(e) => setOtherProvider((e.target as any).value)}>
- {Object.keys(recoveryState.authentication_providers ?? {}).map(
+ {Object.keys(reducer.currentReducerState.authentication_providers ?? {}).map(
(x, i) => (
<option key={i} selected={x === recoveryDocument.provider_url} value={x}>
{x}