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

[Gateway] health check on gateway UI/frontend #1729

Merged
merged 22 commits into from
Jan 9, 2024

Conversation

Jennievon
Copy link
Contributor

Why this change is needed

Please provide a description and a link to the underlying ticket

https://github.com/ten-protocol/ten-internal/issues/2624

What changes were made as part of this PR

Please provide a high level list of the changes made

Testnet health status on gateway frontend

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 Dec 29, 2023

Walkthrough

The update introduces a new feature to monitor the health of a testnet in a wallet extension. A HealthIndicator component has been created and integrated into the header layout to display the testnet's live status. The backend support for this feature includes a new API endpoint and service function to fetch the testnet status. Error handling is also implemented, with user feedback provided through a toast message.

Changes

File Path Change Summary
.../frontend/src/api/general.ts Added functionality to fetch testnet status via HTTP POST request.
.../frontend/src/components/health-indicator.tsx Introduced HealthIndicator React component to show testnet status with UI feedback.
.../frontend/src/components/layouts/header.tsx Imported and included HealthIndicator in the header component.
.../frontend/src/routes/index.ts Added getHealthStatus endpoint to the API routes.
.../frontend/src/services/useGatewayService.ts Added getTestnetStatus function and imported fetchTestnetStatus.

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.

@Jennievon Jennievon marked this pull request as ready for review January 8, 2024 18:54
@Jennievon Jennievon requested a review from zkokelj January 8, 2024 18:59
@Jennievon Jennievon self-assigned this Jan 8, 2024
Base automatically changed from jennifer/health-check-on-gateway to main January 8, 2024 19:00
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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 74e0a39 and 11dc8fd.
Files selected for processing (5)
  • tools/walletextension/frontend/src/api/general.ts (1 hunks)
  • tools/walletextension/frontend/src/components/health-indicator.tsx (1 hunks)
  • tools/walletextension/frontend/src/components/layouts/header.tsx (2 hunks)
  • tools/walletextension/frontend/src/routes/index.ts (1 hunks)
  • tools/walletextension/frontend/src/services/useGatewayService.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/frontend/src/routes/index.ts
Additional comments: 5
tools/walletextension/frontend/src/components/layouts/header.tsx (2)
  • 8-8: The import of the HealthIndicator component is correct and follows the established import pattern of the project.

  • 20-20: The inclusion of the HealthIndicator component in the header layout is consistent with the PR's objective to make the testnet status visible in the UI. Ensure that the visual placement and styling of the HealthIndicator component align with the design specifications and provide a good user experience.

tools/walletextension/frontend/src/services/useGatewayService.ts (3)
  • 17-17: The import of the fetchTestnetStatus function is correct and follows the established import pattern of the project.

  • 80-87: The getTestnetStatus function is implemented correctly, with proper error handling that provides user feedback through a toast message. This aligns with the PR's objective to handle service disruptions or communication errors robustly.

  • 91-91: The getTestnetStatus function is correctly added to the return object of useGatewayService, making it available for use in the components that consume this service.

Comment on lines +6 to +14
export const fetchTestnetStatus = async (): Promise<
ResponseDataInterface<any>
> => {
return await httpRequest<ResponseDataInterface<any>>({
method: "post",
url: pathToUrl(apiRoutes.getHealthStatus),
data: { jsonrpc: "2.0", method: "obscuro_health", params: [], id: 1 },
});
};
Copy link

Choose a reason for hiding this comment

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

The fetchTestnetStatus function is well-structured and uses the httpRequest function to make a POST request. The use of async/await is consistent with modern asynchronous patterns in JavaScript. However, the use of any as a generic type for ResponseDataInterface should be avoided if a more specific type can be used to enhance type safety.

- ResponseDataInterface<any>
+ ResponseDataInterface<SpecificType>

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export const fetchTestnetStatus = async (): Promise<
ResponseDataInterface<any>
> => {
return await httpRequest<ResponseDataInterface<any>>({
method: "post",
url: pathToUrl(apiRoutes.getHealthStatus),
data: { jsonrpc: "2.0", method: "obscuro_health", params: [], id: 1 },
});
};
export const fetchTestnetStatus = async (): Promise<
ResponseDataInterface<SpecificType>
> => {
return await httpRequest<ResponseDataInterface<SpecificType>>({
method: "post",
url: pathToUrl(apiRoutes.getHealthStatus),
data: { jsonrpc: "2.0", method: "obscuro_health", params: [], id: 1 },
});
};

Copy link
Contributor

@zkokelj zkokelj left a comment

Choose a reason for hiding this comment

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

When running npm run build I get warning mentioned below + warning mentioned in another comment. Can you please check and fix these warnings?
Apart from that it looks great and works without any issues.

./src/components/providers/wallet-provider.tsx
202:6 Warning: React Hook useEffect has a missing dependency: 'fetchUserAccounts'. Either include it or remove the dependency array. react-hooks/exhaustive-deps


useEffect(() => {
testnetStatus().then((res) => setStatus(res?.result));
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

./src/components/health-indicator.tsx
25:6 Warning: React Hook useEffect has a missing dependency: 'testnetStatus'. Either include it or remove the dependency array. react-hooks/exhaustive-deps

@Jennievon
Copy link
Contributor Author

Updated now @zkokelj

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 11dc8fd and aa86490.
Files selected for processing (3)
  • tools/walletextension/frontend/src/components/health-indicator.tsx (1 hunks)
  • tools/walletextension/frontend/src/components/providers/wallet-provider.tsx (1 hunks)
  • tools/walletextension/frontend/src/routes/index.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/frontend/src/components/providers/wallet-provider.tsx
Files skipped from review as they are similar to previous changes (1)
  • tools/walletextension/frontend/src/components/health-indicator.tsx
Additional comments: 1
tools/walletextension/frontend/src/routes/index.ts (1)
  • 14-14: The addition of the getHealthStatus endpoint to the apiRoutes object is consistent with the existing API route patterns and follows the versioning convention. This change integrates well with the current structure of the file.

@Jennievon Jennievon requested a review from zkokelj January 9, 2024 00:42
Copy link
Contributor

@zkokelj zkokelj 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 5aee83a into main Jan 9, 2024
2 checks passed
@Jennievon Jennievon deleted the jennifer/health-check-on-gateway-ui branch January 9, 2024 12:47
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