gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated (860e4216c -> cb2059d73)


From: gnunet
Subject: [taler-wallet-core] branch master updated (860e4216c -> cb2059d73)
Date: Thu, 16 Nov 2023 22:53:27 +0100

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a change to branch master
in repository wallet-core.

    from 860e4216c some fixes and examples
     new d26743cab send signature in request body
     new cb2059d73 show better error message

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../aml-backoffice-ui/src/handlers/InputAmount.tsx |  3 +-
 .../aml-backoffice-ui/src/hooks/useCaseDetails.ts  |  8 +--
 .../src/pages/AntiMoneyLaunderingForm.tsx          |  6 +-
 .../aml-backoffice-ui/src/pages/NewFormEntry.tsx   | 68 ++++++++++++++++------
 packages/taler-util/src/http-client/exchange.ts    | 16 ++---
 5 files changed, 66 insertions(+), 35 deletions(-)

diff --git a/packages/aml-backoffice-ui/src/handlers/InputAmount.tsx 
b/packages/aml-backoffice-ui/src/handlers/InputAmount.tsx
index 9be9dd4d0..b6cc78adb 100644
--- a/packages/aml-backoffice-ui/src/handlers/InputAmount.tsx
+++ b/packages/aml-backoffice-ui/src/handlers/InputAmount.tsx
@@ -21,7 +21,8 @@ export function InputAmount<T extends object, K extends keyof 
T>(
       converter={{
         //@ts-ignore
         fromStringUI: (v): AmountJson => {
-          return Amounts.parseOrThrow(`${currency}:${v}`);
+
+          return Amounts.parse(`${currency}:${v}`) ?? 
Amounts.zeroOfCurrency(currency);
         },
         //@ts-ignore
         toStringUI: (v: AmountJson) => {
diff --git a/packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts 
b/packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts
index 9db1e2aec..dbc6763ba 100644
--- a/packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts
+++ b/packages/aml-backoffice-ui/src/hooks/useCaseDetails.ts
@@ -1,14 +1,8 @@
 
-import {
-  HttpResponse,
-  HttpResponseOk
-} from "@gnu-taler/web-util/browser";
-import { AmlExchangeBackend } from "../types.js";
 // FIX default import https://github.com/microsoft/TypeScript/issues/49189
 import { AmountString, OfficerAccount, PaytoString, TalerExchangeApi, 
TalerExchangeResultByMethod, TalerHttpError } from "@gnu-taler/taler-util";
-import _useSWR, { SWRHook, useSWRConfig } from "swr";
+import _useSWR, { SWRHook } from "swr";
 import { useExchangeApiContext } from "../context/config.js";
-import { usePublicBackend } from "./useBackend.js";
 import { useOfficer } from "./useOfficer.js";
 const useSWR = _useSWR as unknown as SWRHook;
 
diff --git a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx 
b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
index 5d2a3dffe..faf9671bb 100644
--- a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
+++ b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx
@@ -13,6 +13,7 @@ import { v1 as form_902_9e_v1 } from "../forms/902_9e.js";
 import { v1 as simplest } from "../forms/simplest.js";
 import { Pages } from "../pages.js";
 import { AmlExchangeBackend } from "../types.js";
+import { useExchangeApiContext } from "../context/config.js";
 
 export type Justification = {
   // form index in the list of forms
@@ -27,11 +28,14 @@ export function AntiMoneyLaunderingForm({ account, 
selectedForm, onSubmit }: { a
   const { i18n } = useTranslationContext()
   const showingFrom = allForms[selectedForm].impl;
   const formName = allForms[selectedForm].name
+
+  const { config } = useExchangeApiContext()
+
   const initial = {
     fullName: "loggedIn_user_fullname",
     when: AbsoluteTime.now(),
     state: AmlExchangeBackend.AmlState.pending,
-    threshold: Amounts.parseOrThrow("KUDOS:1000"),
+    threshold: Amounts.zeroOfCurrency(config.currency),
   };
   return (
     <NiceForm
diff --git a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx 
b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
index e70536cb2..95b1f35c4 100644
--- a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
+++ b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx
@@ -1,12 +1,13 @@
-import { VNode, h } from "preact";
+import { Fragment, VNode, h } from "preact";
 import { AntiMoneyLaunderingForm, allForms } from 
"./AntiMoneyLaunderingForm.js";
 import { Pages } from "../pages.js";
 import { NiceForm } from "../NiceForm.js";
-import { AbsoluteTime, Amounts, TalerExchangeApi, TalerProtocolTimestamp } 
from "@gnu-taler/taler-util";
+import { AbsoluteTime, Amounts, TalerExchangeApi, TalerProtocolTimestamp, 
TranslatedString } from "@gnu-taler/taler-util";
 import { AmlExchangeBackend } from "../types.js";
 import { useOfficer } from "../hooks/useOfficer.js";
 import { HandleAccountNotReady } from "./HandleAccountNotReady.js";
 import { useExchangeApiContext } from "../context/config.js";
+import { LocalNotificationBanner, useLocalNotification, useTranslationContext 
} from "@gnu-taler/web-util/browser";
 
 export function NewFormEntry({
   account,
@@ -15,7 +16,10 @@ export function NewFormEntry({
   account?: string;
   type?: string;
 }): VNode {
+  const { i18n } = useTranslationContext()
   const officer = useOfficer();
+  const { api } = useExchangeApiContext()
+  const [notification, notify, handleError] = useLocalNotification()
 
   if (!account) {
     return <div>no account</div>;
@@ -32,26 +36,52 @@ export function NewFormEntry({
     return <div>WHAT! {type}</div>;
   }
 
-  const { api } = useExchangeApiContext()
 
   return (
-    <AntiMoneyLaunderingForm
-      account={account}
-      selectedForm={selectedForm}
-      onSubmit={async (justification, new_state, new_threshold) => {
-        const decision: TalerExchangeApi.AmlDecision = {
-          justification: JSON.stringify(justification),
-          decision_time: TalerProtocolTimestamp.now(),
-          h_payto: account,
-          new_state,
-          new_threshold: Amounts.stringify(new_threshold),
-          officer_sig: "",
-          kyc_requirements: undefined
-        }
-        api.addDecisionDetails(officer.account, decision);
+    <Fragment>
+      <LocalNotificationBanner notification={notification} />
+
+      <AntiMoneyLaunderingForm
+        account={account}
+        selectedForm={selectedForm}
+        onSubmit={async (justification, new_state, new_threshold) => {
 
-      }}
-    />
+          const decision: Omit<TalerExchangeApi.AmlDecision, "officer_sig"> = {
+            justification: JSON.stringify(justification),
+            decision_time: TalerProtocolTimestamp.now(),
+            h_payto: account,
+            new_state,
+            new_threshold: Amounts.stringify(new_threshold),
+            kyc_requirements: undefined
+          }
+          await handleError(async () => {
+            const resp = await api.addDecisionDetails(officer.account, 
decision);
+            if (resp.type === "fail") {
+              switch (resp.case) {
+                case "unauthorized": return notify({
+                  type: "error",
+                  title: i18n.str`Wrong credentials for "${officer.account}"`,
+                  description: resp.detail.hint as TranslatedString,
+                  debug: resp.detail,
+                })
+                case "officer-or-account-not-found": return notify({
+                  type: "error",
+                  title: i18n.str`Officer or account not found`,
+                  description: resp.detail.hint as TranslatedString,
+                  debug: resp.detail,
+                })
+                case "officer-disabled-or-recent-decision": return notify({
+                  type: "error",
+                  title: i18n.str`Officer disabled or more recent decision was 
already submitted.`,
+                  description: resp.detail.hint as TranslatedString,
+                  debug: resp.detail,
+                })
+              }
+            }
+          })
+        }}
+      />
+    </Fragment>
   );
 }
 
diff --git a/packages/taler-util/src/http-client/exchange.ts 
b/packages/taler-util/src/http-client/exchange.ts
index 2d3e40863..f55be0043 100644
--- a/packages/taler-util/src/http-client/exchange.ts
+++ b/packages/taler-util/src/http-client/exchange.ts
@@ -104,15 +104,13 @@ export class TalerExchangeHttpClient {
    * 
https://docs.taler.net/core/api-exchange.html#post--aml-$OFFICER_PUB-decision
    * 
    */
-  async addDecisionDetails(auth: OfficerAccount, body: 
TalerExchangeApi.AmlDecision) {
+  async addDecisionDetails(auth: OfficerAccount, decision: 
Omit<TalerExchangeApi.AmlDecision, "officer_sig">) {
     const url = new URL(`aml/${auth.id}/decision`, this.baseUrl);
 
+    const body = buildDecisionSignature(auth.signingKey, decision)
     const resp = await this.httpLib.fetch(url.href, {
       method: "POST",
       body,
-      headers: {
-        "Taler-AML-Officer-Signature": buildDecisionSignature(auth.signingKey, 
body)
-      },
     });
 
     switch (resp.status) {
@@ -140,8 +138,8 @@ function buildQuerySignature(key: SigningKey): string {
 
 function buildDecisionSignature(
   key: SigningKey,
-  decision: TalerExchangeApi.AmlDecision,
-): string {
+  decision: Omit<TalerExchangeApi.AmlDecision, "officer_sig">,
+): TalerExchangeApi.AmlDecision {
   const zero = new Uint8Array(new ArrayBuffer(64))
 
   const sigBlob = 
buildSigPS(TalerSignaturePurpose.TALER_SIGNATURE_AML_DECISION)
@@ -154,5 +152,9 @@ function buildDecisionSignature(
     .put(bufferForUint32(decision.new_state))
     .build();
 
-  return encodeCrock(eddsaSign(sigBlob, key));
+  const officer_sig = encodeCrock(eddsaSign(sigBlob, key));
+  return {
+    ...decision,
+    officer_sig
+  }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]