aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/pages
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-01-03 14:52:00 -0300
committerSebastian <sebasjm@gmail.com>2024-01-03 14:52:00 -0300
commit1a71cd5ba2e9afb0ba7ef22760ecbe8b44aad953 (patch)
tree7d73293db6dca3ce0ac89d36a52472bd75fa8aa4 /packages/aml-backoffice-ui/src/pages
parent609ad091e332e4150b4d472284e5a9518cbe7571 (diff)
downloadwallet-core-1a71cd5ba2e9afb0ba7ef22760ecbe8b44aad953.tar.xz
split forms js
Diffstat (limited to 'packages/aml-backoffice-ui/src/pages')
-rw-r--r--packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx101
-rw-r--r--packages/aml-backoffice-ui/src/pages/CaseDetails.tsx19
-rw-r--r--packages/aml-backoffice-ui/src/pages/Cases.stories.tsx2
-rw-r--r--packages/aml-backoffice-ui/src/pages/Cases.tsx21
-rw-r--r--packages/aml-backoffice-ui/src/pages/CreateAccount.tsx6
-rw-r--r--packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx5
-rw-r--r--packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx53
-rw-r--r--packages/aml-backoffice-ui/src/pages/UnlockAccount.tsx4
8 files changed, 43 insertions, 168 deletions
diff --git a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
index ede8c9955..07ef0481a 100644
--- a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
+++ b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
@@ -1,22 +1,14 @@
import { AbsoluteTime, AmountJson, Amounts, Codec, OperationResult, buildCodecForObject, codecForNumber, codecForString, codecOptional } from "@gnu-taler/taler-util";
+import { DefaultForm, useTranslationContext } from "@gnu-taler/web-util/browser";
import { h } from "preact";
-import { v1 as form_902_11e_v1 } from "../forms/902_11e.js";
-import { v1 as form_902_12e_v1 } from "../forms/902_12e.js";
-import { v1 as form_902_13e_v1 } from "../forms/902_13e.js";
-import { v1 as form_902_15e_v1 } from "../forms/902_15e.js";
-import { v1 as form_902_1e_v1 } from "../forms/902_1e.js";
-import { v1 as form_902_4e_v1 } from "../forms/902_4e.js";
-import { v1 as form_902_5e_v1 } from "../forms/902_5e.js";
-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";
-import { DefaultForm, FlexibleForm, useTranslationContext } from "@gnu-taler/web-util/browser";
+import { FormMetadata } from "../forms/index.js";
+import { Pages } from "../pages.js";
+import { AmlExchangeBackend } from "../utils/types.js";
export function AntiMoneyLaunderingForm({ account, formId, onSubmit }: { account: string, formId: string, onSubmit: (justification: Justification, state: AmlExchangeBackend.AmlState, threshold: AmountJson) => Promise<void>; }) {
const { i18n } = useTranslationContext()
- const theForm = allForms.find((v) => v.id === formId)
+ const theForm = window.amlExchangeBackoffice!.forms(i18n).find((v) => v.id === formId)
if (!theForm) {
return <div>form with id {formId} not found</div>
}
@@ -66,24 +58,6 @@ export function AntiMoneyLaunderingForm({ account, formId, onSubmit }: { account
);
}
-export interface BaseForm {
- state: AmlExchangeBackend.AmlState;
- threshold: AmountJson;
-}
-
-const DocumentDuplicateIcon = <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
- <path stroke-linecap="round" stroke-linejoin="round" d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75" />
-</svg>
-
-
-export type FormMetadata<T extends BaseForm> = {
- label: string,
- id: string,
- version: number,
- icon: h.JSX.Element,
- impl: (current: BaseForm) => FlexibleForm<T>
-}
-
export type Justification<T = any> = {
// form values
value: T;
@@ -155,68 +129,3 @@ export function parseJustification(s: string, listOfAllKnownForms: FormMetadata<
}
-export const allForms: Array<FormMetadata<BaseForm>> = [
- {
- label: "Simple comment",
- id: "simple_comment",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: simplest,
- },
- {
- label: "Identification form",
- id: "902.1e",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: form_902_1e_v1,
- },
- {
- label: "Operational legal entity or partnership",
- id: "902.11e",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: form_902_11e_v1,
- },
- {
- label: "Foundations",
- id: "902.12e",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: form_902_12e_v1,
- },
- {
- label: "Declaration for trusts",
- id: "902.13e",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: form_902_13e_v1,
- },
- {
- label: "Information on life insurance policies",
- id: "902.15e",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: form_902_15e_v1,
- },
- {
- label: "Declaration of beneficial owner",
- id: "902.9e",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: form_902_9e_v1,
- },
- {
- label: "Customer profile",
- id: "902.5e",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: form_902_5e_v1,
- },
- {
- label: "Risk profile",
- id: "902.4e",
- version: 1,
- icon: DocumentDuplicateIcon,
- impl: form_902_4e_v1,
- },
-];
diff --git a/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx b/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx
index 0a2680b1b..409124121 100644
--- a/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx
+++ b/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx
@@ -6,15 +6,16 @@ import {
TranslatedString,
assertUnreachable
} from "@gnu-taler/taler-util";
-import { DefaultForm, ErrorLoading, Loading, useTranslationContext } from "@gnu-taler/web-util/browser";
+import { DefaultForm, ErrorLoading, InternationalizationAPI, Loading, useTranslationContext } from "@gnu-taler/web-util/browser";
import { format } from "date-fns";
import { Fragment, VNode, h } from "preact";
import { useState } from "preact/hooks";
+import { FormMetadata } from "../forms/index.js";
import { useCaseDetails } from "../hooks/useCaseDetails.js";
import { Pages } from "../pages.js";
-import { AmlExchangeBackend } from "../types.js";
-import { FormMetadata, Justification, allForms, parseJustification } from "./AntiMoneyLaunderingForm.js";
+import { Justification, parseJustification } from "./AntiMoneyLaunderingForm.js";
import { ShowConsolidated } from "./ShowConsolidated.js";
+import { AmlExchangeBackend } from "../utils/types.js";
export type AmlEvent = AmlFormEvent | AmlFormEventError | KycCollectionEvent | KycExpirationEvent;
type AmlFormEvent = {
@@ -55,7 +56,7 @@ function selectSooner(a: WithTime, b: WithTime) {
return AbsoluteTime.cmp(a.when, b.when);
}
-function titleForJustification(op: ReturnType<typeof parseJustification>): TranslatedString {
+function titleForJustification(op: ReturnType<typeof parseJustification>, i18n: InternationalizationAPI): TranslatedString {
if (op.type === "ok") {
return op.body.justification.label as TranslatedString;
}
@@ -72,13 +73,15 @@ export function getEventsFromAmlHistory(
aml: AmlExchangeBackend.AmlDecisionDetail[],
kyc: AmlExchangeBackend.KycDetail[],
): AmlEvent[] {
+ const { i18n } = useTranslationContext()
const ae: AmlEvent[] = aml.map((a) => {
- const just = parseJustification(a.justification, allForms)
+
+ const just = parseJustification(a.justification, window.amlExchangeBackoffice!.forms(i18n))
return {
type: just.type === "ok" ? "aml-form" : "aml-form-error",
state: a.new_state,
threshold: Amounts.parseOrThrow(a.new_threshold),
- title: titleForJustification(just),
+ title: titleForJustification(just, i18n),
metadata: just.type === "ok" ? just.body.metadata : undefined,
justification: just.type === "ok" ? just.body.justification : undefined,
when: {
@@ -92,14 +95,14 @@ export function getEventsFromAmlHistory(
const ke = kyc.reduce((prev, k) => {
prev.push({
type: "kyc-collection",
- title: "collection" as TranslatedString,
+ title: i18n.str`collection`,
when: AbsoluteTime.fromProtocolTimestamp(k.collection_time),
values: !k.attributes ? {} : k.attributes,
provider: k.provider_section,
});
prev.push({
type: "kyc-expiration",
- title: "expiration" as TranslatedString,
+ title: i18n.str`expiration`,
when: AbsoluteTime.fromProtocolTimestamp(k.expiration_time),
fields: !k.attributes ? [] : Object.keys(k.attributes),
});
diff --git a/packages/aml-backoffice-ui/src/pages/Cases.stories.tsx b/packages/aml-backoffice-ui/src/pages/Cases.stories.tsx
index 0355d5a31..3b9c8dacf 100644
--- a/packages/aml-backoffice-ui/src/pages/Cases.stories.tsx
+++ b/packages/aml-backoffice-ui/src/pages/Cases.stories.tsx
@@ -20,11 +20,11 @@
*/
import * as tests from "@gnu-taler/web-util/testing";
-import { AmlExchangeBackend } from "../types.js";
import {
CasesUI as TestedComponent,
} from "./Cases.js";
import { AmountString } from "@gnu-taler/taler-util";
+import { AmlExchangeBackend } from "../utils/types.js";
export default {
title: "cases",
diff --git a/packages/aml-backoffice-ui/src/pages/Cases.tsx b/packages/aml-backoffice-ui/src/pages/Cases.tsx
index 7161e4086..24f78f2d2 100644
--- a/packages/aml-backoffice-ui/src/pages/Cases.tsx
+++ b/packages/aml-backoffice-ui/src/pages/Cases.tsx
@@ -4,10 +4,10 @@ import { VNode, h } from "preact";
import { useState } from "preact/hooks";
import { useCases } from "../hooks/useCases.js";
import { Pages } from "../pages.js";
-import { AmlExchangeBackend } from "../types.js";
import { Officer } from "./Officer.js";
-import { amlStateConverter } from "./ShowConsolidated.js";
+import { amlStateConverter } from "../utils/converter.js";
+import { AmlExchangeBackend } from "../utils/types.js";
export function CasesUI({ records, filter, onChangeFilter, onFirstPage, onNext }: { onFirstPage?: () => void, onNext?: () => void, filter: AmlExchangeBackend.AmlState, onChangeFilter: (f: AmlExchangeBackend.AmlState) => void, records: TalerExchangeApi.AmlRecord[] }): VNode {
const { i18n } = useTranslationContext();
@@ -42,15 +42,15 @@ export function CasesUI({ records, filter, onChangeFilter, onFirstPage, onNext }
converter={amlStateConverter}
choices={[
{
- label: "Pending" as TranslatedString,
+ label: i18n.str`Pending`,
value: AmlExchangeBackend.AmlState.pending,
},
{
- label: "Frozen" as TranslatedString,
+ label: i18n.str`Frozen`,
value: AmlExchangeBackend.AmlState.frozen,
},
{
- label: "Normal" as TranslatedString,
+ label: i18n.str`Normal`,
value: AmlExchangeBackend.AmlState.normal,
},
]}
@@ -193,17 +193,6 @@ export const HomeIcon = () => <svg xmlns="http://www.w3.org/2000/svg" fill="none
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25" />
</svg>
-
-export const ChevronRightIcon = () => <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
- <path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
-</svg>
-
-
-export const ArrowRightIcon = () => <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
- <path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3" />
-</svg>
-
-
function Pagination({ onFirstPage, onNext }: { onFirstPage?: () => void, onNext?: () => void, }) {
const { i18n } = useTranslationContext()
return (
diff --git a/packages/aml-backoffice-ui/src/pages/CreateAccount.tsx b/packages/aml-backoffice-ui/src/pages/CreateAccount.tsx
index cd4f2d923..603813f8e 100644
--- a/packages/aml-backoffice-ui/src/pages/CreateAccount.tsx
+++ b/packages/aml-backoffice-ui/src/pages/CreateAccount.tsx
@@ -60,7 +60,7 @@ export function CreateAccount({
const error = s?.password?.error ?? s?.repeat?.error;
if (error) {
notifyError(
- "Can't create account" as TranslatedString,
+ i18n.str`Can't create account`,
error as TranslatedString,
);
} else {
@@ -70,7 +70,7 @@ export function CreateAccount({
>
<div class="mb-4">
<Form.InputLine
- label={"Password" as TranslatedString}
+ label={i18n.str`Password`}
name="password"
type="password"
help={
@@ -83,7 +83,7 @@ export function CreateAccount({
</div>
<div class="mb-4">
<Form.InputLine
- label={"Repeat password" as TranslatedString}
+ label={i18n.str`Repeat password`}
name="repeat"
type="password"
required
diff --git a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
index d53ac27c1..fe82df089 100644
--- a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
+++ b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
@@ -4,7 +4,7 @@ import { Fragment, VNode, h } from "preact";
import { useExchangeApiContext } from "../context/config.js";
import { useOfficer } from "../hooks/useOfficer.js";
import { Pages } from "../pages.js";
-import { AntiMoneyLaunderingForm, allForms } from "./AntiMoneyLaunderingForm.js";
+import { AntiMoneyLaunderingForm } from "./AntiMoneyLaunderingForm.js";
import { HandleAccountNotReady } from "./HandleAccountNotReady.js";
export function NewFormEntry({
@@ -80,10 +80,11 @@ export function NewFormEntry({
}
function SelectForm({ account }: { account: string }) {
+ const { i18n } = useTranslationContext()
return (
<div>
<pre>New form for account: {account.substring(0, 16)}...</pre>
- {allForms.map((form, idx) => {
+ {window.amlExchangeBackoffice!.forms(i18n).map((form, idx) => {
return (
<a
href={Pages.newFormEntry.url({ account, type: form.id })}
diff --git a/packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx b/packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx
index f59f8d41f..ad350c0e6 100644
--- a/packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx
+++ b/packages/aml-backoffice-ui/src/pages/ShowConsolidated.tsx
@@ -1,9 +1,10 @@
import { AbsoluteTime, AmountJson, TranslatedString } from "@gnu-taler/taler-util";
import { format } from "date-fns";
import { Fragment, VNode, h } from "preact";
-import { AmlExchangeBackend } from "../types.js";
import { AmlEvent } from "./CaseDetails.js";
-import { DefaultForm, FlexibleForm, UIFormField } from "@gnu-taler/web-util/browser";
+import { DefaultForm, FlexibleForm, UIFormField, useTranslationContext } from "@gnu-taler/web-util/browser";
+import { amlStateConverter } from "../utils/converter.js";
+import { AmlExchangeBackend } from "../utils/types.js";
export function ShowConsolidated({
history,
@@ -12,6 +13,8 @@ export function ShowConsolidated({
history: AmlEvent[];
until: AbsoluteTime;
}): VNode {
+ const { i18n } = useTranslationContext();
+
const cons = getConsolidated(history, until);
const form: FlexibleForm<Consolidated> = {
@@ -32,32 +35,32 @@ export function ShowConsolidated({
},
design: [
{
- title: "AML" as TranslatedString,
+ title: i18n.str`AML`,
fields: [
{
type: "amount",
props: {
- label: "Threshold" as TranslatedString,
+ label: i18n.str`Threshold`,
name: "aml.threshold",
},
},
{
type: "choiceHorizontal",
props: {
- label: "State" as TranslatedString,
+ label: i18n.str`State`,
name: "aml.state",
converter: amlStateConverter,
choices: [
{
- label: "Frozen" as TranslatedString,
+ label: i18n.str`Frozen`,
value: AmlExchangeBackend.AmlState.frozen,
},
{
- label: "Pending" as TranslatedString,
+ label: i18n.str`Pending`,
value: AmlExchangeBackend.AmlState.pending,
},
{
- label: "Normal" as TranslatedString,
+ label: i18n.str`Normal`,
value: AmlExchangeBackend.AmlState.normal,
},
],
@@ -67,7 +70,7 @@ export function ShowConsolidated({
},
Object.entries(cons.kyc).length > 0
? {
- title: "KYC" as TranslatedString,
+ title: i18n.str`KYC`,
fields: Object.entries(cons.kyc).map(([key, field]) => {
const result: UIFormField = {
type: "text",
@@ -167,34 +170,4 @@ function getConsolidated(
}
return prev;
}, initial);
-}
-
-export const amlStateConverter = {
- toStringUI: stringifyAmlState,
- fromStringUI: parseAmlState,
-};
-
-function stringifyAmlState(s: AmlExchangeBackend.AmlState | undefined): string {
- if (s === undefined) return "";
- switch (s) {
- case AmlExchangeBackend.AmlState.normal:
- return "normal";
- case AmlExchangeBackend.AmlState.pending:
- return "pending";
- case AmlExchangeBackend.AmlState.frozen:
- return "frozen";
- }
-}
-
-function parseAmlState(s: string | undefined): AmlExchangeBackend.AmlState {
- switch (s) {
- case "normal":
- return AmlExchangeBackend.AmlState.normal;
- case "pending":
- return AmlExchangeBackend.AmlState.pending;
- case "frozen":
- return AmlExchangeBackend.AmlState.frozen;
- default:
- throw Error(`unknown AML state: ${s}`);
- }
-}
+} \ No newline at end of file
diff --git a/packages/aml-backoffice-ui/src/pages/UnlockAccount.tsx b/packages/aml-backoffice-ui/src/pages/UnlockAccount.tsx
index cd801256a..1b0342b12 100644
--- a/packages/aml-backoffice-ui/src/pages/UnlockAccount.tsx
+++ b/packages/aml-backoffice-ui/src/pages/UnlockAccount.tsx
@@ -32,7 +32,7 @@ export function UnlockAccount({
onSubmit={async (v) => {
try {
await onAccountUnlocked(v.password!);
- notifyInfo("Account unlocked" as TranslatedString);
+ notifyInfo(i18n.str`Account unlocked`);
} catch (e) {
if (e instanceof UnwrapKeyError) {
notifyError(
@@ -47,7 +47,7 @@ export function UnlockAccount({
>
<div class="mb-4">
<Form.InputLine
- label={"Password" as TranslatedString}
+ label={i18n.str`Password`}
name="password"
type="password"
required