import {
ChallengeFeedback,
ChallengeFeedbackStatus,
} from "@gnu-taler/anastasis-core";
import { h, VNode } from "preact";
import { Notifications } from "../../components/Notifications.js";
import { useAnastasisContext } from "../../context/anastasis.js";
import { authMethods, KnownAuthMethods } from "./authMethod/index.js";
import { AnastasisClientFrame } from "./index.js";
export function SolveOverviewFeedbackDisplay(props: {
feedback?: ChallengeFeedback;
}): VNode {
const { feedback } = props;
if (!feedback) {
return
;
}
switch (feedback.state) {
case ChallengeFeedbackStatus.TalerPayment:
return (
To pay you can click here
),
},
]}
/>
);
case ChallengeFeedbackStatus.IbanInstructions:
return (
);
case ChallengeFeedbackStatus.ServerFailure:
return (
);
case ChallengeFeedbackStatus.RateLimitExceeded:
return (
);
case ChallengeFeedbackStatus.Unsupported:
return (
);
case ChallengeFeedbackStatus.TruthUnknown:
return (
);
default:
console.warn(
`unknown challenge feedback status ${JSON.stringify(feedback)}`,
);
return ;
}
}
export function SolveScreen(): VNode {
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
);
}
function SolveNotImplemented(): VNode {
return (
The challenge selected is not supported for this UI. Please update
this version or try using another policy.
{reducer && (
)}
);
}
const chArr = reducer.currentReducerState.recovery_information.challenges;
const selectedUuid = reducer.currentReducerState.selected_challenge_uuid;
const selectedChallenge = chArr.find((ch) => ch.uuid === selectedUuid);
const SolveDialog =
!selectedChallenge ||
!authMethods[selectedChallenge.type as KnownAuthMethods]
? SolveNotImplemented
: authMethods[selectedChallenge.type as KnownAuthMethods].solve ??
SolveNotImplemented;
return ;
}