Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: explorer host unscanned error #475

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 3 additions & 5 deletions apps/explorer/components/Home/HostListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import {
CloudUpload16,
VmdkDisk16,
} from '@siafoundation/react-icons'
import {
SiaCentralExchangeRates,
SiaCentralHost,
} from '@siafoundation/sia-central'
import { SiaCentralExchangeRates } from '@siafoundation/sia-central'
import {
getDownloadCost,
getDownloadSpeed,
Expand All @@ -28,9 +25,10 @@ import {
import { useMemo } from 'react'
import { routes } from '../../config/routes'
import { useExchangeRate } from '../../hooks/useExchangeRate'
import { SiaCentralHostScanned } from '../Host/types'

type Props = {
host: SiaCentralHost
host: SiaCentralHostScanned
rates?: SiaCentralExchangeRates
entity: EntityListItemLayoutProps
}
Expand Down
29 changes: 16 additions & 13 deletions apps/explorer/components/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '@siafoundation/units'
import { HostListItem } from './HostListItem'
import { useExchangeRate } from '../../hooks/useExchangeRate'
import { SiaCentralHostScanned } from '../Host/types'

export function Home({
metrics,
Expand Down Expand Up @@ -222,19 +223,21 @@ export function Home({
</div>
<div>
<EntityList title="Top hosts">
{hosts.map((host) => (
<HostListItem
key={host.public_key}
host={host}
rates={rates}
entity={{
label: host.net_address,
initials: 'H',
avatar: hashToAvatar(host.public_key),
href: routes.host.view.replace(':id', host.public_key),
}}
/>
))}
{hosts
.filter((host) => host.settings)
.map((host) => (
<HostListItem
key={host.public_key}
host={host as SiaCentralHostScanned}
rates={rates}
entity={{
label: host.net_address,
initials: 'H',
avatar: hashToAvatar(host.public_key),
href: routes.host.view.replace(':id', host.public_key),
}}
/>
))}
</EntityList>
</div>
</div>
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"]
}
Loading
Loading