Skip to content

Commit abdaa98

Browse files
committed
Make protocol history item clickable
We want to redirect users to transaction details in the blockexplorer.
1 parent 721c248 commit abdaa98

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

src/components/ViewInBlockExplorer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { supportedChainId } from "../utils/getEnvVariable"
99

1010
export type Chain = "bitcoin" | "ethereum"
1111

12-
const createLinkToBlockExplorerForChain: Record<
12+
export const createLinkToBlockExplorerForChain: Record<
1313
Chain,
1414
(id: string, type: ExplorerDataType) => string
1515
> = {

src/components/tBTC/RecentDeposits.tsx

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import { FC } from "react"
2-
import { BodySm, List, HStack, ListProps } from "@threshold-network/components"
2+
import {
3+
BodySm,
4+
List,
5+
HStack,
6+
ListProps,
7+
LinkBox,
8+
LinkOverlay,
9+
Link,
10+
} from "@threshold-network/components"
311
import shortenAddress from "../../utils/shortenAddress"
412
import Identicon from "../Identicon"
513
import { OutlineListItem } from "../OutlineListItem"
614
import { InlineTokenBalance } from "../TokenBalance"
715
import { getRelativeTime } from "../../utils/date"
816
import { RecentDeposit } from "../../hooks/tbtc/useFetchRecentDeposits"
17+
import ViewInBlockExplorer, {
18+
createLinkToBlockExplorerForChain,
19+
} from "../ViewInBlockExplorer"
20+
import { ExplorerDataType } from "../../utils/createEtherscanLink"
921

1022
export type RecentDepositsProps = {
1123
deposits: RecentDeposit[]
@@ -22,23 +34,46 @@ export const RecentDeposits: FC<RecentDepositsProps> = ({
2234
)
2335
}
2436

25-
const RecentDepositItem: FC<RecentDeposit> = ({ amount, address, date }) => {
37+
const RecentDepositItem: FC<RecentDeposit> = ({
38+
amount,
39+
address,
40+
date,
41+
txHash,
42+
}) => {
2643
return (
27-
<OutlineListItem>
28-
<BodySm>
29-
<InlineTokenBalance
30-
tokenAmount={amount}
31-
withSymbol
32-
tokenSymbol="tBTC"
33-
color="brand.500"
34-
/>
35-
</BodySm>
44+
<LinkBox as={OutlineListItem}>
45+
<LinkOverlay
46+
// We can't use `ViewInBlockExplorer` or our custom `Link` component
47+
// because `LinkOverlay` component from chakra doesn't pass the
48+
// `isExternal` prop forward so `ViewInBlockExplorer` or `Link`
49+
// component sees this link as an internal so the link will open in the
50+
// same tab and the TS compiler throws an error that `to` prop is
51+
// missing because of conditional props of `Link` component.
52+
as={Link}
53+
textDecoration="none"
54+
_hover={{ textDecoration: "none" }}
55+
color="inherit"
56+
isExternal
57+
href={createLinkToBlockExplorerForChain.ethereum(
58+
txHash,
59+
ExplorerDataType.TRANSACTION
60+
)}
61+
>
62+
<BodySm>
63+
<InlineTokenBalance
64+
tokenAmount={amount}
65+
withSymbol
66+
tokenSymbol="tBTC"
67+
color="brand.500"
68+
/>
69+
</BodySm>
70+
</LinkOverlay>
3671
<HStack spacing="2">
3772
<Identicon address={address} />
3873
<BodySm textStyle="chain-identifier">{shortenAddress(address)}</BodySm>
3974
</HStack>
4075
<BodySm>{getRelativeTime(date)}</BodySm>
41-
</OutlineListItem>
76+
</LinkBox>
4277
)
4378
}
4479

0 commit comments

Comments
 (0)