/* eslint-disable @typescript-eslint/camelcase */ import { RecoveryInternalData } from "anastasis-core"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { AsyncButton } from "../../components/AsyncButton"; import { NumberInput } from "../../components/fields/NumberInput"; 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) || 0; const [otherVersion, setOtherVersion] = useState(""); if (!reducer) { return
no reducer in context
} if (!reducer.currentReducerState || reducer.currentReducerState.recovery_state === undefined) { return
invalid state
} async function selectVersion(p: string, n: number): Promise { if (!reducer) return Promise.resolve(); 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 (

Provider {recoveryDocument.provider_url}

{currentVersion === 0 ?

Set to recover the latest version

:

Set to recover the version number {currentVersion}

}

Specify other version below or use the latest

selectVersion(otherProvider, parseInt(otherVersion, 10))}>Confirm
.
); } function ProviderCard({ provider, selected }: { selected?: boolean; provider: string }): VNode { return } return (

{recoveryDocument.provider_url}

{currentVersion === 0 ?

Set to recover the latest version

:

Set to recover the version number {currentVersion}

}

Or you can use another provider

{providerList.map(prov => { if (recoveryDocument.provider_url === prov) return; return })}

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

); }