feat: must be a new password to encrypt

This commit is contained in:
benalleng
2023-08-25 13:40:16 -04:00
committed by Paul Miller
parent b156412521
commit 8f90cc1c19
2 changed files with 23 additions and 4 deletions

View File

@@ -345,7 +345,9 @@ export default {
confirm_password_placeholder: "Enter the same password", confirm_password_placeholder: "Enter the same password",
encrypt: "Encrypt", encrypt: "Encrypt",
skip: "Skip", skip: "Skip",
error_match: "Passwords do not match" error_match: "Passwords do not match",
error_same_as_existingpassword:
"New password must not match existing password"
}, },
decrypt: { decrypt: {
title: "Enter your password", title: "Enter your password",

View File

@@ -1,5 +1,5 @@
import { createForm } from "@modular-forms/solid"; import { createForm } from "@modular-forms/solid";
import { createSignal, Show } from "solid-js"; import { createMemo, createSignal, Show } from "solid-js";
import { import {
BackLink, BackLink,
@@ -31,7 +31,7 @@ export default function Encrypt() {
const [error, setError] = createSignal<Error>(); const [error, setError] = createSignal<Error>();
const [loading, setLoading] = createSignal(false); const [loading, setLoading] = createSignal(false);
const [_encryptPasswordForm, { Form, Field }] = const [encryptPasswordForm, { Form, Field }] =
createForm<EncryptPasswordForm>({ createForm<EncryptPasswordForm>({
initialValues: { initialValues: {
existingPassword: "", existingPassword: "",
@@ -39,11 +39,16 @@ export default function Encrypt() {
confirmPassword: "" confirmPassword: ""
}, },
validate: (values) => { validate: (values) => {
setError(undefined);
const errors: Record<string, string> = {}; const errors: Record<string, string> = {};
if (values.password !== values.confirmPassword) { if (values.password !== values.confirmPassword) {
errors.confirmPassword = i18n.t( errors.confirmPassword = i18n.t(
"settings.encrypt.error_match" "settings.encrypt.error_match"
); );
} else if (values.password === values.existingPassword) {
errors.password = i18n.t(
"settings.encrypt.error_same_as_existingpassword"
);
} }
return errors; return errors;
} }
@@ -66,6 +71,14 @@ export default function Encrypt() {
} }
}; };
const encryptButtonDisabled = createMemo(() => {
return (
!encryptPasswordForm.dirty ||
encryptPasswordForm.invalid ||
!!error()
);
});
return ( return (
<MutinyWalletGuard> <MutinyWalletGuard>
<SafeArea> <SafeArea>
@@ -145,7 +158,11 @@ export default function Encrypt() {
</InfoBox> </InfoBox>
</Show> </Show>
<div /> <div />
<Button intent="blue" loading={loading()}> <Button
intent="blue"
disabled={encryptButtonDisabled()}
loading={loading()}
>
{i18n.t("settings.encrypt.encrypt")} {i18n.t("settings.encrypt.encrypt")}
</Button> </Button>
</VStack> </VStack>