Skip to content

Commit 0816c72

Browse files
committed
feat: walletd state information
1 parent c395f2e commit 0816c72

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

.changeset/forty-toes-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'walletd': minor
3+
---
4+
5+
The profile details now include uptime and version. Closes https://github.com/SiaFoundation/walletd/issues/97

.changeset/many-panthers-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@siafoundation/react-walletd': minor
3+
---
4+
5+
Added useNodeState.

apps/walletd/components/Profile/index.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
1-
import { DaemonProfile, Label, Text } from '@siafoundation/design-system'
1+
import { DaemonProfile, Label, Text, Link } from '@siafoundation/design-system'
22
import { useSyncStatus } from '../../hooks/useSyncStatus'
33
import {
44
useConsensusNetwork,
5+
useNodeState,
56
useSyncerPeers,
67
} from '@siafoundation/react-walletd'
78
import { useDialog } from '../../contexts/dialog'
9+
import { humanTime } from '@siafoundation/units'
810

911
export function Profile() {
1012
const { openDialog } = useDialog()
1113
const peers = useSyncerPeers()
1214
const syncStatus = useSyncStatus()
1315
const network = useConsensusNetwork()
16+
const state = useNodeState({
17+
config: {
18+
swr: {
19+
revalidateOnFocus: false,
20+
},
21+
},
22+
})
23+
24+
const version = state.data?.version
25+
const versionUrl =
26+
version === '?'
27+
? `https://github.com/SiaFoundation/walletd/commits/`
28+
: version?.match(/^v\d+\.\d+\.\d+/)
29+
? `https://github.com/SiaFoundation/walletd/releases/${version}`
30+
: `https://github.com/SiaFoundation/walletd/tree/${version}`
31+
32+
const uptime = state.data
33+
? new Date().getTime() - new Date(state.data?.startTime).getTime()
34+
: 0
35+
1436
return (
1537
<DaemonProfile
1638
name="walletd"
@@ -23,6 +45,16 @@ export function Profile() {
2345
firstTimeSyncing={syncStatus.firstTimeSyncing}
2446
moreThan100BlocksToSync={syncStatus.moreThan100BlocksToSync}
2547
>
48+
{state.data && (
49+
<div className="flex gap-4 justify-between items-center">
50+
<Label size="14" color="subtle" noWrap className="w-[100px]">
51+
Uptime
52+
</Label>
53+
<div className="flex-1 flex justify-end overflow-hidden -mr-0.5 pr-0.5">
54+
<Text size="14">{humanTime(uptime, { format: 'long' })}</Text>
55+
</div>
56+
</div>
57+
)}
2658
{network.data && (
2759
<div className="flex gap-4 justify-between items-center">
2860
<Label size="14" color="subtle" noWrap className="w-[100px]">
@@ -33,7 +65,7 @@ export function Profile() {
3365
</div>
3466
</div>
3567
)}
36-
{/* <div className="flex gap-4 justify-between items-center">
68+
<div className="flex gap-4 justify-between items-center">
3769
<Label size="14" color="subtle" noWrap className="w-[100px]">
3870
Version
3971
</Label>
@@ -46,7 +78,7 @@ export function Profile() {
4678
>
4779
{state.data?.version}
4880
</Link>
49-
</div> */}
81+
</div>
5082
</DaemonProfile>
5183
)
5284
}

libs/react-walletd/src/api.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ import {
3232
WalletMetadata,
3333
} from './siaTypes'
3434

35+
// state
36+
37+
export type StateResponse = {
38+
version: string
39+
commit: string
40+
os: string
41+
buildTime: string
42+
startTime: string
43+
}
44+
45+
export function useNodeState(args?: HookArgsSwr<void, StateResponse>) {
46+
return useGetSwr({
47+
...args,
48+
route: '/state',
49+
})
50+
}
51+
3552
// consensus
3653

3754
export type ConsensusTipResponse = ChainIndex

0 commit comments

Comments
 (0)