Skip to content

Commit

Permalink
fix: background sync loading issue (#2168)
Browse files Browse the repository at this point in the history
fixes the issue where zupass accounts without a devcon ticket will get
into an interstitial loading state every time a background sync happens

cc @ororsatti @ichub
  • Loading branch information
rrrliu authored Nov 12, 2024
1 parent b34222c commit 92d74c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 12 additions & 5 deletions apps/passport-client/new-components/screens/Home/SyncIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ReactElement, useEffect, useState } from "react";
import { useIsSyncSettled } from "../../../src/appHooks";
import {
useExtraSubscriptionFetchRequested,
useIsSyncSettled
} from "../../../src/appHooks";
import { NewLoader } from "../../shared/NewLoader";
import { Typography } from "../../shared/Typography";

Expand All @@ -24,12 +27,16 @@ const getSyncState = (seconds: number): keyof typeof syncStates => {
};
export const SyncIndicator = (): ReactElement => {
const [syncState, setSyncState] = useState<string | undefined>();

const extraFetchSubscriptionRequested = useExtraSubscriptionFetchRequested();
const isSyncSettled = useIsSyncSettled();
const isBackgroundSyncSettled =
isSyncSettled && !extraFetchSubscriptionRequested;

useEffect(() => {
let seconds = 0;
const interval = setInterval(() => {
if (isSyncSettled) {
if (isBackgroundSyncSettled) {
seconds += 10;
setSyncState(syncStates[getSyncState(seconds)](seconds));
} else {
Expand All @@ -38,17 +45,17 @@ export const SyncIndicator = (): ReactElement => {
}
}, 10000);

if (isSyncSettled) {
if (isBackgroundSyncSettled) {
seconds += 10;
setSyncState(syncStates[getSyncState(seconds)](seconds));
} else {
setSyncState(undefined);
seconds = 0;
}
return () => clearInterval(interval);
}, [isSyncSettled]);
}, [isBackgroundSyncSettled]);

if (isSyncSettled && syncState) {
if (isBackgroundSyncSettled && syncState) {
return <Typography color="var(--text-tertiary)">{syncState}</Typography>;
}
return (
Expand Down
3 changes: 1 addition & 2 deletions apps/passport-client/src/appHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ export function useUserShouldAgreeNewPrivacyNotice(): void {
export function useIsSyncSettled(): boolean {
const isDownloaded = useIsDownloaded();
const loadedIssued = useLoadedIssuedPCDs();
const extraFetchSubscriptionRequested = useExtraSubscriptionFetchRequested();
return isDownloaded && loadedIssued && !extraFetchSubscriptionRequested;
return isDownloaded && loadedIssued;
}

export function useIsLoggedIn(): boolean {
Expand Down

0 comments on commit 92d74c7

Please sign in to comment.