Skip to content

Commit

Permalink
fix(dw): unlock profile
Browse files Browse the repository at this point in the history
  • Loading branch information
javadkh2 committed Nov 8, 2024
1 parent a1800b3 commit 80db521
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/apps/dev-wallet/src/App/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ export const Routes: FC = () => {
<Route element={<Redirect if={!isLocked} to={origin} />}>
<Route path="/select-profile" element={<SelectProfile />} />
<Route path="/create-profile/*" element={<CreateProfile />} />
<Route
path="/unlock-profile/:profileId"
element={<UnlockProfile />}
/>
<Route
path="/import-wallet"
element={<ImportWallet setOrigin={setOrigin} />}
Expand Down Expand Up @@ -139,6 +135,10 @@ export const Routes: FC = () => {
</Route>
</Route>
<Route element={<LayoutMini />}>
<Route
path="/unlock-profile/:profileId"
element={<UnlockProfile origin={origin} />}
/>
<Route path="/ready" element={<Ready />} />
<Route path="*" element={<Heading>Not found!</Heading>} />
</Route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import {
TextField,
} from '@kadena/kode-ui';
import { useForm } from 'react-hook-form';
import { Link, Navigate, useParams } from 'react-router-dom';
import { Link, Navigate, useNavigate, useParams } from 'react-router-dom';
import { useWallet } from '../../modules/wallet/wallet.hook';
import { passwordContainer, profileContainer } from './styles.css.ts';

export function UnlockProfile() {
export function UnlockProfile({ origin }: { origin: string }) {
const {
register,
handleSubmit,
setError,
formState: { isValid, errors },
} = useForm<{ password: string }>();
const { profileId } = useParams();
const { profileList, unlockProfile } = useWallet();
const navigate = useNavigate();
const { profileList, unlockProfile, isUnlocked } = useWallet();
const profile = profileList.find((p) => p.uuid === profileId);
const incorrectPasswordMsg = 'Password is incorrect';

Expand All @@ -38,6 +39,11 @@ export function UnlockProfile() {
if (!keySource) {
throw new Error('No key source found');
}
if (isUnlocked) {
navigate('/');
} else {
navigate(origin);
}
} catch (e) {
console.log(e);
setError('password', { type: 'manual', message: incorrectPasswordMsg });
Expand Down

0 comments on commit 80db521

Please sign in to comment.