diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2023-08-15 13:47:29 +0200 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2023-08-15 13:47:29 +0200 |
commit | 819949d7f2cfcce8d334cbfdb701255daac64951 (patch) | |
tree | 592043554f59ec209f9afc1c31c20c4fb585c3ca /packages/merchant-backoffice-ui/src/hooks/index.ts | |
parent | 77ea209ddb6d457db0ce113f91247207cc29fbd8 (diff) | |
parent | adb0e70f151e63d103f27852312319520f4d0a84 (diff) |
Merge branch 'master' into age-withdraw
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/index.ts')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/index.ts | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/index.ts b/packages/merchant-backoffice-ui/src/hooks/index.ts index 316620cf7..b77b9dea8 100644 --- a/packages/merchant-backoffice-ui/src/hooks/index.ts +++ b/packages/merchant-backoffice-ui/src/hooks/index.ts @@ -21,6 +21,7 @@ import { StateUpdater, useCallback, useState } from "preact/hooks"; import { ValueOrFunction } from "../utils/types.js"; +import { useMemoryStorage } from "@gnu-taler/web-util/browser"; const calculateRootPath = () => { const rootPath = @@ -52,14 +53,17 @@ export function useBackendURL( export function useBackendDefaultToken( initialValue?: string, -): [string | undefined, StateUpdater<string | undefined>] { - return useLocalStorage("backend-token", initialValue); +): [string | undefined, ((d: string | undefined) => void)] { + // uncomment for testing + initialValue = "secret-token:secret" as string | undefined + const { update, value } = useMemoryStorage(`backend-token`, initialValue) + return [value, update]; } export function useBackendInstanceToken( id: string, -): [string | undefined, StateUpdater<string | undefined>] { - const [token, setToken] = useLocalStorage(`backend-token-${id}`); +): [string | undefined, ((d: string | undefined) => void)] { + const { update: setToken, value: token, reset } = useMemoryStorage(`backend-token-${id}`) const [defaultToken, defaultSetToken] = useBackendDefaultToken(); // instance named 'default' use the default token @@ -67,15 +71,16 @@ export function useBackendInstanceToken( return [defaultToken, defaultSetToken]; } function updateToken( - value: - | (string | undefined) - | ((s: string | undefined) => string | undefined), + value: (string | undefined) ): void { - setToken((p) => { - const toStore = value instanceof Function ? value(p) : value; - return toStore; - }); + console.log("seeting token", value) + if (value === undefined) { + reset() + } else { + setToken(value) + } } + console.log("token", token) return [token, updateToken]; } |