/* 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 { 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; }; 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); 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
; } 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 (

No requirements for this account

You can close this now
); } return (

Complete any of the following requirements

    {requirements.map((req, idx) => { return (
  • { onFormSelected(req); }} />
  • ); })}
); } export function Start({ token, onLoggedOut }: Props): VNode { const [req, setReq] = useState(); // if (!state) { // return ; // } if (!req) { return setReq(r)} />; } return ( { setReq(undefined); }} /> ); } function RequirementRow({ requirement: req, onFormSelected, }: { requirement: KycRequirementInformation; onFormSelected: () => void; }): VNode { const { i18n } = useTranslationContext(); const { lib } = useExchangeApiContext(); const [notification, withErrorHandler] = useLocalNotificationHandler(); const reqId = req.id; const startHandler = !reqId ? undefined : withErrorHandler( async () => { return lib.exchange.startExternalKycProcess(reqId); }, (res) => { window.open(res.body.redirect_url, "_blank"); }, ); switch (req.form) { case "INFO": { return (

Information

{req.description}

); } case "LINK": { return (

{req.description}

); } default: { return (

{req.description}

); } } } /** * Show the element when the load ended * @param element */ export function doAutoFocus(element: HTMLElement | null): void { if (element) { setTimeout(() => { element.focus({ preventScroll: true }); element.scrollIntoView({ behavior: "smooth", block: "center", inline: "center", }); }, 100); } } export function undefinedIfEmpty( obj: T, ): T | undefined { if (obj === undefined) return undefined; return Object.keys(obj).some( (k) => (obj as Record)[k] !== undefined, ) ? obj : undefined; }