diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-29 11:42:52 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-29 11:42:52 -0300 |
commit | 4ed3a05fdd97b08085e5a390963f9810b93a75fd (patch) | |
tree | 79b9a76aa3af65b83bcd4c77b42845b5c32d9af3 /packages/aml-backoffice-ui/src/hooks | |
parent | 44308fb898372c059cf03a23ad1169d5a6e0c296 (diff) | |
download | wallet-core-4ed3a05fdd97b08085e5a390963f9810b93a75fd.tar.xz |
create form
Diffstat (limited to 'packages/aml-backoffice-ui/src/hooks')
-rw-r--r-- | packages/aml-backoffice-ui/src/hooks/form.ts | 22 | ||||
-rw-r--r-- | packages/aml-backoffice-ui/src/hooks/officer.ts | 18 |
2 files changed, 20 insertions, 20 deletions
diff --git a/packages/aml-backoffice-ui/src/hooks/form.ts b/packages/aml-backoffice-ui/src/hooks/form.ts index fae11c05c..e3d97db8c 100644 --- a/packages/aml-backoffice-ui/src/hooks/form.ts +++ b/packages/aml-backoffice-ui/src/hooks/form.ts @@ -68,11 +68,10 @@ export type FormStatus<T> = }; function constructFormHandler<T>( - form: FormValues<T>, - updateForm: (d: FormValues<T>) => void, + form: RecursivePartial<FormValues<T>>, + updateForm: (d: RecursivePartial<FormValues<T>>) => void, errors: FormErrors<T> | undefined, ): FormHandler<T> { - const keys = Object.keys(form) as Array<keyof T>; const handler = keys.reduce((prev, fieldName) => { @@ -105,17 +104,18 @@ function constructFormHandler<T>( /** * FIXME: Consider sending this to web-utils - * - * - * @param defaultValue - * @param check - * @returns + * + * + * @param defaultValue + * @param check + * @returns */ export function useFormState<T>( - defaultValue: FormValues<T>, - check: (f: FormValues<T>) => FormStatus<T>, + defaultValue: RecursivePartial<FormValues<T>>, + check: (f: RecursivePartial<FormValues<T>>) => FormStatus<T>, ): [FormHandler<T>, FormStatus<T>] { - const [form, updateForm] = useState<FormValues<T>>(defaultValue); + const [form, updateForm] = + useState<RecursivePartial<FormValues<T>>>(defaultValue); const status = check(form); const handler = constructFormHandler(form, updateForm, status.errors); diff --git a/packages/aml-backoffice-ui/src/hooks/officer.ts b/packages/aml-backoffice-ui/src/hooks/officer.ts index 3ac4c857c..dabe866d3 100644 --- a/packages/aml-backoffice-ui/src/hooks/officer.ts +++ b/packages/aml-backoffice-ui/src/hooks/officer.ts @@ -19,6 +19,7 @@ import { LockedAccount, OfficerAccount, OfficerId, + OperationOk, SigningKey, buildCodecForObject, codecForAbsoluteTime, @@ -26,6 +27,7 @@ import { createNewOfficerAccount, decodeCrock, encodeCrock, + opFixedSuccess, unlockOfficerAccount, } from "@gnu-taler/taler-util"; import { buildStorageKey, useExchangeApiContext, useLocalStorage } from "@gnu-taler/web-util/browser"; @@ -60,7 +62,7 @@ export type OfficerState = OfficerNotReady | OfficerReady; export type OfficerNotReady = OfficerNotFound | OfficerLocked; interface OfficerNotFound { state: "not-found"; - create: (password: string) => Promise<void>; + create: (password: string) => Promise<OperationOk<OfficerId>>; } interface OfficerLocked { state: "locked"; @@ -81,7 +83,7 @@ const DEV_ACCOUNT_KEY = buildStorageKey( ); export function useOfficer(): OfficerState { - const exchangeContext = useExchangeApiContext(); + const {lib:{exchange: api}} = useExchangeApiContext(); const [pref] = usePreferences(); pref.keepSessionAfterReload; // dev account, is kept on reloaded. @@ -105,16 +107,12 @@ export function useOfficer(): OfficerState { return { state: "not-found", create: async (pwd: string) => { - const req = await fetch( - new URL("seed", exchangeContext.lib.exchange.baseUrl).href, - ); - const b = await req.blob(); - const ar = await b.arrayBuffer(); - const uintar = new Uint8Array(ar); + const resp = await api.getSeed() + const extraEntropy = resp.type === "ok" ? resp.body : new Uint8Array(); const { id, safe, signingKey } = await createNewOfficerAccount( pwd, - uintar, + extraEntropy, ); officerStorage.update({ account: safe, @@ -124,6 +122,8 @@ export function useOfficer(): OfficerState { // accountStorage.update({ id, signingKey }); const strKey = encodeCrock(signingKey); accountStorage.update({ id, strKey }); + + return opFixedSuccess(id) }, }; } |