From 3267f56dc3de054a7dbdd6cd83305b92cf16bd61 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 13 Mar 2023 00:24:28 -0300 Subject: show/hide key --- .../src/components/form/InputWithAddon.tsx | 2 +- .../src/components/modal/index.tsx | 31 +++++++++++++------- .../src/paths/instance/templates/qr/QrPage.tsx | 14 +++++++-- .../paths/instance/templates/update/UpdatePage.tsx | 34 ++++++++++++++++++++-- 4 files changed, 65 insertions(+), 16 deletions(-) (limited to 'packages') diff --git a/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx b/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx index e5118c722..dbf4e2409 100644 --- a/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx +++ b/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx @@ -23,7 +23,7 @@ import { InputProps, useField } from "./useField.js"; export interface Props extends InputProps { expand?: boolean; - inputType?: "text" | "number"; + inputType?: "text" | "number" | "password"; addonBefore?: ComponentChildren; addonAfter?: ComponentChildren; toStr?: (v?: any) => string; diff --git a/packages/merchant-backoffice-ui/src/components/modal/index.tsx b/packages/merchant-backoffice-ui/src/components/modal/index.tsx index c9c7d0ce5..875e89e92 100644 --- a/packages/merchant-backoffice-ui/src/components/modal/index.tsx +++ b/packages/merchant-backoffice-ui/src/components/modal/index.tsx @@ -20,7 +20,7 @@ */ import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; -import { ComponentChildren, h, VNode } from "preact"; +import { ComponentChildren, Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { useInstanceContext } from "../../context/instance.js"; import { DEFAULT_REQUEST_TIMEOUT } from "../../utils/constants.js"; @@ -65,16 +65,25 @@ export function ConfirmModal({
- - + {onConfirm ? ( + + + + + + ) : ( + + )}
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx index 66ac72ff5..a6b616907 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx @@ -96,20 +96,30 @@ export function QrPage({ template, id: templateId, onBack }: Props): VNode { : template.pos_algorithm === 2 ? `otpauth://totp/${issuer}:${templateId}?secret=${template.pos_key}&issuer=${issuer}&algorithm=SHA1&digits=8&period=30` : undefined; + + const keySlice = template.pos_key?.substring(0, 4); + + const oauthUriWithoutSecret = !template.pos_algorithm + ? undefined + : template.pos_algorithm === 1 + ? `otpauth://totp/${issuer}:${templateId}?secret=${keySlice}...&issuer=${issuer}&algorithm=SHA1&digits=8&period=30` + : template.pos_algorithm === 2 + ? `otpauth://totp/${issuer}:${templateId}?secret=${keySlice}...&issuer=${issuer}&algorithm=SHA1&digits=8&period=30` + : undefined; return (
{oauthUri && ( { + onCancel={() => { setSetupTOTP(false); }} >

Scan this qr code with your TOTP device

-            {oauthUri}
+            {oauthUriWithoutSecret}
           
)} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx index e34e2c746..9fcfcc4bf 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx @@ -57,6 +57,7 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { const { i18n } = useTranslationContext(); const backend = useBackendContext(); + const [showKey, setShowKey] = useState(false); const [state, setState] = useState>(template); const errors: FormErrors = { @@ -161,14 +162,26 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { convert={(v) => Number(v)} /> {state.pos_algorithm && state.pos_algorithm > 0 ? ( - + name="pos_key" label={i18n.str`Point-of-sale key`} + inputType={showKey ? "text" : "password"} help="" + expand tooltip={i18n.str`Useful to validate the purchase`} + addonAfter={ + + {showKey ? ( + + ) : ( + + )} + + } side={ - + + } /> -- cgit v1.2.3