-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathWarpTransferDetailsCard.tsx
More file actions
123 lines (115 loc) · 4.31 KB
/
Copy pathWarpTransferDetailsCard.tsx
File metadata and controls
123 lines (115 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { Tooltip } from '@hyperlane-xyz/widgets';
import Image from 'next/image';
import { useCallback, useEffect, useState } from 'react';
import { TokenIcon } from '../../../components/icons/TokenIcon';
import { Card } from '../../../components/layout/Card';
import SendMoney from '../../../images/icons/send-money.svg';
import { useMultiProvider } from '../../../store';
import { Message, WarpRouteDetails } from '../../../types';
import { tryGetBlockExplorerAddressUrl } from '../../../utils/url';
import { isCollateralRoute } from '../collateral/utils';
import { KeyValueRow } from './KeyValueRow';
import { BlockExplorerAddressUrls } from './types';
interface Props {
message: Message;
warpRouteDetails: WarpRouteDetails | undefined;
blur: boolean;
}
export function WarpTransferDetailsCard({ message, warpRouteDetails, blur }: Props) {
const multiProvider = useMultiProvider();
const [blockExplorerAddressUrls, setBlockExplorerAddressUrls] = useState<
BlockExplorerAddressUrls | undefined
>(undefined);
const getBlockExplorerLinks = useCallback(async (): Promise<
BlockExplorerAddressUrls | undefined
> => {
if (!warpRouteDetails) return undefined;
const [originToken, destinationToken, transferRecipient] = await Promise.all([
tryGetBlockExplorerAddressUrl(
multiProvider,
message.originChainId,
warpRouteDetails.originToken.addressOrDenom,
),
tryGetBlockExplorerAddressUrl(
multiProvider,
message.destinationChainId,
warpRouteDetails.destinationToken.addressOrDenom,
),
tryGetBlockExplorerAddressUrl(
multiProvider,
message.destinationChainId,
warpRouteDetails.transferRecipient,
),
]);
return { originToken, destinationToken, transferRecipient };
}, [message, multiProvider, warpRouteDetails]);
useEffect(() => {
getBlockExplorerLinks()
.then((urls) => setBlockExplorerAddressUrls(urls))
.catch(() => setBlockExplorerAddressUrls(undefined));
}, [getBlockExplorerLinks]);
if (!warpRouteDetails) return null;
const { amount, transferRecipient, originToken, destinationToken } = warpRouteDetails;
const isCollateral = isCollateralRoute(destinationToken.standard);
return (
<Card className="w-full space-y-4">
<div className="flex items-center justify-between">
{warpRouteDetails.originToken.logoURI ? (
<TokenIcon token={warpRouteDetails.originToken} size={28} />
) : (
<Image src={SendMoney} width={28} height={28} alt="" className="opacity-80" />
)}
<div className="flex items-center pb-1">
<h3 className="mr-2 text-md font-medium text-blue-500">Warp Transfer Details</h3>
<Tooltip
id="warp-route-info"
content="Information about the warp route transfer such as the end recipient and amount transferred"
/>
</div>
</div>
{isCollateral && (
<div className="rounded-md bg-blue-50 px-3 py-2 text-xs text-blue-700">
<span className="font-medium">Collateral-backed route:</span> This transfer uses locked
collateral on the destination chain
</div>
)}
<div className="flex flex-wrap gap-x-6 gap-y-4">
<KeyValueRow
label="Amount:"
labelWidth="w-20 sm:w-32"
display={`${amount} ${originToken.symbol}`}
displayWidth="w-64 sm:w-96"
blurValue={blur}
showCopy
/>
<KeyValueRow
label="Origin token:"
labelWidth="w-20 sm:w-32"
display={originToken.addressOrDenom}
displayWidth="w-64 sm:w-96"
blurValue={blur}
link={blockExplorerAddressUrls?.originToken}
showCopy
/>
<KeyValueRow
label="Destination token:"
labelWidth="w-20 sm:w-32"
display={destinationToken.addressOrDenom}
displayWidth="w-64 sm:w-96"
blurValue={blur}
link={blockExplorerAddressUrls?.destinationToken}
showCopy
/>
<KeyValueRow
label="Transfer recipient:"
labelWidth="w-20 sm:w-32"
display={transferRecipient}
displayWidth="w-64 sm:w-96"
blurValue={blur}
link={blockExplorerAddressUrls?.transferRecipient}
showCopy
/>
</div>
</Card>
);
}