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: add anchor tx link to btc block page #2011

Merged
merged 1 commit into from
Feb 21, 2025
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
38 changes: 23 additions & 15 deletions src/app/btcblock/[hash]/BitcoinAnchorDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import { KeyValueVertical } from '../../../common/components/KeyValueVertical';
import { Section } from '../../../common/components/Section';
import { useGlobalContext } from '../../../common/context/useGlobalContext';
import { useBlockByHash } from '../../../common/queries/useBlockByHash';

Check warning on line 10 in src/app/btcblock/[hash]/BitcoinAnchorDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/btcblock/[hash]/BitcoinAnchorDetails.tsx#L10

Added line #L10 was not covered by tests
import { useSuspenseBurnBlock } from '../../../common/queries/useBurnBlock';
import { toRelativeTime, truncateMiddle } from '../../../common/utils/utils';
import { Link } from '../../../ui/Link';
import { Text } from '../../../ui/Text';
import { TextLink } from '../../../ui/TextLink';

Check warning on line 15 in src/app/btcblock/[hash]/BitcoinAnchorDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/btcblock/[hash]/BitcoinAnchorDetails.tsx#L15

Added line #L15 was not covered by tests
import BitcoinIcon from '../../../ui/icons/BitcoinIcon';
import { ExplorerErrorBoundary } from '../../_components/ErrorBoundary';

Expand All @@ -24,6 +26,10 @@
const { data: btcBlock } = useSuspenseBurnBlock(useParamsBlockHash(), {
refetchOnWindowFocus: true,
});
const stxBlockHash = btcBlock?.stacks_blocks?.[0];
const { data: stxBlock } = useBlockByHash(stxBlockHash, {

Check warning on line 30 in src/app/btcblock/[hash]/BitcoinAnchorDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/btcblock/[hash]/BitcoinAnchorDetails.tsx#L29-L30

Added lines #L29 - L30 were not covered by tests
enabled: !!stxBlockHash,
});

const { btcBlockBaseUrl, btcTxBaseUrl } = useGlobalContext().activeNetwork;
const btcBlockBlockTimeUTC = new Date(btcBlock.burn_block_time_iso).toUTCString();
Expand Down Expand Up @@ -64,21 +70,23 @@
}
copyValue={btcBlock.burn_block_hash}
/>
<KeyValueVertical
className="key-value-vertical"
label={'Anchor transaction ID'}
value={
<Link
target="_blank"
href={`${btcTxBaseUrl}/${btcBlock.burn_block_hash.replace('0x', '')}`}
>
<Text fontSize="sm" fontWeight="medium">
{truncateMiddle(btcBlock.burn_block_hash, 8)}
</Text>
</Link>
}
copyValue={btcBlock.burn_block_hash}
/>
{!!stxBlock?.miner_txid && (
<KeyValueVertical
label={'Anchor transaction ID'}
value={
<TextLink
as="a"
target="_blank"
href={`${btcTxBaseUrl}/${stxBlock.miner_txid.replace('0x', '')}`}
>
<Text fontSize={'sm'} fontWeight={'medium'}>
{truncateMiddle(stxBlock.miner_txid, 8)}
</Text>
</TextLink>
}
copyValue={stxBlock.miner_txid}
/>
)}
<KeyValueVertical
className="key-value-vertical"
label={'Timestamp'}
Expand Down
11 changes: 4 additions & 7 deletions src/common/queries/useBlockByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@

const BLOCK_QUERY_KEY = 'block';

export function useBlockByHash(
hash?: string,
options: Partial<Omit<UseSuspenseQueryOptions<any, any, Block, any>, 'queryKey'>> = {}
) {
export function useBlockByHash(hash?: string, options: any = {}) {
const apiClient = useApiClient();
return useQuery({
return useQuery<Block>({

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

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useBlockByHash.ts#L12

Added line #L12 was not covered by tests
queryKey: ['blockByHash', hash],
queryFn: async () => {
if (!hash) return undefined;
return await callApiWithErrorHandling(apiClient, '/extended/v2/blocks/{height_or_hash}', {
return (await callApiWithErrorHandling(apiClient, '/extended/v2/blocks/{height_or_hash}', {

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

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useBlockByHash.ts#L16

Added line #L16 was not covered by tests
params: { path: { height_or_hash: hash } },
});
})) as unknown as Block;
},
staleTime: Infinity,
enabled: !!hash,
Expand Down
Loading