From 62cec679833db48465d67194e39b29db985aa430 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Fri, 26 May 2023 10:54:42 -0300
Subject: using taler crypto

---
 .../exchange-backoffice-ui/src/pages/Officer.tsx   | 53 ++++++++++++++--------
 1 file changed, 33 insertions(+), 20 deletions(-)

(limited to 'packages/exchange-backoffice-ui/src/pages/Officer.tsx')

diff --git a/packages/exchange-backoffice-ui/src/pages/Officer.tsx b/packages/exchange-backoffice-ui/src/pages/Officer.tsx
index 39e368b37..40ec33018 100644
--- a/packages/exchange-backoffice-ui/src/pages/Officer.tsx
+++ b/packages/exchange-backoffice-ui/src/pages/Officer.tsx
@@ -1,4 +1,11 @@
-import { AbsoluteTime, TranslatedString } from "@gnu-taler/taler-util";
+import {
+  AbsoluteTime,
+  Codec,
+  TranslatedString,
+  buildCodecForObject,
+  codecForAbsoluteTime,
+  codecForString,
+} from "@gnu-taler/taler-util";
 import {
   notifyError,
   notifyInfo,
@@ -10,12 +17,25 @@ import { VNode, h } from "preact";
 import { useEffect, useState } from "preact/hooks";
 import {
   Account,
+  LockedAccount,
   UnwrapKeyError,
   createNewAccount,
   unlockAccount,
 } from "../account.js";
 import { createNewForm } from "../handlers/forms.js";
-import { Officer, codecForOfficer } from "../Dashboard.js";
+
+export interface Officer {
+  account: LockedAccount;
+  when: AbsoluteTime;
+}
+
+const codecForLockedAccount = codecForString() as Codec<LockedAccount>;
+
+export const codecForOfficer = (): Codec<Officer> =>
+  buildCodecForObject<Officer>()
+    .property("account", codecForLockedAccount) // FIXME
+    .property("when", codecForAbsoluteTime) // FIXME
+    .build("Officer");
 
 export function Officer() {
   const password = useMemoryStorage("password");
@@ -29,7 +49,7 @@ export function Officer() {
       return;
     }
 
-    unlockAccount(officer.value.salt, officer.value.key, password.value)
+    unlockAccount(officer.value.account, password.value)
       .then((keys) => setKeys(keys ?? { accountId: "", pub: "" }))
       .catch((e) => {
         if (e instanceof UnwrapKeyError) {
@@ -38,16 +58,12 @@ export function Officer() {
       });
   }, [officer.value, password.value]);
 
-  if (
-    officer.value === undefined ||
-    !officer.value.key ||
-    !officer.value.salt
-  ) {
+  if (officer.value === undefined || !officer.value.account) {
     return (
       <CreateAccount
-        onNewAccount={(salt, key, pwd) => {
+        onNewAccount={(account, pwd) => {
           password.update(pwd);
-          officer.update({ salt, when: AbsoluteTime.now(), key });
+          officer.update({ account, when: AbsoluteTime.now() });
         }}
       />
     );
@@ -56,8 +72,7 @@ export function Officer() {
   if (password.value === undefined) {
     return (
       <UnlockAccount
-        salt={officer.value.salt}
-        sealedKey={officer.value.key}
+        lockedAccount={officer.value.account}
         onAccountUnlocked={(pwd) => {
           password.update(pwd);
         }}
@@ -114,7 +129,7 @@ export function Officer() {
 function CreateAccount({
   onNewAccount,
 }: {
-  onNewAccount: (salt: string, accountId: string, password: string) => void;
+  onNewAccount: (account: LockedAccount, password: string) => void;
 }): VNode {
   const { i18n } = useTranslationContext();
   const Form = createNewForm<{
@@ -158,8 +173,8 @@ function CreateAccount({
               };
             }}
             onSubmit={async (v) => {
-              const keys = await createNewAccount(v.password);
-              onNewAccount(keys.salt, keys.accountId, v.password);
+              const account = await createNewAccount(v.password);
+              onNewAccount(account, v.password);
             }}
           >
             <div class="mb-4">
@@ -198,12 +213,10 @@ function CreateAccount({
 }
 
 function UnlockAccount({
-  salt,
-  sealedKey,
+  lockedAccount,
   onAccountUnlocked,
 }: {
-  salt: string;
-  sealedKey: string;
+  lockedAccount: LockedAccount;
   onAccountUnlocked: (password: string) => void;
 }): VNode {
   const Form = createNewForm<{
@@ -228,7 +241,7 @@ function UnlockAccount({
             onSubmit={async (v) => {
               try {
                 // test login
-                await unlockAccount(salt, sealedKey, v.password);
+                await unlockAccount(lockedAccount, v.password);
 
                 onAccountUnlocked(v.password ?? "");
                 notifyInfo("Account unlocked" as TranslatedString);
-- 
cgit v1.2.3

