Skip to content

Commit

Permalink
feat: hostd v2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Aug 12, 2024
1 parent 6ad3f2f commit 2cf55b9
Show file tree
Hide file tree
Showing 41 changed files with 861 additions and 340 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-hats-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/design-system': minor
---

The TransactionDetailsDialog now supports an Event type instead of txType.
7 changes: 7 additions & 0 deletions .changeset/famous-pears-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/hostd-js': minor
'@siafoundation/hostd-react': minor
'@siafoundation/hostd-types': minor
---

Updated with v2 endpoints and data types. Closes https://github.com/SiaFoundation/hostd/issues/440
9 changes: 9 additions & 0 deletions .changeset/kind-trains-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@siafoundation/hostd-js': minor
'@siafoundation/hostd-react': minor
'@siafoundation/hostd-types': minor
'@siafoundation/types': minor
'@siafoundation/walletd-types': minor
---

Core Event types have been moved to the core types library. Closes https://github.com/SiaFoundation/hostd/issues/440
5 changes: 5 additions & 0 deletions .changeset/old-hounds-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hostd': minor
---

The app has been updated to use the new v2 endpoints and data types. Closes https://github.com/SiaFoundation/hostd/issues/440
6 changes: 6 additions & 0 deletions .changeset/two-olives-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'walletd': minor
'@siafoundation/units': minor
---

Event and transaction utility methods have been moved to the units library.
4 changes: 2 additions & 2 deletions apps/hostd-e2e/src/specs/volumes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from '../fixtures/volumes'

test('can create and delete a volume', async ({ page }) => {
const name = 'my-new-bucket'
const path = '/tmp'
const name = 'my-new-volume'
const path = '/data'
await login({ page })
await navigateToVolumes({ page })
await deleteVolumeIfExists(page, name, path)
Expand Down
6 changes: 3 additions & 3 deletions apps/hostd/components/CmdRoot/WalletCmdGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { routes } from '../../config/routes'
import { useRouter } from 'next/router'
import { useDialog } from '../../contexts/dialog'
import { CommandGroup, CommandItemNav, CommandItemSearch } from './Item'
import { useStateHost } from '@siafoundation/hostd-react'
import { useWallet } from '@siafoundation/hostd-react'
import { Page } from './types'

const commandPage = {
Expand All @@ -20,7 +20,7 @@ type Props = {
export function WalletCmdGroup({ currentPage, parentPage, pushPage }: Props) {
const { openDialog, closeDialog } = useDialog()
const router = useRouter()
const state = useStateHost({
const wallet = useWallet({
config: {
swr: {
revalidateOnFocus: false,
Expand Down Expand Up @@ -81,7 +81,7 @@ export function WalletCmdGroup({ currentPage, parentPage, pushPage }: Props) {
currentPage={currentPage}
commandPage={commandPage}
onSelect={() => {
copyToClipboard(state.data?.walletAddress, 'wallet address')
copyToClipboard(wallet.data?.address, 'wallet address')
closeDialog()
}}
>
Expand Down
4 changes: 2 additions & 2 deletions apps/hostd/components/Config/AnnounceButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useDialog } from '../../contexts/dialog'
import {
useSettings,
useSettingsAnnounce,
useStateHost,
useHostState,
useTxPoolFee,
} from '@siafoundation/hostd-react'
import { humanSiacoin } from '@siafoundation/units'
Expand All @@ -21,7 +21,7 @@ export function AnnounceButton() {
const { openConfirmDialog } = useDialog()
const txpoolFee = useTxPoolFee()
const settingsAnnounce = useSettingsAnnounce()
const host = useStateHost()
const host = useHostState()
const settings = useSettings({
config: {
swr: {
Expand Down
8 changes: 4 additions & 4 deletions apps/hostd/components/HostdTestnetWarningBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { TestnetWarningBanner } from '@siafoundation/design-system'
import { useStateHost } from '@siafoundation/hostd-react'
import { useConsensusNetwork } from '@siafoundation/hostd-react'

export function HostdTestnetWarningBanner() {
const host = useStateHost({
const host = useConsensusNetwork({
config: {
swr: {
revalidateOnFocus: false,
},
},
})

if (!host.data || host.data.network === 'Mainnet') {
if (!host.data || host.data.name === 'mainnet') {
return null
}

return <TestnetWarningBanner testnetName={host.data.network} />
return <TestnetWarningBanner testnetName={host.data.name} />
}
24 changes: 20 additions & 4 deletions apps/hostd/components/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
} from '@siafoundation/design-system'
import {
useSettings,
useStateHost,
useHostState,
useSyncerPeers,
useWallet,
useConsensusNetwork,
} from '@siafoundation/hostd-react'
import { useSyncStatus } from '../../hooks/useSyncStatus'
import { useDialog } from '../../contexts/dialog'
Expand All @@ -17,7 +19,21 @@ import { humanTime } from '@siafoundation/units'

export function Profile() {
const { openDialog } = useDialog()
const state = useStateHost({
const state = useHostState({
config: {
swr: {
revalidateOnFocus: false,
},
},
})
const wallet = useWallet({
config: {
swr: {
revalidateOnFocus: false,
},
},
})
const network = useConsensusNetwork({
config: {
swr: {
revalidateOnFocus: false,
Expand Down Expand Up @@ -94,7 +110,7 @@ export function Profile() {
<ValueCopyable
size="14"
maxLength={24}
value={state.data?.walletAddress}
value={wallet.data?.address}
type="address"
/>
</div>
Expand All @@ -114,7 +130,7 @@ export function Profile() {
Network
</Label>
<div className="flex-1 flex justify-end overflow-hidden">
<Text size="14">{state.data?.network}</Text>
<Text size="14">{network.data?.name}</Text>
</div>
</div>
<div className="flex gap-2 justify-between items-center">
Expand Down
15 changes: 15 additions & 0 deletions apps/hostd/components/Wallet/StateError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Text } from '@siafoundation/design-system'
import { MisuseOutline32 } from '@siafoundation/react-icons'

export function StateError() {
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px]">
<Text>
<MisuseOutline32 className="scale-[200%]" />
</Text>
<Text color="subtle" className="text-center max-w-[500px]">
Error fetching transactions.
</Text>
</div>
)
}
15 changes: 15 additions & 0 deletions apps/hostd/components/Wallet/StateNoneMatching.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Text } from '@siafoundation/design-system'
import { Filter32 } from '@siafoundation/react-icons'

export function StateNoneMatching() {
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px]">
<Text>
<Filter32 className="scale-[200%]" />
</Text>
<Text color="subtle" className="text-center max-w-[500px]">
No transactions matching filters.
</Text>
</div>
)
}
15 changes: 15 additions & 0 deletions apps/hostd/components/Wallet/StateNoneYet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Text } from '@siafoundation/design-system'
import { Money32 } from '@siafoundation/react-icons'

export function StateNoneYet() {
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px]">
<Text>
<Money32 className="scale-[200%]" />
</Text>
<Text color="subtle" className="text-center max-w-[500px]">
The wallet has no transactions yet.
</Text>
</div>
)
}
52 changes: 35 additions & 17 deletions apps/hostd/components/Wallet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {
EntityList,
WalletLayoutActions,
BalanceEvolution,
PaginatorUnknownTotal,
Table,
} from '@siafoundation/design-system'
import { useWallet } from '@siafoundation/hostd-react'
import { useDialog } from '../../contexts/dialog'
Expand All @@ -11,18 +10,30 @@ import BigNumber from 'bignumber.js'
import { HostdSidenav } from '../HostdSidenav'
import { HostdAuthedLayout } from '../HostdAuthedLayout'
import { useSyncStatus } from '../../hooks/useSyncStatus'
import { EmptyState } from './EmptyState'
import { useTransactions } from '../../contexts/transactions'
import { WalletFilterBar } from './WalletFilterBar'
import { StateNoneMatching } from './StateNoneMatching'
import { StateNoneYet } from './StateNoneYet'
import { StateError } from './StateError'

export function Wallet() {
const { openDialog } = useDialog()
const wallet = useWallet()
const { isSynced, isWalletSynced, syncPercent, walletScanPercent } =
useSyncStatus()

const { dataset, balances, metrics, offset, limit, dataState, pageCount } =
useTransactions()
const {
balances,
metrics,
dataset,
dataState,
columns,
cellContext,
sortableColumns,
sortDirection,
sortField,
toggleSort,
} = useTransactions()

return (
<HostdAuthedLayout
Expand Down Expand Up @@ -51,26 +62,33 @@ export function Wallet() {
}
stats={<WalletFilterBar />}
>
<div className="p-6 flex flex-col gap-5">
<div className="flex flex-col gap-4 px-6 py-7 min-w-fit">
{balances?.length && balances.find((b) => b.sc) ? (
<BalanceEvolution
balances={balances}
isLoading={metrics.isValidating}
/>
) : null}
<EntityList
title="Transactions"
dataset={dataset}
<Table
testId="transactionsTable"
isLoading={dataState === 'loading'}
emptyState={<EmptyState />}
actions={
<PaginatorUnknownTotal
offset={offset}
limit={limit}
pageTotal={pageCount}
isLoading={dataState === 'loading'}
/>
emptyState={
dataState === 'noneMatchingFilters' ? (
<StateNoneMatching />
) : dataState === 'noneYet' ? (
<StateNoneYet />
) : dataState === 'error' ? (
<StateError />
) : null
}
pageSize={6}
data={dataset}
context={cellContext}
columns={columns}
sortableColumns={sortableColumns}
sortDirection={sortDirection}
sortField={sortField}
toggleSort={toggleSort}
/>
</div>
</HostdAuthedLayout>
Expand Down
4 changes: 2 additions & 2 deletions apps/hostd/config/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stateHostRoute } from '@siafoundation/hostd-types'
import { hostStateRoute } from '@siafoundation/hostd-types'

export const routes = {
home: '/',
Expand Down Expand Up @@ -28,4 +28,4 @@ export const routes = {
login: '/login',
}

export const connectivityRoute = stateHostRoute
export const connectivityRoute = hostStateRoute
4 changes: 2 additions & 2 deletions apps/hostd/contexts/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
checkIfAnyResourcesErrored,
} from './resources'
import { useOnValid } from './useOnValid'
import { useStateHost } from '@siafoundation/hostd-react'
import { useHostState } from '@siafoundation/hostd-react'

export function useConfigMain() {
const { settings, settingsPinned, dynDNSCheck } = useResources()
Expand Down Expand Up @@ -54,7 +54,7 @@ export function useConfigMain() {
[resources]
)

const state = useStateHost()
const state = useHostState()
const pinningEnabled = state.data?.explorer.enabled
const revalidateAndResetForm = useCallback(async () => {
const _settings = await settings.mutate()
Expand Down
4 changes: 2 additions & 2 deletions apps/hostd/contexts/config/useForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect, useMemo, useRef } from 'react'
import { getFields } from './fields'
import useLocalStorageState from 'use-local-storage-state'
import { useSiaCentralExchangeRates } from '@siafoundation/sia-central-react'
import { useStateHost } from '@siafoundation/hostd-react'
import { useHostState } from '@siafoundation/hostd-react'
import { useAutoCalculatedFields } from './useAutoCalculatedFields'

export function useForm() {
Expand All @@ -25,7 +25,7 @@ export function useForm() {
})

const rates = useSiaCentralExchangeRates()
const state = useStateHost()
const state = useHostState()
const pinningEnabled = state.data?.explorer.enabled
// Field validation is only re-applied on re-mount,
// so we pass a ref with latest data that can be used interally.
Expand Down
Loading

0 comments on commit 2cf55b9

Please sign in to comment.