Skip to content

Commit

Permalink
refactor: split out renterd-types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Apr 15, 2024
1 parent 387742e commit a399372
Show file tree
Hide file tree
Showing 43 changed files with 1,402 additions and 612 deletions.
3 changes: 1 addition & 2 deletions apps/renterd/contexts/alerts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import {
triggerErrorToast,
triggerSuccessToast,
} from '@siafoundation/design-system'
import { AlertSeverity, AlertsParams } from '@siafoundation/renterd-types'
import {
AlertSeverity,
AlertsParams,
useAlerts as useAlertsData,
useAlertsDismiss,
} from '@siafoundation/renterd-react'
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/config/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
GougingSettings,
RedundancySettings,
UploadPackingSettings,
} from '@siafoundation/renterd-react'
} from '@siafoundation/renterd-types'
import { SiaCentralHostsNetworkAveragesResponse } from '@siafoundation/sia-central'
import BigNumber from 'bignumber.js'
import { TBToBytes } from '@siafoundation/units'
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/config/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
GougingSettings,
RedundancySettings,
UploadPackingSettings,
} from '@siafoundation/renterd-react'
} from '@siafoundation/renterd-types'
import {
toHastings,
toSiacoins,
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/contracts/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ArrowUpLeft16, CheckmarkFilled16 } from '@siafoundation/react-icons'
import { humanBytes, humanDate } from '@siafoundation/units'
import { ContractData, TableColumnId } from './types'
import { ContractContextMenu } from '../../components/Contracts/ContractContextMenu'
import { ContractState } from '@siafoundation/renterd-react'
import { ContractState } from '@siafoundation/renterd-types'
import { cx } from 'class-variance-authority'

type Context = {
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/contracts/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContractState } from '@siafoundation/renterd-react'
import { ContractState } from '@siafoundation/renterd-types'
import BigNumber from 'bignumber.js'

export type ContractData = {
Expand Down
6 changes: 2 additions & 4 deletions apps/renterd/contexts/contracts/useContractMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import {
colors,
getDataIntervalLabelFormatter,
} from '@siafoundation/design-system'
import {
ContractMetricsParams,
useMetricsContract,
} from '@siafoundation/renterd-react'
import { ContractMetricsParams } from '@siafoundation/renterd-types'
import { useMetricsContract } from '@siafoundation/renterd-react'
import { useMemo } from 'react'
import BigNumber from 'bignumber.js'
import { ChartContractCategory, ChartContractKey } from './types'
Expand Down
6 changes: 2 additions & 4 deletions apps/renterd/contexts/filesDirectory/dataset.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
ObjectDirectoryParams,
useObjectDirectory,
} from '@siafoundation/renterd-react'
import { ObjectDirectoryParams } from '@siafoundation/renterd-types'
import { useObjectDirectory } from '@siafoundation/renterd-react'
import { useDataset as useDatasetGeneric } from '../filesManager/dataset'
import { bucketAndKeyParamsFromPath } from '../../lib/paths'
import { useRouter } from 'next/router'
Expand Down
5 changes: 3 additions & 2 deletions apps/renterd/contexts/filesFlat/dataset.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ObjectListParams, useObjectList } from '@siafoundation/renterd-react'
import { ObjectListPayload } from '@siafoundation/renterd-types'
import { useObjectList } from '@siafoundation/renterd-react'
import { SortField } from '../filesManager/types'
import { useDataset as useDatasetGeneric } from '../filesManager/dataset'
import { useRouter } from 'next/router'
Expand All @@ -20,7 +21,7 @@ export function useDataset({ sortDirection, sortField }: Props) {
const marker = router.query.marker as string

const params = useMemo(() => {
const p: ObjectListParams = {
const p: ObjectListPayload = {
bucket: activeBucketName,
sortBy: sortField,
sortDir: sortDirection,
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/filesManager/dataset.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjEntry } from '@siafoundation/renterd-react'
import { ObjEntry } from '@siafoundation/renterd-types'
import { sortBy, toPairs } from '@technically/lodash'
import useSWR from 'swr'
import { useContracts } from '../contracts'
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/filesManager/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bucket } from '@siafoundation/renterd-react'
import { Bucket } from '@siafoundation/renterd-types'
import { FullPath } from '../../lib/paths'
import { TableColumn } from '@siafoundation/design-system'
import { MultipartUpload } from '../../lib/multipartUpload'
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/filesManager/uploads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
minutesInMilliseconds,
triggerErrorToast,
} from '@siafoundation/design-system'
import { Bucket } from '@siafoundation/renterd-types'
import {
Bucket,
useBuckets,
useMultipartUploadAbort,
useMultipartUploadPart,
Expand Down
5 changes: 2 additions & 3 deletions apps/renterd/contexts/hosts/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import { HostContext, HostData, TableColumnId } from './types'
import { format, formatDistance, formatRelative } from 'date-fns'
import { HostContextMenu } from '../../components/Hosts/HostContextMenu'
import { useWorkflows } from '@siafoundation/react-core'
import { AutopilotHost, RhpScanPayload } from '@siafoundation/renterd-types'
import {
AutopilotHost,
RhpScanRequest,
useHostsAllowlist,
workerRhpScanRoute,
} from '@siafoundation/renterd-react'
Expand Down Expand Up @@ -215,7 +214,7 @@ export const columns: HostsTableColumn[] = (
render: function LastScan({ data }) {
const { workflows } = useWorkflows()
const isPending = workflows.find(
(wf: { path?: string; payload?: RhpScanRequest }) =>
(wf: { path?: string; payload?: RhpScanPayload }) =>
wf.path.startsWith(workerRhpScanRoute) &&
wf.payload?.hostKey === data.publicKey
)
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/hosts/dataset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useMemo } from 'react'
import BigNumber from 'bignumber.js'
import { HostData } from './types'
import { Host } from '@siafoundation/renterd-types'
import {
Host,
useAutopilotHostsSearch,
useHostsAllowlist,
useHostsBlocklist,
Expand Down
2 changes: 2 additions & 0 deletions apps/renterd/contexts/hosts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import {
HostsSearchFilterMode,
HostsUsabilityMode,
} from '@siafoundation/renterd-types'
import {
useAutopilotHostsSearch,
useHostsAllowlist,
useHostsBlocklist,
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/hosts/types.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AutopilotHost } from '@siafoundation/renterd-react'
import { AutopilotHost } from '@siafoundation/renterd-types'
import BigNumber from 'bignumber.js'
import { ContractData } from '../contracts/types'

Expand Down
3 changes: 2 additions & 1 deletion apps/renterd/hooks/useContractSetSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HookArgsSwr } from '@siafoundation/react-core'
import { ContractSetSettings, useSetting } from '@siafoundation/renterd-react'
import { ContractSetSettings } from '@siafoundation/renterd-types'
import { useSetting } from '@siafoundation/renterd-react'

export function useContractSetSettings(
args?: HookArgsSwr<void, ContractSetSettings>
Expand Down
3 changes: 2 additions & 1 deletion apps/renterd/hooks/useGougingSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HookArgsSwr } from '@siafoundation/react-core'
import { GougingSettings, useSetting } from '@siafoundation/renterd-react'
import { GougingSettings } from '@siafoundation/renterd-types'
import { useSetting } from '@siafoundation/renterd-react'

export function useGougingSettings(args?: HookArgsSwr<void, GougingSettings>) {
return useSetting<GougingSettings>({
Expand Down
3 changes: 2 additions & 1 deletion apps/renterd/hooks/useRedundancySettings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HookArgsSwr } from '@siafoundation/react-core'
import { RedundancySettings, useSetting } from '@siafoundation/renterd-react'
import { RedundancySettings } from '@siafoundation/renterd-types'
import { useSetting } from '@siafoundation/renterd-react'

export function useRedundancySettings(
args?: HookArgsSwr<void, RedundancySettings>
Expand Down
6 changes: 2 additions & 4 deletions apps/renterd/hooks/useS3AuthenticationSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { HookArgsSwr } from '@siafoundation/react-core'
import {
S3AuthenticationSettings,
useSetting,
} from '@siafoundation/renterd-react'
import { S3AuthenticationSettings } from '@siafoundation/renterd-types'
import { useSetting } from '@siafoundation/renterd-react'

export function useS3AuthenticationSettings(
args?: HookArgsSwr<void, S3AuthenticationSettings>
Expand Down
3 changes: 2 additions & 1 deletion apps/renterd/hooks/useUploadPackingSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HookArgsSwr } from '@siafoundation/react-core'
import { UploadPackingSettings, useSetting } from '@siafoundation/renterd-react'
import { UploadPackingSettings } from '@siafoundation/renterd-types'
import { useSetting } from '@siafoundation/renterd-react'

export function useUploadPackingSettings(
args?: HookArgsSwr<void, UploadPackingSettings>
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/lib/health.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Obj, SlabSlice } from '@siafoundation/renterd-react'
import { Obj, SlabSlice } from '@siafoundation/renterd-types'
import { min } from '@technically/lodash'
import { ContractData } from '../contexts/contracts/types'

Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/mock/mock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SetupServer } from 'msw/node'
import { HttpResponse, http } from 'msw'
import { Bucket, RedundancySettings } from '@siafoundation/renterd-react'
import { Bucket, RedundancySettings } from '@siafoundation/renterd-types'

export function mockApiBusBuckets(server: SetupServer) {
server.use(
Expand Down
10 changes: 4 additions & 6 deletions libs/renterd-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
"description": " React hooks for interacting with `renterd`.",
"version": "4.0.0",
"license": "MIT",
"peerDependencies": {
"@siafoundation/react-core": "^1.1.0",
"@siafoundation/types": "^0.2.0",
"swr": "^2.1.1"
},
"dependencies": {
"@technically/lodash": "^4.17.0"
"@technically/lodash": "^4.17.0",
"@siafoundation/react-core": "^1.1.0",
"swr": "^2.1.1",
"@siafoundation/renterd-types": "0.0.0"
},
"types": "./src/index.d.ts"
}
80 changes: 36 additions & 44 deletions libs/renterd-react/src/autopilot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AutopilotConfig, Host } from './siaTypes'
import { HostsSearchPayload, StateResponse } from './bus'
import {
useGetSwr,
usePostSwr,
Expand All @@ -10,38 +8,49 @@ import {
delay,
usePostFunc,
} from '@siafoundation/react-core'

type AutopilotStatus = {
configured: boolean
migrating: boolean
migratingLastStart: string
scanning: boolean
scanningLastStart: string
synced: boolean
uptimeMS: string
}

export type AutopilotState = AutopilotStatus & StateResponse
import {
AutopilotConfigParams,
AutopilotConfigResponse,
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse,
AutopilotHostsSearchParams,
AutopilotHostsSearchPayload,
AutopilotHostsSearchResponse,
AutopilotStateParams,
AutopilotStateResponse,
AutopilotTriggerParams,
AutopilotTriggerPayload,
AutopilotTriggerResponse,
} from '@siafoundation/renterd-types'

const autopilotStateKey = '/autopilot/state'

export function useAutopilotState(args?: HookArgsSwr<void, AutopilotState>) {
export function useAutopilotState(
args?: HookArgsSwr<AutopilotStateParams, AutopilotStateResponse>
) {
return useGetSwr({
...args,
route: autopilotStateKey,
})
}

const autopilotConfigKey = '/autopilot/config'
export function useAutopilotConfig(args?: HookArgsSwr<void, AutopilotConfig>) {
export function useAutopilotConfig(
args?: HookArgsSwr<AutopilotConfigParams, AutopilotConfigResponse>
) {
return useGetSwr({
...args,
route: autopilotConfigKey,
})
}

export function useAutopilotConfigUpdate(
args?: HookArgsCallback<void, AutopilotConfig, void>
args?: HookArgsCallback<
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse
>
) {
return usePutFunc({ ...args, route: autopilotConfigKey }, async (mutate) => {
mutate((key) => key === autopilotConfigKey)
Expand All @@ -55,35 +64,14 @@ export function useAutopilotConfigUpdate(
})
}

export type AutopilotHost = {
host: Host
checks?: {
score: number
scoreBreakdown: {
age: number
collateral: number
interactions: number
storageRemaining: number
prices: number
uptime: number
version: number
}
unusableReasons: string[]
gougingBreakdown: {
contractErr?: string
downloadErr?: string
gougingErr?: string
uploadErr?: string
}
gouging: boolean
usable: boolean
}
}

export const autopilotHostsKey = '/autopilot/hosts'

export function useAutopilotHostsSearch(
args?: HookArgsWithPayloadSwr<void, HostsSearchPayload, AutopilotHost[]>
args?: HookArgsWithPayloadSwr<
AutopilotHostsSearchParams,
AutopilotHostsSearchPayload,
AutopilotHostsSearchResponse
>
) {
return usePostSwr({
...args,
Expand All @@ -92,7 +80,11 @@ export function useAutopilotHostsSearch(
}

export function useAutopilotTrigger(
args?: HookArgsCallback<void, { forceScan: boolean }, { triggered: boolean }>
args?: HookArgsCallback<
AutopilotTriggerParams,
AutopilotTriggerPayload,
AutopilotTriggerResponse
>
) {
return usePostFunc({
...args,
Expand Down
Loading

0 comments on commit a399372

Please sign in to comment.