diff options
author | Sebastian <sebasjm@gmail.com> | 2021-11-12 13:12:27 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-11-12 13:12:27 -0300 |
commit | 38b84bb8051db2f03b152d66c34a1cb4c8944a12 (patch) | |
tree | 1e7a23bacb5287a53da51f93faee8667292c56ee /packages/anastasis-webui/src/pages/home/SecretEditorScreen.tsx | |
parent | 377e78e8543b67c22798479fcf2d2f8d1dae5b28 (diff) | |
download | wallet-core-38b84bb8051db2f03b152d66c34a1cb4c8944a12.tar.xz |
fix #7059
Diffstat (limited to 'packages/anastasis-webui/src/pages/home/SecretEditorScreen.tsx')
-rw-r--r-- | packages/anastasis-webui/src/pages/home/SecretEditorScreen.tsx | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/packages/anastasis-webui/src/pages/home/SecretEditorScreen.tsx b/packages/anastasis-webui/src/pages/home/SecretEditorScreen.tsx index 226e43ddf..be8135ef5 100644 --- a/packages/anastasis-webui/src/pages/home/SecretEditorScreen.tsx +++ b/packages/anastasis-webui/src/pages/home/SecretEditorScreen.tsx @@ -10,10 +10,12 @@ import { FileInput, FileTypeContent } from "../../components/fields/FileInput"; export function SecretEditorScreen(): VNode { const reducer = useAnastasisContext(); const [secretValue, setSecretValue] = useState(""); - const [secretFile, _setSecretFile] = useState<FileTypeContent | undefined>(undefined); + const [secretFile, _setSecretFile] = useState<FileTypeContent | undefined>( + undefined, + ); function setSecretFile(v) { - setSecretValue("") // reset secret value when uploading a file - _setSecretFile(v) + setSecretValue(""); // reset secret value when uploading a file + _setSecretFile(v); } const currentSecretName = @@ -34,14 +36,16 @@ export function SecretEditorScreen(): VNode { } const secretNext = async (): Promise<void> => { - const secret = secretFile ? { - value: encodeCrock(stringToBytes(secretValue)), - filename: secretFile.name, - mime: secretFile.type, - } : { - value: encodeCrock(stringToBytes(secretValue)), - mime: "text/plain", - } + const secret = secretFile + ? { + value: encodeCrock(stringToBytes(secretValue)), + filename: secretFile.name, + mime: secretFile.type, + } + : { + value: encodeCrock(stringToBytes(secretValue)), + mime: "text/plain", + }; return reducer.runTransaction(async (tx) => { await tx.transition("enter_secret_name", { name: secretName, @@ -55,9 +59,14 @@ export function SecretEditorScreen(): VNode { await tx.transition("next", {}); }); }; - const errors = !secretName ? 'Add a secret name' : ( - (!secretValue && !secretFile) ? 'Add a secret value or a choose a file to upload' : undefined - ) + const errors = !secretName + ? "Add a secret name" + : !secretValue && !secretFile + ? "Add a secret value or a choose a file to upload" + : undefined; + function goNextIfNoErrors(): void { + if (!errors) secretNext(); + } return ( <AnastasisClientFrame hideNext={errors} @@ -69,12 +78,14 @@ export function SecretEditorScreen(): VNode { label="Secret name:" tooltip="The secret name allows you to identify your secret when restoring it. It is a label that you can choose freely." grabFocus + onConfirm={goNextIfNoErrors} bind={[secretName, setSecretName]} /> </div> <div class="block"> <TextInput disabled={!!secretFile} + onConfirm={goNextIfNoErrors} label="Enter the secret as text:" bind={[secretValue, setSecretValue]} /> @@ -82,10 +93,12 @@ export function SecretEditorScreen(): VNode { <div class="block"> Or upload a secret file <FileInput label="Choose file" onChange={setSecretFile} /> - {secretFile && <div> - Uploading secret file <b>{secretFile.name}</b> <a onClick={() => setSecretFile(undefined)}>cancel</a> - </div> - } + {secretFile && ( + <div> + Uploading secret file <b>{secretFile.name}</b>{" "} + <a onClick={() => setSecretFile(undefined)}>cancel</a> + </div> + )} </div> </AnastasisClientFrame> ); |