Skip to content

Commit

Permalink
fix: grant links, explorer logs and flatten blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Sep 27, 2023
1 parent 043bf82 commit bc9b654
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 41 deletions.
2 changes: 0 additions & 2 deletions apps/explorer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ COPY --chown=nextjs:nodejs ./dist/apps/explorer/.next/standalone ./
COPY --chown=nextjs:nodejs ./dist/apps/explorer/.next/static ./dist/apps/explorer/.next/static
COPY --chown=nextjs:nodejs ./dist/apps/explorer/public ./apps/explorer/public

RUN npm i sharp

USER nextjs
EXPOSE 3000

Expand Down
2 changes: 0 additions & 2 deletions apps/explorer/Dockerfile.zen
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ COPY --chown=nextjs:nodejs ./dist/apps/explorer-testnet-zen/.next/standalone ./
COPY --chown=nextjs:nodejs ./dist/apps/explorer-testnet-zen/.next/static ./dist/apps/explorer-testnet-zen/.next/static
COPY --chown=nextjs:nodejs ./dist/apps/explorer-testnet-zen/public ./apps/explorer/public

RUN npm i sharp

USER nextjs
EXPOSE 3000

Expand Down
17 changes: 17 additions & 0 deletions apps/explorer/app/api/revalidate/path/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { revalidatePath } from 'next/cache'
import { NextRequest, NextResponse } from 'next/server'

export async function GET(request: NextRequest) {
const path = request.nextUrl.searchParams.get('path')

if (path) {
revalidatePath(path)
return NextResponse.json({ revalidated: true, now: Date.now() })
}

return NextResponse.json({
revalidated: false,
now: Date.now(),
message: 'Missing path to revalidate',
})
}
17 changes: 17 additions & 0 deletions apps/explorer/app/api/revalidate/tag/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NextRequest, NextResponse } from 'next/server'
import { revalidateTag } from 'next/cache'

export async function GET(request: NextRequest) {
const tag = request.nextUrl.searchParams.get('tag')

if (tag) {
revalidateTag(tag)
return NextResponse.json({ revalidated: true, now: Date.now() })
}

return NextResponse.json({
revalidated: false,
now: Date.now(),
message: 'Missing tag to revalidate',
})
}
15 changes: 11 additions & 4 deletions apps/explorer/app/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { MetadataRoute } from 'next'
import { network } from '../config'

const title = 'siascan'
const description =
network === 'mainnet'
? 'Sia blockchain and host explorer.'
: 'Zen blockchain and host explorer.'

export default function manifest(): MetadataRoute.Manifest {
return {
name: 'Sia - Explorer',
short_name: 'Sia',
description: 'Sia blockchain explorer',
name: title,
short_name: title,
description,
start_url: '/',
display: 'standalone',
background_color: '#fff',
theme_color: '#fff',
icons: [
{
src: '/favicon.ico',
sizes: 'any',
sizes: '16x16',
type: 'image/x-icon',
},
],
Expand Down
90 changes: 75 additions & 15 deletions apps/explorer/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Metadata } from 'next'
import { appLink, network, siaCentralApi } from '../config'
import { Home } from '../components/Home'
import {
SiaCentralBlock,
getSiaCentralBlock,
getSiaCentralBlockLatest,
getSiaCentralBlocks,
getSiaCentralExchangeRates,
getSiaCentralHosts,
getSiaCentralHostsNetworkMetrics,
} from '@siafoundation/sia-central'
import { range } from 'lodash'
import { buildMetadata } from '../lib/utils'
import { humanBytes } from '@siafoundation/sia-js'

export function generateMetadata(): Metadata {
const title = 'siascan'
Expand All @@ -31,7 +32,7 @@ export default async function HomePage() {
{ data: m, error: metricsError },
{ data: lb, error: latestBlockError },
{ data: r, error: exchangeRatesError, },
{ data: h, error: hostsError }
{ data: h, error: hostsError },
] = await Promise.all([
getSiaCentralHostsNetworkMetrics({
config: {
Expand Down Expand Up @@ -59,30 +60,89 @@ export default async function HomePage() {
])

const lastBlockHeight = lb?.block.height || 0
const { data: bs, error: blocksError } = await getSiaCentralBlocks({
payload: {
heights: range(lastBlockHeight - 5, lastBlockHeight),
},
config: {
api: siaCentralApi,
},
})
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,
},
})
])

if (metricsError || latestBlockError || exchangeRatesError || hostsError || blocksError) {
console.log({
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)
}
}

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

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 || ''))),
exchangeRates: humanBytes(Buffer.byteLength(JSON.stringify(r || ''))),
hosts: humanBytes(Buffer.byteLength(JSON.stringify(h || ''))),
})

return (
<Home
metrics={m}
blockHeight={lastBlockHeight}
blocks={bs?.blocks || []}
blocks={blocks}
hosts={h?.hosts || []}
rates={r?.rates}
/>
Expand Down
2 changes: 0 additions & 2 deletions apps/hostd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ COPY --chown=nextjs:nodejs ./dist/apps/hostd/.next/standalone ./
COPY --chown=nextjs:nodejs ./dist/apps/hostd/.next/static ./dist/apps/hostd/.next/static
COPY --chown=nextjs:nodejs ./dist/apps/hostd/public ./apps/hostd/public

RUN npm i sharp

USER nextjs
EXPOSE 3000

Expand Down
2 changes: 0 additions & 2 deletions apps/renterd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ COPY --chown=nextjs:nodejs ./dist/apps/renterd/.next/standalone ./
COPY --chown=nextjs:nodejs ./dist/apps/renterd/.next/static ./dist/apps/renterd/.next/static
COPY --chown=nextjs:nodejs ./dist/apps/renterd/public ./apps/renterd/public

RUN npm i sharp

USER nextjs
EXPOSE 3000

Expand Down
2 changes: 0 additions & 2 deletions apps/walletd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ COPY --chown=nextjs:nodejs ./dist/apps/walletd/.next/standalone ./
COPY --chown=nextjs:nodejs ./dist/apps/walletd/.next/static ./dist/apps/walletd/.next/static
COPY --chown=nextjs:nodejs ./dist/apps/walletd/public ./apps/walletd/public

RUN npm i sharp

USER nextjs
EXPOSE 3000

Expand Down
2 changes: 0 additions & 2 deletions apps/website/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ COPY --chown=nextjs:nodejs ./dist/apps/website/.next/standalone ./
COPY --chown=nextjs:nodejs ./dist/apps/website/.next/static ./dist/apps/website/.next/static
COPY --chown=nextjs:nodejs ./dist/apps/website/public ./apps/website/public

RUN npm i sharp

USER nextjs
EXPOSE 3000

Expand Down
2 changes: 1 addition & 1 deletion apps/website/components/CalloutProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function CalloutProject({
{idea ? (
router.asPath.startsWith(routes.grants.index) ? (
<Link
href={webLinks.forumGrants}
href={webLinks.forumGrantsProposed}
target="_blank"
underline="accent"
color="contrast"
Expand Down
3 changes: 2 additions & 1 deletion apps/website/components/PageHead.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SitePageHead, webLinks } from '@siafoundation/design-system'
import { webLinks } from '@siafoundation/design-system'
import { SitePageHead } from './SitePageHead'
import { appName, newsFeedName } from '../config/app'
import { routes } from '../config/routes'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { webLinks } from '../data/webLinks'
import { webLinks } from '@siafoundation/design-system'
import Head from 'next/head'
import Script from 'next/script'

Expand Down
6 changes: 3 additions & 3 deletions apps/website/pages/grants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ export default function Grants({
</Li>
<Li>
Submit your proposal at{' '}
<Link href={webLinks.forumGrants} target="_blank">
{webLinks.forumGrants}
<Link href={webLinks.forumGrantsProposed} target="_blank">
{webLinks.forumGrantsProposed}
</Link>
.
</Li>
Expand Down Expand Up @@ -319,7 +319,7 @@ export default function Grants({
</>
}
actionTitle="Create a proposal"
actionLink={webLinks.forumGrants}
actionLink={webLinks.forumGrantsProposed}
actionNewTab
/>
</SectionGradient>
Expand Down
3 changes: 2 additions & 1 deletion libs/design-system/src/data/webLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const webLinks = {
twitterHandle: '@sia__foundation',
reddit: 'https://reddit.com/r/siacoin',
forum: 'https://forum.sia.tech/',
forumGrants: 'https://forum.sia.tech/c/grants/8',
forumGrants: 'https://forum.sia.tech/c/grants/',
forumGrantsProposed: 'https://forum.sia.tech/c/grants/proposed/',
merch: 'https://siagear.tech/',
email: '[email protected]',
benchmarks: 'https://benchmarks.sia.tech',
Expand Down
1 change: 0 additions & 1 deletion libs/design-system/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export * from './site/TransparentGradient'
export * from './site/PatternedPanel'
export * from './site/Callout'
export * from './site/Links'
export * from './site/SitePageHead'
export * from './site/NextAppSsrAppRouter'
export * from './site/NextAppCsr'
export * from './site/NextDocument'
Expand Down
4 changes: 2 additions & 2 deletions libs/sia-central/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ export type SiaCentralBlock = {
height: number
nonce: number[]
size: string
transactions: SiaCentralTransaction[]
siacoin_outputs: SiaCentralSiacoinOutput[]
transactions?: SiaCentralTransaction[]
siacoin_outputs?: SiaCentralSiacoinOutput[]
siafund_pool: string
timestamp: string
}
Expand Down

0 comments on commit bc9b654

Please sign in to comment.