Fix account verification error not showing

This commit is contained in:
Zoe Roux 2023-07-10 00:36:31 +09:00
parent 7797a7bf53
commit d2a5d4b3ec

View File

@ -55,15 +55,16 @@ export const useAccounts = () => {
if (accounts && selected !== null) check(); if (accounts && selected !== null) check();
else setVerified({status: "unverified"}); else setVerified({status: "unverified"});
}, [accounts, selected, verified.status]); }, [accounts, selected]);
if (accounts === null || verified.status === "loading") return { type: "loading" } as const; if (accounts === null || verified.status === "loading") return { type: "loading" } as const;
if (accounts !== null && verified.status === "unverified") return { type: "loading" } as const;
if (verified.status === "error") { if (verified.status === "error") {
return { return {
type: "error", type: "error",
error: verified.error, error: verified.error,
retry: () => setVerified({ status: "loading" }), retry: () => setVerified({ status: "loading" }),
}; } as const;
} }
return { type: "ok", accounts, selected } as const; return { type: "ok", accounts, selected } as const;
}; };
@ -86,13 +87,8 @@ export const ConnectionError = ({ error, retry }: { error?: string; retry: () =>
export const AccountContext = createContext<ReturnType<typeof useAccounts>>({ type: "loading" }); export const AccountContext = createContext<ReturnType<typeof useAccounts>>({ type: "loading" });
let initialRender = true;
const App = () => { const App = () => {
// Using context on the initial one to keep the splashscreen and not show a spinner. const info = useContext(AccountContext);
// eslint-disable-next-line react-hooks/rules-of-hooks
const info = initialRender ? useContext(AccountContext) : useAccounts();
initialRender = false;
if (info.type === "loading") return <CircularProgress /> if (info.type === "loading") return <CircularProgress />
if (info.type === "error") return <ConnectionError error={info.error} retry={info.retry} />; if (info.type === "error") return <ConnectionError error={info.error} retry={info.retry} />;
if (info.selected === null) return <Redirect href="/login" />; if (info.selected === null) return <Redirect href="/login" />;