From 0e79a79e6b9f159b3aebc39f2e278f062c4d4410 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 30 Jan 2024 15:05:01 +0100 Subject: formatting, comments, always return httpResp in OperationResult --- .../src/pages/AntiMoneyLaunderingForm.tsx | 113 ++++++++++++++------- 1 file changed, 74 insertions(+), 39 deletions(-) (limited to 'packages/aml-backoffice-ui/src') diff --git a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx index aa1247d5f..21faff058 100644 --- a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx +++ b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx @@ -1,19 +1,44 @@ -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 { + 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 { useExchangeApiContext } from "../context/config.js"; import { FormMetadata, uiForms } from "../forms/declaration.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; }) { - const { i18n } = useTranslationContext() - const theForm = uiForms.forms(i18n).find((v) => v.id === formId) +export function AntiMoneyLaunderingForm({ + account, + formId, + onSubmit, +}: { + account: string; + formId: string; + onSubmit: ( + justification: Justification, + state: AmlExchangeBackend.AmlState, + threshold: AmountJson, + ) => Promise; +}) { + const { i18n } = useTranslationContext(); + const theForm = uiForms.forms(i18n).find((v) => v.id === formId); if (!theForm) { - return
form with id {formId} not found
+ return
form with id {formId} not found
; } - const { config } = useExchangeApiContext() + const { config } = useExchangeApiContext(); const initial = { when: AbsoluteTime.now(), @@ -24,9 +49,10 @@ export function AntiMoneyLaunderingForm({ account, formId, onSubmit }: { account { }} + onUpdate={() => {}} onSubmit={(formValue) => { - if (formValue.state === undefined || formValue.threshold === undefined) return; + if (formValue.state === undefined || formValue.threshold === undefined) + return; const st = formValue.state; const amount = formValue.threshold; @@ -34,8 +60,8 @@ export function AntiMoneyLaunderingForm({ account, formId, onSubmit }: { account id: theForm.id, label: theForm.label, version: theForm.version, - value: formValue - } + value: formValue, + }; onSubmit(justification, st, amount); }} @@ -61,17 +87,16 @@ export function AntiMoneyLaunderingForm({ account, formId, onSubmit }: { account export type Justification = { // form values value: T; -} & Omit, "icon">, "impl"> +} & Omit, "icon">, "impl">; export function stringifyJustification(j: Justification): string { - return JSON.stringify(j) + return JSON.stringify(j); } - type SimpleFormMetadata = { - version?: number, - id?: string, -} + version?: number; + id?: string; +}; export const codecForSimpleFormMetadata = (): Codec => buildCodecForObject() @@ -80,52 +105,62 @@ export const codecForSimpleFormMetadata = (): Codec => .build("SimpleFormMetadata"); type ParseJustificationFail = - "not-json" | - "id-not-found" | - "form-not-found" | - "version-not-found"; + | "not-json" + | "id-not-found" + | "form-not-found" + | "version-not-found"; -export function parseJustification(s: string, listOfAllKnownForms: FormMetadata[]): OperationResult<{ justification: Justification, metadata: FormMetadata }, ParseJustificationFail> { +export function parseJustification( + s: string, + listOfAllKnownForms: FormMetadata[], +): OperationResult< + { justification: Justification; metadata: FormMetadata }, + ParseJustificationFail +> { try { - const justification = JSON.parse(s) - const info = codecForSimpleFormMetadata().decode(justification) + const justification = JSON.parse(s); + const info = codecForSimpleFormMetadata().decode(justification); if (!info.id) { return { + httpResp: undefined as any, type: "fail", case: "id-not-found", - detail: {} as any - } + detail: {} as any, + }; } if (!info.version) { return { + httpResp: undefined as any, type: "fail", case: "version-not-found", - detail: {} as any - } + detail: {} as any, + }; } const found = listOfAllKnownForms.find((f) => { - return f.id === info.id && f.version === info.version - }) + return f.id === info.id && f.version === info.version; + }); if (!found) { return { + httpResp: undefined as any, type: "fail", case: "form-not-found", - detail: {} as any - } + detail: {} as any, + }; } return { + httpResp: undefined as any, type: "ok", body: { - justification, metadata: found - } - } + justification, + metadata: found, + }, + }; } catch (e) { return { + httpResp: undefined as any, type: "fail", case: "not-json", - detail: {} as any - } + detail: {} as any, + }; } - } - -- cgit v1.2.3