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

feat: walletd state information #572

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading