import { AbsoluteTime, AmountJson, Amounts, Codec, OperationResult, buildCodecForObject, codecForNumber, codecForString, codecOptional } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { h } from "preact"; import { NiceForm } from "../NiceForm.js"; 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 { FlexibleForm } from "../forms/index.js"; export function AntiMoneyLaunderingForm({ account, formId, onSubmit }: { account: string, formId: string, onSubmit: (justification: Justification, state: AmlExchangeBackend.AmlState, threshold: AmountJson) => Promise; }) { const { i18n } = useTranslationContext() const theForm = allForms.find((v) => v.id === formId) if (!theForm) { return
form with id {formId} not found
} const { config } = useExchangeApiContext() const initial = { when: AbsoluteTime.now(), state: AmlExchangeBackend.AmlState.pending, threshold: Amounts.zeroOfCurrency(config.currency), }; return ( { }} onSubmit={(formValue) => { if (formValue.state === undefined || formValue.threshold === undefined) return; const st = formValue.state; const amount = formValue.threshold; const justification: Justification = { id: theForm.id, label: theForm.label, version: theForm.version, value: formValue } onSubmit(justification, st, amount); }} >
Cancel
); } export interface BaseForm { state: AmlExchangeBackend.AmlState; threshold: AmountJson; } const DocumentDuplicateIcon = export type FormMetadata = { label: string, id: string, version: number, icon: h.JSX.Element, impl: (current: BaseForm) => FlexibleForm } export type Justification = { // form values value: T; } & Omit, "icon">, "impl"> export function stringifyJustification(j: Justification): string { return JSON.stringify(j) } type SimpleFormMetadata = { version?: number, id?: string, } export const codecForSimpleFormMetadata = (): Codec => buildCodecForObject() .property("id", codecOptional(codecForString())) .property("version", codecOptional(codecForNumber())) .build("SimpleFormMetadata"); type ParseJustificationFail = "not-json" | "id-not-found" | "form-not-found" | "version-not-found"; export function parseJustification(s: string, listOfAllKnownForms: FormMetadata[]): OperationResult<{ justification: Justification, metadata: FormMetadata }, ParseJustificationFail> { try { const justification = JSON.parse(s) const info = codecForSimpleFormMetadata().decode(justification) if (!info.id) { return { type: "fail", case: "id-not-found", detail: {} as any } } if (!info.version) { return { type: "fail", case: "version-not-found", detail: {} as any } } const found = listOfAllKnownForms.find((f) => { return f.id === info.id && f.version === info.version }) if (!found) { return { type: "fail", case: "form-not-found", detail: {} as any } } return { type: "ok", body: { justification, metadata: found } } } catch (e) { return { type: "fail", case: "not-json", detail: {} as any } } } export const allForms: Array> = [ { 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, }, ];