aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/pages
diff options
context:
space:
mode:
Diffstat (limited to 'packages/aml-backoffice-ui/src/pages')
-rw-r--r--packages/aml-backoffice-ui/src/pages/CaseDetails.tsx131
-rw-r--r--packages/aml-backoffice-ui/src/pages/Cases.tsx53
-rw-r--r--packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx40
3 files changed, 91 insertions, 133 deletions
diff --git a/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx b/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx
index d02d8b395..ce820d612 100644
--- a/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx
+++ b/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx
@@ -13,64 +13,13 @@ import { FlexibleForm } from "../forms/index.js";
import { UIFormField } from "../handlers/forms.js";
import { Pages } from "../pages.js";
import { AmlExchangeBackend } from "../types.js";
+import { HandleAccountNotReady } from "./HandleAccountNotReady.js";
+import { useTranslationContext } from "@gnu-taler/web-util/browser";
+import { useOfficer } from "../hooks/useOfficer.js";
+import { buildQuerySignature } from "../account.js";
+import { useCaseDetails } from "../hooks/useCaseDetails.js";
+import { handleNotOkResult } from "../utils/errors.js";
-const response: AmlExchangeBackend.AmlDecisionDetails = {
- aml_history: [
- {
- justification: "Lack of documentation",
- decider_pub: "ASDASDASD",
- decision_time: {
- t_s: Date.now() / 1000,
- },
- new_state: 2,
- new_threshold: "USD:0",
- },
- {
- justification: "Doing a transfer of high amount",
- decider_pub: "ASDASDASD",
- decision_time: {
- t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 6,
- },
- new_state: 1,
- new_threshold: "USD:2000",
- },
- {
- justification: "Account is known to the system",
- decider_pub: "ASDASDASD",
- decision_time: {
- t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 9,
- },
- new_state: 0,
- new_threshold: "USD:100",
- },
- ],
- kyc_attributes: [
- {
- collection_time: {
- t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 8,
- },
- expiration_time: {
- t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 4,
- },
- provider_section: "asdasd",
- attributes: {
- name: "Sebastian",
- },
- },
- {
- collection_time: {
- t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 5,
- },
- expiration_time: {
- t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 2,
- },
- provider_section: "asdasd",
- attributes: {
- creditCard: "12312312312",
- },
- },
- ],
-};
type AmlEvent = AmlFormEvent | KycCollectionEvent | KycExpirationEvent;
type AmlFormEvent = {
type: "aml-form";
@@ -127,7 +76,7 @@ function getEventsFromAmlHistory(
});
prev.push({
type: "kyc-expiration",
- title: "expired" as TranslatedString,
+ title: "expiration" as TranslatedString,
when: AbsoluteTime.fromProtocolTimestamp(k.expiration_time),
fields: !k.attributes ? [] : Object.keys(k.attributes),
});
@@ -136,19 +85,30 @@ function getEventsFromAmlHistory(
return ae.concat(ke).sort(selectSooner);
}
-export function CaseDetails({ account }: { account?: string }) {
- const events = getEventsFromAmlHistory(
- response.aml_history,
- response.kyc_attributes,
- );
- console.log("DETAILS", events, events[events.length - 1 - 2]);
- const [selected, setSelected] = useState<AmlEvent>(
- events[events.length - 1 - 2],
- );
+export function CaseDetails({ account: paytoHash }: { account: string }) {
+ const [selected, setSelected] = useState<AmlEvent | undefined>(undefined);
+
+ const officer = useOfficer();
+ const { i18n } = useTranslationContext();
+ if (officer.state !== "ready") {
+ return <HandleAccountNotReady officer={officer} />;
+ }
+ const signature =
+ officer.state === "ready"
+ ? buildQuerySignature(officer.account.signingKey)
+ : undefined;
+ const details = useCaseDetails(officer.account.accountId, paytoHash, signature)
+ if (!details.ok && !details.loading) {
+ return handleNotOkResult(i18n)(details);
+ }
+ const aml_history = details.loading ? [] : details.data.aml_history
+ const kyc_attributes = details.loading ? [] : details.data.kyc_attributes
+ const events = getEventsFromAmlHistory(aml_history,kyc_attributes);
+
return (
<div>
<a
- href={Pages.newFormEntry.url({ account })}
+ href={Pages.newFormEntry.url({ account: paytoHash })}
class="m-4 block rounded-md w-fit border-0 px-3 py-2 text-center text-sm bg-indigo-700 text-white shadow-sm hover:bg-indigo-700"
>
New AML form
@@ -271,13 +231,24 @@ function ShowConsolidated({
history: AmlEvent[];
until: AmlEvent;
}): VNode {
- console.log("UNTIL", until);
const cons = getConsolidated(history, until.when);
const form: FlexibleForm<Consolidated> = {
versionId: "1",
behavior: (form) => {
- return {};
+ return {
+ aml: {
+ threshold: {
+ hidden: !form.aml
+ },
+ since: {
+ hidden: !form.aml
+ },
+ state: {
+ hidden: !form.aml
+ }
+ }
+ };
},
design: [
{
@@ -356,8 +327,8 @@ function ShowConsolidated({
interface Consolidated {
aml: {
- state?: AmlExchangeBackend.AmlState;
- threshold?: AmountJson;
+ state: AmlExchangeBackend.AmlState;
+ threshold: AmountJson;
since: AbsoluteTime;
};
kyc: {
@@ -375,7 +346,13 @@ function getConsolidated(
): Consolidated {
const initial: Consolidated = {
aml: {
- since: AbsoluteTime.never(),
+ state: AmlExchangeBackend.AmlState.normal,
+ threshold: {
+ currency: "ARS",
+ value: 1000,
+ fraction: 0,
+ },
+ since: AbsoluteTime.never()
},
kyc: {},
};
@@ -391,9 +368,11 @@ function getConsolidated(
break;
}
case "aml-form": {
- prev.aml.threshold = cur.threshold;
- prev.aml.state = cur.state;
- prev.aml.since = cur.when;
+ prev.aml = {
+ since: cur.when,
+ state: cur.state,
+ threshold: cur.threshold
+ }
break;
}
case "kyc-collection": {
diff --git a/packages/aml-backoffice-ui/src/pages/Cases.tsx b/packages/aml-backoffice-ui/src/pages/Cases.tsx
index 8b115ed7e..990c0d2d4 100644
--- a/packages/aml-backoffice-ui/src/pages/Cases.tsx
+++ b/packages/aml-backoffice-ui/src/pages/Cases.tsx
@@ -12,59 +12,6 @@ import { buildQuerySignature } from "../account.js";
import { handleNotOkResult } from "../utils/errors.js";
import { useTranslationContext } from "@gnu-taler/web-util/browser";
-const response: AmlExchangeBackend.AmlRecords = {
- records: [
- {
- current_state: 0,
- h_payto: "QWEQWEQWEQWEWQE",
- rowid: 1,
- threshold: "USD 100",
- },
- {
- current_state: 1,
- h_payto: "ASDASDASD",
- rowid: 1,
- threshold: "USD 100",
- },
- {
- current_state: 2,
- h_payto: "ZXCZXCZXCXZC",
- rowid: 1,
- threshold: "USD 1000",
- },
- {
- current_state: 0,
- h_payto: "QWEQWEQWEQWEWQE",
- rowid: 1,
- threshold: "USD 100",
- },
- {
- current_state: 1,
- h_payto: "ASDASDASD",
- rowid: 1,
- threshold: "USD 100",
- },
- {
- current_state: 2,
- h_payto: "ZXCZXCZXCXZC",
- rowid: 1,
- threshold: "USD 1000",
- },
- ].map((e, idx) => {
- e.rowid = idx;
- e.threshold = `${e.threshold}${idx}`;
- return e;
- }),
-};
-
-function doFilter(
- list: typeof response.records,
- filter: AmlExchangeBackend.AmlState | undefined,
-): typeof response.records {
- if (filter === undefined) return list;
- return list.filter((r) => r.current_state === filter);
-}
-
export function Cases() {
const officer = useOfficer();
const { i18n } = useTranslationContext();
diff --git a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
index bbd04daee..13e78b169 100644
--- a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
+++ b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
@@ -2,8 +2,12 @@ import { VNode, h } from "preact";
import { allForms } from "./AntiMoneyLaunderingForm.js";
import { Pages } from "../pages.js";
import { NiceForm } from "../NiceForm.js";
-import { AbsoluteTime, Amounts } from "@gnu-taler/taler-util";
+import { AbsoluteTime, Amounts, TalerProtocolTimestamp } from "@gnu-taler/taler-util";
import { AmlExchangeBackend } from "../types.js";
+import { useAmlCasesAPI } from "../hooks/useCaseDetails.js";
+import { useOfficer } from "../hooks/useOfficer.js";
+import { HandleAccountNotReady } from "./HandleAccountNotReady.js";
+import { buildDecisionSignature, buildQuerySignature } from "../account.js";
export function NewFormEntry({
account,
@@ -12,30 +16,58 @@ export function NewFormEntry({
account?: string;
type?: string;
}): VNode {
+ const officer = useOfficer();
+
if (!account) {
return <div>no account</div>;
}
if (!type) {
return <SelectForm account={account} />;
}
+ if (officer.state !== "ready") {
+ return <HandleAccountNotReady officer={officer} />;
+ }
const selectedForm = Number.parseInt(type ?? "0", 10);
if (Number.isNaN(selectedForm)) {
return <div>WHAT! {type}</div>;
}
const showingFrom = allForms[selectedForm].impl;
+ const formName = allForms[selectedForm].name
const initial = {
fullName: "loggedIn_user_fullname",
when: AbsoluteTime.now(),
state: AmlExchangeBackend.AmlState.pending,
- threshold: Amounts.parseOrThrow("USD:10"),
+ threshold: Amounts.parseOrThrow("ARS:1000"),
};
+ const api = useAmlCasesAPI()
+
return (
<NiceForm
initial={initial}
form={showingFrom(initial)}
- onSubmit={(v) => {
- alert(JSON.stringify(v));
+ onSubmit={(formValue) => {
+ if (formValue.state === undefined || formValue.threshold === undefined) return;
+
+ const justification = {
+ index: selectedForm,
+ name: formName,
+ value: formValue
+ }
+ const decision: AmlExchangeBackend.AmlDecision = {
+ justification: JSON.stringify(justification),
+ decision_time: TalerProtocolTimestamp.now(),
+ h_payto: account,
+ new_state: formValue.state,
+ new_threshold: Amounts.stringify(formValue.threshold),
+ officer_sig: "",
+ kyc_requirements: undefined
+ }
+ const signature = buildDecisionSignature(officer.account.signingKey, decision);
+ decision.officer_sig = signature
+ api.updateDecision(officer.account.accountId, decision);
+
+ // alert(JSON.stringify(formValue));
}}
>
<div class="mt-6 flex items-center justify-end gap-x-6">