diff options
author | Sebastian <sebasjm@gmail.com> | 2024-09-09 18:47:37 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-09-09 18:48:00 -0300 |
commit | caccb24902e30dff9edcba1685ce23445378b4b8 (patch) | |
tree | bb02d84c54dd1f08b6319d1d7526620fdd3f181a | |
parent | 049b369f745edb5f8a2d7ec57d5af98ca81b05fa (diff) |
show bic in aml search
-rw-r--r-- | packages/aml-backoffice-ui/src/hooks/account.ts | 4 | ||||
-rw-r--r-- | packages/aml-backoffice-ui/src/pages/Search.tsx | 126 | ||||
-rw-r--r-- | packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx | 40 |
3 files changed, 124 insertions, 46 deletions
diff --git a/packages/aml-backoffice-ui/src/hooks/account.ts b/packages/aml-backoffice-ui/src/hooks/account.ts index 9889c906d..e2b590a68 100644 --- a/packages/aml-backoffice-ui/src/hooks/account.ts +++ b/packages/aml-backoffice-ui/src/hooks/account.ts @@ -14,8 +14,12 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ import { + encodeCrock, + hashPaytoUri, OfficerAccount, PaytoString, + PaytoUri, + stringifyPaytoUri, TalerExchangeResultByMethod, TalerHttpError, } from "@gnu-taler/taler-util"; diff --git a/packages/aml-backoffice-ui/src/pages/Search.tsx b/packages/aml-backoffice-ui/src/pages/Search.tsx index bcdca0243..f9612c025 100644 --- a/packages/aml-backoffice-ui/src/pages/Search.tsx +++ b/packages/aml-backoffice-ui/src/pages/Search.tsx @@ -14,24 +14,29 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ import { + assertUnreachable, buildPayto, encodeCrock, hashPaytoUri, + HttpStatusCode, parsePaytoUri, PaytoUri, stringifyPaytoUri, + TalerError, TranslatedString, } from "@gnu-taler/taler-util"; import { + Attention, convertUiField, getConverterById, InternationalizationAPI, + Loading, RenderAllFieldsByUiConfig, UIFormElementConfig, UIHandlerId, useTranslationContext, } from "@gnu-taler/web-util/browser"; -import { h, VNode } from "preact"; +import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { FormErrors, @@ -44,6 +49,8 @@ import { import { useOfficer } from "../hooks/officer.js"; import { undefinedIfEmpty } from "./CreateAccount.js"; import { HandleAccountNotReady } from "./HandleAccountNotReady.js"; +import { useAccountInformation } from "../hooks/account.js"; +import { ErrorLoadingWithDebug } from "../components/ErrorLoadingWithDebug.js"; export function Search() { const officer = useOfficer(); @@ -88,19 +95,77 @@ export function Search() { </form> {paytoForm.status.status !== "ok" ? undefined : paytoForm.status.result - .paytoType === "x-taler-bank" ? ( + .paytoType === "x-taler-bank" ? ( <XTalerBankForm onSearch={setPayto} /> ) : paytoForm.status.result.paytoType === "iban" ? ( <IbanForm onSearch={setPayto} /> ) : ( <GenericForm onSearch={setPayto} /> )} - <pre>{!paytoUri ? undefined : stringifyPaytoUri(paytoUri)}</pre> - <pre>{!paytoUri ? undefined : encodeCrock(hashPaytoUri(paytoUri))}</pre> + {!paytoUri ? undefined : <ShowResult payto={paytoUri} />} </div> ); } +function ShowResult({ payto }: { payto: PaytoUri }): VNode { + const account = encodeCrock(hashPaytoUri(payto)); + const { i18n } = useTranslationContext(); + + const details = useAccountInformation(account); + if (!details) { + return <Loading /> + } + if (details instanceof TalerError) { + return <ErrorLoadingWithDebug error={details} />; + } + if (details.type === "fail") { + switch (details.case) { + case HttpStatusCode.Forbidden: { + return ( + <Fragment> + <Attention type="danger" title={i18n.str`Operation denied`}> + <i18n.Translate> + This account signature is wrong, contact administrator or create + a new one. + </i18n.Translate> + </Attention> + </Fragment> + ); + } + case HttpStatusCode.Conflict: { + return ( + <Fragment> + <Attention type="danger" title={i18n.str`Operation denied`}> + <i18n.Translate> + This account doesn't have access. Request account activation + sending your public key. + </i18n.Translate> + </Attention> + </Fragment> + ); + + } + case HttpStatusCode.NotFound: { + return ( + <Fragment> + <Attention type="danger" title={i18n.str`Operation denied`}> + <i18n.Translate>This account is not known.</i18n.Translate> + </Attention> + </Fragment> + ); + } + default: { + assertUnreachable(details) + } + } + } + + return <div > + found {JSON.stringify(details.body.details, undefined, 2)} + </div> +} + + function XTalerBankForm({ onSearch, }: { @@ -117,13 +182,13 @@ function XTalerBankForm({ form.status.status === "fail" ? undefined : buildPayto( - "x-taler-bank", - form.status.result.hostname, - form.status.result.account, - { - "receiver-name": form.status.result.name, - }, - ); + "x-taler-bank", + form.status.result.hostname, + form.status.result.account, + { + "receiver-name": encodeURIComponent(form.status.result.name), + }, + ); return ( <form @@ -165,9 +230,9 @@ function IbanForm({ const paytoUri = form.status.status === "fail" ? undefined - : buildPayto("iban", form.status.result.account, undefined, { - "receiver-name": form.status.result.name, - }); + : buildPayto("iban", form.status.result.account, form.status.result.bic, { + "receiver-name": encodeURIComponent(form.status.result.name), + }); return ( <form @@ -309,6 +374,7 @@ function createGenericPaytoValidator(i18n: InternationalizationAPI) { interface PaytoUriIBANForm { account: string; name: string; + bic: string; } function createIbanPaytoValidator(i18n: InternationalizationAPI) { @@ -324,6 +390,7 @@ function createIbanPaytoValidator(i18n: InternationalizationAPI) { const result: PaytoUriIBANForm = { account: state.account!, name: state.name!, + bic: state.bic!, }; return { status: "ok", @@ -334,6 +401,7 @@ function createIbanPaytoValidator(i18n: InternationalizationAPI) { const result: RecursivePartial<PaytoUriIBANForm> = { account: state.account, name: state.name, + bic: state.bic, }; return { status: "fail", @@ -433,17 +501,25 @@ const genericFields: ( const ibanFields: (i18n: InternationalizationAPI) => UIFormElementConfig[] = ( i18n, ) => [ - { - id: "account" as UIHandlerId, - type: "text", - required: true, - label: i18n.str`Account`, - help: i18n.str`International Bank Account Number`, - placeholder: i18n.str`DE1231231231`, - // validator: (value) => validateIBAN(value, i18n), - }, - receiverName(i18n), -]; + { + id: "account" as UIHandlerId, + type: "text", + required: true, + label: i18n.str`Account`, + help: i18n.str`International Bank Account Number`, + placeholder: i18n.str`DE1231231231`, + // validator: (value) => validateIBAN(value, i18n), + }, + receiverName(i18n), + { + id: "bic" as UIHandlerId, + type: "text", + label: i18n.str`Bank`, + help: i18n.str`Business Identifier Code`, + placeholder: i18n.str`GENODEM1GLS`, + // validator: (value) => validateIBAN(value, i18n), + }, + ]; const talerBankFields: ( i18n: InternationalizationAPI, diff --git a/packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx b/packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx index 67d3f3f7a..2866755c2 100644 --- a/packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx +++ b/packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx @@ -68,27 +68,25 @@ export function ShowConsolidated({ const formConfig: FormConfiguration = { type: "double-column", - design: [ - Object.entries(fixed).length > 0 - ? { - title: i18n.str`KYC collected info`, - fields: Object.entries(fixed).map(([key, field]) => { - const result: UIFormElementConfig = { - type: "text", - label: key as TranslatedString, - id: `${key}.value` as UIHandlerId, - disabled: true, - help: `At ${ - field.since.t_ms === "never" - ? "never" - : format(field.since.t_ms, "dd/MM/yyyy HH:mm:ss") - }` as TranslatedString, - }; - return result; - }), - } - : undefined!, - ], + design: Object.entries(fixed).length > 0 ? [ + + { + title: i18n.str`KYC collected info`, + fields: Object.entries(fixed).map(([key, field]) => { + const result: UIFormElementConfig = { + type: "text", + label: key as TranslatedString, + id: `${key}.value` as UIHandlerId, + disabled: true, + help: `At ${field.since.t_ms === "never" + ? "never" + : format(field.since.t_ms, "dd/MM/yyyy HH:mm:ss") + }` as TranslatedString, + }; + return result; + }), + } + ] : [], }; const shape: Array<UIHandlerId> = formConfig.design.flatMap((field) => getShapeFromFields(field.fields), |