Skip to content

Commit

Permalink
fix: explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Sep 28, 2023
1 parent d313a62 commit 6b6a00a
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 91 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
ASSETS: ${{ github.workspace }}/assets
- name: Containers
shell: bash
run: npx nx run-many --target=container --configuration=production-testnet-zen -all --parallel=5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [![Sia Web](https://sia.tech/assets/banners/sia-banner-web.png)](http://sia.tech)
[![Sia Web](https://sia.tech/assets/banners/sia-banner-web.png)](http://sia.tech)

# Web

Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/app/opengraph-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { network, siaCentralApi } from '../config'
import { humanBytes } from '@siafoundation/sia-js'
import { PreviewValue } from '../components/OGImage/Preview'

export const revalidate = 60
export const revalidate = 0

export const alt = 'Contract'
export const size = {
Expand Down
76 changes: 7 additions & 69 deletions apps/explorer/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { Metadata } from 'next'
import { appLink, network, siaCentralApi } from '../config'
import { Home } from '../components/Home'
import {
SiaCentralBlock,
getSiaCentralBlock,
getSiaCentralBlockLatest,
getSiaCentralExchangeRates,
getSiaCentralHosts,
getSiaCentralHostsNetworkMetrics,
} from '@siafoundation/sia-central'
import { buildMetadata } from '../lib/utils'
import { humanBytes } from '@siafoundation/sia-js'
import { getLastFewBlocks } from '../lib/blocks'

export function generateMetadata(): Metadata {
const title = 'siascan'
Expand All @@ -25,7 +24,7 @@ export function generateMetadata(): Metadata {
})
}

export const revalidate = 60
export const revalidate = 0

export default async function HomePage() {
const [
Expand Down Expand Up @@ -60,90 +59,29 @@ export default async function HomePage() {
])

const lastBlockHeight = lb?.block.height || 0
const [one, two, three, four] = await Promise.all([
getSiaCentralBlock({
params: {
id: String(lastBlockHeight - 1),
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralBlock({
params: {
id: String(lastBlockHeight - 2),
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralBlock({
params: {
id: String(lastBlockHeight - 3),
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralBlock({
params: {
id: String(lastBlockHeight - 4),
},
config: {
api: siaCentralApi,
},
}),
])

const blocks: SiaCentralBlock[] = []
if (lastBlockHeight) {
if (lb) {
blocks.push(lb.block)
}
if (one.data) {
blocks.push(one.data.block)
}
if (two.data) {
blocks.push(two.data.block)
}
if (three.data) {
blocks.push(three.data.block)
}
if (four.data) {
blocks.push(four.data.block)
}
}
const blocks = await getLastFewBlocks(lb?.block)

if (
metricsError ||
latestBlockError ||
exchangeRatesError ||
hostsError ||
latestBlockError ||
one.error ||
two.error ||
three.error ||
four.error
blocks.error
) {
console.log(new Date().toISOString(), {
metricsError,
latestBlockError,
blockOneError: one.error,
blockTwoError: two.error,
blockThreeError: three.error,
blockFourError: four.error,
exchangeRatesError,
blocksError: blocks.error,
hostsError,
})
}

console.log(new Date().toISOString(), {
metrics: humanBytes(Buffer.byteLength(JSON.stringify(m || ''))),
latestBlock: humanBytes(Buffer.byteLength(JSON.stringify(lb || ''))),
blockOne: humanBytes(Buffer.byteLength(JSON.stringify(one || ''))),
blockTwo: humanBytes(Buffer.byteLength(JSON.stringify(two || ''))),
blockThree: humanBytes(Buffer.byteLength(JSON.stringify(three || ''))),
blockFour: humanBytes(Buffer.byteLength(JSON.stringify(four || ''))),
blocks: humanBytes(Buffer.byteLength(JSON.stringify(blocks || ''))),
exchangeRates: humanBytes(Buffer.byteLength(JSON.stringify(r || ''))),
hosts: humanBytes(Buffer.byteLength(JSON.stringify(h || ''))),
})
Expand All @@ -152,7 +90,7 @@ export default async function HomePage() {
<Home
metrics={m}
blockHeight={lastBlockHeight}
blocks={blocks}
blocks={blocks?.blocks || []}
hosts={h?.hosts || []}
rates={r?.rates}
/>
Expand Down
116 changes: 116 additions & 0 deletions apps/explorer/lib/blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { siaCentralApi } from '../config'
import {
SiaCentralBlock,
getSiaCentralBlock,
getSiaCentralBlocks,
} from '@siafoundation/sia-central'
import { range } from 'lodash'

export async function getLastFewBlocksOneByOne(block?: SiaCentralBlock) {
if (!block) {
return {
error: 'no block',
}
}
const lastBlockHeight = block.height || 0
const [one, two, three, four] = await Promise.all([
getSiaCentralBlock({
params: {
id: String(lastBlockHeight - 1),
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralBlock({
params: {
id: String(lastBlockHeight - 2),
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralBlock({
params: {
id: String(lastBlockHeight - 3),
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralBlock({
params: {
id: String(lastBlockHeight - 4),
},
config: {
api: siaCentralApi,
},
}),
])

const blocks: SiaCentralBlock[] = []
if (one.error) {
return {
error: one.error,
}
}
if (two.error) {
return {
error: two.error,
}
}
if (three.error) {
return {
error: three.error,
}
}
if (four.error) {
return {
error: four.error,
}
}
if (block) {
blocks.push(block)
}
if (one.data) {
blocks.push(one.data.block)
}
if (two.data) {
blocks.push(two.data.block)
}
if (three.data) {
blocks.push(three.data.block)
}
if (four.data) {
blocks.push(four.data.block)
}
return {
blocks,
}
}

export async function getLastFewBlocks(block?: SiaCentralBlock) {
if (!block) {
return {
error: 'no block',
}
}
const lastBlockHeight = block.height || 0
const response = await getSiaCentralBlocks({
payload: {
heights: range(lastBlockHeight - 4, lastBlockHeight),
},
config: {
api: siaCentralApi,
},
})

if (response.data?.blocks) {
return {
blocks: [block, ...response.data.blocks],
}
}
return {
error: response.data?.message,
}
}
10 changes: 2 additions & 8 deletions apps/explorer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"resolveJsonModule": true,
"isolatedModules": true,
"incremental": true,
"types": [
"jest",
"node"
],
"types": ["jest", "node"],
"plugins": [
{
"name": "next"
Expand All @@ -31,8 +28,5 @@
"../../dist/apps/explorer-testnet-zen/.next/types/**/*.ts",
"../../dist/apps/explorer/.next/types/**/*.ts"
],
"exclude": [
"node_modules",
"jest.config.ts"
]
"exclude": ["node_modules", "jest.config.ts"]
}
7 changes: 1 addition & 6 deletions apps/website/config/siteMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,9 @@ export const menuSections = [
links: [
{
link: webLinks.explore.mainnet,
title: 'Sia Foundation Explorer',
title: 'Siascan Explorer',
newTab: true,
},
// {
// link: webLinks.siaStats,
// title: 'SiaStats Explorer',
// newTab: true,
// },
{
link: webLinks.storageStats,
title: 'Sia Central Host Explorer',
Expand Down
2 changes: 1 addition & 1 deletion libs/data-sources/src/lib/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export function getAssetPath(filePath: string) {
}

export function getAssetsDirectory() {
return process.env['ASSETS'] || './'
return process.env['ASSETS'] || '/assets'
}
1 change: 0 additions & 1 deletion libs/design-system/src/data/webLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ export const webLinks = {
storageStats: 'https://hosts.siacentral.com/',
hostTroubleshoot: 'https://troubleshoot.siacentral.com/',
coinmarketcap: 'https://coinmarketcap.com/currencies/siacoin/',
// siaStats: 'https://siastats.info',
jobs: 'https://siafoundation.homerun.co/',
}
8 changes: 4 additions & 4 deletions server/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ beta.siascan.com {
api.siascan.com {
import cloudflare
encode gzip
# temporary, will be included in the explorer API

# temporary, will be included in the explorer API
handle_path /revenue* {
uri strip_prefix /revenue
reverse_proxy localhost:10005
}
}

handle_path /zen/revenue* {
uri strip_prefix /zen_revenue
reverse_proxy localhost:11005
}

route * {
respond 404
respond 404
}
}

Expand Down

0 comments on commit 6b6a00a

Please sign in to comment.