Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added tenure height #1885

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { 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,7 +35,7 @@
);

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();

Expand All @@ -58,10 +58,13 @@
}
/>
<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 { 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 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('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()),

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
Loading