Skip to content

Commit

Permalink
feat: add anchor tx link to btc block page
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr committed Feb 21, 2025
1 parent 348a807 commit 8e6bf30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
40 changes: 25 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 { useParamsBlockHash } from '../../../app/block/[hash]/useParamsBlockHash
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,12 +26,18 @@ export function BitcoinAnchorDetailsBase() {
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();

if (!btcBlock) return null;

console.log('222', btcBlock);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L39 was not covered by tests

return (
<StyledSection title="Bitcoin anchor details">
<KeyValueVertical
Expand Down Expand Up @@ -64,21 +72,23 @@ export function BitcoinAnchorDetailsBase() {
}
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 && (
<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
5 changes: 1 addition & 4 deletions src/common/queries/useBlockByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { useApiClient } from '../../api/useApiClient';

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 = {}) {
const apiClient = useApiClient();
return useQuery({
queryKey: ['blockByHash', hash],
Expand Down
3 changes: 2 additions & 1 deletion src/common/queries/useBurnBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function useFetchMultipleBurnBlocks(): (
}

export function useBurnBlock(
heightOrHash: number | string,
heightOrHash: number | string | undefined,
options: any = {}
): UseQueryResult<BurnBlock> {
const apiClient = useApiClient();
Expand All @@ -79,6 +79,7 @@ export function useBurnBlock(
);
},
staleTime: Infinity,
enabled: !!heightOrHash,
...options,
});
}
Expand Down

0 comments on commit 8e6bf30

Please sign in to comment.