-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathWarpTransferDetailsCard.tsx
More file actions
140 lines (131 loc) · 4.86 KB
/
Copy pathWarpTransferDetailsCard.tsx
File metadata and controls
140 lines (131 loc) · 4.86 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { Tooltip } from '@hyperlane-xyz/widgets';
import { useCallback, useEffect, useState } from 'react';
import { TokenIcon } from '../../../components/icons/TokenIcon';
import { SectionCard } from '../../../components/layout/SectionCard';
import { useMultiProvider } from '../../../store';
import { Message, WarpRouteDetails } from '../../../types';
import { tryGetBlockExplorerAddressUrl } from '../../../utils/url';
import { isCollateralRoute } from '../collateral/utils';
import { useWarpFees } from '../warpFees/useWarpFees';
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 = await tryGetBlockExplorerAddressUrl(
multiProvider,
message.originChainId,
warpRouteDetails.originToken.addressOrDenom,
);
const destinationToken = await tryGetBlockExplorerAddressUrl(
multiProvider,
message.destinationChainId,
warpRouteDetails.destinationToken.addressOrDenom,
);
const transferRecipient = await tryGetBlockExplorerAddressUrl(
multiProvider,
message.destinationChainId,
warpRouteDetails.transferRecipient,
);
return { originToken, destinationToken, transferRecipient };
}, [message, multiProvider, warpRouteDetails]);
useEffect(() => {
getBlockExplorerLinks()
.then((urls) => setBlockExplorerAddressUrls(urls))
.catch(() => setBlockExplorerAddressUrls(undefined));
}, [getBlockExplorerLinks]);
const warpFees = useWarpFees(message, warpRouteDetails);
if (!warpRouteDetails) return null;
const { amount, transferRecipient, originToken, destinationToken } = warpRouteDetails;
const isCollateral = isCollateralRoute(destinationToken.standard);
return (
<SectionCard
className="w-full"
title="Warp Transfer Details"
icon={
<Tooltip
id="warp-route-info"
content="Information about the warp route transfer such as the end recipient and amount transferred"
/>
}
>
<div className="flex gap-4 sm:gap-6">
{/* Token Logo Column */}
{warpRouteDetails.originToken.logoURI && (
<div className="flex flex-shrink-0 items-center justify-center">
<TokenIcon token={warpRouteDetails.originToken} size={80} />
</div>
)}
{/* Details Column */}
<div className="min-w-0 flex-1 space-y-4">
{isCollateral && (
<div className="rounded bg-primary-50 px-3 py-2 text-xs text-primary-700">
<span className="font-medium">Collateral-backed route:</span> This transfer uses
locked collateral on the destination chain
</div>
)}
<div className="space-y-2">
<KeyValueRow
label="Amount:"
labelWidth="w-28 sm:w-32"
display={`${amount} ${originToken.symbol}`}
blurValue={blur}
showCopy
/>
{warpFees && (
<>
<KeyValueRow
label="Warp fee:"
labelWidth="w-28 sm:w-32"
display={`${warpFees.bridgeFee} ${warpFees.tokenSymbol}`}
blurValue={blur}
/>
<KeyValueRow
label="Total sent:"
labelWidth="w-28 sm:w-32"
display={`${warpFees.totalSent} ${warpFees.tokenSymbol}`}
blurValue={blur}
/>
</>
)}
<KeyValueRow
label="Origin token:"
labelWidth="w-28 sm:w-32"
display={originToken.addressOrDenom}
blurValue={blur}
link={blockExplorerAddressUrls?.originToken}
showCopy
/>
<KeyValueRow
label="Destination token:"
labelWidth="w-28 sm:w-32"
display={destinationToken.addressOrDenom}
blurValue={blur}
link={blockExplorerAddressUrls?.destinationToken}
showCopy
/>
<KeyValueRow
label="Transfer recipient:"
labelWidth="w-28 sm:w-32"
display={transferRecipient}
blurValue={blur}
link={blockExplorerAddressUrls?.transferRecipient}
showCopy
/>
</div>
</div>
</div>
</SectionCard>
);
}