Skip to content

Commit

Permalink
fix: explorer host scan error
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Jan 27, 2024
1 parent b58aff8 commit f345609
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 107 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-plums-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'explorer': minor
---

Fixed an error where looking up a host was showing an error page for unscanned hosts.
13 changes: 13 additions & 0 deletions apps/explorer/app/host/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ export default async function Image({ params }) {
)
}

if (!h.host.settings) {
return getOGImage(
{
id: h.host.public_key,
title: h.host.net_address,
subtitle: truncate(h.host.public_key, 30),
initials: 'H',
avatar: true,
},
size
)
}

const values = [
{
label: 'storage',
Expand Down
5 changes: 4 additions & 1 deletion apps/explorer/components/Host/HostHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { hashToAvatar } from '../../lib/avatar'
import { HostPricing } from './HostPricing'
import { HostInfo } from './HostInfo'
import { SiaCentralHostScanned } from './types'

type Props = {
host: SiaCentralHost
Expand All @@ -30,7 +31,9 @@ export function HostHeader({ host, rates }: Props) {
/>
<div className="flex flex-wrap gap-3 items-start justify-between w-full">
<HostInfo host={host} />
<HostPricing host={host} rates={rates} />
{host.settings && (
<HostPricing host={host as SiaCentralHostScanned} rates={rates} />
)}
</div>
</div>
</div>
Expand Down
44 changes: 23 additions & 21 deletions apps/explorer/components/Host/HostInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,30 @@ export function HostInfo({ host }: Props) {
</Text>
</Text>
</Tooltip>
<Tooltip
content={
host.settings.accepting_contracts
? 'Host is accepting contracts'
: 'Host is not accepting contracts'
}
>
<Text
size="14"
color={host.settings.accepting_contracts ? 'green' : 'subtle'}
className="flex gap-1 items-center"
{host.settings && (
<Tooltip
content={
host.settings.accepting_contracts
? 'Host is accepting contracts'
: 'Host is not accepting contracts'
}
>
{host.settings.accepting_contracts ? (
<CheckmarkFilled16 />
) : (
<WarningFilled16 />
)}
{host.settings.accepting_contracts
? 'Accepting contracts'
: 'Not accepting contracts'}
</Text>
</Tooltip>
<Text
size="14"
color={host.settings.accepting_contracts ? 'green' : 'subtle'}
className="flex gap-1 items-center"
>
{host.settings.accepting_contracts ? (
<CheckmarkFilled16 />
) : (
<WarningFilled16 />
)}
{host.settings.accepting_contracts
? 'Accepting contracts'
: 'Not accepting contracts'}
</Text>
</Tooltip>
)}
</div>
<div className="flex flex-wrap gap-x-2 gap-y-1 items-center">
<Tooltip content={`Host version ${host.version}`}>
Expand Down
8 changes: 3 additions & 5 deletions apps/explorer/components/Host/HostPricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {
CloudUpload16,
VmdkDisk16,
} from '@siafoundation/react-icons'
import {
SiaCentralExchangeRates,
SiaCentralHost,
} from '@siafoundation/sia-central'
import { SiaCentralExchangeRates } from '@siafoundation/sia-central'
import { useMemo } from 'react'
import {
getDownloadCost,
Expand All @@ -21,9 +18,10 @@ import {
getUploadSpeed,
} from '@siafoundation/units'
import { useExchangeRate } from '../../hooks/useExchangeRate'
import { SiaCentralHostScanned } from './types'

type Props = {
host: SiaCentralHost
host: SiaCentralHostScanned
rates?: SiaCentralExchangeRates
}

Expand Down
8 changes: 3 additions & 5 deletions apps/explorer/components/Host/HostSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use client'

import { useMemo } from 'react'
import {
SiaCentralExchangeRates,
SiaCentralHost,
} from '@siafoundation/sia-central'
import { SiaCentralExchangeRates } from '@siafoundation/sia-central'
import { DatumProps, ExplorerDatum } from '../ExplorerDatum'
import { Panel, toFixedOrPrecision } from '@siafoundation/design-system'
import BigNumber from 'bignumber.js'
Expand All @@ -20,9 +17,10 @@ import {
} from '@siafoundation/units'
import { useExchangeRate } from '../../hooks/useExchangeRate'
import { siacoinToFiat } from '../../lib/currency'
import { SiaCentralHostScanned } from './types'

type Props = {
host: SiaCentralHost
host: SiaCentralHostScanned
rates?: SiaCentralExchangeRates
}

Expand Down
19 changes: 18 additions & 1 deletion apps/explorer/components/Host/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
import { ContentLayout } from '../ContentLayout'
import { HostHeader } from './HostHeader'
import { HostSettings } from './HostSettings'
import { Panel, Text } from '@siafoundation/design-system'
import { SiaCentralHostScanned } from './types'
import { formatDistance } from 'date-fns'

type Props = {
host: SiaCentralHost
Expand All @@ -14,7 +17,21 @@ type Props = {
export function Host({ host, rates }: Props) {
return (
<ContentLayout heading={<HostHeader host={host} rates={rates} />}>
<HostSettings host={host} rates={rates} />
{host.settings ? (
<HostSettings host={host as SiaCentralHostScanned} rates={rates} />
) : (
<Panel className="p-4 flex items-center">
<Text>
Detailed information will be available once the host has been
successfully scanned.
{host.last_scan !== '0001-01-01T00:00:00Z' &&
` Last scan attempt was ${formatDistance(
new Date(host.last_scan),
new Date()
)} ago.`}
</Text>
</Panel>
)}
</ContentLayout>
)
}
12 changes: 12 additions & 0 deletions apps/explorer/components/Host/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client'

import {
SiaCentralHost,
SiaCentralHostSettings,
} from '@siafoundation/sia-central'

export type SiaCentralHostScanned = SiaCentralHost & {
settings: SiaCentralHostSettings
// price_table: SiaCentralHostPriceTable
// benchmark: SiaCentralHostBenchmark
}
3 changes: 1 addition & 2 deletions apps/explorer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"**/*.js",
"**/*.jsx",
"next-env.d.ts",
"../../dist/apps/explorer-testnet-zen/.next/types/**/*.ts",
"../../dist/apps/explorer/.next/types/**/*.ts"
".next/types/**/*.ts"
],
"exclude": ["node_modules", "jest.config.ts"]
}
142 changes: 74 additions & 68 deletions libs/sia-central/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,77 @@ export type SiaCentralNetworkStats = {
}
}

export type SiaCentralHostSettings = {
netaddress: string
version: string
accepting_contracts: boolean
max_download_batch_size: number
max_duration: number
max_revise_batch_size: number
remaining_storage: number
sector_size: number
total_storage: number
window_size: number
revision_number: number
base_rpc_price: string
collateral: string
max_collateral: string
contract_price: string
download_price: string
sector_access_price: string
storage_price: string
upload_price: string
ephemeral_account_expiry: number
max_ephemeral_account_balance: string
sia_mux_port: string
}

export type SiaCentralHostPriceTable = {
uid: string
validity: number
hostblockheight: number
updatepricetablecost: string
accountbalancecost: string
fundaccountcost: string
latestrevisioncost: string
subscriptionmemorycost: string
subscriptionnotificationcost: string
initbasecost: string
memorytimecost: string
downloadbandwidthcost: string
uploadbandwidthcost: string
dropsectorsbasecost: string
dropsectorsunitcost: string
hassectorbasecost: string
readbasecost: string
readlengthcost: string
renewcontractcost: string
revisionbasecost: string
swapsectorcost: string
writebasecost: string
writelengthcost: string
writestorecost: string
txnfeeminrecommended: string
txnfeemaxrecommended: string
contractprice: string
collateralcost: string
maxcollateral: string
maxduration: number
windowsize: number
registryentriesleft: number
registryentriestotal: number
}

export type SiaCentralHostBenchmark = {
contract_time: number
upload_time: number
download_time: number
data_size: number
last_attempt: string
last_successful: string
error?: string
}

export type SiaCentralHost = {
net_address: string
public_key: string
Expand All @@ -80,74 +151,9 @@ export type SiaCentralHost = {
last_success_scan: string
country_code: string
location: [number, number]
settings: {
netaddress: string
version: string
accepting_contracts: boolean
max_download_batch_size: number
max_duration: number
max_revise_batch_size: number
remaining_storage: number
sector_size: number
total_storage: number
window_size: number
revision_number: number
base_rpc_price: string
collateral: string
max_collateral: string
contract_price: string
download_price: string
sector_access_price: string
storage_price: string
upload_price: string
ephemeral_account_expiry: number
max_ephemeral_account_balance: string
sia_mux_port: string
}
price_table: {
uid: string
validity: number
hostblockheight: number
updatepricetablecost: string
accountbalancecost: string
fundaccountcost: string
latestrevisioncost: string
subscriptionmemorycost: string
subscriptionnotificationcost: string
initbasecost: string
memorytimecost: string
downloadbandwidthcost: string
uploadbandwidthcost: string
dropsectorsbasecost: string
dropsectorsunitcost: string
hassectorbasecost: string
readbasecost: string
readlengthcost: string
renewcontractcost: string
revisionbasecost: string
swapsectorcost: string
writebasecost: string
writelengthcost: string
writestorecost: string
txnfeeminrecommended: string
txnfeemaxrecommended: string
contractprice: string
collateralcost: string
maxcollateral: string
maxduration: number
windowsize: number
registryentriesleft: number
registryentriestotal: number
}
benchmark: {
contract_time: number
upload_time: number
download_time: number
data_size: number
last_attempt: string
last_successful: string
error?: string
}
settings?: SiaCentralHostSettings
price_table?: SiaCentralHostPriceTable
benchmark?: SiaCentralHostBenchmark
}

export type SiaCentralContract = {
Expand Down
10 changes: 6 additions & 4 deletions libs/units/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ export function getUploadSpeed(host: SiaCentralPartialHost) {
}

export function getRemainingOverTotalStorage(host: SiaCentralHost) {
return `${humanBytes(host.settings.remaining_storage)}/${humanBytes(
host.settings.total_storage
)} remaining`
return host.settings
? `${humanBytes(host.settings.remaining_storage)}/${humanBytes(
host.settings.total_storage
)} remaining`
: '-'
}

export function getRemainingStorage(host: SiaCentralHost) {
return humanBytes(host.settings.remaining_storage)
return host.settings ? humanBytes(host.settings.remaining_storage) : '-'
}

0 comments on commit f345609

Please sign in to comment.