import { ChallengeFeedbackStatus, ChallengeInfo, } from "@gnu-taler/anastasis-core"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { AsyncButton } from "../../../components/AsyncButton"; import { TextInput } from "../../../components/fields/TextInput"; import { useAnastasisContext } from "../../../context/anastasis"; import { AnastasisClientFrame } from "../index"; import { SolveOverviewFeedbackDisplay } from "../SolveScreen"; import { shouldHideConfirm } from "./helpers"; import { AuthMethodSolveProps } from "./index"; export function AuthMethodTotpSolve(props: AuthMethodSolveProps): VNode { const [answerCode, setAnswerCode] = useState(""); const reducer = useAnastasisContext(); if (!reducer) { return ( no reducer in context ); } if (reducer.currentReducerState?.reducer_type !== "recovery") { return ( invalid state ); } if (!reducer.currentReducerState.recovery_information) { return ( no recovery information found ); } if (!reducer.currentReducerState.selected_challenge_uuid) { return ( invalid state reducer.back()}> Back ); } const chArr = reducer.currentReducerState.recovery_information.challenges; const challengeFeedback = reducer.currentReducerState.challenge_feedback ?? {}; const selectedUuid = reducer.currentReducerState.selected_challenge_uuid; const challenges: { [uuid: string]: ChallengeInfo; } = {}; for (const ch of chArr) { challenges[ch.uuid] = ch; } const feedback = challengeFeedback[selectedUuid]; async function onNext(): Promise { console.log(`sending TOTP code '${answerCode}'`); return reducer?.transition("solve_challenge", { answer: answerCode, }); } function onCancel(): void { reducer?.back(); } return ( enter the totp solution Cancel {!shouldHideConfirm(feedback) && ( Confirm )} ); }
enter the totp solution