Skip to content

Commit

Permalink
fix(explorer): fix network request calls when navigating to block by …
Browse files Browse the repository at this point in the history
…height
  • Loading branch information
telestrial committed Nov 5, 2024
1 parent b70880f commit 6172484
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-eggs-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'explorer': minor
---

Fixed bug experienced when navigating directly to a block by its height.
34 changes: 19 additions & 15 deletions apps/explorer/app/block/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,28 @@ export function generateMetadata({ params }): Metadata {
export const revalidate = 0

export default async function Page({ params }) {
const id = params?.id as number
let id: string

// 1. Grab the tip at this height.
const [tipInfo, tipInfoError] = await to(
explored.consensusTipByHeight({ params: { height: id } })
)
// Check if the incoming id is referencing height.
if (!isNaN(Number(params?.id))) {
// If it is, we need the block ID.

if (tipInfoError) {
throw tipInfoError
}
if (!tipInfo) {
throw notFound()
// Grab the tip at this height.
const [tipInfo, tipInfoError] = await to(
explored.consensusTipByHeight({ params: { height: params?.id } })
)

if (tipInfoError) throw tipInfoError
if (!tipInfo) throw notFound()

id = tipInfo.id
} else {
// If it is not the height, it is referencing the ID. No call necessary.
id = params?.id
}

// 2. Get the block using the id from the previous request.
const [block, blockError] = await to(
explored.blockByID({ params: { id: tipInfo.id } })
)
// Get the block using the id from the previous request.
const [block, blockError] = await to(explored.blockByID({ params: { id } }))

if (blockError) {
throw blockError
Expand All @@ -59,5 +63,5 @@ export default async function Page({ params }) {
return notFound()
}

return <Block block={block} blockID={tipInfo.id} />
return <Block block={block} blockID={id} />
}

0 comments on commit 6172484

Please sign in to comment.