commit fc83b400c52c54084913701592176949c404769f
parent c9fc43fda50166cd678ae5da6436568e5b6a7322
Author: Sebastian <sebasjm@gmail.com>
Date: Mon, 24 Mar 2025 18:01:25 -0300
take from props and events utils
Diffstat:
5 files changed, 45 insertions(+), 296 deletions(-)
diff --git a/packages/aml-backoffice-ui/src/hooks/server-info.ts b/packages/aml-backoffice-ui/src/hooks/server-info.ts
@@ -14,30 +14,23 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
import {
- AbsoluteTime,
+ AML_EVENTS_INFO,
+ AmlEventsName,
AmlSpaDialect,
- assertUnreachable,
EventCounter,
OfficerAccount,
OperationOk,
opFixedSuccess,
- PaytoString,
- TalerCorebankApi,
TalerExchangeErrorsByMethod,
TalerExchangeResultByMethod,
TalerHttpError,
} from "@gnu-taler/taler-util";
// FIX default import https://github.com/microsoft/TypeScript/issues/49189
import { useExchangeApiContext } from "@gnu-taler/web-util/browser";
-import _useSWR, { mutate, SWRHook } from "swr";
-import { useOfficer } from "./officer.js";
-import { AmlProgram } from "../../../taler-util/lib/types-taler-kyc-aml.js";
-import {
- AML_EVENTS_INFO,
- AmlEventsName,
-} from "../pages/decision/aml-events.js";
import { useMemo } from "preact/hooks";
+import _useSWR, { SWRHook } from "swr";
import { Timeframe } from "../pages/Dashboard.js";
+import { useOfficer } from "./officer.js";
const useSWR = _useSWR as unknown as SWRHook;
export function useServerMeasures() {
@@ -76,6 +69,10 @@ export type ServerStats = {
[name: string]: EventCounter;
};
+const TOPS_EVENTS: AmlEventsName[] = [];
+const GLS_EVENTS: AmlEventsName[] = [];
+const TESTING_EVENTS: AmlEventsName[] = [];
+
export function useServerStatistics(
dialect: AmlSpaDialect,
current: Timeframe,
@@ -88,13 +85,12 @@ export function useServerStatistics(
lib: { exchange: api },
} = useExchangeApiContext();
- const keys = useMemo(() => {
- return Object.entries(AML_EVENTS_INFO)
- .filter(([name, info]) => {
- return info.dialect.includes(dialect);
- })
- .map(([name]) => name as AmlEventsName);
- }, [dialect]);
+ const keys =
+ dialect === AmlSpaDialect.GLS
+ ? GLS_EVENTS
+ : dialect === AmlSpaDialect.TOPS
+ ? TOPS_EVENTS
+ : TESTING_EVENTS;
type Success = TalerExchangeResultByMethod<"getAmlKycStatistics">;
type Error = TalerExchangeErrorsByMethod<"getAmlKycStatistics">;
diff --git a/packages/aml-backoffice-ui/src/pages/Dashboard.tsx b/packages/aml-backoffice-ui/src/pages/Dashboard.tsx
@@ -15,10 +15,10 @@
*/
import {
AbsoluteTime,
+ AmlEventsName,
AmlSpaDialect,
assertUnreachable,
HttpStatusCode,
- OperationFail,
OperationOk,
TalerCorebankApi,
TalerError,
@@ -41,7 +41,6 @@ import { ErrorLoadingWithDebug } from "../components/ErrorLoadingWithDebug.js";
import { useOfficer } from "../hooks/officer.js";
import { usePreferences } from "../hooks/preferences.js";
import { useServerStatistics } from "../hooks/server-info.js";
-import { AmlEventsName } from "./decision/aml-events.js";
import { HandleAccountNotReady } from "./HandleAccountNotReady.js";
import { Officer } from "./Officer.js";
@@ -256,14 +255,18 @@ function labelForEvent(name: AmlEventsName, i18n: InternationalizationAPI) {
return i18n.str`Account from high-risk country incorporated`;
case AmlEventsName.ACCOUNT_CLOSED_HR_COUNTRY:
return i18n.str`Account from high-risk country removed`;
- case AmlEventsName.ACCOUNT_MROS_REPORTED_ART9:
+ case AmlEventsName.ACCOUNT_OPENED_INT_ORG_PEP:
+ return i18n.str`Account from dometic PEP incorporated`;
+ case AmlEventsName.ACCOUNT_CLOSED_INT_ORG_PEP:
+ return i18n.str`Account from dometic PEP removed`;
+ case AmlEventsName.ACCOUNT_MROS_REPORTED_SUSPICION_SIMPLE:
return i18n.str`MROS reported by obligation`;
- case AmlEventsName.ACCOUNT_MROS_REPORTED_ART305:
+ case AmlEventsName.ACCOUNT_MROS_REPORTED_SUSPICION_SUBSTANTIATED:
return i18n.str`MROS reported by right`;
- case AmlEventsName.ACCOUNT_INVESTIGATION_ART6_COMPLETED:
+ case AmlEventsName.ACCOUNT_INVESTIGATION_COMPLETED:
return i18n.str`Investigations after Art 6 Gwg completed`;
- case AmlEventsName.ACCOUNT_INVESTIGATION_ART6_FAILED:
- return i18n.str`Investigations after Art 6 Gwg failed`;
+ case AmlEventsName.ACCOUNT_INVESTIGATION_STARTED:
+ return i18n.str`Investigations after Art 6 Gwg started`;
case AmlEventsName.TEST_EVENT_KEY_1:
return i18n.str`TEST_EVENT_KEY_1`;
case AmlEventsName.TEST_EVENT_KEY_2:
@@ -305,14 +308,18 @@ function descriptionForEvent(
return i18n.str`Account from high-risk country incorporated`;
case AmlEventsName.ACCOUNT_CLOSED_HR_COUNTRY:
return i18n.str`Account from high-risk country removed`;
- case AmlEventsName.ACCOUNT_MROS_REPORTED_ART9:
+ case AmlEventsName.ACCOUNT_MROS_REPORTED_SUSPICION_SIMPLE:
return i18n.str`MROS reported by obligation`;
- case AmlEventsName.ACCOUNT_MROS_REPORTED_ART305:
+ case AmlEventsName.ACCOUNT_MROS_REPORTED_SUSPICION_SUBSTANTIATED:
return i18n.str`MROS reported by right`;
- case AmlEventsName.ACCOUNT_INVESTIGATION_ART6_COMPLETED:
+ case AmlEventsName.ACCOUNT_INVESTIGATION_COMPLETED:
return i18n.str`Investigations after Art 6 Gwg completed`;
- case AmlEventsName.ACCOUNT_INVESTIGATION_ART6_FAILED:
- return i18n.str`Investigations after Art 6 Gwg failed`;
+ case AmlEventsName.ACCOUNT_INVESTIGATION_STARTED:
+ return i18n.str`Investigations after Art 6 Gwg started`;
+ case AmlEventsName.ACCOUNT_OPENED_INT_ORG_PEP:
+ return i18n.str`Investigations after Art 6 Gwg opened`;
+ case AmlEventsName.ACCOUNT_CLOSED_INT_ORG_PEP:
+ return i18n.str`Investigations after Art 6 Gwg closed`;
case AmlEventsName.TEST_EVENT_KEY_1:
return i18n.str`TEST_EVENT_KEY_1`;
case AmlEventsName.TEST_EVENT_KEY_2:
diff --git a/packages/aml-backoffice-ui/src/pages/decision/Events.tsx b/packages/aml-backoffice-ui/src/pages/decision/Events.tsx
@@ -1,5 +1,7 @@
import {
+ AML_EVENTS_INFO,
AmlDecision,
+ AmlEventsName,
AmlSpaDialect,
assertUnreachable,
MeasureInformation,
@@ -22,7 +24,6 @@ import {
useCurrentDecisionRequest,
} from "../../hooks/decision-request.js";
import { usePreferences } from "../../hooks/preferences.js";
-import { AML_EVENTS_INFO, AmlEventsName } from "./aml-events.js";
import { useAccountActiveDecision } from "../../hooks/decisions.js";
/**
@@ -162,14 +163,18 @@ function labelForEvent(event: AmlEventsName, i18n: InternationalizationAPI) {
return i18n.str`Account from high-risk country incorporated`;
case AmlEventsName.ACCOUNT_CLOSED_HR_COUNTRY:
return i18n.str`Account from high-risk country removed`;
- case AmlEventsName.ACCOUNT_MROS_REPORTED_ART9:
+ case AmlEventsName.ACCOUNT_MROS_REPORTED_SUSPICION_SIMPLE:
return i18n.str`MROS reported by obligation`;
- case AmlEventsName.ACCOUNT_MROS_REPORTED_ART305:
+ case AmlEventsName.ACCOUNT_MROS_REPORTED_SUSPICION_SUBSTANTIATED:
return i18n.str`MROS reported by right`;
- case AmlEventsName.ACCOUNT_INVESTIGATION_ART6_COMPLETED:
+ case AmlEventsName.ACCOUNT_INVESTIGATION_COMPLETED:
return i18n.str`Investigations after Art 6 Gwg completed`;
- case AmlEventsName.ACCOUNT_INVESTIGATION_ART6_FAILED:
- return i18n.str`Investigations after Art 6 Gwg failed`;
+ case AmlEventsName.ACCOUNT_INVESTIGATION_STARTED:
+ return i18n.str`Investigations after Art 6 Gwg started`;
+ case AmlEventsName.ACCOUNT_OPENED_INT_ORG_PEP:
+ return i18n.str`Account from international organization PEP incorporated`;
+ case AmlEventsName.ACCOUNT_CLOSED_INT_ORG_PEP:
+ return i18n.str`Account from international organization PEP removed`;
case AmlEventsName.TEST_EVENT_KEY_1:
return i18n.str`TEST_EVENT_KEY_1`;
case AmlEventsName.TEST_EVENT_KEY_2:
@@ -206,7 +211,7 @@ function calculateEventsBasedOnState(
if (
currentState &&
- info.shouldBeTriggered(request, currentState, dialect)
+ info.shouldBeTriggered(currentState.limits, currentState.properties ?? {}, request.properties ?? {}, ((request.attributes ?? {}) as Record<string, unknown>))
) {
prev.on.push(field);
} else {
diff --git a/packages/aml-backoffice-ui/src/pages/decision/aml-events.ts b/packages/aml-backoffice-ui/src/pages/decision/aml-events.ts
@@ -1,171 +0,0 @@
-import { AmlDecision, AmlSpaDialect } from "@gnu-taler/taler-util";
-import { TalerAmlProperties } from "@gnu-taler/web-util/browser";
-import { DecisionRequest } from "../../hooks/decision-request.js";
-
-export enum AmlEventsName {
- ACCOUNT_OPENED = "ACCOUNT_OPENED",
- ACCOUNT_CLOSED = "ACCOUNT_CLOSED",
-
- ACCOUNT_OPENED_HIGH_RISK = "ACCOUNT_OPENED_HIGH_RISK",
- ACCOUNT_CLOSED_HIGH_RISK = "ACCOUNT_CLOSED_HIGH_RISK",
- ACCOUNT_OPENED_DOMESTIC_PEP = "ACCOUNT_OPENED_DOMESTIC_PEP",
- ACCOUNT_CLOSED_DOMESTIC_PEP = "ACCOUNT_CLOSED_DOMESTIC_PEP",
- ACCOUNT_OPENED_FOREIGN_PEP = "ACCOUNT_OPENED_FOREIGN_PEP",
- ACCOUNT_CLOSED_FOREIGN_PEP = "ACCOUNT_CLOSED_FOREIGN_PEP",
- ACCOUNT_OPENED_HR_COUNTRY = "ACCOUNT_OPENED_HR_COUNTRY",
- ACCOUNT_CLOSED_HR_COUNTRY = "ACCOUNT_CLOSED_HR_COUNTRY",
-
- ACCOUNT_MROS_REPORTED_ART9 = "ACCOUNT_MROS_REPORTED_ART9",
- ACCOUNT_MROS_REPORTED_ART305 = "ACCOUNT_MROS_REPORTED_ART305",
- ACCOUNT_INVESTIGATION_ART6_COMPLETED = "ACCOUNT_INVESTIGATION_ART6_COMPLETED",
- ACCOUNT_INVESTIGATION_ART6_FAILED = "ACCOUNT_INVESTIGATION_ART6_FAILED",
-
- TEST_EVENT_KEY_1 = "TEST_EVENT_KEY_1",
- TEST_EVENT_KEY_2 = "TEST_EVENT_KEY_2",
- TEST_EVENT_KEY_3 = "TEST_EVENT_KEY_3",
- TEST_EVENT_KEY_4 = "TEST_EVENT_KEY_4",
- TEST_EVENT_KEY_5 = "TEST_EVENT_KEY_5",
-}
-
-export type EventMapInfo = {
- [name in AmlEventsName]: {
- // fieldLabel: TranslatedString;
- dialect: AmlSpaDialect[];
- shouldBeTriggered: (
- req: DecisionRequest,
- status: AmlDecision,
- d: AmlSpaDialect,
- ) => boolean;
- };
-};
-
-export const AML_EVENTS_INFO: EventMapInfo = {
- ACCOUNT_OPENED: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- ACCOUNT_CLOSED: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- ACCOUNT_OPENED_HIGH_RISK: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- ACCOUNT_CLOSED_HIGH_RISK: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- ACCOUNT_OPENED_DOMESTIC_PEP: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- ACCOUNT_CLOSED_DOMESTIC_PEP: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- ACCOUNT_OPENED_FOREIGN_PEP: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- ACCOUNT_CLOSED_FOREIGN_PEP: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- ACCOUNT_OPENED_HR_COUNTRY: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- ACCOUNT_CLOSED_HR_COUNTRY: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- ACCOUNT_MROS_REPORTED_ART305: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- ACCOUNT_MROS_REPORTED_ART9: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- ACCOUNT_INVESTIGATION_ART6_COMPLETED: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- ACCOUNT_INVESTIGATION_ART6_FAILED: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- TEST_EVENT_KEY_1: {
- dialect: [AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- return true;
- },
- },
- TEST_EVENT_KEY_2: {
- dialect: [AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- return true;
- },
- },
- TEST_EVENT_KEY_3: {
- dialect: [AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- return true;
- },
- },
- TEST_EVENT_KEY_4: {
- dialect: [AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- return true;
- },
- },
- TEST_EVENT_KEY_5: {
- dialect: [AmlSpaDialect.TESTING],
- shouldBeTriggered(req, dialect) {
- return true;
- },
- },
-};
diff --git a/packages/aml-backoffice-ui/src/pages/decision/aml-properties.ts b/packages/aml-backoffice-ui/src/pages/decision/aml-properties.ts
@@ -1,88 +0,0 @@
-import { AmlDecision, AmlSpaDialect } from "@gnu-taler/taler-util";
-import { TalerAmlProperties } from "@gnu-taler/web-util/browser";
-import { DecisionRequest } from "../../hooks/decision-request.js";
-
-export type PropertiesMapInfo = {
- [name in keyof typeof TalerAmlProperties]: {
- // fieldLabel: TranslatedString;
- dialect: AmlSpaDialect[];
- shouldBeOn: (
- req: DecisionRequest,
- status: AmlDecision,
- d: AmlSpaDialect,
- ) => boolean;
- };
-};
-
-export const AML_PROPERTIES_INFO: PropertiesMapInfo = {
- AML_ACCOUNT_ACTIVE_DEPOSIT: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- AML_DOMESTIC_PEP: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- AML_FOREIGN_PEP: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- AML_HIGH_RISK_BUSINESS: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- AML_HIGH_RISK_COUNTRY: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- AML_INVESTIGATION_ART6_COMPLETED: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- AML_INVESTIGATION_ART6_FAILED: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- AML_MROS_REPORTED_ART305: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
- AML_MROS_REPORTED_ART9: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_ACCOUNT_ACTIVE_DEPOSIT];
- },
- },
- AML_NO_OPERATION_DURING_PERIOD: {
- dialect: [AmlSpaDialect.TOPS, AmlSpaDialect.TESTING],
- shouldBeOn(req, dialect) {
- if (!req.properties) return false;
- return !!req.properties[TalerAmlProperties.AML_DOMESTIC_PEP];
- },
- },
-};