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
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
92d7197
wip: add an endpoint for health check
Jennievon Dec 21, 2023
9896ed7
feat: add endpoint for health check
Jennievon Dec 22, 2023
e8beeee
add ui for health check on Tenscan
Jennievon Dec 22, 2023
e64a7c5
Merge branch 'main' of https://github.com/ten-protocol/go-ten into je…
Jennievon Dec 29, 2023
2394bbf
Merge branch 'main' of https://github.com/ten-protocol/go-ten into je…
Jennievon Dec 29, 2023
e71c46e
Merge branch 'jennifer/2624-add-a-health-indicator-for-testnet-on-ten…
Jennievon Dec 29, 2023
ba87900
Refactor health status method names
Jennievon Dec 29, 2023
6386d90
Merge branch 'main' of https://github.com/ten-protocol/go-ten into je…
Jennievon Dec 29, 2023
d87f71a
Refactor health check function calls
Jennievon Dec 29, 2023
1e681f3
Merge branch 'jennifer/2624-add-a-health-indicator-for-testnet-on-ten…
Jennievon Dec 29, 2023
566d935
feat: endpoint to fetch testnet health status
Jennievon Dec 29, 2023
be80a1b
wip: testnet health check status
Jennievon Dec 29, 2023
e2e35c6
Merge branch 'main' of https://github.com/ten-protocol/go-ten into je…
Jennievon Jan 8, 2024
92bc4b7
Merge branch 'main' of https://github.com/ten-protocol/go-ten into je…
Jennievon Jan 8, 2024
7f5cd34
create rpcClient and tenClinet to call health
zkokelj Jan 8, 2024
6084191
Merge branch 'jennifer/health-check-on-gateway' of https://github.com…
Jennievon Jan 8, 2024
2f86d09
feat: update health status
Jennievon Jan 8, 2024
2303441
feat: format health response
Jennievon Jan 8, 2024
d470675
Merge branch 'jennifer/health-check-on-gateway' of https://github.com…
Jennievon Jan 8, 2024
11dc8fd
Merge branch 'main' of https://github.com/ten-protocol/go-ten into je…
Jennievon Jan 8, 2024
b7da853
Update getHealthStatus API route
Jennievon Jan 8, 2024
aa86490
fix useEffect warning msgs
Jennievon Jan 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tools/walletextension/frontend/src/api/general.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ResponseDataInterface } from "@/types/interfaces";
import { httpRequest } from ".";
import { pathToUrl } from "@/routes/router";
import { apiRoutes } from "@/routes";

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 },
});
};
Comment on lines +6 to +14
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 },
});
};

45 changes: 45 additions & 0 deletions tools/walletextension/frontend/src/components/health-indicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { useEffect } from "react";
import { Badge, badgeVariants } from "./ui/badge";
import useGatewayService from "@/services/useGatewayService";
import { Skeleton } from "./ui/skeleton";

const HealthIndicator = () => {
const { getTestnetStatus } = useGatewayService();
const [loading, setLoading] = React.useState(false);
const [status, setStatus] = React.useState<boolean>();

const testnetStatus = async () => {
setLoading(true);
try {
const status = await getTestnetStatus();
return status;
} catch (error) {
console.error(error);
} finally {
setLoading(false);
}
};

useEffect(() => {
testnetStatus().then((res) => setStatus(res?.result));
}, []);
Jennievon marked this conversation as resolved.
Show resolved Hide resolved
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


return (
<div className="flex items-center space-x-2 border rounded-lg p-2">
<h3 className="text-sm">Testnet Status: </h3>
{loading ? (
<Skeleton className="h-4 w-10" />
) : (
<Badge
variant={
(status ? "success" : "destructive") as keyof typeof badgeVariants
}
>
{status ? "Live" : "Down"}
</Badge>
)}
</div>
);
};
Jennievon marked this conversation as resolved.
Show resolved Hide resolved

export default HealthIndicator;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Link from "next/link";
import { HamburgerMenuIcon } from "@radix-ui/react-icons";
import { useState } from "react";
import { Button } from "../ui/button";
import HealthIndicator from "../health-indicator";

export default function Header() {
return (
Expand All @@ -16,6 +17,7 @@ export default function Header() {
<div className="hidden md:flex items-center space-x-4">
<MainNav className="mx-6" />
<div className="flex items-center space-x-4">
<HealthIndicator />
<ModeToggle />
<ConnectWalletButton />
</div>
Expand Down
3 changes: 3 additions & 0 deletions tools/walletextension/frontend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const apiRoutes = {
queryAccountToken: `/${tenGatewayVersion}/query/`,
revoke: `/${tenGatewayVersion}/revoke/`,
version: `/version/`,

// **** INFO ****
getHealthStatus: "/network-health/",
};

export const requestMethods = {
Expand Down
11 changes: 11 additions & 0 deletions tools/walletextension/frontend/src/services/useGatewayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getToken,
switchToTenNetwork,
} from "@/api/ethRequests";
import { fetchTestnetStatus } from "@/api/general";

const useGatewayService = () => {
const { token, provider, fetchUserAccounts, setLoading } =
Expand Down Expand Up @@ -76,8 +77,18 @@ const useGatewayService = () => {
}
};

const getTestnetStatus = async () => {
try {
return await fetchTestnetStatus();
} catch (error) {
showToast(ToastType.DESTRUCTIVE, "Unable to connect to Obscuro Testnet");
throw error;
}
};

return {
connectToTenTestnet,
getTestnetStatus,
};
};

Expand Down
Loading