From 4e8eb3b2c31665584a4242d70d890e8fb6d69a6c Mon Sep 17 00:00:00 2001 From: PhilReact Date: Sat, 26 Apr 2025 10:34:15 +0300 Subject: [PATCH] added the option to change the wallet's password --- public/locales/de/auth.json | 8 +- public/locales/en/auth.json | 8 +- public/locales/es/auth.json | 8 +- public/locales/fr/auth.json | 8 +- public/locales/it/auth.json | 8 +- public/locales/ru/auth.json | 8 +- src/App.tsx | 136 +------------- src/ExtStates/NotAuthenticated.tsx | 2 +- src/components/Auth/DownloadWallet.tsx | 248 +++++++++++++++++++++++++ src/components/Explore/Explore.tsx | 2 +- 10 files changed, 302 insertions(+), 134 deletions(-) create mode 100644 src/components/Auth/DownloadWallet.tsx diff --git a/public/locales/de/auth.json b/public/locales/de/auth.json index fc83d42..5b14183 100644 --- a/public/locales/de/auth.json +++ b/public/locales/de/auth.json @@ -31,7 +31,13 @@ "return_to_list": "zurück zur Liste", "wallet": { "password_confirmation": "Wallet-Passwort bestätigen", - "password": "Wallet-Passwort" + "password": "Wallet-Passwort", + "keep_password": "aktuelles Passwort beibehalten", + "new_password": "neues Passwort", + "error": { + "missing_new_password": "bitte neues Passwort eingeben", + "missing_password": "bitte Passwort eingeben" + } }, "welcome": "willkommen bei" } diff --git a/public/locales/en/auth.json b/public/locales/en/auth.json index 26cab11..2ee037e 100644 --- a/public/locales/en/auth.json +++ b/public/locales/en/auth.json @@ -31,7 +31,13 @@ "return_to_list": "return to list", "wallet": { "password_confirmation": "confirm wallet password", - "password": "wallet password" + "password": "wallet password", + "keep_password": "keep current password", + "new_password": "new password", + "error": { + "missing_new_password": "please enter a new password", + "missing_password": "please enter your password" + } }, "welcome": "welcome to" } diff --git a/public/locales/es/auth.json b/public/locales/es/auth.json index 3c62c24..5d4b8b6 100644 --- a/public/locales/es/auth.json +++ b/public/locales/es/auth.json @@ -31,7 +31,13 @@ "return_to_list": "volver a la lista", "wallet": { "password_confirmation": "confirmar contraseña del monedero", - "password": "contraseña del monedero" + "password": "contraseña del monedero", + "keep_password": "mantener la contraseña actual", + "new_password": "nueva contraseña", + "error": { + "missing_new_password": "por favor ingresa una nueva contraseña", + "missing_password": "por favor ingresa tu contraseña" + } }, "welcome": "bienvenido a" } diff --git a/public/locales/fr/auth.json b/public/locales/fr/auth.json index 06d08d5..f314d3e 100644 --- a/public/locales/fr/auth.json +++ b/public/locales/fr/auth.json @@ -31,7 +31,13 @@ "return_to_list": "retour à la liste", "wallet": { "password_confirmation": "confirmer le mot de passe du portefeuille", - "password": "mot de passe du portefeuille" + "password": "mot de passe du portefeuille", + "keep_password": "garder le mot de passe actuel", + "new_password": "nouveau mot de passe", + "error": { + "missing_new_password": "veuillez entrer un nouveau mot de passe", + "missing_password": "veuillez entrer votre mot de passe" + } }, "welcome": "bienvenue sur" } diff --git a/public/locales/it/auth.json b/public/locales/it/auth.json index 345c154..ad00833 100644 --- a/public/locales/it/auth.json +++ b/public/locales/it/auth.json @@ -30,7 +30,13 @@ "password": "password", "wallet": { "password_confirmation": "conferma la password del wallet", - "password": "password del wallet" + "password": "password del wallet", + "keep_password": "mantieni la password attuale", + "new_password": "nuova password", + "error": { + "missing_new_password": "per favore inserisci una nuova password", + "missing_password": "per favore inserisci la tua password" + } }, "return_to_list": "ritorna alla lista", "welcome": "benvenuto in" diff --git a/public/locales/ru/auth.json b/public/locales/ru/auth.json index 3ae2327..797220b 100644 --- a/public/locales/ru/auth.json +++ b/public/locales/ru/auth.json @@ -31,7 +31,13 @@ "return_to_list": "вернуться к списку", "wallet": { "password_confirmation": "подтвердите пароль кошелька", - "password": "пароль кошелька" + "password": "пароль кошелька", + "keep_password": "сохранить текущий пароль", + "new_password": "новый пароль", + "error": { + "missing_new_password": "пожалуйста, введите новый пароль", + "missing_password": "пожалуйста, введите ваш пароль" + } }, "welcome": "добро пожаловать в" } diff --git a/src/App.tsx b/src/App.tsx index ba57d99..7c66d9d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -137,6 +137,7 @@ import { GeneralNotifications } from './components/GeneralNotifications'; import { PdfViewer } from './common/PdfViewer'; import ThemeSelector from './components/Theme/ThemeSelector.tsx'; import { useTranslation } from 'react-i18next'; +import { DownloadWallet } from './components/Auth/DownloadWallet.tsx'; type extStates = | 'not-authenticated' @@ -919,27 +920,6 @@ function App() { } }, [authenticatedMode]); - const confirmPasswordToDownload = async () => { - try { - setWalletToBeDownloadedError(''); - if (!walletToBeDownloadedPassword) { - setSendPaymentError('Please enter your password'); - return; - } - setIsLoading(true); - await new Promise((res) => { - setTimeout(() => { - res(); - }, 250); - }); - const res = await saveWalletFunc(walletToBeDownloadedPassword); - } catch (error: any) { - setWalletToBeDownloadedError(error?.message); - } finally { - setIsLoading(false); - } - }; - const saveFileToDiskFunc = async () => { try { await saveFileToDisk( @@ -1676,7 +1656,7 @@ function App() { textTransform: 'uppercase', }} > - {t('core:wallet_other')} + {t('core:wallet.wallet_other')} } placement="left" @@ -2692,110 +2672,14 @@ function App() { )} {extState === 'download-wallet' && ( - <> - - - - - - - -
- -
- - - - - - {t('auth:download_account', { postProcess: 'capitalize' })} - - - - - - {!walletToBeDownloaded && ( - <> - - {t('auth:wallet.password_confirmation', { - postProcess: 'capitalize', - })} - - - - - - setWalletToBeDownloadedPassword(e.target.value) - } - /> - - - - - {t('auth:password_confirmation', { - postProcess: 'capitalize', - })} - - {walletToBeDownloadedError} - - )} - - {walletToBeDownloaded && ( - <> - { - await saveFileToDiskFunc(); - await showInfo({ - message: t('auth:keep_secure', { - postProcess: 'capitalize', - }), - }); - }} - > - {t('auth:download_account', { - postProcess: 'capitalize', - })} - - - )} - + )} {extState === 'create-wallet' && ( <> diff --git a/src/ExtStates/NotAuthenticated.tsx b/src/ExtStates/NotAuthenticated.tsx index 28892a9..3c8afd9 100644 --- a/src/ExtStates/NotAuthenticated.tsx +++ b/src/ExtStates/NotAuthenticated.tsx @@ -703,7 +703,7 @@ export const NotAuthenticated = ({ visibility: importedApiKey ? 'visible' : 'hidden', }} > - {t('auth:apikey.key', { postProcess: 'capitalize' })}: $ + {t('auth:apikey.key', { postProcess: 'capitalize' })}:{' '} {importedApiKey} diff --git a/src/components/Auth/DownloadWallet.tsx b/src/components/Auth/DownloadWallet.tsx new file mode 100644 index 0000000..12b46f4 --- /dev/null +++ b/src/components/Auth/DownloadWallet.tsx @@ -0,0 +1,248 @@ +import { Box, Checkbox, FormControlLabel, Typography } from '@mui/material'; +import { Spacer } from '../../common/Spacer'; +import { Return } from '../../assets/Icons/Return'; +import { CustomButton, CustomLabel, TextP } from '../../styles/App-styles'; +import { PasswordField } from '../PasswordField/PasswordField'; +import { ErrorText } from '../ErrorText/ErrorText'; +import Logo1Dark from '../../assets/svgs/Logo1Dark.svg'; +import { useTranslation } from 'react-i18next'; +import { saveFileToDisk } from '../../utils/generateWallet/generateWallet'; +import { useState } from 'react'; +import { decryptStoredWallet } from '../../utils/decryptWallet'; +import PhraseWallet from '../../utils/generateWallet/phrase-wallet'; +import { crypto, walletVersion } from '../../constants/decryptWallet'; + +export const DownloadWallet = ({ + returnToMain, + setIsLoading, + showInfo, + rawWallet, + setWalletToBeDownloaded, + walletToBeDownloaded, +}) => { + const [walletToBeDownloadedPassword, setWalletToBeDownloadedPassword] = + useState(''); + const [newPassword, setNewPassword] = useState(''); + const [keepCurrentPassword, setKeepCurrentPassword] = useState(true); + + const [walletToBeDownloadedError, setWalletToBeDownloadedError] = + useState(''); + + const { t } = useTranslation(['auth']); + + const saveFileToDiskFunc = async () => { + try { + await saveFileToDisk( + walletToBeDownloaded.wallet, + walletToBeDownloaded.qortAddress + ); + } catch (error: any) { + setWalletToBeDownloadedError(error?.message); + } + }; + + const saveWalletFunc = async (password: string, newPassword) => { + let wallet = structuredClone(rawWallet); + + const res = await decryptStoredWallet(password, wallet); + const wallet2 = new PhraseWallet(res, wallet?.version || walletVersion); + const passwordToUse = newPassword || password; + wallet = await wallet2.generateSaveWalletData( + passwordToUse, + crypto.kdfThreads, + () => {} + ); + + setWalletToBeDownloaded({ + wallet, + qortAddress: rawWallet.address0, + }); + return { + wallet, + qortAddress: rawWallet.address0, + }; + }; + + const confirmPasswordToDownload = async () => { + try { + setWalletToBeDownloadedError(''); + if (!keepCurrentPassword && !newPassword) { + setWalletToBeDownloadedError( + t('auth:wallet.error.missing_new_password', { + postProcess: 'capitalize', + }) + ); + return; + } + if (!walletToBeDownloadedPassword) { + setWalletToBeDownloadedError( + t('auth:wallet.error.missing_password', { postProcess: 'capitalize' }) + ); + return; + } + setIsLoading(true); + await new Promise((res) => { + setTimeout(() => { + res(); + }, 250); + }); + const newPasswordForWallet = !keepCurrentPassword ? newPassword : null; + const res = await saveWalletFunc( + walletToBeDownloadedPassword, + newPasswordForWallet + ); + } catch (error: any) { + setWalletToBeDownloadedError(error?.message); + } finally { + setIsLoading(false); + } + }; + + return ( + <> + + + + + + + +
+ +
+ + + + + + {t('auth:download_account', { postProcess: 'capitalize' })} + + + + + + {!walletToBeDownloaded && ( + <> + + {t('auth:wallet.password_confirmation', { + postProcess: 'capitalize', + })} + + + + + setWalletToBeDownloadedPassword(e.target.value)} + /> + + + + setKeepCurrentPassword(e.target.checked)} + checked={keepCurrentPassword} + edge="start" + tabIndex={-1} + disableRipple + /> + } + label={ + + + {t('auth:wallet.keep_password', { + postProcess: 'capitalize', + })} + + + } + /> + + {!keepCurrentPassword && ( + <> + + {t('auth:wallet.new_password', { + postProcess: 'capitalize', + })} + + + + setNewPassword(e.target.value)} + /> + + + )} + + + {t('auth:password_confirmation', { + postProcess: 'capitalize', + })} + + + {walletToBeDownloadedError} + + )} + + {walletToBeDownloaded && ( + <> + { + await saveFileToDiskFunc(); + await showInfo({ + message: t('auth:keep_secure', { + postProcess: 'capitalize', + }), + }); + }} + > + {t('auth:download_account', { + postProcess: 'capitalize', + })} + + + )} + + ); +}; diff --git a/src/components/Explore/Explore.tsx b/src/components/Explore/Explore.tsx index ae1988e..266fdd5 100644 --- a/src/components/Explore/Explore.tsx +++ b/src/components/Explore/Explore.tsx @@ -124,7 +124,7 @@ export const Explore = ({ setDesktopViewMode }) => { fontSize: '1rem', }} > - {t('core:wallet_other', { postProcess: 'capitalize' })} + {t('core:wallet.wallet_other', { postProcess: 'capitalize' })}