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 b172c1f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 204 deletions.
16 changes: 10 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';

Check warning on line 13 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L13

Added line #L13 was not covered by tests
import { SkeletonTxsList } from '../../../features/txs-list/SkeletonTxsList';
import { Box } from '../../../ui/Box';
import { Flex } from '../../../ui/Flex';
Expand All @@ -35,10 +35,11 @@ const BlockTxsList = dynamic(
);

export default function BlockPage({ params: { hash } }: any) {
const { data: block } = useSuspenseBlockByHash(hash, { refetchOnWindowFocus: true });
const { data: block } = useSuspenseBlockByHeightOrHash(hash, { refetchOnWindowFocus: true });

Check warning on line 38 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L38

Added line #L38 was not covered by tests
const title = (block && `STX Block #${block.height.toLocaleString()}`) || '';
const { isOpen, onToggle, onClose } = useDisclosure();

console.log(block);

Check warning on line 42 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L42

Added line #L42 was not covered by tests
return (
<>
<PageTitle>{title}</PageTitle>
Expand All @@ -58,10 +59,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';

Check warning on line 6 in src/common/queries/useBlockByHash.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useBlockByHash.ts#L6

Added line #L6 was not covered by tests

const BLOCK_QUERY_KEY = 'block';

Check warning on line 8 in src/common/queries/useBlockByHash.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useBlockByHash.ts#L8

Added line #L8 was not covered by tests

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(

Check warning on line 33 in src/common/queries/useBlockByHash.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useBlockByHash.ts#L33

Added line #L33 was not covered by tests
heightOrHash?: string,
options: Partial<
Omit<UseSuspenseQueryOptions<any, any, BlockWithTenureHeight, any>, 'queryKey'>
> = {}

Check warning on line 37 in src/common/queries/useBlockByHash.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useBlockByHash.ts#L37

Added line #L37 was not covered by tests
) {
const api = useApi();
if (!hash) throw new Error('Hash is required');
const { url: activeNetworkUrl } = useGlobalContext().activeNetwork;

Check warning on line 39 in src/common/queries/useBlockByHash.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useBlockByHash.ts#L39

Added line #L39 was not covered by tests
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()),

Check warning on line 44 in src/common/queries/useBlockByHash.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useBlockByHash.ts#L44

Added line #L44 was not covered by tests
staleTime: Infinity,
...options,
});
Expand Down

0 comments on commit b172c1f

Please sign in to comment.