Skip to content
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

Merged
merged 4 commits into from
Jan 17, 2024
Merged

Refactor testnet status update #1748

merged 4 commits into from
Jan 17, 2024

Conversation

Jennievon
Copy link
Contributor

@Jennievon Jennievon commented Jan 17, 2024

Why this change is needed

Please provide a description and a link to the underlying ticket
https://github.com/ten-protocol/ten-internal/issues/2775

What changes were made as part of this PR

Please provide a high level list of the changes made
Update Testnet Status on Tenscan and the Gateway to be healthy, regardless of p2p errors

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Jan 17, 2024

Walkthrough

The recent updates across the tenscan and walletextension frontend codebases focus on refining the handling and display of testnet status. The changes include a more specific return type for the fetchTestnetStatus function, the introduction of a local status state in the HealthIndicator components, and a streamlined useGeneralService hook with a fixed refetch interval. Additionally, an errors field has been added to the ResponseDataInterface to better manage error information.

Changes

File Path Change Summary
tools/tenscan/frontend/api/general.ts Updated return type from ResponseDataInterface<any> to ResponseDataInterface<boolean>.
tools/tenscan/frontend/src/components/health-indicator.tsx
walletextension/.../health-indicator.tsx
Added local status state; adjusted badge/text display based on status. Refactored isMounted to local variable; updated status state logic with OverallHealth and error handling.
tools/tenscan/frontend/src/services/useGeneralService.ts Removed setNoPolling and refetchTestnetStatus; set refetchInterval to 10000.
tools/tenscan/frontend/src/types/interfaces/index.ts Added errors field to ResponseDataInterface.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3ba9d7c and e59c2b5.
Files selected for processing (5)
  • tools/tenscan/frontend/api/general.ts (1 hunks)
  • tools/tenscan/frontend/src/components/health-indicator.tsx (1 hunks)
  • tools/tenscan/frontend/src/services/useGeneralService.ts (1 hunks)
  • tools/tenscan/frontend/src/types/interfaces/index.ts (1 hunks)
  • tools/walletextension/frontend/src/components/health-indicator.tsx (2 hunks)
Additional comments: 5
tools/tenscan/frontend/api/general.ts (1)
  • 7-9: The return type of fetchTestnetStatus has been correctly updated to ResponseDataInterface<boolean>, which provides stricter type checking and should help prevent type-related bugs.
tools/tenscan/frontend/src/components/health-indicator.tsx (2)
  • 6-20: The logic for setting the status state based on testnetStatus.result and testnetStatus.errors is clear and should work as intended. However, ensure that the error string "[p2p]" is a standardized and documented way of indicating a specific error condition.
  • 27-30: The badge variant and text are now correctly determined by the status state, which should make the display of health status more responsive to changes.
tools/tenscan/frontend/src/types/interfaces/index.ts (1)
  • 60-60: The addition of an optional errors field to ResponseDataInterface is a good practice for error handling. Ensure that all parts of the application that use this interface are updated to handle this new field.
tools/walletextension/frontend/src/components/health-indicator.tsx (1)
  • 33-39: The logic for setting the status state based on OverallHealth and errors containing "[p2p]" is consistent with the changes in the other HealthIndicator component. Ensure that this logic is in line with the application's error handling strategy.

Comment on lines +6 to +12
const { data: testnetStatus, isLoading: isStatusLoading } = useQuery({
queryKey: ["testnetStatus"],
queryFn: () => fetchTestnetStatus(),
// refetchInterval: noPolling ? false : pollingInterval,
refetchInterval: 10000,
});

return { testnetStatus, isStatusLoading, setNoPolling, refetchTestnetStatus };
return { testnetStatus, isStatusLoading };
Copy link

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.

Comment on lines 25 to 44
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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of isMounted to guard against state updates on an unmounted component is a good practice to avoid memory leaks. However, consider using a more robust solution like a cleanup function or the AbortController API to cancel any in-flight requests when the component unmounts.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e59c2b5 and ddd9fae.
Files selected for processing (1)
  • tools/walletextension/frontend/src/components/health-indicator.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tools/walletextension/frontend/src/components/health-indicator.tsx

@Jennievon Jennievon changed the title Fix health status Refactor testnet status update Jan 17, 2024
Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Jennievon Jennievon merged commit 7f0ad72 into main Jan 17, 2024
1 of 2 checks passed
@Jennievon Jennievon deleted the jennifer/fix-health-status branch January 17, 2024 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants