diff --git a/apps/blog/components/dialog-login.tsx b/apps/blog/components/dialog-login.tsx index a0012e8b..f711f480 100644 --- a/apps/blog/components/dialog-login.tsx +++ b/apps/blog/components/dialog-login.tsx @@ -18,7 +18,7 @@ function DialogLogin({ children }: { children: ReactNode }) { } }}> {children} - e.preventDefault()}> + e.preventDefault()}> diff --git a/packages/smart-signer/components/auth/form.tsx b/packages/smart-signer/components/auth/form.tsx index 564f1b00..6f7b445c 100644 --- a/packages/smart-signer/components/auth/form.tsx +++ b/packages/smart-signer/components/auth/form.tsx @@ -63,7 +63,7 @@ const SignInForm = forwardRef(({ preferredKeyTyp } - return + return { step === Steps.SAFE_STORAGE_LOGIN && ( diff --git a/packages/smart-signer/components/auth/methods/safestorage.tsx b/packages/smart-signer/components/auth/methods/safestorage.tsx index f5d7bf7d..40256d16 100644 --- a/packages/smart-signer/components/auth/methods/safestorage.tsx +++ b/packages/smart-signer/components/auth/methods/safestorage.tsx @@ -31,10 +31,12 @@ import { KeyType, LoginType } from "@smart-signer/types/common"; const formSchema = z.object({ username, - password: z.string(), + password: z.string().min(6, { + message: "Password length should be more than 6 characters" + }), wif: z.string(), keyType: z.enum(['posting', 'active']) -}) +}); export type SafeStorageRef = { cancel: () => Promise; }; @@ -70,9 +72,9 @@ const SafeStorage = forwardRef(({ onSetStep, s password: "", wif: "", keyType: preferredKeyTypes[0] - }, + } }); - + async function onSave(values: SafeStorageForm) { const { username, password, wif, keyType } = values; @@ -101,28 +103,30 @@ const SafeStorage = forwardRef(({ onSetStep, s } }; - async function onUnlock({ username, password }: SafeStorageForm) { - try { - setError(null); - await authClient.current?.unlock(username, password); - setAuthUsers(await authClient.current?.getAuths() || []); - form.setValue('password', ''); - form.setValue('wif', ''); - } catch (error) { - setError((error as AuthorizationError).message); - setLoading(false); - } - } - - async function onSign({ username, keyType }: SafeStorageForm): Promise { - await sign(LoginType.hbauth, username, KeyType[keyType]); - } - - async function onSubmitAuth({ username }: SafeStorageForm): Promise { - setLoading(true); - await submit(username); - setLoading(false); - } + {/* TODO: Re-work offline flow */ } + // async function onUnlock({ username, password }: SafeStorageForm) { + // try { + // setError(null); + // await authClient.current?.unlock(username, password); + // setAuthUsers(await authClient.current?.getAuths() || []); + // form.setValue('password', ''); + // form.setValue('wif', ''); + // } catch (error) { + // setError((error as AuthorizationError).message); + // setLoading(false); + // } + // } + + {/* TODO: Re-work offline flow */ } + // async function onSign({ username, keyType }: SafeStorageForm): Promise { + // await sign(LoginType.hbauth, username, KeyType[keyType]); + // } + + // async function onSubmitAuth({ username }: SafeStorageForm): Promise { + // setLoading(true); + // await submit(username); + // setLoading(false); + // } async function finalize({ username, keyType }: SafeStorageForm) { try { @@ -194,125 +198,124 @@ const SafeStorage = forwardRef(({ onSetStep, s {error && {error}} } loading={loading}> - {!userFound?.unlocked ? - ( - - {/* Username */} - ( - - - {/* Place holder, enter username if there is no user, otherwise select user from menu or enter new user*/} - - - {authUsers.length ? ( - - - - - - - - { - authUsers.map(({ username }) => { - return ( - { - form.setValue('username', username); - form.trigger(); - }} - disabled={form.getValues().username === username} - > - {username} - - ) - }) - } - - - ) : null} - - {/* Show select menu if there is length of auth users */} - - {errors.username && {t(errors.username?.message!)}} - - )} - /> - - {/* Password */} + null)}> + {/* Username */} + ( + + + {/* Place holder, enter username if there is no user, otherwise select user from menu or enter new user*/} + + + {authUsers.length ? ( + + + + + + + + { + authUsers.map(({ username }) => { + return ( + { + form.setValue('username', username); + form.trigger(); + }} + disabled={form.getValues().username === username} + > + {username} + + ) + }) + } + + + ) : null} + + {/* Show select menu if there is length of auth users */} + + {errors.username && {t(errors.username?.message!)}} + + )} + /> + + {/* Password */} + ( + + + + + + + )} + /> + + {/* WIF */} + {!userFound && ( + + + + + + + )} + />} + + {/* Key Type selection is shown if there is more than one preferred key type */} + { + preferredKeyTypes.length > 1 && ( ( - + + { + preferredKeyTypes.map((type) => { + return + + {type} + + }) + } + )} /> - - {/* WIF */} - {!userFound && ( - - - - - - - )} - />} - - {/* Key Type selection is shown if there is more than one preferred key type */} - { - preferredKeyTypes.length > 1 && ( - ( - - - - { - preferredKeyTypes.map((type) => { - return - - {type} - - }) - } - - - - - )} - /> - ) - } - - {/* Show this for new user, otherwise show unlock then authorize */} - - { - userFound - ? - ( - <> - - {t("login_form.signin_safe_storage.button_signin")} - - + { + userFound + ? + ( + <> + + {t("login_form.signin_safe_storage.button_signin")} + + {/* TODO: Re-work offline flow */} + {/* (({ onSetStep, s onClick={form.handleSubmit(onUnlock)} > {t("login_form.signin_safe_storage.button_unlock")} - > - ) - : - - {t("login_form.signin_safe_storage.button_save")} - - } - - - - - - { - cancelAuth(); - onSetStep(Steps.OTHER_LOGIN_OPTIONS); - }}> - {t("login_form.signin_safe_storage.button_other")} - - - ) - : - ( + */} + > + ) + : + + {t("login_form.signin_safe_storage.button_save")} + + } + + + + + { + cancelAuth(); + onSetStep(Steps.OTHER_LOGIN_OPTIONS); + }}> + {t("login_form.signin_safe_storage.button_other")} + + + + + {/* TODO: Re-work offline flow */} + {/* ( {t("login_form.signin_safe_storage.description_unlocked_detailed")} @@ -366,8 +370,8 @@ const SafeStorage = forwardRef(({ onSetStep, s {t("login_form.signin_safe_storage.button_cancel")} - ) - } + ) */} + ) diff --git a/packages/smart-signer/components/auth/step.tsx b/packages/smart-signer/components/auth/step.tsx index d5217cff..064c4744 100644 --- a/packages/smart-signer/components/auth/step.tsx +++ b/packages/smart-signer/components/auth/step.tsx @@ -6,12 +6,12 @@ export interface StepProps { title?: string; description?: ReactNode; footer?: ReactNode; - loading?: boolean + loading?: boolean; } const Step: FC> = ({ children, description, title, footer, loading = false }) => { return ( - + {loading &&
{t("login_form.signin_safe_storage.description_unlocked_detailed")} @@ -366,8 +370,8 @@ const SafeStorage = forwardRef(({ onSetStep, s {t("login_form.signin_safe_storage.button_cancel")}