This repository was archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathindex.js
More file actions
369 lines (353 loc) · 11.4 KB
/
Copy pathindex.js
File metadata and controls
369 lines (353 loc) · 11.4 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// @flow
import React, { useCallback } from "react";
import { useTranslation, Trans } from "react-i18next";
import { useSelector } from "react-redux";
import type { MappedSwapOperation } from "@ledgerhq/live-common/lib/exchange/swap/types";
import {
getAccountUnit,
getAccountCurrency,
getAccountName,
getMainAccount,
} from "@ledgerhq/live-common/lib/account";
import {
getDefaultExplorerView,
getTransactionExplorer,
} from "@ledgerhq/live-common/lib/explorers";
import { operationStatusList } from "@ledgerhq/live-common/lib/exchange/swap";
import { getProviderName } from "@ledgerhq/live-common/lib/exchange/swap/utils";
import { useHistory } from "react-router-dom";
import styled from "styled-components";
import Box from "~/renderer/components/Box";
import Link from "~/renderer/components/Link";
import Tooltip from "~/renderer/components/Tooltip";
import LinkWithExternalIcon from "~/renderer/components/LinkWithExternalIcon";
import Ellipsis from "~/renderer/components/Ellipsis";
import CopyWithFeedback from "~/renderer/components/CopyWithFeedback";
import Text from "~/renderer/components/Text";
import CryptoCurrencyIcon from "~/renderer/components/CryptoCurrencyIcon";
import FormattedVal from "~/renderer/components/FormattedVal";
import { shallowAccountsSelector } from "~/renderer/reducers/accounts";
import IconSwap from "~/renderer/icons/Swap";
import IconArrowDown from "~/renderer/icons/ArrowDown";
import { rgba } from "~/renderer/styles/helpers";
import type { ThemedComponent } from "~/renderer/styles/StyleProvider";
import { getStatusColor } from "~/renderer/screens/exchange/swap/History/OperationRow";
import IconClock from "~/renderer/icons/Clock";
import {
B,
GradientHover,
OpDetailsData,
OpDetailsSection,
OpDetailsTitle,
} from "~/renderer/drawers/OperationDetails/styledComponents";
import { openURL } from "~/renderer/linking";
import { urls } from "~/config/urls";
import IconExclamationCircle from "~/renderer/icons/ExclamationCircle";
import useTheme from "~/renderer/hooks/useTheme";
import { setTrackingSource } from "~/renderer/analytics/TrackPage";
import { DataList } from "~/renderer/drawers/OperationDetails";
import uniq from "lodash/uniq";
import FormattedDate from "~/renderer/components/FormattedDate";
const Value = styled(Box).attrs(() => ({
fontSize: 4,
color: "palette.text.shade50",
ff: "Inter|Medium",
}))`
flex: 1;
${p => (p.status ? `color:${getStatusColor(p.status, p.theme)};` : "")}
`;
const Status: ThemedComponent<{}> = styled.div`
height: 36px;
width: 36px;
display: flex;
position: relative;
align-items: center;
justify-content: center;
align-self: center;
border-radius: 50%;
background: ${p => rgba(getStatusColor(p.status, p.theme), 0.1)};
& > * {
color: ${p => getStatusColor(p.status, p.theme)};
}
`;
const WrapperClock: ThemedComponent<{}> = styled(Box).attrs(() => ({
bg: "palette.background.paper",
color: "palette.text.shade60",
}))`
border-radius: 50%;
position: absolute;
bottom: -2px;
right: -2px;
padding: 3px;
`;
const SelectableTextWrapper: ThemedComponent<{}> = styled(Box).attrs(p => ({
ff: "Inter",
color: p.color || "palette.text.shade80",
fontSize: 4,
relative: true,
}))`
width: 100%;
${GradientHover} {
display: none;
}
&:hover ${GradientHover} {
display: flex;
& > * {
cursor: pointer;
}
}
&:hover ${Value} {
color: ${p => p.theme.colors.palette.text.shade100};
font-weight: 400;
}
}
`;
const SwapOperationDetails = ({
mappedSwapOperation,
onClose,
}: {
mappedSwapOperation: MappedSwapOperation,
onClose: () => void,
}) => {
const {
fromAccount,
toAccount,
operation,
provider,
swapId,
status,
fromAmount,
toAmount,
} = mappedSwapOperation;
const history = useHistory();
const fromUnit = getAccountUnit(fromAccount);
const fromCurrency = getAccountCurrency(fromAccount);
const toUnit = getAccountUnit(toAccount);
const toCurrency = getAccountCurrency(toAccount);
const accounts = useSelector(shallowAccountsSelector);
const normalisedFromAmount = fromAmount.times(-1);
const theme = useTheme();
const statusColor = getStatusColor(status, theme);
const { t } = useTranslation();
const url =
fromCurrency.type === "CryptoCurrency" &&
getTransactionExplorer(getDefaultExplorerView(fromCurrency), operation.hash);
const openAccount = useCallback(
account => {
const parentAccount =
account.type !== "Account" ? accounts.find(a => a.id === account.parentId) : null;
const mainAccount = getMainAccount(account, parentAccount);
const url = `/account/${mainAccount.id}/${parentAccount ? account.id : ""}`;
setTrackingSource("swap operation details");
history.push({ pathname: url });
onClose();
},
[accounts, history, onClose],
);
// Fixme, at this point it might be a good idea to refactor into the op details modal
const senders = uniq(operation.senders);
const recipients = uniq(operation.recipients);
const currencyName = fromCurrency
? fromCurrency.type === "TokenCurrency"
? fromCurrency.parentCurrency.name
: fromCurrency.name
: undefined;
return (
<Box flow={3} px={20} mt={20}>
<Status status={status}>
<IconSwap size={18} />
{operationStatusList.pending.includes(status) ? (
<WrapperClock>
<IconClock size={16} />
</WrapperClock>
) : null}
</Status>
<Text ff="Inter|SemiBold" textAlign="center" fontSize={4} color="palette.text.shade60" my={1}>
<Trans i18nKey="swap.operationDetailsModal.title" />
</Text>
<Box my={2} alignItems="center">
<Box selectable>
<FormattedVal
color={normalisedFromAmount.isNegative() ? "palette.text.shade100" : undefined}
unit={fromUnit}
alwaysShowSign
showCode
val={normalisedFromAmount}
fontSize={6}
disableRounding
/>
</Box>
<Box my={1} color={"palette.text.shade50"}>
<IconArrowDown size={16} />
</Box>
<Box selectable>
<FormattedVal
unit={toUnit}
alwaysShowSign
showCode
val={toAmount}
fontSize={6}
disableRounding
color={statusColor}
/>
</Box>
</Box>
{url ? (
<Box m={0} ff="Inter|SemiBold" horizontal justifyContent="center" fontSize={4} mb={1}>
<LinkWithExternalIcon
fontSize={4}
onClick={() =>
openURL(url, "viewSwapOperationInExplorer", { currencyId: currencyName })
}
label={t("operationDetails.viewOperation")}
/>
</Box>
) : null}
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.provider" />
</OpDetailsTitle>
<OpDetailsData>
<LinkWithExternalIcon
fontSize={12}
onClick={() => openURL(urls.swap.providers[provider]?.main)}
>
{getProviderName(provider)}
</LinkWithExternalIcon>
</OpDetailsData>
</OpDetailsSection>
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.txid" />
</OpDetailsTitle>
<OpDetailsData>
<Box>
<SelectableTextWrapper selectable>
<Value data-test-id="details-swap-id">{swapId}</Value>
<GradientHover>
<CopyWithFeedback text={swapId} />
</GradientHover>
</SelectableTextWrapper>
</Box>
</OpDetailsData>
</OpDetailsSection>
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.status" />
</OpDetailsTitle>
<OpDetailsData>
<Box horizontal alignItems="center">
<Value mr={1} status={status} style={{ textTransform: "capitalize" }}>
{status}
</Value>
<Tooltip
content={
<Box style={{ maxWidth: 180 }}>
<Trans i18nKey={`swap.operationDetailsModal.statusTooltips.${status}`} />
</Box>
}
>
<IconExclamationCircle size={12} color={statusColor} />
</Tooltip>
</Box>
</OpDetailsData>
</OpDetailsSection>
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.date" />
</OpDetailsTitle>
<OpDetailsData>
<Box>
<FormattedDate date={operation.date} format="L" />
</Box>
</OpDetailsData>
</OpDetailsSection>
<B />
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.from" />
</OpDetailsTitle>
<OpDetailsData>
<Box horizontal alignItems={"center"}>
<Box mr={1} alignItems={"center"}>
<CryptoCurrencyIcon size={16} currency={fromCurrency} />
</Box>
<Box flex={1} color={"palette.text.shade100"}>
<Ellipsis>
<Link onClick={() => openAccount(fromAccount)}>{getAccountName(fromAccount)}</Link>
</Ellipsis>
</Box>
</Box>
</OpDetailsData>
</OpDetailsSection>
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.initialAmount" />
</OpDetailsTitle>
<OpDetailsData>
<Box>
<FormattedVal
unit={fromUnit}
showCode
val={fromAmount}
disableRounding
color={"palette.text.shade50"}
/>
</Box>
</OpDetailsData>
</OpDetailsSection>
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.fromAddress" count={senders?.length} />
</OpDetailsTitle>
<OpDetailsData>
<DataList lines={senders} t={t} />
</OpDetailsData>
</OpDetailsSection>
<B />
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.to" />
</OpDetailsTitle>
<OpDetailsData>
<Box horizontal alignItems={"center"}>
<Box mr={1} alignItems={"center"}>
<CryptoCurrencyIcon size={16} currency={toCurrency} />
</Box>
<Box flex={1} color={"palette.text.shade100"}>
<Ellipsis>
<Link onClick={() => openAccount(toAccount)}>{getAccountName(toAccount)}</Link>
</Ellipsis>
</Box>
</Box>
</OpDetailsData>
</OpDetailsSection>
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.creditedAmount" />
</OpDetailsTitle>
<OpDetailsData>
<Box>
<FormattedVal
unit={toUnit}
showCode
val={toAmount}
fotSize={6}
disableRounding
color={"palette.text.shade50"}
/>
</Box>
</OpDetailsData>
</OpDetailsSection>
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey="swap.operationDetailsModal.toProvider" />
</OpDetailsTitle>
<OpDetailsData>
<DataList lines={recipients} t={t} />
</OpDetailsData>
</OpDetailsSection>
</Box>
);
};
export default SwapOperationDetails;