From 1e39c57cb972c6de224c177dd28ae3a315fbe590 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 24 Oct 2022 11:12:28 -0300 Subject: wallet dev mode and backup into devmode --- .../src/context/devContext.ts | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'packages/taler-wallet-webextension/src/context') diff --git a/packages/taler-wallet-webextension/src/context/devContext.ts b/packages/taler-wallet-webextension/src/context/devContext.ts index b710716b5..c494b9403 100644 --- a/packages/taler-wallet-webextension/src/context/devContext.ts +++ b/packages/taler-wallet-webextension/src/context/devContext.ts @@ -21,16 +21,17 @@ import { createContext, h, VNode } from "preact"; import { useContext } from "preact/hooks"; -import { useLocalStorage } from "../hooks/useLocalStorage.js"; +import { useWalletDevMode } from "../hooks/useWalletDevMode.js"; +import { ToggleHandler } from "../mui/handlers.js"; interface Type { devMode: boolean; - toggleDevMode: () => Promise; + devModeToggle: ToggleHandler; } const Context = createContext({ devMode: false, - toggleDevMode: async () => { - return; + devModeToggle: { + button: {}, }, }); @@ -40,28 +41,28 @@ export const DevContextProviderForTesting = ({ value, children, }: { - value: boolean; + value?: boolean; children: any; }): VNode => { return h(Context.Provider, { value: { - devMode: value, - toggleDevMode: async () => { - return; - }, + devMode: !!value, + devModeToggle: { + value, button: {} + } }, children, }); }; export const DevContextProvider = ({ children }: { children: any }): VNode => { - const [value, setter] = useLocalStorage("devMode"); - const devMode = value === "true"; - const toggleDevMode = async (): Promise => - setter((v) => (!v ? "true" : undefined)); + const devModeToggle = useWalletDevMode(); + const value: Type = { devMode: !!devModeToggle.value, devModeToggle } + //support for function as children, useful for getting the value right away children = children.length === 1 && typeof children === "function" - ? children({ devMode }) + ? children(value) : children; - return h(Context.Provider, { value: { devMode, toggleDevMode }, children }); + + return h(Context.Provider, { value, children }); }; -- cgit v1.2.3