import { AbsoluteTime, Amounts, HttpStatusCode, TalerExchangeApi, TalerProtocolTimestamp, TranslatedString } from "@gnu-taler/taler-util";
import { LocalNotificationBanner, useLocalNotification, useTranslationContext } from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
import { useExchangeApiContext } from "../context/config.js";
import { useOfficer } from "../hooks/useOfficer.js";
import { Pages } from "../pages.js";
import { AntiMoneyLaunderingForm } from "./AntiMoneyLaunderingForm.js";
import { HandleAccountNotReady } from "./HandleAccountNotReady.js";
import { uiForms } from "../forms/declaration.js";
export function NewFormEntry({
account,
type,
}: {
account?: string;
type?: string;
}): VNode {
const { i18n } = useTranslationContext()
const officer = useOfficer();
const { api } = useExchangeApiContext()
const [notification, notify, handleError] = useLocalNotification()
if (!account) {
return
no account
;
}
if (!type) {
return ;
}
if (officer.state !== "ready") {
return ;
}
return (
{
const decision: Omit = {
justification: JSON.stringify(justification),
decision_time: TalerProtocolTimestamp.now(),
h_payto: account,
new_state,
new_threshold: Amounts.stringify(new_threshold),
kyc_requirements: undefined
}
await handleError(async () => {
const resp = await api.addDecisionDetails(officer.account, decision);
if (resp.type === "ok") {
window.location.href = Pages.cases.url;
return;
}
switch (resp.case) {
case HttpStatusCode.Forbidden:
case HttpStatusCode.Unauthorized: return notify({
type: "error",
title: i18n.str`Wrong credentials for "${officer.account}"`,
description: resp.detail.hint as TranslatedString,
debug: resp.detail,
when: AbsoluteTime.now(),
})
case HttpStatusCode.NotFound: return notify({
type: "error",
title: i18n.str`Officer or account not found`,
description: resp.detail.hint as TranslatedString,
debug: resp.detail,
when: AbsoluteTime.now(),
})
case HttpStatusCode.Conflict: return notify({
type: "error",
title: i18n.str`Officer disabled or more recent decision was already submitted.`,
description: resp.detail.hint as TranslatedString,
debug: resp.detail,
when: AbsoluteTime.now(),
})
}
})
}}
/>
);
}
function SelectForm({ account }: { account: string }) {
const { i18n } = useTranslationContext()
return (
New form for account: {account.substring(0, 16)}...
{uiForms.forms(i18n).map((form, idx) => {
return (
{form.label}
);
})}
);
}