Skip to content

Commit 5634bac

Browse files
authored
Merge pull request #48 from codingknite/gbq-tx-tags
Gbq tx tags
2 parents 5cc7a52 + 364cb67 commit 5634bac

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

lib/hooks/useTxTags.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
interface TxTagsResponse {
4+
success: boolean;
5+
data: {
6+
hash: string;
7+
tags: string;
8+
confirmed: string | null;
9+
block_id: string | null;
10+
created_at: string;
11+
};
12+
}
13+
14+
interface TxTagsProps {
15+
txHash: string | undefined | null;
16+
}
17+
18+
export function useTxTags({ txHash }: TxTagsProps) {
19+
const { data, error, isLoading } = useQuery({
20+
queryKey: [ 'get tx tags', txHash ],
21+
queryFn: async() => {
22+
const response = await fetch(
23+
'https://arweaveid-api.vercel.app/api/tx-tags',
24+
{
25+
method: 'POST',
26+
body: JSON.stringify({
27+
txHash,
28+
}),
29+
headers: {
30+
'Content-Type': 'application/json',
31+
},
32+
},
33+
);
34+
35+
const data = (await response.json()) as TxTagsResponse;
36+
37+
if (data.success) {
38+
const tags = JSON.parse(data.data.tags) as Array<[string, string]>;
39+
return tags;
40+
}
41+
42+
return null;
43+
},
44+
enabled: Boolean(txHash),
45+
});
46+
47+
return { data, error, isLoading };
48+
}

ui/shared/statusTag/WvmTxTag.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { TagLabel, Tooltip } from '@chakra-ui/react';
2+
import React from 'react';
3+
4+
import Tag from 'ui/shared/chakra/Tag';
5+
6+
interface Props {
7+
tag: string;
8+
}
9+
const WvmTxTag = ({ tag }: Props) => {
10+
11+
return (
12+
<Tooltip>
13+
<Tag
14+
color="#fff"
15+
backgroundColor="#232452"
16+
display="flex"
17+
padding="2px 5px"
18+
>
19+
<TagLabel display="block">{ tag }</TagLabel>
20+
</Tag>
21+
</Tooltip>
22+
);
23+
};
24+
25+
export default WvmTxTag;

ui/tx/details/TxInfo.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import config from 'configs/app';
2828
import { WEI, WEI_IN_GWEI } from 'lib/consts';
2929
import { useArweaveId } from 'lib/hooks/useArweaveId';
3030
import { useBlobScan } from 'lib/hooks/useBlobScan';
31+
import { useTxTags } from 'lib/hooks/useTxTags';
3132
import { useWvmArchiver } from 'lib/hooks/useWvmArchiver';
3233
import getNetworkValidatorTitle from 'lib/networks/getNetworkValidatorTitle';
3334
import getConfirmationDuration from 'lib/tx/getConfirmationDuration';
@@ -50,6 +51,7 @@ import RawInputData from 'ui/shared/RawInputData';
5051
import BlobScanTag from 'ui/shared/statusTag/BlobScanTag';
5152
import TxStatus from 'ui/shared/statusTag/TxStatus';
5253
import WvmArchiverTag from 'ui/shared/statusTag/WvmArchiverTag';
54+
import WvmTxTag from 'ui/shared/statusTag/WvmTxTag';
5355
import TextSeparator from 'ui/shared/TextSeparator';
5456
import TxFeeStability from 'ui/shared/tx/TxFeeStability';
5557
import Utilization from 'ui/shared/Utilization/Utilization';
@@ -88,6 +90,13 @@ const TxInfo = ({ data, isLoading, socketStatus }: Props) => {
8890
block: data?.block,
8991
});
9092

93+
const { data: txTags, isLoading: isTxTagsLoading } = useTxTags({
94+
txHash: data?.hash,
95+
});
96+
97+
// eslint-disable-next-line no-console
98+
console.log('txTags', txTags);
99+
91100
const truncateArweaveId = (address: string) => {
92101
const start = address.slice(0, 28);
93102
const end = address.slice(-4);
@@ -509,7 +518,28 @@ const TxInfo = ({ data, isLoading, socketStatus }: Props) => {
509518
<Skeleton>loading...</Skeleton>
510519
) }
511520

512-
<DetailsInfoItemDivider/>
521+
{ txTags ? (
522+
<>
523+
<DetailsInfoItemDivider/>
524+
<DetailsInfoItem.Label
525+
hint="The transaction tags associated with the transaction"
526+
isLoading={ isTxTagsLoading }
527+
>
528+
Tags
529+
</DetailsInfoItem.Label>
530+
<Box display="flex" flexDir="column" gap={ 2 }>
531+
{ txTags.map((tag: [string, string]) => (
532+
<Box key={ tag[0] } display="flex">
533+
<Box minWidth="120px" flexShrink={ 0 }>
534+
<WvmTxTag tag={ tag[0] }/>
535+
</Box>
536+
<Text flexGrow={ 1 } wordBreak="break-word">{ tag[1] }</Text>
537+
</Box>
538+
)) }
539+
</Box>
540+
<DetailsInfoItemDivider/>
541+
</>
542+
) : null }
513543

514544
<TxDetailsActions
515545
hash={ data.hash }

0 commit comments

Comments
 (0)