From 8e9c19507b66c6046cfa45d50ae1e816ed26d1a6 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner Date: Fri, 15 Nov 2024 16:36:05 -0500 Subject: [PATCH] add support for block hash and extrinsic hash dynamic route --- explorer/src/components/Consensus/Block/Block.tsx | 2 +- explorer/src/components/Consensus/Block/query.ts | 6 ++++-- explorer/src/components/Consensus/Extrinsic/query.ts | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/explorer/src/components/Consensus/Block/Block.tsx b/explorer/src/components/Consensus/Block/Block.tsx index c5f00893..556d0386 100644 --- a/explorer/src/components/Consensus/Block/Block.tsx +++ b/explorer/src/components/Consensus/Block/Block.tsx @@ -25,7 +25,7 @@ export const Block: FC = () => { const { loading, setIsVisible } = useSquidQuery( QUERY_BLOCK_BY_ID, { - variables: { blockId: blockId ?? '0' }, + variables: { blockId: blockId ?? '0', blockHash: blockId?.toString() ?? '' }, skip: !inFocus, }, Routes.consensus, diff --git a/explorer/src/components/Consensus/Block/query.ts b/explorer/src/components/Consensus/Block/query.ts index f89c8fb9..de5c3d86 100644 --- a/explorer/src/components/Consensus/Block/query.ts +++ b/explorer/src/components/Consensus/Block/query.ts @@ -30,8 +30,10 @@ export const QUERY_BLOCKS = gql` ` export const QUERY_BLOCK_BY_ID = gql` - query BlockById($blockId: numeric!) { - consensus_blocks(where: { height: { _eq: $blockId } }) { + query BlockById($blockId: numeric!, $blockHash: String!) { + consensus_blocks( + where: { _or: [{ height: { _eq: $blockId } }, { hash: { _eq: $blockHash } }] } + ) { id height hash diff --git a/explorer/src/components/Consensus/Extrinsic/query.ts b/explorer/src/components/Consensus/Extrinsic/query.ts index d7b15772..aea007df 100644 --- a/explorer/src/components/Consensus/Extrinsic/query.ts +++ b/explorer/src/components/Consensus/Extrinsic/query.ts @@ -30,7 +30,9 @@ export const QUERY_EXTRINSICS = gql` export const QUERY_EXTRINSIC_BY_ID = gql` query ExtrinsicsById($extrinsicId: String!) { - consensus_extrinsics(where: { id: { _eq: $extrinsicId } }) { + consensus_extrinsics( + where: { _or: [{ id: { _eq: $extrinsicId } }, { hash: { _eq: $extrinsicId } }] } + ) { id index_in_block hash