-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tenscan] health check UI on Tenscan (#1719)
* ui for health check on Tenscan * Refactor health status method names * Refactor health check function calls
- Loading branch information
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ResponseDataInterface } from "@/src/types/interfaces"; | ||
import { httpRequest } from "."; | ||
import { pathToUrl } from "@/src/routes/router"; | ||
import { apiRoutes } from "@/src/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 }, | ||
}); | ||
}; |
24 changes: 24 additions & 0 deletions
24
tools/tenscan/frontend/src/components/health-indicator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
import { Badge, badgeVariants } from "./ui/badge"; | ||
import { useGeneralService } from "../services/useGeneralService"; | ||
|
||
const HealthIndicator = () => { | ||
const { testnetStatus } = useGeneralService(); | ||
|
||
return ( | ||
<div className="flex items-center space-x-2 border rounded-lg p-2"> | ||
<h3 className="text-sm">Testnet Status: </h3> | ||
<Badge | ||
variant={ | ||
(testnetStatus?.result | ||
? "success" | ||
: "destructive") as keyof typeof badgeVariants | ||
} | ||
> | ||
{testnetStatus?.result ? "Live" : "Down"} | ||
</Badge> | ||
</div> | ||
); | ||
}; | ||
|
||
export default HealthIndicator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fetchTestnetStatus } from "@/api/general"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useState } from "react"; | ||
|
||
export const useGeneralService = () => { | ||
const [noPolling, setNoPolling] = useState(false); | ||
|
||
const { | ||
data: testnetStatus, | ||
isLoading: isStatusLoading, | ||
refetch: refetchTestnetStatus, | ||
} = useQuery({ | ||
queryKey: ["testnetStatus"], | ||
queryFn: () => fetchTestnetStatus(), | ||
// refetchInterval: noPolling ? false : pollingInterval, | ||
}); | ||
|
||
return { testnetStatus, isStatusLoading, setNoPolling, refetchTestnetStatus }; | ||
}; |