taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 6126e4259c8c916e5498a053d8c4413e72b38c09
parent a3a589fcd55af8dd87514dddde2fcbfe978b6540
Author: Florian Dold <florian@dold.me>
Date:   Tue, 18 Feb 2025 18:29:34 +0100

-formatting, explicit types

Diffstat:
Mpackages/aml-backoffice-ui/src/hooks/decisions.ts | 21++++++++++++++++++---
Mpackages/aml-backoffice-ui/src/hooks/officer.ts | 22++++++++++++++--------
2 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/packages/aml-backoffice-ui/src/hooks/decisions.ts b/packages/aml-backoffice-ui/src/hooks/decisions.ts @@ -17,15 +17,18 @@ import { useState } from "preact/hooks"; // FIX default import https://github.com/microsoft/TypeScript/issues/49189 import { + AmlDecision, + HttpStatusCode, OfficerAccount, + OperationFail, OperationOk, opFixedSuccess, - opSuccessFromHttp, + TalerError, TalerExchangeResultByMethod, TalerHttpError, } from "@gnu-taler/taler-util"; import { useExchangeApiContext } from "@gnu-taler/web-util/browser"; -import _useSWR, { SWRHook, mutate } from "swr"; +import _useSWR, { mutate, SWRHook } from "swr"; import { useOfficer } from "./officer.js"; const useSWR = _useSWR as unknown as SWRHook; @@ -169,11 +172,23 @@ export function useAccountDecisions(accountStr: string) { } /** + * FIXME: The return type doesn't look quite right. + * * @param account * @param args * @returns */ -export function useAccountActiveDecision(accountStr?: string) { +export function useAccountActiveDecision(accountStr?: string): + | OperationFail<HttpStatusCode.NotFound> + | OperationFail<HttpStatusCode.Forbidden> + | OperationFail<HttpStatusCode.Conflict> + | TalerError<{ + requestUrl: string; + requestMethod: string; + }> + | OperationOk<undefined> + | OperationOk<AmlDecision> + | undefined { const officer = useOfficer(); const session = accountStr !== undefined && officer.state === "ready" diff --git a/packages/aml-backoffice-ui/src/hooks/officer.ts b/packages/aml-backoffice-ui/src/hooks/officer.ts @@ -30,7 +30,11 @@ import { opFixedSuccess, unlockOfficerAccount, } from "@gnu-taler/taler-util"; -import { buildStorageKey, useExchangeApiContext, useLocalStorage } from "@gnu-taler/web-util/browser"; +import { + buildStorageKey, + useExchangeApiContext, + useLocalStorage, +} from "@gnu-taler/web-util/browser"; import { useMemo } from "preact/hooks"; import { usePreferences } from "./preferences.js"; @@ -83,7 +87,9 @@ const DEV_ACCOUNT_KEY = buildStorageKey( ); export function useOfficer(): OfficerState { - const {lib:{exchange: api}} = useExchangeApiContext(); + const { + lib: { exchange: api }, + } = useExchangeApiContext(); const [pref] = usePreferences(); pref.keepSessionAfterReload; // dev account, is kept on reloaded. @@ -107,7 +113,7 @@ export function useOfficer(): OfficerState { return { state: "not-found", create: async (pwd: string) => { - const resp = await api.getSeed() + const resp = await api.getSeed(); const extraEntropy = resp.type === "ok" ? resp.body : new Uint8Array(); const { id, safe, signingKey } = await createNewOfficerAccount( @@ -123,7 +129,7 @@ export function useOfficer(): OfficerState { const strKey = encodeCrock(signingKey); accountStorage.update({ id, strKey }); - return opFixedSuccess(id) + return opFixedSuccess(id); }, }; } @@ -133,7 +139,7 @@ export function useOfficer(): OfficerState { state: "locked", forget: () => { officerStorage.reset(); - return opFixedSuccess(undefined) + return opFixedSuccess(undefined); }, tryUnlock: async (pwd: string) => { const ac = await unlockOfficerAccount(officer.account, pwd); @@ -142,7 +148,7 @@ export function useOfficer(): OfficerState { id: ac.id, strKey: encodeCrock(ac.signingKey), }); - return opFixedSuccess(undefined) + return opFixedSuccess(undefined); }, }; } @@ -152,12 +158,12 @@ export function useOfficer(): OfficerState { account, lock: () => { accountStorage.reset(); - return opFixedSuccess(undefined) + return opFixedSuccess(undefined); }, forget: () => { officerStorage.reset(); accountStorage.reset(); - return opFixedSuccess(undefined) + return opFixedSuccess(undefined); }, }; }