-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gateway] health check on gateway UI/frontend (#1729)
* feat: format health response * Update getHealthStatus API route * fix useEffect warning msgs
- Loading branch information
Showing
6 changed files
with
88 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 "@/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 }, | ||
}); | ||
}; |
57 changes: 57 additions & 0 deletions
57
tools/walletextension/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,57 @@ | ||
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); | ||
} | ||
}; | ||
|
||
// using useRef to avoid memory leak | ||
let isMounted = React.useRef(true); | ||
|
||
useEffect(() => { | ||
testnetStatus().then((res) => { | ||
if (isMounted.current) { | ||
setStatus(res?.result); | ||
} | ||
}); | ||
|
||
return () => { | ||
isMounted.current = false; | ||
}; | ||
// eslint-disable-next-line 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> | ||
); | ||
}; | ||
|
||
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
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