/* eslint-disable @typescript-eslint/camelcase */ import { AuthMethod } from "anastasis-core"; import { ComponentChildren, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { useAnastasisContext } from "../../context/anastasis"; import { authMethods, KnownAuthMethods } from "./authMethodSetup"; import { AnastasisClientFrame } from "./index"; const getKeys = Object.keys as (obj: T) => Array export function AuthenticationEditorScreen(): VNode { const [noProvidersAck, setNoProvidersAck] = useState(false) const [selectedMethod, setSelectedMethod] = useState(undefined); const reducer = useAnastasisContext() if (!reducer) { return
no reducer in context
} if (!reducer.currentReducerState || reducer.currentReducerState.backup_state === undefined) { return
invalid state
} const configuredAuthMethods: AuthMethod[] = reducer.currentReducerState.authentication_methods ?? []; const haveMethodsConfigured = configuredAuthMethods.length > 0; function removeByIndex(index: number): void { if (reducer) reducer.transition("delete_authentication", { authentication_method: index, }) } const camByType: { [s: string]: AuthMethodWithRemove[] } = {} for (let index = 0; index < configuredAuthMethods.length; index++) { const cam = { ...configuredAuthMethods[index], remove: () => removeByIndex(index) } const prevValue = camByType[cam.type] || [] prevValue.push(cam) camByType[cam.type] = prevValue; } const providers = reducer.currentReducerState.authentication_providers!; const authAvailableSet = new Set(); for (const provKey of Object.keys(providers)) { const p = providers[provKey]; if ("http_status" in p && (!("error_code" in p)) && p.methods) { for (const meth of p.methods) { authAvailableSet.add(meth.type); } } } if (selectedMethod) { const cancel = (): void => setSelectedMethod(undefined); const addMethod = (args: any): void => { reducer.transition("add_authentication", args); setSelectedMethod(undefined); }; const AuthSetup = authMethods[selectedMethod].screen ?? AuthMethodNotImplemented; return ( ); } function MethodButton(props: { method: KnownAuthMethods }): VNode { return (
); } const errors = !haveMethodsConfigured ? "There is not enough authentication methods." : undefined; return (
{getKeys(authMethods).map(method => )}
{authAvailableSet.size === 0 && setNoProvidersAck(true)} description="No providers founds" label="Add a provider manually"> We have found no trusted cloud providers for your recovery secret. You can add a provider manually. To add a provider you must know the provider URL (e.g. https://provider.com)

More about cloud providers

} {/* {haveMethodsConfigured && ( configuredAuthMethods.map((x, i) => { return (

{x.type} ({x.instructions}){" "}

); }) )} */}
When recovering your wallet, you will be asked to verify your identity via the methods you configure here.
); } type AuthMethodWithRemove = AuthMethod & { remove: () => void } export interface AuthMethodSetupProps { method: string; addAuthMethod: (x: any) => void; configured: AuthMethodWithRemove[]; cancel: () => void; } function AuthMethodNotImplemented(props: AuthMethodSetupProps): VNode { return (

This auth method is not implemented yet, please choose another one.

); } function ConfirmModal({ active, description, onCancel, onConfirm, children, danger, disabled, label = 'Confirm' }: Props): VNode { return
} interface Props { active?: boolean; description?: string; onCancel?: () => void; onConfirm?: () => void; label?: string; children?: ComponentChildren; danger?: boolean; disabled?: boolean; }