From 91cd9df960b38e089dde69a6ca7f451fd67fc41f Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Thu, 4 Apr 2024 11:03:02 -0400 Subject: [PATCH] feat: walletd state information --- .changeset/forty-toes-reflect.md | 5 +++ .changeset/many-panthers-wonder.md | 5 +++ apps/walletd/components/Profile/index.tsx | 38 +++++++++++++++++++++-- libs/react-walletd/src/api.ts | 17 ++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 .changeset/forty-toes-reflect.md create mode 100644 .changeset/many-panthers-wonder.md diff --git a/.changeset/forty-toes-reflect.md b/.changeset/forty-toes-reflect.md new file mode 100644 index 000000000..94ba300f3 --- /dev/null +++ b/.changeset/forty-toes-reflect.md @@ -0,0 +1,5 @@ +--- +'walletd': minor +--- + +The profile details now include uptime and version. Closes https://github.com/SiaFoundation/walletd/issues/97 diff --git a/.changeset/many-panthers-wonder.md b/.changeset/many-panthers-wonder.md new file mode 100644 index 000000000..9c6ef8576 --- /dev/null +++ b/.changeset/many-panthers-wonder.md @@ -0,0 +1,5 @@ +--- +'@siafoundation/react-walletd': minor +--- + +Added useNodeState. diff --git a/apps/walletd/components/Profile/index.tsx b/apps/walletd/components/Profile/index.tsx index a9e3c84ec..2821c7f7d 100644 --- a/apps/walletd/components/Profile/index.tsx +++ b/apps/walletd/components/Profile/index.tsx @@ -1,16 +1,38 @@ -import { DaemonProfile, Label, Text } from '@siafoundation/design-system' +import { DaemonProfile, Label, Text, Link } from '@siafoundation/design-system' import { useSyncStatus } from '../../hooks/useSyncStatus' import { useConsensusNetwork, + useNodeState, useSyncerPeers, } from '@siafoundation/react-walletd' import { useDialog } from '../../contexts/dialog' +import { humanTime } from '@siafoundation/units' export function Profile() { const { openDialog } = useDialog() const peers = useSyncerPeers() const syncStatus = useSyncStatus() const network = useConsensusNetwork() + const state = useNodeState({ + config: { + swr: { + revalidateOnFocus: false, + }, + }, + }) + + const version = state.data?.version + const versionUrl = + version === '?' + ? `https://github.com/SiaFoundation/walletd/commits/` + : version?.match(/^v\d+\.\d+\.\d+/) + ? `https://github.com/SiaFoundation/walletd/releases/${version}` + : `https://github.com/SiaFoundation/walletd/tree/${version}` + + const uptime = state.data + ? new Date().getTime() - new Date(state.data?.startTime).getTime() + : 0 + return ( + {state.data && ( +
+ +
+ {humanTime(uptime, { format: 'long' })} +
+
+ )} {network.data && (
)} - {/*
+
@@ -46,7 +78,7 @@ export function Profile() { > {state.data?.version} -
*/} +
) } diff --git a/libs/react-walletd/src/api.ts b/libs/react-walletd/src/api.ts index 2c1886685..79918066c 100644 --- a/libs/react-walletd/src/api.ts +++ b/libs/react-walletd/src/api.ts @@ -32,6 +32,23 @@ import { WalletMetadata, } from './siaTypes' +// state + +export type StateResponse = { + version: string + commit: string + os: string + buildTime: string + startTime: string +} + +export function useNodeState(args?: HookArgsSwr) { + return useGetSwr({ + ...args, + route: '/state', + }) +} + // consensus export type ConsensusTipResponse = ChainIndex