Skip to content

Commit

Permalink
feat: added tenure height
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Oct 30, 2024
1 parent 1c35949 commit 6306f78
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/app/block/[hash]/PageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function BlockPage({ params: { hash } }: any) {
const title = (block && `STX Block #${block.height.toLocaleString()}`) || '';
const { isOpen, onToggle, onClose } = useDisclosure();

console.log(block);
return (
<>
<PageTitle>{title}</PageTitle>
Expand All @@ -60,8 +61,14 @@ export default function BlockPage({ params: { hash } }: any) {
<KeyValueHorizontal label={'Mined'} value={<Timestamp ts={block.block_time} />} />
<KeyValueHorizontal
label={'Transactions'}
value={<Value>{block.txs.length}</Value>}
value={<Value>{block.tx_count}</Value>}
/>
{(block as any)?.tenure_height !== null && (
<KeyValueHorizontal
label={'Tenure Height'}
value={<Value>{(block as any)?.tenure_height}</Value>}
/>
)}
{!block.canonical ? (
<KeyValueHorizontal
label={'Canonical'}
Expand Down
29 changes: 21 additions & 8 deletions src/common/queries/useBlockByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { UseSuspenseQueryOptions, useQuery, useSuspenseQuery } from '@tanstack/r
import { Block } from '@stacks/stacks-blockchain-api-types';

import { useApi } from '../api/useApi';
import { useGlobalContext } from '../context/useGlobalContext';

const BLOCK_QUERY_KEY = 'block';

export function useBlockByHash(
hash?: string,
Expand All @@ -21,18 +24,28 @@ export function useBlockByHash(
});
}

// TODO: Use this until we update @stacks.stacks-blockchain-client
interface BlockWithTenureHeight extends Block {
tenure_height: number | null;
tx_count: number;
}

export function useSuspenseBlockByHash(
hash?: string,
options: Partial<Omit<UseSuspenseQueryOptions<any, any, Block, any>, 'queryKey'>> = {}
heightOrHash?: string,
options: Partial<
Omit<UseSuspenseQueryOptions<any, any, BlockWithTenureHeight, any>, 'queryKey'>
> = {}
) {
const api = useApi();
if (!hash) throw new Error('Hash is required');
const { url: activeNetworkUrl } = useGlobalContext().activeNetwork;
// const api = useApi();
if (!heightOrHash) throw new Error('Hash is required');
return useSuspenseQuery({
queryKey: ['blockByHash', hash],
queryKey: [BLOCK_QUERY_KEY, heightOrHash],
queryFn: () =>
api.blocksApi.getBlockByHash({
hash,
}),
fetch(`${activeNetworkUrl}/extended/v2/blocks/${heightOrHash}`).then(res => res.json()),
// api.blocksApi.getBlockByHash({
// hash,
// }),
staleTime: Infinity,
...options,
});
Expand Down

0 comments on commit 6306f78

Please sign in to comment.