-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor testnet status update #1748
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ const HealthIndicator = () => { | |
setLoading(true); | ||
try { | ||
const status = await getTestnetStatus(); | ||
|
||
return status; | ||
} catch (error) { | ||
console.error(error); | ||
|
@@ -20,18 +21,27 @@ const HealthIndicator = () => { | |
} | ||
}; | ||
|
||
// using useRef to avoid memory leak | ||
let isMounted = React.useRef(true); | ||
|
||
useEffect(() => { | ||
let isMounted = true; | ||
|
||
// if overall health is true, status is set to true | ||
// if overall health is false but if the error includes [p2p], status is set to true | ||
|
||
testnetStatus().then((res) => { | ||
if (isMounted.current) { | ||
setStatus(res?.result); | ||
if (isMounted) { | ||
// setStatus(res?.result?.OverallHealth); | ||
if (res?.result?.OverallHealth) { | ||
setStatus(true); | ||
} else if (res?.result?.Errors?.includes("[p2p]")) { | ||
setStatus(true); | ||
} else { | ||
setStatus(false); | ||
} | ||
} | ||
}); | ||
|
||
return () => { | ||
isMounted.current = false; | ||
isMounted = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
refetchInterval
is now set to a constant value of 10000, which standardizes the polling mechanism. Ensure that this interval is appropriate for the application's needs and does not lead to unnecessary network traffic or user interface updates.