/* eslint-disable @typescript-eslint/camelcase */ import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { useAnastasisContext } from "../../context/anastasis"; import { AnastasisClientFrame } from "./index"; export function SecretSelectionScreen(): VNode { const [selectingVersion, setSelectingVersion] = useState(false); const [otherProvider, setOtherProvider] = useState(""); const reducer = useAnastasisContext() const currentVersion = reducer?.currentReducerState && ("recovery_document" in reducer.currentReducerState) && reducer.currentReducerState.recovery_document?.version; const [otherVersion, setOtherVersion] = useState(currentVersion || 0); if (!reducer) { return
no reducer in context
} if (!reducer.currentReducerState || reducer.currentReducerState.recovery_state === undefined) { return
invalid state
} function selectVersion(p: string, n: number): void { if (!reducer) return; reducer.runTransaction(async (tx) => { await tx.transition("change_version", { version: n, provider_url: p, }); }); setSelectingVersion(false); } const providerList = Object.keys(reducer.currentReducerState.authentication_providers ?? {}) const recoveryDocument = reducer.currentReducerState.recovery_document if (!recoveryDocument) { return (

No recovery document found, try with another provider

Provider
) } if (selectingVersion) { return (

Select a different version of the secret

Provider
Version setOtherVersion(Number((e.target as HTMLInputElement).value))} type="number" /> setOtherVersion(0)}>set to latest version
); } return (

{recoveryDocument.provider_url}

Secret version {recoveryDocument.version} setSelectingVersion(true)}>use another version
Secret name {recoveryDocument.secret_name}

Secret found, you can select another version or continue to the challenges solving

); }