aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-01-30 15:05:01 +0100
committerFlorian Dold <florian@dold.me>2024-01-30 15:05:01 +0100
commit0e79a79e6b9f159b3aebc39f2e278f062c4d4410 (patch)
tree30273b53255d22a567f1f6eec4f6c11cabbd72d7 /packages/aml-backoffice-ui/src
parent2d2c43a3015a52de9a4c08a329e51b3e713380dc (diff)
downloadwallet-core-0e79a79e6b9f159b3aebc39f2e278f062c4d4410.tar.xz
formatting, comments, always return httpResp in OperationResult
Diffstat (limited to 'packages/aml-backoffice-ui/src')
-rw-r--r--packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx113
1 files changed, 74 insertions, 39 deletions
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<void>; }) {
- 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<void>;
+}) {
+ const { i18n } = useTranslationContext();
+ const theForm = uiForms.forms(i18n).find((v) => v.id === formId);
if (!theForm) {
- return <div>form with id {formId} not found</div>
+ return <div>form with id {formId} not found</div>;
}
- const { config } = useExchangeApiContext()
+ const { config } = useExchangeApiContext();
const initial = {
when: AbsoluteTime.now(),
@@ -24,9 +49,10 @@ export function AntiMoneyLaunderingForm({ account, formId, onSubmit }: { account
<DefaultForm
initial={initial}
form={theForm.impl(initial)}
- onUpdate={() => { }}
+ 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<T = any> = {
// form values
value: T;
-} & Omit<Omit<FormMetadata<any>, "icon">, "impl">
+} & Omit<Omit<FormMetadata<any>, "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<SimpleFormMetadata> =>
buildCodecForObject<SimpleFormMetadata>()
@@ -80,52 +105,62 @@ export const codecForSimpleFormMetadata = (): Codec<SimpleFormMetadata> =>
.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<any>[]): OperationResult<{ justification: Justification, metadata: FormMetadata<any> }, ParseJustificationFail> {
+export function parseJustification(
+ s: string,
+ listOfAllKnownForms: FormMetadata<any>[],
+): OperationResult<
+ { justification: Justification; metadata: FormMetadata<any> },
+ 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,
+ };
}
-
}
-