/*
This file is part of GNU Taler
(C) 2022-2024 Taler Systems S.A.
GNU Taler is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
GNU Taler; see the file COPYING. If not, see
*/
import {
AccessToken,
HttpStatusCode,
KycRequirementInformation,
TalerError,
assertUnreachable,
} from "@gnu-taler/taler-util";
import {
Attention,
Button,
Loading,
LocalNotificationBanner,
useExchangeApiContext,
useLocalNotificationHandler,
useTranslationContext,
} from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
import { useEffect, useState } from "preact/hooks";
import { ErrorLoadingWithDebug } from "../components/ErrorLoadingWithDebug.js";
import { useKycInfo } from "../hooks/kyc.js";
import { FillForm } from "./FillForm.js";
type Props = {
onLoggedOut: () => void;
token: AccessToken;
};
export function ShowReqList({
token,
onFormSelected,
}: {
token: AccessToken;
onFormSelected: (r: KycRequirementInformation) => void;
}): VNode {
const { i18n } = useTranslationContext();
const [notification, withErrorHandler] = useLocalNotificationHandler();
// const { lib } = useExchangeApiContext();
// const { state, start } = useSessionState();
const result = useKycInfo(token);
const firstAccount =
result &&
!(result instanceof TalerError) &&
result.type === "ok" &&
result.body.requirements.length > 0
? result.body.requirements[0]
: undefined;
useEffect(() => {
if (firstAccount) onFormSelected(firstAccount);
}, [firstAccount]);
if (!result) {
return ;
}
if (result instanceof TalerError) {
return ;
}
if (result.type === "fail") {
switch (result.case) {
case HttpStatusCode.NotModified: {
return
not modified
;
}
case HttpStatusCode.NoContent: {
return
not requirements
;
}
case HttpStatusCode.Accepted: {
return
accepted
;
}
default: {
assertUnreachable(result);
}
}
}
const errors = undefinedIfEmpty({
// password: !password ? i18n.str`required` : undefined,
// url: !url
// ? i18n.str`required`
// : !safeToURL(url)
// ? i18n.str`invalid format`
// : undefined,
});
// const onStart =
// !!errors
// ? undefined
// : withErrorHandler(
// async () => {
// return {
// type: "ok",
// body: {},
// }
// // return lib.exchange.uploadKycForm(
// // "clientId",
// // createRFC8959AccessTokenEncoded(password),
// // );
// },
// (ok) => {
// // start({
// // nonce: ok.body.nonce,
// // clientId,
// // redirectURL: url,
// // state: encodeCrock(randomBytes(32)),
// // });
// onCreated();
// },
// // () => {
// // // switch (fail.case) {
// // // case HttpStatusCode.NotFound:
// // // return i18n.str`Client doesn't exist.`;
// // // }
// // },
// );
// const requirements: typeof result.body.requirements = [{
// description: "this is the form description, click to show the form field bla bla bla",
// form: "asdasd" as KycBuiltInFromId,
// description_i18n: {},
// id: "ASDASD" as KycRequirementInformationId,
// }, {
// description: "this is the description of the link and service provider.",
// form: "LINK",
// description_i18n: {},
// id: "ASDASD" as KycRequirementInformationId,
// }, {
// description: "you can't click this because this is only information, wait until AML officer replies.",
// form: "INFO",
// description_i18n: {},
// id: "ASDASD" as KycRequirementInformationId,
// }]
const requirements = result.body.requirements;
if (!result.body.requirements.length) {
return (