@@ -3,29 +3,25 @@ import BigNumber from 'bignumber.js'
3
3
import { HostData } from './types'
4
4
import { Host } from '@siafoundation/renterd-types'
5
5
import {
6
- useAutopilotHostsSearch ,
7
6
useHostsAllowlist ,
8
7
useHostsBlocklist ,
9
- useHostsSearch ,
8
+ useHosts ,
10
9
} from '@siafoundation/renterd-react'
11
10
import { ContractData } from '../contracts/types'
12
- import { useApp } from '../app'
13
11
import { SiaCentralHost } from '@siafoundation/sia-central-types'
14
12
15
13
export function useDataset ( {
16
- autopilotStatus,
17
- regularResponse,
18
- autopilotResponse,
14
+ response,
19
15
allContracts,
16
+ autopilotID,
20
17
allowlist,
21
18
blocklist,
22
19
isAllowlistActive,
23
20
geoHosts,
24
21
onHostSelect,
25
22
} : {
26
- autopilotStatus : ReturnType < typeof useApp > [ 'autopilot' ] [ 'status' ]
27
- regularResponse : ReturnType < typeof useHostsSearch >
28
- autopilotResponse : ReturnType < typeof useAutopilotHostsSearch >
23
+ response : ReturnType < typeof useHosts >
24
+ autopilotID : string
29
25
allContracts : ContractData [ ]
30
26
allowlist : ReturnType < typeof useHostsAllowlist >
31
27
blocklist : ReturnType < typeof useHostsBlocklist >
@@ -34,51 +30,28 @@ export function useDataset({
34
30
onHostSelect : ( publicKey : string , location ?: [ number , number ] ) => void
35
31
} ) {
36
32
return useMemo < HostData [ ] | null > ( ( ) => {
37
- if ( autopilotStatus === 'off' ) {
38
- return (
39
- regularResponse . data ?. map ( ( host ) => {
40
- const sch = geoHosts . find ( ( gh ) => gh . public_key === host . publicKey )
41
- return {
42
- onClick : ( ) => onHostSelect ( host . publicKey , sch ?. location ) ,
43
- ...getHostFields ( host , allContracts ) ,
44
- ...getAllowedFields ( {
45
- host,
46
- allowlist : allowlist . data ,
47
- blocklist : blocklist . data ,
48
- isAllowlistActive,
49
- } ) ,
50
- ...getAutopilotFields ( ) ,
51
- location : sch ?. location ,
52
- countryCode : sch ?. country_code ,
53
- }
54
- } ) || null
55
- )
56
- } else if ( autopilotStatus === 'on' ) {
57
- return (
58
- autopilotResponse . data ?. map ( ( ah ) => {
59
- const sch = geoHosts . find ( ( gh ) => gh . public_key === ah . host . publicKey )
60
- return {
61
- onClick : ( ) => onHostSelect ( ah . host . publicKey , sch ?. location ) ,
62
- ...getHostFields ( ah . host , allContracts ) ,
63
- ...getAllowedFields ( {
64
- host : ah . host ,
65
- allowlist : allowlist . data ,
66
- blocklist : blocklist . data ,
67
- isAllowlistActive,
68
- } ) ,
69
- ...getAutopilotFields ( ah . checks ) ,
70
- location : sch ?. location ,
71
- countryCode : sch ?. country_code ,
72
- }
73
- } ) || null
74
- )
75
- }
76
- return null
33
+ return (
34
+ response . data ?. map ( ( host ) => {
35
+ const sch = geoHosts . find ( ( gh ) => gh . public_key === host . publicKey )
36
+ return {
37
+ onClick : ( ) => onHostSelect ( host . publicKey , sch ?. location ) ,
38
+ ...getHostFields ( host , allContracts ) ,
39
+ ...getAllowedFields ( {
40
+ host,
41
+ allowlist : allowlist . data ,
42
+ blocklist : blocklist . data ,
43
+ isAllowlistActive,
44
+ } ) ,
45
+ ...getAutopilotFields ( host . checks ?. [ autopilotID ] ) ,
46
+ location : sch ?. location ,
47
+ countryCode : sch ?. country_code ,
48
+ }
49
+ } ) || null
50
+ )
77
51
} , [
78
52
onHostSelect ,
79
- autopilotStatus ,
80
- regularResponse . data ,
81
- autopilotResponse . data ,
53
+ autopilotID ,
54
+ response . data ,
82
55
allContracts ,
83
56
allowlist . data ,
84
57
blocklist . data ,
@@ -159,42 +132,52 @@ function getAllowedFields({
159
132
}
160
133
161
134
function getAutopilotFields ( ahc ?: {
162
- score : number
163
- gougingBreakdown : {
164
- contractErr ?: string
165
- downloadErr ?: string
166
- gougingErr ?: string
167
- uploadErr ?: string
168
- }
169
- gouging : boolean
170
- scoreBreakdown : {
135
+ score : {
171
136
age : number
172
137
collateral : number
173
138
interactions : number
174
- prices : number
175
139
storageRemaining : number
140
+ prices : number
176
141
uptime : number
177
142
version : number
178
143
}
179
- unusableReasons : string [ ]
180
- usable : boolean
144
+ gouging : {
145
+ contractErr ?: string
146
+ downloadErr ?: string
147
+ gougingErr ?: string
148
+ uploadErr ?: string
149
+ pruneErr ?: string
150
+ }
151
+ usability : {
152
+ blocked : boolean
153
+ gouging : boolean
154
+ lowScore : boolean
155
+ notAcceptingContracts : boolean
156
+ notAnnounced : boolean
157
+ notCompletingScan : boolean
158
+ offline : boolean
159
+ redundantIP : boolean
160
+ }
181
161
} ) {
182
162
return {
183
- score : new BigNumber ( ahc ?. score || 0 ) ,
184
- scoreBreakdown : {
185
- age : new BigNumber ( ahc ?. scoreBreakdown . age || 0 ) ,
186
- collateral : new BigNumber ( ahc ?. scoreBreakdown . collateral || 0 ) ,
187
- interactions : new BigNumber ( ahc ?. scoreBreakdown . interactions || 0 ) ,
188
- prices : new BigNumber ( ahc ?. scoreBreakdown . prices || 0 ) ,
189
- storageRemaining : new BigNumber (
190
- ahc ?. scoreBreakdown . storageRemaining || 0
191
- ) ,
192
- uptime : new BigNumber ( ahc ?. scoreBreakdown . uptime || 0 ) ,
193
- version : new BigNumber ( ahc ?. scoreBreakdown . version || 0 ) ,
194
- } ,
195
- gougingBreakdown : ahc ?. gougingBreakdown || { } ,
163
+ score : ahc
164
+ ? {
165
+ age : new BigNumber ( ahc ?. score . age || 0 ) ,
166
+ collateral : new BigNumber ( ahc ?. score . collateral || 0 ) ,
167
+ interactions : new BigNumber ( ahc ?. score . interactions || 0 ) ,
168
+ prices : new BigNumber ( ahc ?. score . prices || 0 ) ,
169
+ storageRemaining : new BigNumber ( ahc ?. score . storageRemaining || 0 ) ,
170
+ uptime : new BigNumber ( ahc ?. score . uptime || 0 ) ,
171
+ version : new BigNumber ( ahc ?. score . version || 0 ) ,
172
+ }
173
+ : undefined ,
174
+ isGouging : ahc
175
+ ? Object . values ( ahc . gouging || { } ) . some ( ( v ) => v )
176
+ : undefined ,
177
+ isUsable : ahc
178
+ ? Object . values ( ahc . usability || { } ) . every ( ( v ) => ! v )
179
+ : undefined ,
196
180
gouging : ahc ?. gouging ,
197
- unusableReasons : ahc ?. unusableReasons || [ ] ,
198
- usable : ahc ?. usable ,
181
+ usability : ahc ?. usability ,
199
182
}
200
183
}
0 commit comments