diff --git a/src/app.tsx b/src/app.tsx index eaed5b40..58b152f0 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -15,29 +15,33 @@ import { SettingsLayout } from '@shared/settingsLayout'; import './index.css'; const appLoader = async () => { - const account = await getActiveAccount(); - const stronghold = sessionStorage.getItem('stronghold'); - const privkey = JSON.parse(stronghold).state.privkey || null; - const onboarding = localStorage.getItem('onboarding'); - const step = JSON.parse(onboarding).state.step || null; + try { + const account = await getActiveAccount(); + const stronghold = sessionStorage.getItem('stronghold'); + const privkey = JSON.parse(stronghold).state.privkey || null; + const onboarding = localStorage.getItem('onboarding'); + const step = JSON.parse(onboarding).state.step || null; - if (step) { - return redirect(step); + if (step) { + return redirect(step); + } + + if (!account) { + return redirect('/auth/welcome'); + } else { + if (account.privkey.length > 35) { + return redirect('/auth/migrate'); + } + + if (!privkey) { + return redirect('/auth/unlock'); + } + } + + return null; + } catch (e) { + throw new Error('App failed to load'); } - - if (!account) { - return redirect('/auth/welcome'); - } - - if (account && account.privkey.length > 35) { - return redirect('/auth/migrate'); - } - - if (account && !privkey) { - return redirect('/auth/unlock'); - } - - return null; }; const router = createBrowserRouter([ diff --git a/src/app/auth/unlock.tsx b/src/app/auth/unlock.tsx index 0dd45ad3..2306256a 100644 --- a/src/app/auth/unlock.tsx +++ b/src/app/auth/unlock.tsx @@ -31,21 +31,12 @@ export function UnlockScreen() { const navigate = useNavigate(); const setPrivkey = useStronghold((state) => state.setPrivkey); - const [passwordInput, setPasswordInput] = useState('password'); - const [loading, setLoading] = useState(false); + const [showPassword, setShowPassword] = useState(false); + const [loading, setLoading] = useState(false); const { account } = useAccount(); const { load } = useSecureStorage(); - // toggle private key - const showPassword = () => { - if (passwordInput === 'password') { - setPasswordInput('text'); - } else { - setPasswordInput('password'); - } - }; - const { register, setError, @@ -62,20 +53,19 @@ export function UnlockScreen() { setPrivkey(privkey); // redirect to home navigate('/', { replace: true }); - } catch { - setLoading(false); + } catch (e) { setError('password', { type: 'custom', - message: 'Wrong password', + message: e, }); } } else { - setLoading(false); setError('password', { type: 'custom', message: 'Password is required and must be greater than 3', }); } + setLoading(false); }; return ( @@ -89,15 +79,15 @@ export function UnlockScreen() {