aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx')
-rw-r--r--packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx68
1 files changed, 49 insertions, 19 deletions
diff --git a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
index e70536cb2..95b1f35c4 100644
--- a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
+++ b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
@@ -1,12 +1,13 @@
-import { VNode, h } from "preact";
+import { Fragment, VNode, h } from "preact";
import { AntiMoneyLaunderingForm, allForms } from "./AntiMoneyLaunderingForm.js";
import { Pages } from "../pages.js";
import { NiceForm } from "../NiceForm.js";
-import { AbsoluteTime, Amounts, TalerExchangeApi, TalerProtocolTimestamp } from "@gnu-taler/taler-util";
+import { AbsoluteTime, Amounts, TalerExchangeApi, TalerProtocolTimestamp, TranslatedString } from "@gnu-taler/taler-util";
import { AmlExchangeBackend } from "../types.js";
import { useOfficer } from "../hooks/useOfficer.js";
import { HandleAccountNotReady } from "./HandleAccountNotReady.js";
import { useExchangeApiContext } from "../context/config.js";
+import { LocalNotificationBanner, useLocalNotification, useTranslationContext } from "@gnu-taler/web-util/browser";
export function NewFormEntry({
account,
@@ -15,7 +16,10 @@ export function NewFormEntry({
account?: string;
type?: string;
}): VNode {
+ const { i18n } = useTranslationContext()
const officer = useOfficer();
+ const { api } = useExchangeApiContext()
+ const [notification, notify, handleError] = useLocalNotification()
if (!account) {
return <div>no account</div>;
@@ -32,26 +36,52 @@ export function NewFormEntry({
return <div>WHAT! {type}</div>;
}
- const { api } = useExchangeApiContext()
return (
- <AntiMoneyLaunderingForm
- account={account}
- selectedForm={selectedForm}
- onSubmit={async (justification, new_state, new_threshold) => {
- const decision: TalerExchangeApi.AmlDecision = {
- justification: JSON.stringify(justification),
- decision_time: TalerProtocolTimestamp.now(),
- h_payto: account,
- new_state,
- new_threshold: Amounts.stringify(new_threshold),
- officer_sig: "",
- kyc_requirements: undefined
- }
- api.addDecisionDetails(officer.account, decision);
+ <Fragment>
+ <LocalNotificationBanner notification={notification} />
+
+ <AntiMoneyLaunderingForm
+ account={account}
+ selectedForm={selectedForm}
+ onSubmit={async (justification, new_state, new_threshold) => {
- }}
- />
+ const decision: Omit<TalerExchangeApi.AmlDecision, "officer_sig"> = {
+ 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 === "fail") {
+ switch (resp.case) {
+ case "unauthorized": return notify({
+ type: "error",
+ title: i18n.str`Wrong credentials for "${officer.account}"`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case "officer-or-account-not-found": return notify({
+ type: "error",
+ title: i18n.str`Officer or account not found`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case "officer-disabled-or-recent-decision": 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,
+ })
+ }
+ }
+ })
+ }}
+ />
+ </Fragment>
);
}