From 7e37b347447b6fc418f11160d439a7596b039680 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Fri, 21 Jul 2023 15:50:53 -0300
Subject: case details and missing decision encryption

---
 .../aml-backoffice-ui/src/pages/NewFormEntry.tsx   | 40 +++++++++++++++++++---
 1 file changed, 36 insertions(+), 4 deletions(-)

(limited to 'packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx')

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">
-- 
cgit v1.2.3

