From 3847f2ddb80c96a69caeeac5e312807c50f1dcbb Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 4 Nov 2021 16:51:19 -0300 Subject: secret selecting --- .../src/pages/home/SecretSelectionScreen.tsx | 134 +++++++++++---------- 1 file changed, 68 insertions(+), 66 deletions(-) (limited to 'packages') diff --git a/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx b/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx index e1aeb3939..e8af75229 100644 --- a/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx +++ b/packages/anastasis-webui/src/pages/home/SecretSelectionScreen.tsx @@ -1,6 +1,9 @@ /* eslint-disable @typescript-eslint/camelcase */ +import { RecoveryInternalData } from "anastasis-core"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; +import { AsyncButton } from "../../components/AsyncButton"; +import { NumberInput } from "../../components/fields/NumberInput"; import { useAnastasisContext } from "../../context/anastasis"; import { AnastasisClientFrame } from "./index"; @@ -9,11 +12,11 @@ export function SecretSelectionScreen(): VNode { const [otherProvider, setOtherProvider] = useState(""); const reducer = useAnastasisContext() - const currentVersion = reducer?.currentReducerState + const currentVersion = (reducer?.currentReducerState && ("recovery_document" in reducer.currentReducerState) - && reducer.currentReducerState.recovery_document?.version; + && reducer.currentReducerState.recovery_document?.version) || 0; - const [otherVersion, setOtherVersion] = useState(currentVersion || 0); + const [otherVersion, setOtherVersion] = useState(""); if (!reducer) { return
no reducer in context
@@ -22,15 +25,15 @@ export function SecretSelectionScreen(): VNode { return
invalid state
} - function selectVersion(p: string, n: number): void { - if (!reducer) return; - reducer.runTransaction(async (tx) => { + async function selectVersion(p: string, n: number): Promise { + if (!reducer) return Promise.resolve(); + return reducer.runTransaction(async (tx) => { await tx.transition("change_version", { version: n, provider_url: p, }); + setSelectingVersion(false); }); - setSelectingVersion(false); } const providerList = Object.keys(reducer.currentReducerState.authentication_providers ?? {}) @@ -60,78 +63,77 @@ export function SecretSelectionScreen(): VNode { if (selectingVersion) { return ( -

Select a different version of the secret

- - - - - - - - - - -
Provider - -
Version - setOtherVersion(Number((e.target as HTMLInputElement).value))} - type="number" /> - - setOtherVersion(0)}>set to latest version -
-
- - +
+
+
+

Provider {recoveryDocument.provider_url}

+
+ {currentVersion === 0 ?

+ Set to recover the latest version +

:

+ Set to recover the version number {currentVersion} +

} +

Specify other version below or use the latest

+
+
+ +
+
+
+ +
+ + selectVersion(otherProvider, parseInt(otherVersion, 10))}>Confirm +
+
+
+
+ . +
); } + + function ProviderCard({ provider, selected }: { selected?: boolean; provider: string }): VNode { + return + } + return (
-
-
+
+

{recoveryDocument.provider_url}

- - - - - - - - - - - -
- Secret version - - - - {recoveryDocument.version} setSelectingVersion(true)}>use another version
- Secret name - - - - {recoveryDocument.secret_name}
+
+ {currentVersion === 0 ?

+ Set to recover the latest version +

:

+ Set to recover the version number {currentVersion} +

} +
- +
-
- -
+

+ Or you can use another provider +

+ {providerList.map(prov => { + if (recoveryDocument.provider_url === prov) return; + return + })}
-
+

Secret found, you can select another version or continue to the challenges solving

-- cgit v1.2.3