Skip to content

Commit

Permalink
feat: walletd state information
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Apr 15, 2024
1 parent 23168c6 commit 61de825
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-toes-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'walletd': minor
---

The profile details now include uptime and version. Closes https://github.com/SiaFoundation/walletd/issues/97
5 changes: 5 additions & 0 deletions .changeset/many-panthers-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/react-walletd': minor
---

Added useNodeState.
38 changes: 35 additions & 3 deletions apps/walletd/components/Profile/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<DaemonProfile
name="walletd"
Expand All @@ -23,6 +45,16 @@ export function Profile() {
firstTimeSyncing={syncStatus.firstTimeSyncing}
moreThan100BlocksToSync={syncStatus.moreThan100BlocksToSync}
>
{state.data && (
<div className="flex gap-4 justify-between items-center">
<Label size="14" color="subtle" noWrap className="w-[100px]">
Uptime
</Label>
<div className="flex-1 flex justify-end overflow-hidden -mr-0.5 pr-0.5">
<Text size="14">{humanTime(uptime, { format: 'long' })}</Text>
</div>
</div>
)}
{network.data && (
<div className="flex gap-4 justify-between items-center">
<Label size="14" color="subtle" noWrap className="w-[100px]">
Expand All @@ -33,7 +65,7 @@ export function Profile() {
</div>
</div>
)}
{/* <div className="flex gap-4 justify-between items-center">
<div className="flex gap-4 justify-between items-center">
<Label size="14" color="subtle" noWrap className="w-[100px]">
Version
</Label>
Expand All @@ -46,7 +78,7 @@ export function Profile() {
>
{state.data?.version}
</Link>
</div> */}
</div>
</DaemonProfile>
)
}
17 changes: 17 additions & 0 deletions libs/react-walletd/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void, StateResponse>) {
return useGetSwr({
...args,
route: '/state',
})
}

// consensus

export type ConsensusTipResponse = ChainIndex
Expand Down

0 comments on commit 61de825

Please sign in to comment.