Skip to content

Commit 2347945

Browse files
authored
Fix: update status syncing atom so its not perpetually syncing (#1948)
1 parent 200bd4b commit 2347945

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

apps/namadillo/src/App/Layout/SyncIndicator.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ export const SyncIndicator = (): JSX.Element => {
3333
const syncStatus = useAtomValue(syncStatusAtom);
3434
const indexerServicesSyncStatus = useAtomValue(indexerServicesSyncStatusAtom);
3535
const chainStatus = useAtomValue(chainStatusAtom);
36+
const [blockHeightSync, setBlockHeightSync] = useState<boolean | null>(null);
3637
const [indexerBlockHeight, setIndexerBlockHeight] = useState<number | null>(
3738
null
3839
);
3940
const { errors } = syncStatus;
4041
const { services } = indexerServicesSyncStatus;
4142
const isChainStatusError =
42-
!chainStatus?.height || !chainStatus?.epoch || !indexerBlockHeight;
43+
!chainStatus?.height || !chainStatus?.epoch || !blockHeightSync;
4344
const api = useAtomValue(indexerApiAtom);
4445

4546
const isError =
@@ -50,7 +51,7 @@ export const SyncIndicator = (): JSX.Element => {
5051
const isSyncing =
5152
syncStatus.isSyncing ||
5253
indexerServicesSyncStatus.isSyncing ||
53-
indexerBlockHeight !== chainStatus?.height;
54+
!blockHeightSync;
5455

5556
useEffect(() => {
5657
(async () => {
@@ -59,6 +60,7 @@ export const SyncIndicator = (): JSX.Element => {
5960
Date.now()
6061
);
6162
setIndexerBlockHeight(indexerBlockHeight);
63+
setBlockHeightSync(indexerBlockHeight === chainStatus?.height);
6264
})();
6365
}, [chainStatus?.height]);
6466

apps/namadillo/src/atoms/syncStatus/atoms.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ export const syncStatusAtom = atom((get) => {
3232
get(votedProposalsAtom),
3333
];
3434

35-
const isSyncing = queries.some((q) => q.isFetching);
35+
// Change the logic here to only consider a query as "syncing" if:
36+
// 1. It's fetching AND not yet successful (initial load) OR
37+
// 2. It's in an error state and fetching (trying to recover)
38+
const isSyncing = queries.some(
39+
(q) => (q.isFetching && !q.isSuccess) || (q.isError && q.isFetching)
40+
);
3641
const isError = queries.some((q) => q.isError);
3742
const errors = queries.filter((q) => q.isError).map((q) => q.error);
3843

0 commit comments

Comments
 (0)