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 31, 2024
1 parent 477e687 commit da1337e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 204 deletions.
15 changes: 9 additions & 6 deletions src/app/block/[hash]/PageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Section } from '../../../common/components/Section';
import { Timestamp } from '../../../common/components/Timestamp';
import { Value } from '../../../common/components/Value';
import '../../../common/components/loaders/skeleton-text';
import { useSuspenseBlockByHash } from '../../../common/queries/useBlockByHash';
import { useSuspenseBlockByHeightOrHash } from '../../../common/queries/useBlockByHash';
import { SkeletonTxsList } from '../../../features/txs-list/SkeletonTxsList';
import { Box } from '../../../ui/Box';
import { Flex } from '../../../ui/Flex';
Expand All @@ -35,7 +35,7 @@ const BlockTxsList = dynamic(
);

export default function BlockPage({ params: { hash } }: any) {
const { data: block } = useSuspenseBlockByHash(hash, { refetchOnWindowFocus: true });
const { data: block } = useSuspenseBlockByHeightOrHash(hash, { refetchOnWindowFocus: true });
const title = (block && `STX Block #${block.height.toLocaleString()}`) || '';
const { isOpen, onToggle, onClose } = useDisclosure();

Expand All @@ -58,10 +58,13 @@ 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>}
/>
<KeyValueHorizontal label={'Transactions'} value={<Value>{block.tx_count}</Value>} />
{block.tenure_height !== null && (
<KeyValueHorizontal
label={'Tenure Height'}
value={<Value>{block.tenure_height}</Value>}
/>
)}
{!block.canonical ? (
<KeyValueHorizontal
label={'Canonical'}
Expand Down
99 changes: 0 additions & 99 deletions src/app/microblock/[hash]/PageClient.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions src/app/microblock/[hash]/layout.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/app/microblock/[hash]/page.tsx

This file was deleted.

56 changes: 0 additions & 56 deletions src/app/microblock/[hash]/tx-lists/MicroblockTxsList.tsx

This file was deleted.

27 changes: 18 additions & 9 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,24 @@ export function useBlockByHash(
});
}

export function useSuspenseBlockByHash(
hash?: string,
options: Partial<Omit<UseSuspenseQueryOptions<any, any, Block, any>, 'queryKey'>> = {}
// TODO: Use this until we update @stacks/stacks-blockchain-client
interface BlockWithTenureHeight extends Block {
tenure_height: number | null;
tx_count: number;
}

export function useSuspenseBlockByHeightOrHash(
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;
if (!heightOrHash) throw new Error('Height or 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()),
staleTime: Infinity,
...options,
});
Expand Down

0 comments on commit da1337e

Please sign in to comment.