From 895a3c360b6e5dd63ee72c7f82ad68ac02b55b09 Mon Sep 17 00:00:00 2001 From: hypertensiune Date: Sat, 14 Sep 2024 23:09:27 +0300 Subject: [PATCH] Fixed generator history --- extension/src/lib/firebase.ts | 4 ++-- extension/src/pages/Vault/Tabs/GeneratorTab/index.tsx | 9 ++++++--- extension/src/pages/Vault/index.tsx | 2 +- extension/src/pages/VaultCreate/index.tsx | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/extension/src/lib/firebase.ts b/extension/src/lib/firebase.ts index a0aee0a..25b57b1 100644 --- a/extension/src/lib/firebase.ts +++ b/extension/src/lib/firebase.ts @@ -81,7 +81,7 @@ export async function createVault(name: string, password: string, symmetricKey: await setDoc(doc(db, "vaults", "ids"), { [name.toLowerCase()]: user.user.uid }, { merge: true }); - await setDoc(doc(db, user.user.uid, "psk"), { "psk": symmetricKey, "master": password }); + await setDoc(doc(db, user.user.uid, "psk"), { "psk": symmetricKey }); await setDoc(doc(db, user.user.uid, "passwords"), {}); await setDoc(doc(db, user.user.uid, "notes"), {}); await setDoc(doc(db, user.user.uid, "history"), { "history": [] }); @@ -242,7 +242,7 @@ export async function setGeneratorHistory(passwords: string[]) { if (unlockedVaultID === undefined) { return false; } - if(passwords.length > 0) { + if(passwords.length == 0) { return false; } diff --git a/extension/src/pages/Vault/Tabs/GeneratorTab/index.tsx b/extension/src/pages/Vault/Tabs/GeneratorTab/index.tsx index ecee64f..55f1cc3 100644 --- a/extension/src/pages/Vault/Tabs/GeneratorTab/index.tsx +++ b/extension/src/pages/Vault/Tabs/GeneratorTab/index.tsx @@ -32,7 +32,7 @@ function printPassword(password: string) { function HistoryDrawer({ history, clear, opened, close }: { history: string[], clear: () => void, opened: boolean, close: any }) { const [modal, modalHandlers] = useDisclosure(false); - + return ( <> @@ -83,10 +83,13 @@ export default function Generator({ _history, options, setOptions }: { _history: const [history, setHistory] = useState(_history); - const password = generatePassword(options); + const [password, setPassword] = useState(generatePassword(options)); useEffect(() => { + const generated = generatePassword(options); + setPassword(generated); + if (timeoutHandle != null) { clearInterval(timeoutHandle); } @@ -95,7 +98,7 @@ export default function Generator({ _history, options, setOptions }: { _history: if (history.length > 15) { newarr.pop() } - newarr.unshift(password); + newarr.unshift(generated); setHistory(newarr); setGeneratorHistory(newarr); diff --git a/extension/src/pages/Vault/index.tsx b/extension/src/pages/Vault/index.tsx index 6abd74f..72f99de 100644 --- a/extension/src/pages/Vault/index.tsx +++ b/extension/src/pages/Vault/index.tsx @@ -163,7 +163,7 @@ export default function Vault() { /> - + diff --git a/extension/src/pages/VaultCreate/index.tsx b/extension/src/pages/VaultCreate/index.tsx index 2c9c40e..57e4201 100644 --- a/extension/src/pages/VaultCreate/index.tsx +++ b/extension/src/pages/VaultCreate/index.tsx @@ -24,7 +24,7 @@ export default function VaultCreate({vaults }: { vaults: string[] }) { initialValues: { password: '', confirm: '', name: '' }, validate: { - name: (value) => (value.length == 0 ? 'Vault name is required' : vaults?.includes(value) ? 'Vault already exists' : null), + name: (value) => (value.length == 0 ? 'Vault name is required' : vaults?.includes(value.toLowerCase()) ? 'Vault already exists' : null), password: (value) => (value.length < 15 ? 'Passwords should be at least 15 characters' : null), confirm: (value, values) => (value !== values.password ? 'Passwords did not match' : null) }