From 6c6f50444ebcf4494b24c10980ed5d266f973176 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Mon, 14 Aug 2023 09:34:38 +0700 Subject: [PATCH] polish splash screen --- src/app.tsx | 46 ++++++++++--------- src/app/auth/unlock.tsx | 26 ++++------- src/app/auth/welcome.tsx | 25 +++++----- .../components/{blocks => widgets}/feed.tsx | 0 .../{blocks => widgets}/hashtag.tsx | 0 .../components/{blocks => widgets}/image.tsx | 0 .../{blocks => widgets}/network.tsx | 0 .../components/{blocks => widgets}/thread.tsx | 0 .../components/{blocks => widgets}/user.tsx | 0 src/app/space/index.tsx | 12 ++--- src/app/splash.tsx | 36 +++++++++------ src/utils/hooks/useAccount.tsx | 2 +- 12 files changed, 75 insertions(+), 72 deletions(-) rename src/app/space/components/{blocks => widgets}/feed.tsx (100%) rename src/app/space/components/{blocks => widgets}/hashtag.tsx (100%) rename src/app/space/components/{blocks => widgets}/image.tsx (100%) rename src/app/space/components/{blocks => widgets}/network.tsx (100%) rename src/app/space/components/{blocks => widgets}/thread.tsx (100%) rename src/app/space/components/{blocks => widgets}/user.tsx (100%) 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() {