wallet dev mode and backup into devmode
This commit is contained in:
parent
45b225ec22
commit
6d376f3dac
@ -138,9 +138,14 @@ export function PopupNavBar({ path = "" }: { path?: string }): VNode {
|
|||||||
>
|
>
|
||||||
<i18n.Translate>Balance</i18n.Translate>
|
<i18n.Translate>Balance</i18n.Translate>
|
||||||
</a>
|
</a>
|
||||||
<a href={Pages.backup} class={path.startsWith("/backup") ? "active" : ""}>
|
<JustInDevMode>
|
||||||
<i18n.Translate>Backup</i18n.Translate>
|
<a
|
||||||
</a>
|
href={Pages.backup}
|
||||||
|
class={path.startsWith("/backup") ? "active" : ""}
|
||||||
|
>
|
||||||
|
<i18n.Translate>Backup</i18n.Translate>
|
||||||
|
</a>
|
||||||
|
</JustInDevMode>
|
||||||
<div style={{ display: "flex", paddingTop: 4, justifyContent: "right" }}>
|
<div style={{ display: "flex", paddingTop: 4, justifyContent: "right" }}>
|
||||||
<a href={Pages.qr}>
|
<a href={Pages.qr}>
|
||||||
<SvgIcon
|
<SvgIcon
|
||||||
@ -172,14 +177,14 @@ export function WalletNavBar({ path = "" }: { path?: string }): VNode {
|
|||||||
>
|
>
|
||||||
<i18n.Translate>Balance</i18n.Translate>
|
<i18n.Translate>Balance</i18n.Translate>
|
||||||
</a>
|
</a>
|
||||||
<a
|
|
||||||
href={Pages.backup}
|
|
||||||
class={path.startsWith("/backup") ? "active" : ""}
|
|
||||||
>
|
|
||||||
<i18n.Translate>Backup</i18n.Translate>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<JustInDevMode>
|
<JustInDevMode>
|
||||||
|
<a
|
||||||
|
href={Pages.backup}
|
||||||
|
class={path.startsWith("/backup") ? "active" : ""}
|
||||||
|
>
|
||||||
|
<i18n.Translate>Backup</i18n.Translate>
|
||||||
|
</a>
|
||||||
|
|
||||||
<a href={Pages.dev} class={path.startsWith("/dev") ? "active" : ""}>
|
<a href={Pages.dev} class={path.startsWith("/dev") ? "active" : ""}>
|
||||||
<i18n.Translate>Dev</i18n.Translate>
|
<i18n.Translate>Dev</i18n.Translate>
|
||||||
</a>
|
</a>
|
||||||
|
@ -21,16 +21,17 @@
|
|||||||
|
|
||||||
import { createContext, h, VNode } from "preact";
|
import { createContext, h, VNode } from "preact";
|
||||||
import { useContext } from "preact/hooks";
|
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 {
|
interface Type {
|
||||||
devMode: boolean;
|
devMode: boolean;
|
||||||
toggleDevMode: () => Promise<void>;
|
devModeToggle: ToggleHandler;
|
||||||
}
|
}
|
||||||
const Context = createContext<Type>({
|
const Context = createContext<Type>({
|
||||||
devMode: false,
|
devMode: false,
|
||||||
toggleDevMode: async () => {
|
devModeToggle: {
|
||||||
return;
|
button: {},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -40,28 +41,28 @@ export const DevContextProviderForTesting = ({
|
|||||||
value,
|
value,
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
value: boolean;
|
value?: boolean;
|
||||||
children: any;
|
children: any;
|
||||||
}): VNode => {
|
}): VNode => {
|
||||||
return h(Context.Provider, {
|
return h(Context.Provider, {
|
||||||
value: {
|
value: {
|
||||||
devMode: value,
|
devMode: !!value,
|
||||||
toggleDevMode: async () => {
|
devModeToggle: {
|
||||||
return;
|
value, button: {}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DevContextProvider = ({ children }: { children: any }): VNode => {
|
export const DevContextProvider = ({ children }: { children: any }): VNode => {
|
||||||
const [value, setter] = useLocalStorage("devMode");
|
const devModeToggle = useWalletDevMode();
|
||||||
const devMode = value === "true";
|
const value: Type = { devMode: !!devModeToggle.value, devModeToggle }
|
||||||
const toggleDevMode = async (): Promise<void> =>
|
//support for function as children, useful for getting the value right away
|
||||||
setter((v) => (!v ? "true" : undefined));
|
|
||||||
children =
|
children =
|
||||||
children.length === 1 && typeof children === "function"
|
children.length === 1 && typeof children === "function"
|
||||||
? children({ devMode })
|
? children(value)
|
||||||
: children;
|
: children;
|
||||||
return h(Context.Provider, { value: { devMode, toggleDevMode }, children });
|
|
||||||
|
return h(Context.Provider, { value, children });
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
This file is part of GNU Taler
|
||||||
|
(C) 2022 Taler Systems S.A.
|
||||||
|
|
||||||
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useState, useEffect } from "preact/hooks";
|
||||||
|
import { wxClient } from "../wxApi.js";
|
||||||
|
import { ToggleHandler } from "../mui/handlers.js";
|
||||||
|
import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
||||||
|
|
||||||
|
export function useWalletDevMode(): ToggleHandler {
|
||||||
|
const [enabled, setEnabled] = useState<undefined | boolean>(undefined);
|
||||||
|
const [error, setError] = useState<TalerError | undefined>();
|
||||||
|
const toggle = async (): Promise<void> => {
|
||||||
|
return handleOpen(enabled, setEnabled).catch((e) => {
|
||||||
|
setError(TalerError.fromException(e));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function getValue(): Promise<void> {
|
||||||
|
const res = await wxClient.call(WalletApiOperation.GetVersion, {});
|
||||||
|
setEnabled(res.devMode);
|
||||||
|
}
|
||||||
|
getValue();
|
||||||
|
}, []);
|
||||||
|
return {
|
||||||
|
value: enabled,
|
||||||
|
button: {
|
||||||
|
onClick: enabled === undefined ? undefined : toggle,
|
||||||
|
error,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleOpen(
|
||||||
|
currentValue: undefined | boolean,
|
||||||
|
onChange: (value: boolean) => void,
|
||||||
|
): Promise<void> {
|
||||||
|
const nextValue = !currentValue
|
||||||
|
await wxClient.call(WalletApiOperation.SetDevMode, { devModeEnabled: nextValue });
|
||||||
|
onChange(nextValue);
|
||||||
|
return;
|
||||||
|
}
|
@ -37,6 +37,7 @@ const version = {
|
|||||||
bank: "0:0:0",
|
bank: "0:0:0",
|
||||||
hash: "d439c3e1bc743f2aa47de4457953dba6ecb0e20f",
|
hash: "d439c3e1bc743f2aa47de4457953dba6ecb0e20f",
|
||||||
version: "0.9.0-dev.1",
|
version: "0.9.0-dev.1",
|
||||||
|
devMode: false,
|
||||||
},
|
},
|
||||||
webexVersion: {
|
webexVersion: {
|
||||||
version: "0.9.0.13",
|
version: "0.9.0.13",
|
||||||
@ -46,6 +47,7 @@ const version = {
|
|||||||
|
|
||||||
export const AllOff = createExample(TestedComponent, {
|
export const AllOff = createExample(TestedComponent, {
|
||||||
deviceName: "this-is-the-device-name",
|
deviceName: "this-is-the-device-name",
|
||||||
|
devModeToggle: { value: false, button: {} },
|
||||||
autoOpenToggle: { value: false, button: {} },
|
autoOpenToggle: { value: false, button: {} },
|
||||||
clipboardToggle: { value: false, button: {} },
|
clipboardToggle: { value: false, button: {} },
|
||||||
setDeviceName: () => Promise.resolve(),
|
setDeviceName: () => Promise.resolve(),
|
||||||
@ -54,6 +56,7 @@ export const AllOff = createExample(TestedComponent, {
|
|||||||
|
|
||||||
export const OneChecked = createExample(TestedComponent, {
|
export const OneChecked = createExample(TestedComponent, {
|
||||||
deviceName: "this-is-the-device-name",
|
deviceName: "this-is-the-device-name",
|
||||||
|
devModeToggle: { value: false, button: {} },
|
||||||
autoOpenToggle: { value: false, button: {} },
|
autoOpenToggle: { value: false, button: {} },
|
||||||
clipboardToggle: { value: false, button: {} },
|
clipboardToggle: { value: false, button: {} },
|
||||||
setDeviceName: () => Promise.resolve(),
|
setDeviceName: () => Promise.resolve(),
|
||||||
@ -62,6 +65,7 @@ export const OneChecked = createExample(TestedComponent, {
|
|||||||
|
|
||||||
export const WithOneExchange = createExample(TestedComponent, {
|
export const WithOneExchange = createExample(TestedComponent, {
|
||||||
deviceName: "this-is-the-device-name",
|
deviceName: "this-is-the-device-name",
|
||||||
|
devModeToggle: { value: false, button: {} },
|
||||||
autoOpenToggle: { value: false, button: {} },
|
autoOpenToggle: { value: false, button: {} },
|
||||||
clipboardToggle: { value: false, button: {} },
|
clipboardToggle: { value: false, button: {} },
|
||||||
setDeviceName: () => Promise.resolve(),
|
setDeviceName: () => Promise.resolve(),
|
||||||
@ -83,6 +87,7 @@ export const WithOneExchange = createExample(TestedComponent, {
|
|||||||
|
|
||||||
export const WithExchangeInDifferentState = createExample(TestedComponent, {
|
export const WithExchangeInDifferentState = createExample(TestedComponent, {
|
||||||
deviceName: "this-is-the-device-name",
|
deviceName: "this-is-the-device-name",
|
||||||
|
devModeToggle: { value: false, button: {} },
|
||||||
autoOpenToggle: { value: false, button: {} },
|
autoOpenToggle: { value: false, button: {} },
|
||||||
clipboardToggle: { value: false, button: {} },
|
clipboardToggle: { value: false, button: {} },
|
||||||
setDeviceName: () => Promise.resolve(),
|
setDeviceName: () => Promise.resolve(),
|
||||||
|
@ -19,6 +19,7 @@ import {
|
|||||||
ExchangeTosStatus,
|
ExchangeTosStatus,
|
||||||
WalletCoreVersion,
|
WalletCoreVersion,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
|
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
||||||
import { Fragment, h, VNode } from "preact";
|
import { Fragment, h, VNode } from "preact";
|
||||||
import { Checkbox } from "../components/Checkbox.js";
|
import { Checkbox } from "../components/Checkbox.js";
|
||||||
import { ErrorTalerOperation } from "../components/ErrorTalerOperation.js";
|
import { ErrorTalerOperation } from "../components/ErrorTalerOperation.js";
|
||||||
@ -36,26 +37,26 @@ import {
|
|||||||
import { useDevContext } from "../context/devContext.js";
|
import { useDevContext } from "../context/devContext.js";
|
||||||
import { useTranslationContext } from "../context/translation.js";
|
import { useTranslationContext } from "../context/translation.js";
|
||||||
import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
|
import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
|
||||||
import { useBackupDeviceName } from "../hooks/useBackupDeviceName.js";
|
|
||||||
import { useAutoOpenPermissions } from "../hooks/useAutoOpenPermissions.js";
|
import { useAutoOpenPermissions } from "../hooks/useAutoOpenPermissions.js";
|
||||||
|
import { useBackupDeviceName } from "../hooks/useBackupDeviceName.js";
|
||||||
|
import { useClipboardPermissions } from "../hooks/useClipboardPermissions.js";
|
||||||
import { ToggleHandler } from "../mui/handlers.js";
|
import { ToggleHandler } from "../mui/handlers.js";
|
||||||
import { Pages } from "../NavigationBar.js";
|
import { Pages } from "../NavigationBar.js";
|
||||||
import * as wxApi from "../wxApi.js";
|
|
||||||
import { platform } from "../platform/api.js";
|
import { platform } from "../platform/api.js";
|
||||||
import { useClipboardPermissions } from "../hooks/useClipboardPermissions.js";
|
import { wxClient } from "../wxApi.js";
|
||||||
|
|
||||||
const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined;
|
const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined;
|
||||||
|
|
||||||
export function SettingsPage(): VNode {
|
export function SettingsPage(): VNode {
|
||||||
const autoOpenToggle = useAutoOpenPermissions();
|
const autoOpenToggle = useAutoOpenPermissions();
|
||||||
const clipboardToggle = useClipboardPermissions();
|
const clipboardToggle = useClipboardPermissions();
|
||||||
const { devMode, toggleDevMode } = useDevContext();
|
const { devModeToggle } = useDevContext();
|
||||||
const { name, update } = useBackupDeviceName();
|
const { name, update } = useBackupDeviceName();
|
||||||
const webex = platform.getWalletWebExVersion();
|
const webex = platform.getWalletWebExVersion();
|
||||||
|
|
||||||
const exchangesHook = useAsyncAsHook(async () => {
|
const exchangesHook = useAsyncAsHook(async () => {
|
||||||
const list = await wxApi.listExchanges();
|
const list = await wxClient.call(WalletApiOperation.ListExchanges, {});
|
||||||
const version = await wxApi.getVersion();
|
const version = await wxClient.call(WalletApiOperation.GetVersion, {});
|
||||||
return { exchanges: list.exchanges, version };
|
return { exchanges: list.exchanges, version };
|
||||||
});
|
});
|
||||||
const { exchanges, version } =
|
const { exchanges, version } =
|
||||||
@ -70,8 +71,7 @@ export function SettingsPage(): VNode {
|
|||||||
setDeviceName={update}
|
setDeviceName={update}
|
||||||
autoOpenToggle={autoOpenToggle}
|
autoOpenToggle={autoOpenToggle}
|
||||||
clipboardToggle={clipboardToggle}
|
clipboardToggle={clipboardToggle}
|
||||||
developerMode={devMode}
|
devModeToggle={devModeToggle}
|
||||||
toggleDeveloperMode={toggleDevMode}
|
|
||||||
webexVersion={{
|
webexVersion={{
|
||||||
version: webex.version,
|
version: webex.version,
|
||||||
hash: GIT_HASH,
|
hash: GIT_HASH,
|
||||||
@ -86,8 +86,7 @@ export interface ViewProps {
|
|||||||
setDeviceName: (s: string) => Promise<void>;
|
setDeviceName: (s: string) => Promise<void>;
|
||||||
autoOpenToggle: ToggleHandler;
|
autoOpenToggle: ToggleHandler;
|
||||||
clipboardToggle: ToggleHandler;
|
clipboardToggle: ToggleHandler;
|
||||||
developerMode: boolean;
|
devModeToggle: ToggleHandler;
|
||||||
toggleDeveloperMode: () => Promise<void>;
|
|
||||||
knownExchanges: Array<ExchangeListItem>;
|
knownExchanges: Array<ExchangeListItem>;
|
||||||
coreVersion: WalletCoreVersion | undefined;
|
coreVersion: WalletCoreVersion | undefined;
|
||||||
webexVersion: {
|
webexVersion: {
|
||||||
@ -100,10 +99,9 @@ export function SettingsView({
|
|||||||
knownExchanges,
|
knownExchanges,
|
||||||
autoOpenToggle,
|
autoOpenToggle,
|
||||||
clipboardToggle,
|
clipboardToggle,
|
||||||
developerMode,
|
devModeToggle,
|
||||||
coreVersion,
|
coreVersion,
|
||||||
webexVersion,
|
webexVersion,
|
||||||
toggleDeveloperMode,
|
|
||||||
}: ViewProps): VNode {
|
}: ViewProps): VNode {
|
||||||
const { i18n, lang, supportedLang, changeLanguage } = useTranslationContext();
|
const { i18n, lang, supportedLang, changeLanguage } = useTranslationContext();
|
||||||
|
|
||||||
@ -248,8 +246,8 @@ export function SettingsView({
|
|||||||
More options and information useful for debugging
|
More options and information useful for debugging
|
||||||
</i18n.Translate>
|
</i18n.Translate>
|
||||||
}
|
}
|
||||||
enabled={developerMode}
|
enabled={devModeToggle.value!}
|
||||||
onToggle={toggleDeveloperMode}
|
onToggle={devModeToggle.button.onClick!}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<JustInDevMode>
|
<JustInDevMode>
|
||||||
|
@ -151,6 +151,7 @@ async function dispatch(
|
|||||||
r = wrapResponse({ newValue: res });
|
r = wrapResponse({ newValue: res });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//FIXME: implement type checked api like WalletCoreApi
|
||||||
case "toggleHeaderListener": {
|
case "toggleHeaderListener": {
|
||||||
const newVal = req.payload.value;
|
const newVal = req.payload.value;
|
||||||
logger.trace("new extended permissions value", newVal);
|
logger.trace("new extended permissions value", newVal);
|
||||||
|
Loading…
Reference in New Issue
Block a user