Skip to content

Commit

Permalink
Merge pull request #109 from palladians/fix/fix-wrong-password-bricking
Browse files Browse the repository at this point in the history
fix(wallet): fix wrong password reopen brick
  • Loading branch information
teddyjfpender authored Dec 23, 2023
2 parents 8fe0550 + c068e12 commit f8a2a0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/features/src/lock/views/unlock-wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@palladxyz/persistence'
import { useVault } from '@palladxyz/vault'
import { EyeIcon, EyeOffIcon } from 'lucide-react'
import { useEffect, useState } from 'react'
import { FormEvent, useEffect, useState } from 'react'
import { useForm } from 'react-hook-form'
import { useNavigate } from 'react-router-dom'
import { z } from 'zod'
Expand Down Expand Up @@ -59,6 +59,10 @@ export const UnlockWalletView = () => {
})
}, 100)
}
const togglePassword = (event: FormEvent<HTMLButtonElement>) => {
event.preventDefault()
setShowPassword(!showPassword)
}
useEffect(() => {
const unsub = useVault.persist.onFinishHydration(async () => {
const authenticated =
Expand Down Expand Up @@ -127,7 +131,7 @@ export const UnlockWalletView = () => {
variant="outline"
size="icon"
data-testid="unlockWallet__togglePasswordVisible"
onClick={() => setShowPassword(!showPassword)}
onClick={togglePassword}
>
{showPassword ? <EyeOffIcon /> : <EyeIcon />}
</Button>
Expand Down
19 changes: 14 additions & 5 deletions packages/features/src/onboarding/views/start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ export const StartView = () => {
useEffect(() => {
const initialRedirect = async () => {
if (!isStoreInitialized) return setAppInitialized(true)
const spendingPassword =
(await getSessionPersistence().getItem('spendingPassword')) || ''
const spendingPasswordSet = spendingPassword.length > 0
let spendingPassword
try {
spendingPassword =
(await getSessionPersistence().getItem('spendingPassword')) || ''
} catch {
return navigate('/unlock')
}
const spendingPasswordSet = spendingPassword?.length > 0
if (!spendingPasswordSet) return navigate('/unlock')
const authenticated =
(await getSecurePersistence().getItem('foo')) === 'bar'
let authenticated
try {
authenticated = (await getSecurePersistence().getItem('foo')) === 'bar'
} catch {
authenticated = false
}
if (!authenticated) return navigate('/unlock')
return navigate('/dashboard')
}
Expand Down

0 comments on commit f8a2a0c

Please sign in to comment.