Skip to content

Commit 0d89bd1

Browse files
committed
feat: show explorer links on redeem page
1 parent d9ca25e commit 0d89bd1

File tree

4 files changed

+92
-24
lines changed

4 files changed

+92
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
import Link from '@mui/material/Link';
3+
import ArrowOutwardIcon from '@mui/icons-material/ArrowOutward';
4+
import { makeStyles } from 'tss-react/mui';
5+
6+
const useStyles = makeStyles()((theme) => ({
7+
addressLink: {
8+
display: 'inline-flex',
9+
alignItems: 'center',
10+
overflow: 'hidden',
11+
color: theme.palette.text.primary,
12+
opacity: 0.6,
13+
},
14+
}));
15+
16+
interface ExplorerLinkProps {
17+
url: string;
18+
text: string;
19+
}
20+
21+
const ExplorerLink: React.FC<ExplorerLinkProps> = ({ url, text }) => {
22+
const { classes } = useStyles();
23+
24+
if (!(url && text)) return null;
25+
26+
return (
27+
<Link
28+
onClick={(e) => e.stopPropagation()}
29+
className={classes.addressLink}
30+
href={url}
31+
rel="noreferrer noopener"
32+
target="_blank"
33+
>
34+
{text}
35+
<ArrowOutwardIcon
36+
sx={{
37+
height: '10px',
38+
width: '10px',
39+
marginLeft: '2px',
40+
}}
41+
/>
42+
</Link>
43+
);
44+
};
45+
46+
export default ExplorerLink;

wormhole-connect/src/utils/index.ts

+24-13
Original file line numberDiff line numberDiff line change
@@ -284,23 +284,34 @@ export const isEmptyObject = (value: object | null | undefined) => {
284284
return true;
285285
};
286286

287-
export const getTokenExplorerUrl = (chain: Chain, address: string) => {
287+
export type ExplorerPathType = 'wallet' | 'tx' | 'token';
288+
289+
export const getExplorerUrl = (
290+
chain: Chain,
291+
path: string,
292+
pathType: ExplorerPathType,
293+
) => {
288294
const chainConfig = config.chains[chain]!;
289-
let explorerUrl = '';
295+
const baseUrl = chainConfig.explorerUrl;
290296

291-
if (chain === 'Sui') {
292-
explorerUrl = `${chainConfig.explorerUrl}coin/${address}`;
293-
} else if (chain === 'Aptos') {
294-
if (isHexString(address)) {
295-
explorerUrl = `${chainConfig.explorerUrl}fungible_asset/${address}`;
296-
} else {
297-
explorerUrl = `${chainConfig.explorerUrl}coin/${address}`;
298-
}
299-
} else {
300-
explorerUrl = `${chainConfig.explorerUrl}address/${address}`;
297+
if (pathType === 'wallet') {
298+
return `${baseUrl}address/${path}`;
299+
}
300+
301+
if (pathType === 'tx') {
302+
return `${baseUrl}tx/${path}`;
301303
}
302304

303-
return explorerUrl;
305+
switch (chain) {
306+
case 'Sui':
307+
return `${baseUrl}coin/${path}`;
308+
case 'Aptos':
309+
return `${baseUrl}${
310+
isHexString(path) ? 'fungible_asset' : 'coin'
311+
}/${path}`;
312+
default:
313+
return `${baseUrl}address/${path}`;
314+
}
304315
};
305316

306317
// Frankenstein tokens are wormhole-wrapped tokens that are not native to the chain

wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenItem.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import TokenIcon from 'icons/TokenIcons';
1515
import { Token } from 'config/tokens';
1616

1717
import type { Chain } from '@wormhole-foundation/sdk';
18-
import { chainDisplayName, getTokenExplorerUrl } from 'utils';
18+
import { chainDisplayName, getExplorerUrl } from 'utils';
1919
import ChainIcon from 'icons/ChainIcons';
2020

2121
const useStyles = makeStyles()((theme) => ({
@@ -59,10 +59,10 @@ function TokenItem(props: TokenItemProps) {
5959
const theme = useTheme();
6060

6161
const { chain, token } = props;
62-
// If the token is native to the chain, show the token's address.
63-
// Otherwise, show the wrapped token's address.
6462
const address = token.tokenId?.address.toString();
65-
const explorerURL = address ? getTokenExplorerUrl(chain, address) : undefined;
63+
const explorerURL = address
64+
? getExplorerUrl(chain, address, 'token')
65+
: undefined;
6666
const addressDisplay = `${token.shortAddress}`;
6767

6868
return (

wormhole-connect/src/views/v2/Redeem/TransactionDetails/index.tsx

+18-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import { makeStyles } from 'tss-react/mui';
1313
import config from 'config';
1414
import { RouteContext } from 'contexts/RouteContext';
1515
import AssetBadge from 'components/AssetBadge';
16+
import ExplorerLink from 'components/ExplorerLink';
1617
import {
1718
calculateUSDPrice,
19+
getExplorerUrl,
1820
millisToHumanString,
1921
trimAddress,
20-
trimTxHash,
2122
} from 'utils';
2223
import { getExplorerInfo } from 'utils/sdkv2';
2324
import { amount as sdkAmount } from '@wormhole-foundation/sdk';
@@ -88,6 +89,9 @@ const TransactionDetails = () => {
8889
);
8990

9091
const senderAddress = sender ? trimAddress(sender) : '';
92+
const explorerUrl = sender
93+
? getExplorerUrl(fromChain, sender, 'wallet')
94+
: '';
9195

9296
const formattedAmount = sdkAmount.display(sdkAmount.truncate(amount, 6));
9397

@@ -107,7 +111,7 @@ const TransactionDetails = () => {
107111
{usdAmount ? separator : null}
108112
{sourceChainConfig.displayName}
109113
{separator}
110-
{senderAddress}
114+
<ExplorerLink url={explorerUrl} text={senderAddress} />
111115
</>
112116
)}
113117
</Typography>
@@ -121,6 +125,7 @@ const TransactionDetails = () => {
121125
getTokenPrice,
122126
amount,
123127
sender,
128+
sendTx,
124129
theme.palette.text.secondary,
125130
isFetchingTokenPrices,
126131
separator,
@@ -141,6 +146,9 @@ const TransactionDetails = () => {
141146
);
142147

143148
const recipientAddress = recipient ? trimAddress(recipient) : '';
149+
const explorerUrl = recipient
150+
? getExplorerUrl(toChain, recipient, 'wallet')
151+
: '';
144152

145153
const formattedReceiveAmount = receiveAmount
146154
? sdkAmount.display(sdkAmount.truncate(receiveAmount, 6))
@@ -162,7 +170,7 @@ const TransactionDetails = () => {
162170
{usdAmount ? separator : null}
163171
{destChainConfig.displayName}
164172
{separator}
165-
{recipientAddress}
173+
<ExplorerLink url={explorerUrl} text={recipientAddress} />
166174
</>
167175
)}
168176
</Typography>
@@ -335,14 +343,17 @@ const TransactionDetails = () => {
335343
);
336344
}, [eta, theme.palette.text.secondary, toChain]);
337345

346+
const trimmedTx = sendTx ? trimAddress(sendTx) : '';
347+
const explorerUrl = sendTx ? getExplorerUrl(fromChain, sendTx, 'tx') : '';
348+
338349
return (
339350
<div className={classes.container}>
340351
<Card className={classes.card}>
341352
<CardContent>
342-
<Typography
343-
color={theme.palette.text.secondary}
344-
marginBottom="12px"
345-
>{`Transaction #${trimTxHash(sendTx)}`}</Typography>
353+
<Typography color={theme.palette.text.secondary} marginBottom="12px">
354+
{`Transaction #`}
355+
<ExplorerLink url={explorerUrl} text={trimmedTx} />
356+
</Typography>
346357
{sentAmount}
347358
{verticalConnector}
348359
{receivedAmount}

0 commit comments

Comments
 (0)