aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-11-16 18:53:08 -0300
committerSebastian <sebasjm@gmail.com>2023-11-16 18:53:08 -0300
commitcb2059d73e9b94d7b4179680017b962d12fcf790 (patch)
tree71c12ffcc45d2645071fb625e5b4d7e07473352f /packages/aml-backoffice-ui/src
parentd26743cabc0d629c225b7367b17aab871daf768b (diff)
downloadwallet-core-cb2059d73e9b94d7b4179680017b962d12fcf790.tar.xz
show better error message
Diffstat (limited to 'packages/aml-backoffice-ui/src')
-rw-r--r--packages/aml-backoffice-ui/src/handlers/InputAmount.tsx3
-rw-r--r--packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts8
-rw-r--r--packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx6
-rw-r--r--packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx68
4 files changed, 57 insertions, 28 deletions
diff --git a/packages/aml-backoffice-ui/src/handlers/InputAmount.tsx b/packages/aml-backoffice-ui/src/handlers/InputAmount.tsx
index 9be9dd4d0..b6cc78adb 100644
--- a/packages/aml-backoffice-ui/src/handlers/InputAmount.tsx
+++ b/packages/aml-backoffice-ui/src/handlers/InputAmount.tsx
@@ -21,7 +21,8 @@ export function InputAmount<T extends object, K extends keyof T>(
converter={{
//@ts-ignore
fromStringUI: (v): AmountJson => {
- return Amounts.parseOrThrow(`${currency}:${v}`);
+
+ return Amounts.parse(`${currency}:${v}`) ?? Amounts.zeroOfCurrency(currency);
},
//@ts-ignore
toStringUI: (v: AmountJson) => {
diff --git a/packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts b/packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts
index 9db1e2aec..dbc6763ba 100644
--- a/packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts
+++ b/packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts
@@ -1,14 +1,8 @@
-import {
- HttpResponse,
- HttpResponseOk
-} from "@gnu-taler/web-util/browser";
-import { AmlExchangeBackend } from "../types.js";
// FIX default import https://github.com/microsoft/TypeScript/issues/49189
import { AmountString, OfficerAccount, PaytoString, TalerExchangeApi, TalerExchangeResultByMethod, TalerHttpError } from "@gnu-taler/taler-util";
-import _useSWR, { SWRHook, useSWRConfig } from "swr";
+import _useSWR, { SWRHook } from "swr";
import { useExchangeApiContext } from "../context/config.js";
-import { usePublicBackend } from "./useBackend.js";
import { useOfficer } from "./useOfficer.js";
const useSWR = _useSWR as unknown as SWRHook;
diff --git a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
index 5d2a3dffe..faf9671bb 100644
--- a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
+++ b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
@@ -13,6 +13,7 @@ import { v1 as form_902_9e_v1 } from "../forms/902_9e.js";
import { v1 as simplest } from "../forms/simplest.js";
import { Pages } from "../pages.js";
import { AmlExchangeBackend } from "../types.js";
+import { useExchangeApiContext } from "../context/config.js";
export type Justification = {
// form index in the list of forms
@@ -27,11 +28,14 @@ export function AntiMoneyLaunderingForm({ account, selectedForm, onSubmit }: { a
const { i18n } = useTranslationContext()
const showingFrom = allForms[selectedForm].impl;
const formName = allForms[selectedForm].name
+
+ const { config } = useExchangeApiContext()
+
const initial = {
fullName: "loggedIn_user_fullname",
when: AbsoluteTime.now(),
state: AmlExchangeBackend.AmlState.pending,
- threshold: Amounts.parseOrThrow("KUDOS:1000"),
+ threshold: Amounts.zeroOfCurrency(config.currency),
};
return (
<NiceForm
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>
);
}