diff options
author | Sebastian <sebasjm@gmail.com> | 2023-11-16 18:53:08 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-11-16 18:53:08 -0300 |
commit | cb2059d73e9b94d7b4179680017b962d12fcf790 (patch) | |
tree | 71c12ffcc45d2645071fb625e5b4d7e07473352f /packages/aml-backoffice-ui/src/pages | |
parent | d26743cabc0d629c225b7367b17aab871daf768b (diff) | |
download | wallet-core-cb2059d73e9b94d7b4179680017b962d12fcf790.tar.xz |
show better error message
Diffstat (limited to 'packages/aml-backoffice-ui/src/pages')
-rw-r--r-- | packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx | 6 | ||||
-rw-r--r-- | packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx | 68 |
2 files changed, 54 insertions, 20 deletions
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> ); } |