Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

636 check for existing wallet #719

Closed
Prev Previous commit
Next Next commit
initial working solution with react router loader
  • Loading branch information
Zachary Johnson committed Jan 26, 2024
commit 441b043fe717987fe48647272adb8deb3a258543
4 changes: 4 additions & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -123,6 +123,10 @@ export default function App() {
<Route
id="create-wallet"
path={routes.createWallet}
loader={async () => {
const abortCtrl = new AbortController()
return Api.getWalletAll(abortCtrl)
}}
element={<CreateWallet parentRoute={'home'} startWallet={startWallet} />}
/>

5 changes: 5 additions & 0 deletions src/components/WalletCreationForm.tsx
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import { useCallback } from 'react'
import * as rb from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
import { Formik, FormikErrors } from 'formik'
import { useLoaderData } from 'react-router-dom'
import Sprite from './Sprite'
import { JM_WALLET_FILE_EXTENSION, sanitizeWalletName } from '../utils'
import styles from './WalletCreationForm.module.css'
@@ -37,13 +38,17 @@ const WalletCreationForm = ({
onSubmit,
}: WalletCreationFormProps) => {
const { t, i18n } = useTranslation()
const existingWallets: any = useLoaderData()

const validate = useCallback(
(values: CreateWalletFormValues) => {
const errors = {} as FormikErrors<CreateWalletFormValues>
if (!values.walletName || !validateWalletName(values.walletName)) {
errors.walletName = t('create_wallet.feedback_invalid_wallet_name')
}
if (existingWallets.wallets.includes(`${values.walletName}.jmdat`)) {
errors.walletName = t('create_wallet.feedback_wallet_name_already_exists')
}
if (!values.password) {
errors.password = t('create_wallet.feedback_invalid_password')
}
1 change: 1 addition & 0 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -130,6 +130,7 @@
"label_wallet_name": "Wallet name",
"placeholder_wallet_name": "Your Wallet...",
"feedback_invalid_wallet_name": "Please choose a valid wallet name: Use only letters, numbers, underscores or hyphens.",
"feedback_wallet_name_already_exists": "This wallet name already exists. Please choose another one.",
"label_password": "Password to unlock the wallet",
"placeholder_password": "Choose a secure password...",
"feedback_invalid_password": "Please set a password.",