From cb2059d73e9b94d7b4179680017b962d12fcf790 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 16 Nov 2023 18:53:08 -0300 Subject: show better error message --- .../aml-backoffice-ui/src/handlers/InputAmount.tsx | 3 +- .../aml-backoffice-ui/src/hooks/useCaseDetails.ts | 8 +-- .../src/pages/AntiMoneyLaunderingForm.tsx | 6 +- .../aml-backoffice-ui/src/pages/NewFormEntry.tsx | 68 ++++++++++++++++------ 4 files changed, 57 insertions(+), 28 deletions(-) (limited to 'packages/aml-backoffice-ui/src') 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( 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 ( no account; @@ -32,26 +36,52 @@ export function NewFormEntry({ return
WHAT! {type}
; } - const { api } = useExchangeApiContext() return ( - { - 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); + + + + { - }} - /> + 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 === "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, + }) + } + } + }) + }} + /> + ); } -- cgit v1.2.3