Fix the connection error retry button

This commit is contained in:
Zoe Roux 2023-07-11 16:19:25 +09:00
parent e8d4c128da
commit 6ac8af9946
2 changed files with 9 additions and 3 deletions

View File

@ -76,6 +76,7 @@ const ThemedStack = ({ onLayout }: { onLayout?: () => void }) => {
);
};
let rendered: boolean = false;
export default function Root() {
const [queryClient] = useState(() => createQueryClient());
@ -83,7 +84,8 @@ export default function Root() {
const [fontsLoaded] = useFonts({ Poppins_300Light, Poppins_400Regular, Poppins_900Black });
const info = useAccounts();
if (!fontsLoaded || info.type === "loading") return <SplashScreen />;
if (!fontsLoaded || (!rendered && info.type === "loading")) return <SplashScreen />;
rendered = true;
return (
<AccountContext.Provider value={info}>
<QueryClientProvider client={queryClient}>

View File

@ -34,6 +34,7 @@ export const useAccounts = () => {
status: "ok" | "error" | "loading" | "unverified";
error?: string;
}>({ status: "loading" });
const [retryCount, setRetryCount] = useState(0);
// TODO: Remember the last selected account.
const selected = accounts?.length ? 0 : null;
@ -55,7 +56,7 @@ export const useAccounts = () => {
if (accounts && selected !== null) check();
else setVerified({status: "unverified"});
}, [accounts, selected]);
}, [accounts, selected, retryCount]);
if (accounts === null || verified.status === "loading") return { type: "loading" } as const;
if (accounts !== null && verified.status === "unverified") return { type: "loading" } as const;
@ -63,7 +64,10 @@ export const useAccounts = () => {
return {
type: "error",
error: verified.error,
retry: () => setVerified({ status: "loading" }),
retry: () => {
setVerified({ status: "loading" })
setRetryCount((x) => x + 1);
},
} as const;
}
return { type: "ok", accounts, selected } as const;