aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-12-27 15:59:46 -0300
committerSebastian <sebasjm@gmail.com>2023-12-27 15:59:46 -0300
commit4e6631071e1f69db697334cccba77e09f393507e (patch)
tree0d81bf73d5bb10fe56d123046626be9da3662582 /packages/aml-backoffice-ui/src
parent8fb8506b274c07440895c8412586b3745aa8fa1b (diff)
downloadwallet-core-4e6631071e1f69db697334cccba77e09f393507e.tar.xz
use seed from exchange
Diffstat (limited to 'packages/aml-backoffice-ui/src')
-rw-r--r--packages/aml-backoffice-ui/src/context/config.ts3
-rw-r--r--packages/aml-backoffice-ui/src/hooks/useOfficer.ts25
2 files changed, 18 insertions, 10 deletions
diff --git a/packages/aml-backoffice-ui/src/context/config.ts b/packages/aml-backoffice-ui/src/context/config.ts
index 2df7ff40d..ba16482be 100644
--- a/packages/aml-backoffice-ui/src/context/config.ts
+++ b/packages/aml-backoffice-ui/src/context/config.ts
@@ -29,11 +29,12 @@ export type Type = {
url: URL,
config: TalerExchangeApi.ExchangeVersionResponse,
api: TalerExchangeHttpClient,
-};
+} | undefined;
const Context = createContext<Type>(undefined as any);
export const useExchangeApiContext = (): Type => useContext(Context);
+export const useMaybeExchangeApiContext = (): Type | undefined => useContext(Context);
export function ExchangeApiContextTesting({ config, children }: { config: TalerExchangeApi.ExchangeVersionResponse, children?: ComponentChildren; }): VNode {
return h(Context.Provider, {
diff --git a/packages/aml-backoffice-ui/src/hooks/useOfficer.ts b/packages/aml-backoffice-ui/src/hooks/useOfficer.ts
index 64cf79cc9..fe989f3eb 100644
--- a/packages/aml-backoffice-ui/src/hooks/useOfficer.ts
+++ b/packages/aml-backoffice-ui/src/hooks/useOfficer.ts
@@ -20,6 +20,7 @@ import {
useMemoryStorage,
} from "@gnu-taler/web-util/browser";
import { useMemo } from "preact/hooks";
+import { useExchangeApiContext, useMaybeExchangeApiContext } from "../context/config.js";
export interface Officer {
account: LockedAccount;
@@ -35,9 +36,9 @@ type OfficerAccountString = {
export const codecForOfficerAccount = (): Codec<OfficerAccountString> =>
buildCodecForObject<OfficerAccountString>()
- .property("id", codecForString()) // FIXME
- .property("strKey", codecForString()) // FIXME
- .build("OfficerAccount");
+ .property("id", codecForString()) // FIXME
+ .property("strKey", codecForString()) // FIXME
+ .build("OfficerAccount");
export const codecForOfficer = (): Codec<Officer> =>
buildCodecForObject<Officer>()
@@ -68,6 +69,7 @@ const DEV_ACCOUNT_KEY = buildStorageKey("account-dev", codecForOfficerAccount())
const ACCOUNT_KEY = "account";
export function useOfficer(): OfficerState {
+ const exchangeContext = useMaybeExchangeApiContext();
// dev account, is save when reloaded.
const accountStorage = useLocalStorage(DEV_ACCOUNT_KEY);
const account = useMemo(() => {
@@ -78,19 +80,24 @@ export function useOfficer(): OfficerState {
}
}, [accountStorage.value])
-
+
// const accountStorage = useMemoryStorage<OfficerAccount>(ACCOUNT_KEY);
// const account = accountStorage.value;
- const officerStorage = useLocalStorage(OFFICER_KEY);
+ const officerStorage = useLocalStorage(OFFICER_KEY);
const officer = officerStorage.value;
-
if (officer === undefined) {
return {
state: "not-found",
create: async (pwd: string) => {
- const { id, safe, signingKey } = await createNewOfficerAccount(pwd);
+ if (!exchangeContext) return;
+ const req = await fetch(new URL("seed", exchangeContext.api.baseUrl).href)
+ const b = await req.blob()
+ const ar = await b.arrayBuffer()
+ const uintar = new Uint8Array(ar)
+
+ const { id, safe, signingKey } = await createNewOfficerAccount(pwd, uintar);
officerStorage.update({
account: safe,
when: AbsoluteTime.now(),
@@ -98,7 +105,7 @@ export function useOfficer(): OfficerState {
// accountStorage.update({ id, signingKey });
const strKey = encodeCrock(signingKey)
- accountStorage.update({id, strKey })
+ accountStorage.update({ id, strKey })
},
};
}
@@ -112,7 +119,7 @@ export function useOfficer(): OfficerState {
tryUnlock: async (pwd: string) => {
const ac = await unlockOfficerAccount(officer.account, pwd);
// accountStorage.update(ac);
- accountStorage.update({id: ac.id, strKey: encodeCrock(ac.signingKey)})
+ accountStorage.update({ id: ac.id, strKey: encodeCrock(ac.signingKey) })
},
};
}