Skip to content

Commit

Permalink
feat: Disable Milestone stats in milestoneFeed (debug)
Browse files Browse the repository at this point in the history
  • Loading branch information
msarcev committed Nov 21, 2023
1 parent d707193 commit 82d7724
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/src/helpers/hooks/useBlockFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useBlockFeed(network: string): [
const fetchLatestCachedMilestones = useCallback(async () => {
if (apiClient) {
const latestMilestones: ILatestMilestonesReponse = await apiClient.latestMilestones(network);
if (isMounted && latestMilestones.milestones.length > 0) {
if (isMounted && latestMilestones.milestones && latestMilestones.milestones.length > 0) {
setMilestones(
latestMilestones.milestones.slice(0, MAX_MILESTONE_ITEMS)
);
Expand Down
37 changes: 21 additions & 16 deletions client/src/helpers/hooks/useMilestoneStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,36 @@ export function useMilestoneStats(network: string, milestoneIndex: string | null
IMilestoneAnalyticStats | null,
boolean
] {
const [milestoneStatsEnabled] = useState(false);
const isMounted = useIsMounted();
const [apiClient] = useState(ServiceFactory.get<StardustApiClient>(`api-client-${STARDUST}`));
const [milestoneStats, setMilestoneStats] = useState<IMilestoneAnalyticStats | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);

useEffect(() => {
setIsLoading(true);
if (milestoneIndex) {
// eslint-disable-next-line no-void
void (async () => {
apiClient.milestoneStats({
network,
milestoneIndex
}).then(response => {
if (isMounted) {
setMilestoneStats(response ?? null);
}
}).finally(() => {
setIsLoading(false);
});
})();
if (milestoneStatsEnabled) {
setIsLoading(true);
if (milestoneIndex) {
// eslint-disable-next-line no-void
void (async () => {
apiClient.milestoneStats({
network,
milestoneIndex
}).then(response => {
if (isMounted) {
setMilestoneStats(response ?? null);
}
}).finally(() => {
setIsLoading(false);
});
})();
} else {
setIsLoading(false);
}
} else {
setIsLoading(false);
}
}, [network, milestoneIndex]);
}, [network, milestoneIndex, milestoneStatsEnabled]);

return [milestoneStats, isLoading];
}

0 comments on commit 82d7724

Please sign in to comment.