@rango-dev/widget-embedded 0.12.1-next.11 → 0.12.1-next.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Widget.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +14 -4
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsChip/BlockchainsChip.styles.d.ts +6 -1
- package/dist/components/BlockchainsChip/BlockchainsChip.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +6 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +90 -15
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +18 -3
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +24 -4
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +18 -3
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +6 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts +18 -3
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +24 -4
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts +24 -4
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.types.d.ts +3 -1
- package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +6 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SelectableCategoryList/SelectableCategoryList.styles.d.ts +18 -3
- package/dist/components/SelectableCategoryList/SelectableCategoryList.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +30 -5
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +24 -4
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts +1 -8
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +35 -153
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +6 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +6 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +24 -4
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +207 -9
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +24 -4
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/constants/errors.d.ts +2 -2
- package/dist/constants/routing.d.ts +12 -2
- package/dist/constants/routing.d.ts.map +1 -1
- package/dist/globalStyles.d.ts +1 -1
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +3 -6
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/types/config.d.ts +3 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +2 -0
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +4 -2
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Widget.tsx +2 -1
- package/src/components/BlockchainList/BlockchainList.styles.ts +6 -5
- package/src/components/BlockchainList/BlockchainList.tsx +5 -8
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +26 -4
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +1 -1
- package/src/components/Layout/Layout.styles.ts +1 -2
- package/src/components/Layout/Layout.tsx +2 -2
- package/src/components/RouteErrors/RouteErrors.styles.ts +2 -1
- package/src/components/RouteErrors/RouteErrors.tsx +37 -26
- package/src/components/RouteErrors/RouteErrors.types.ts +3 -1
- package/src/components/RouteErrors/RouteErrorsModal.tsx +38 -11
- package/src/components/SwapDetails/SwapDetails.helpers.tsx +9 -26
- package/src/components/SwapDetails/SwapDetails.styles.ts +1 -9
- package/src/components/SwapDetails/SwapDetails.tsx +99 -73
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +3 -7
- package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +3 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +1 -0
- package/src/components/TokenList/TokenList.styles.ts +7 -1
- package/src/components/TokenList/TokenList.tsx +3 -2
- package/src/constants/errors.ts +2 -2
- package/src/constants/routing.ts +17 -2
- package/src/globalStyles.ts +1 -4
- package/src/hooks/useFetchBestRoute.ts +2 -2
- package/src/hooks/useSwapInput.ts +10 -1
- package/src/hooks/useTheme.ts +37 -75
- package/src/pages/ConfirmSwapPage.tsx +47 -19
- package/src/pages/Home.tsx +90 -42
- package/src/types/config.ts +3 -0
- package/src/utils/configs.ts +3 -0
- package/src/utils/routing.ts +56 -13
- package/src/utils/swap.ts +35 -19
|
@@ -14,20 +14,33 @@ import {
|
|
|
14
14
|
Divider,
|
|
15
15
|
IconButton,
|
|
16
16
|
RouteCost,
|
|
17
|
+
RouteSummary,
|
|
17
18
|
StepDetails,
|
|
18
|
-
|
|
19
|
+
theme,
|
|
19
20
|
Typography,
|
|
20
21
|
useCopyToClipboard,
|
|
22
|
+
usePaddingRight,
|
|
21
23
|
} from '@rango-dev/ui';
|
|
22
24
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
23
25
|
import React, { useEffect, useRef, useState } from 'react';
|
|
24
26
|
import { useNavigate } from 'react-router-dom';
|
|
25
27
|
|
|
26
28
|
import { navigationRoutes } from '../../constants/navigationRoutes';
|
|
29
|
+
import {
|
|
30
|
+
GAS_FEE_MAX_DECIMALS,
|
|
31
|
+
GAS_FEE_MIN_DECIMALS,
|
|
32
|
+
PERCENTAGE_CHANGE_MAX_DECIMALS,
|
|
33
|
+
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
34
|
+
TOKEN_AMOUNT_MAX_DECIMALS,
|
|
35
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
36
|
+
USD_VALUE_MAX_DECIMALS,
|
|
37
|
+
USD_VALUE_MIN_DECIMALS,
|
|
38
|
+
} from '../../constants/routing';
|
|
27
39
|
import { useNavigateBack } from '../../hooks/useNavigateBack';
|
|
28
40
|
import { useBestRouteStore } from '../../store/bestRoute';
|
|
29
41
|
import { useMetaStore } from '../../store/meta';
|
|
30
42
|
import { numberToString } from '../../utils/numbers';
|
|
43
|
+
import { getPriceImpactLevel } from '../../utils/routing';
|
|
31
44
|
import {
|
|
32
45
|
getLastConvertedTokenInFailedSwap,
|
|
33
46
|
getPercentageChange,
|
|
@@ -44,21 +57,14 @@ import {
|
|
|
44
57
|
} from '../SwapDetailsModal';
|
|
45
58
|
|
|
46
59
|
import {
|
|
47
|
-
AMOUNT_DECIMALS,
|
|
48
|
-
getPriceImpactWarningLevel,
|
|
49
60
|
getSteps,
|
|
50
61
|
getStepState,
|
|
51
|
-
MIN_DECIMALS,
|
|
52
|
-
PERCENT_DECIMALS,
|
|
53
62
|
RESET_INTERVAL,
|
|
54
63
|
SECONDS,
|
|
55
64
|
} from './SwapDetails.helpers';
|
|
56
|
-
import {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Separator,
|
|
60
|
-
StepsList,
|
|
61
|
-
} from './SwapDetails.styles';
|
|
65
|
+
import { Container, HeaderDetails, StepsList } from './SwapDetails.styles';
|
|
66
|
+
|
|
67
|
+
const DEFAULT_CONTENT_PADDING = 20;
|
|
62
68
|
|
|
63
69
|
export function SwapDetails(props: SwapDetailsProps) {
|
|
64
70
|
const { swap, requestId, onDelete, onCancel: onCancelProps } = props;
|
|
@@ -67,13 +73,18 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
67
73
|
const retry = useBestRouteStore.use.retry();
|
|
68
74
|
const navigate = useNavigate();
|
|
69
75
|
const { navigateBackFrom } = useNavigateBack();
|
|
70
|
-
const listRef = useRef(null);
|
|
76
|
+
const listRef = useRef<HTMLDivElement | null>(null);
|
|
71
77
|
const [_, handleCopy] = useCopyToClipboard(RESET_INTERVAL);
|
|
72
78
|
const [modalState, setModalState] = useState<ModalState>(null);
|
|
73
79
|
const [showCompletedModal, setShowCompletedModal] = useState<
|
|
74
80
|
'success' | 'failed' | null
|
|
75
81
|
>(null);
|
|
76
82
|
|
|
83
|
+
usePaddingRight({
|
|
84
|
+
elementRef: listRef,
|
|
85
|
+
paddingRight: theme.sizes[DEFAULT_CONTENT_PADDING],
|
|
86
|
+
});
|
|
87
|
+
|
|
77
88
|
const onCancel = () => {
|
|
78
89
|
onCancelProps();
|
|
79
90
|
setModalState(null);
|
|
@@ -142,10 +153,6 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
142
153
|
const [firstStep, lastStep] = [swap.steps[0], swap.steps[numberOfSteps - 1]];
|
|
143
154
|
const outputAmount =
|
|
144
155
|
lastStep.outputAmount || lastStep.expectedOutputAmountHumanReadable;
|
|
145
|
-
const percentageChange =
|
|
146
|
-
swap.inputAmount && outputAmount
|
|
147
|
-
? getPercentageChange(swap.inputAmount, outputAmount)
|
|
148
|
-
: null;
|
|
149
156
|
|
|
150
157
|
const totalFee = swap.steps.reduce(
|
|
151
158
|
(totalFee, steps) => totalFee + parseFloat(steps.feeInUsd || ''),
|
|
@@ -165,7 +172,13 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
165
172
|
|
|
166
173
|
const outputUsdValue = numberToString(
|
|
167
174
|
String(
|
|
168
|
-
parseFloat(
|
|
175
|
+
parseFloat(
|
|
176
|
+
numberToString(
|
|
177
|
+
outputAmount,
|
|
178
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
179
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
180
|
+
)
|
|
181
|
+
) *
|
|
169
182
|
(getUsdPrice(
|
|
170
183
|
lastStep.toBlockchain,
|
|
171
184
|
lastStep.toSymbol,
|
|
@@ -173,16 +186,32 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
173
186
|
tokens
|
|
174
187
|
) || 0)
|
|
175
188
|
),
|
|
176
|
-
|
|
177
|
-
|
|
189
|
+
USD_VALUE_MIN_DECIMALS,
|
|
190
|
+
USD_VALUE_MAX_DECIMALS
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const inputUsdValue = numberToString(
|
|
194
|
+
String(
|
|
195
|
+
parseFloat(swap.inputAmount) *
|
|
196
|
+
(getUsdPrice(
|
|
197
|
+
firstStep.fromBlockchain,
|
|
198
|
+
firstStep.fromSymbol,
|
|
199
|
+
firstStep.fromSymbolAddress,
|
|
200
|
+
tokens
|
|
201
|
+
) || 0)
|
|
202
|
+
),
|
|
203
|
+
USD_VALUE_MIN_DECIMALS,
|
|
204
|
+
USD_VALUE_MAX_DECIMALS
|
|
178
205
|
);
|
|
179
206
|
|
|
207
|
+
const percentageChange = getPercentageChange(inputUsdValue, outputUsdValue);
|
|
208
|
+
|
|
180
209
|
const completeModalDesc =
|
|
181
210
|
showCompletedModal === 'success'
|
|
182
|
-
? `You have
|
|
211
|
+
? `You have received ${numberToString(
|
|
183
212
|
outputAmount,
|
|
184
|
-
|
|
185
|
-
|
|
213
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
214
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
186
215
|
)} ${
|
|
187
216
|
steps[numberOfSteps - 1].to.token.displayName
|
|
188
217
|
} in ${getConciseAddress(
|
|
@@ -265,64 +294,57 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
265
294
|
<RouteCost
|
|
266
295
|
fee={numberToString(
|
|
267
296
|
String(totalFee),
|
|
268
|
-
|
|
269
|
-
|
|
297
|
+
GAS_FEE_MIN_DECIMALS,
|
|
298
|
+
GAS_FEE_MAX_DECIMALS
|
|
270
299
|
)}
|
|
271
300
|
time={minutes}
|
|
272
301
|
steps={numberOfSteps}
|
|
273
302
|
/>
|
|
274
|
-
<
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
AMOUNT_DECIMALS
|
|
282
|
-
),
|
|
283
|
-
usdValue: numberToString(
|
|
284
|
-
String(
|
|
285
|
-
parseFloat(swap.inputAmount) *
|
|
286
|
-
(getUsdPrice(
|
|
287
|
-
firstStep.fromBlockchain,
|
|
288
|
-
firstStep.fromSymbol,
|
|
289
|
-
firstStep.fromSymbolAddress,
|
|
290
|
-
tokens
|
|
291
|
-
) || 0)
|
|
303
|
+
<RouteSummary
|
|
304
|
+
from={{
|
|
305
|
+
price: {
|
|
306
|
+
value: numberToString(
|
|
307
|
+
swap.inputAmount,
|
|
308
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
309
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
292
310
|
),
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
311
|
+
usdValue: inputUsdValue,
|
|
312
|
+
},
|
|
313
|
+
token: {
|
|
314
|
+
displayName: steps[0].from.token.displayName,
|
|
315
|
+
image: steps[0].from.token.image,
|
|
316
|
+
},
|
|
317
|
+
chain: {
|
|
318
|
+
image: steps[0].from.chain.image,
|
|
319
|
+
displayName: steps[0].from.chain.displayName,
|
|
320
|
+
},
|
|
300
321
|
}}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
322
|
+
to={{
|
|
323
|
+
price: {
|
|
324
|
+
value: numberToString(
|
|
325
|
+
outputAmount,
|
|
326
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
327
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
328
|
+
),
|
|
329
|
+
usdValue: outputUsdValue,
|
|
330
|
+
},
|
|
331
|
+
token: {
|
|
332
|
+
displayName: steps[numberOfSteps - 1].to.token.displayName,
|
|
333
|
+
image: steps[numberOfSteps - 1].to.token.image,
|
|
334
|
+
},
|
|
335
|
+
chain: {
|
|
336
|
+
image: steps[numberOfSteps - 1].to.chain.image,
|
|
337
|
+
displayName: steps[numberOfSteps - 1].to.chain.displayName,
|
|
338
|
+
},
|
|
318
339
|
}}
|
|
319
|
-
chain={{ image: steps[numberOfSteps - 1].to.chain.image }}
|
|
320
340
|
percentageChange={numberToString(
|
|
321
341
|
percentageChange,
|
|
322
|
-
|
|
323
|
-
|
|
342
|
+
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
343
|
+
PERCENTAGE_CHANGE_MAX_DECIMALS
|
|
344
|
+
)}
|
|
345
|
+
warningLevel={getPriceImpactLevel(
|
|
346
|
+
percentageChange?.toNumber() ?? 0
|
|
324
347
|
)}
|
|
325
|
-
warningLevel={getPriceImpactWarningLevel(percentageChange)}
|
|
326
348
|
/>
|
|
327
349
|
</div>
|
|
328
350
|
<div className="title-steps">
|
|
@@ -368,12 +390,16 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
368
390
|
diagnosisUrl={diagnosisUrl}
|
|
369
391
|
onClose={() => setShowCompletedModal(null)}
|
|
370
392
|
status={showCompletedModal}
|
|
371
|
-
priceValue={numberToString(
|
|
393
|
+
priceValue={numberToString(
|
|
394
|
+
outputAmount,
|
|
395
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
396
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
397
|
+
)}
|
|
372
398
|
usdValue={outputUsdValue}
|
|
373
399
|
percentageChange={numberToString(
|
|
374
400
|
percentageChange,
|
|
375
|
-
|
|
376
|
-
|
|
401
|
+
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
402
|
+
PERCENTAGE_CHANGE_MAX_DECIMALS
|
|
377
403
|
)}
|
|
378
404
|
token={{
|
|
379
405
|
displayName: steps[numberOfSteps - 1].to.token.displayName,
|
|
@@ -6,12 +6,8 @@ import React from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { WalletContainer } from './SwapDetailsModal.styles';
|
|
8
8
|
|
|
9
|
-
export const WalletStateContent = ({
|
|
10
|
-
type,
|
|
11
|
-
title,
|
|
12
|
-
currentStepWallet,
|
|
13
|
-
message,
|
|
14
|
-
}: WalletStateContentProps) => {
|
|
9
|
+
export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
10
|
+
const { type, title, currentStepWallet, message, showWalletButton } = props;
|
|
15
11
|
const { connect, getWalletInfo, state: walletState } = useWallets();
|
|
16
12
|
const walletType = currentStepWallet?.walletType;
|
|
17
13
|
const isConnected = walletType && walletState(walletType).connected;
|
|
@@ -19,7 +15,7 @@ export const WalletStateContent = ({
|
|
|
19
15
|
return (
|
|
20
16
|
<>
|
|
21
17
|
<MessageBox type={type} title={title} description={message} />
|
|
22
|
-
{walletType && (
|
|
18
|
+
{showWalletButton && walletType && (
|
|
23
19
|
<WalletContainer>
|
|
24
20
|
<Wallet
|
|
25
21
|
title={getWalletInfo(walletType).name}
|
|
@@ -29,6 +29,9 @@ export function SwapDetailsModal(props: ModalPropTypes) {
|
|
|
29
29
|
title={modalNetworkValues[state].title}
|
|
30
30
|
currentStepWallet={currentStepWallet}
|
|
31
31
|
message={message}
|
|
32
|
+
showWalletButton={
|
|
33
|
+
state !== PendingSwapNetworkStatus.WaitingForNetworkChange
|
|
34
|
+
}
|
|
32
35
|
/>
|
|
33
36
|
)}
|
|
34
37
|
{state === 'delete' && (
|
|
@@ -46,6 +46,7 @@ export interface ModalNetworkValueTypes {
|
|
|
46
46
|
export interface WalletStateContentProps extends ModalNetworkValueTypes {
|
|
47
47
|
currentStepWallet: WalletTypeAndAddress | null;
|
|
48
48
|
message: string;
|
|
49
|
+
showWalletButton: boolean;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
export type CancelContentProps = Pick<ModalPropTypes, 'onClose' | 'onCancel'>;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { styled, Typography } from '@rango-dev/ui';
|
|
2
2
|
|
|
3
|
+
export const Container = styled('div', {
|
|
4
|
+
display: 'flex',
|
|
5
|
+
flexDirection: 'column',
|
|
6
|
+
flexGrow: 1,
|
|
7
|
+
});
|
|
8
|
+
|
|
3
9
|
export const Title = styled('div', {
|
|
4
10
|
display: 'flex',
|
|
5
11
|
alignItems: 'center',
|
|
@@ -11,7 +17,7 @@ export const Title = styled('div', {
|
|
|
11
17
|
},
|
|
12
18
|
});
|
|
13
19
|
export const List = styled('ul', {
|
|
14
|
-
|
|
20
|
+
flexGrow: 1,
|
|
15
21
|
padding: 0,
|
|
16
22
|
margin: 0,
|
|
17
23
|
listStyle: 'none',
|
|
@@ -28,6 +28,7 @@ import { generateRangeColors } from '../../utils/common';
|
|
|
28
28
|
import { LoadingTokenList } from './LoadingTokenList';
|
|
29
29
|
import {
|
|
30
30
|
BalanceContainer,
|
|
31
|
+
Container,
|
|
31
32
|
End,
|
|
32
33
|
ImageSection,
|
|
33
34
|
List,
|
|
@@ -257,13 +258,13 @@ export function TokenList(props: PropTypes) {
|
|
|
257
258
|
};
|
|
258
259
|
|
|
259
260
|
return (
|
|
260
|
-
<
|
|
261
|
+
<Container>
|
|
261
262
|
<Typography variant="label" size="large">
|
|
262
263
|
{i18n.t('Select Token')}
|
|
263
264
|
</Typography>
|
|
264
265
|
<Divider size={4} />
|
|
265
266
|
{loadingStatus === 'loading' && <LoadingTokenList size={PAGE_SIZE} />}
|
|
266
267
|
{loadingStatus === 'success' && <List>{renderList()}</List>}
|
|
267
|
-
</
|
|
268
|
+
</Container>
|
|
268
269
|
);
|
|
269
270
|
}
|
package/src/constants/errors.ts
CHANGED
|
@@ -22,7 +22,7 @@ export const errorMessages = {
|
|
|
22
22
|
decreaseAmount: i18n.t('Bridge Limit Error: Please decrease your amount'),
|
|
23
23
|
},
|
|
24
24
|
highValueLossError: {
|
|
25
|
-
|
|
25
|
+
impactTitle: i18n.t('High Price Impact'),
|
|
26
26
|
title: i18n.t('Price impact is too high!'),
|
|
27
27
|
description: i18n.t(
|
|
28
28
|
'The price impact is significantly higher than the allowed amount. If you are sure, continue, otherwise, change the swap.'
|
|
@@ -35,7 +35,7 @@ export const errorMessages = {
|
|
|
35
35
|
),
|
|
36
36
|
},
|
|
37
37
|
unknownPriceError: {
|
|
38
|
-
|
|
38
|
+
impactTitle: i18n.t('USD Price Unknown'),
|
|
39
39
|
title: i18n.t('USD Price Unknown, Cannot calculate Price Impact.'),
|
|
40
40
|
description: i18n.t(
|
|
41
41
|
'USD Price Unknown, Cannot calculate Price Impact. The price impact may be higher than usual. Are you sure to continue the Swap?'
|
package/src/constants/routing.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
export const LOW_PRICE_IMPACT = 3;
|
|
2
|
-
export const HIGHT_PRICE_IMPACT = 10;
|
|
1
|
+
export const LOW_PRICE_IMPACT = -3;
|
|
2
|
+
export const HIGHT_PRICE_IMPACT = -10;
|
|
3
|
+
|
|
4
|
+
export const TOKEN_AMOUNT_MIN_DECIMALS = 6;
|
|
5
|
+
export const TOKEN_AMOUNT_MAX_DECIMALS = 6;
|
|
6
|
+
|
|
7
|
+
export const USD_VALUE_MIN_DECIMALS = 4;
|
|
8
|
+
export const USD_VALUE_MAX_DECIMALS = 4;
|
|
9
|
+
|
|
10
|
+
export const GAS_FEE_MIN_DECIMALS = 2;
|
|
11
|
+
export const GAS_FEE_MAX_DECIMALS = 2;
|
|
12
|
+
|
|
13
|
+
export const PERCENTAGE_CHANGE_MIN_DECIMALS = 2;
|
|
14
|
+
export const PERCENTAGE_CHANGE_MAX_DECIMALS = 2;
|
|
15
|
+
|
|
16
|
+
export const BALANCE_MIN_DECIMALS = 8;
|
|
17
|
+
export const BALANCE_MAX_DECIMALS = 8;
|
package/src/globalStyles.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { globalCss } from '@rango-dev/ui';
|
|
2
2
|
|
|
3
|
-
export const globalFont = (
|
|
3
|
+
export const globalFont = () =>
|
|
4
4
|
globalCss({
|
|
5
5
|
'@import': [
|
|
6
6
|
"url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap')",
|
|
7
7
|
"url('https://fonts.cdnfonts.com/css/times-new-roman')",
|
|
8
8
|
],
|
|
9
|
-
body: {
|
|
10
|
-
fontFamily,
|
|
11
|
-
},
|
|
12
9
|
})();
|
|
@@ -12,11 +12,11 @@ interface UseFetchBestRoute {
|
|
|
12
12
|
|
|
13
13
|
export function useFetchBestRoute(): UseFetchBestRoute {
|
|
14
14
|
const [loading, setLoading] = useState(false);
|
|
15
|
-
const cancel = () => abortController.current?.abort();
|
|
16
15
|
const abortController = useRef<AbortController | null>(null);
|
|
16
|
+
const cancel = () => abortController.current?.abort();
|
|
17
17
|
|
|
18
18
|
const fetch: UseFetchBestRoute['fetch'] = async (requestBody) => {
|
|
19
|
-
|
|
19
|
+
cancel();
|
|
20
20
|
abortController.current = new AbortController();
|
|
21
21
|
|
|
22
22
|
setLoading(true);
|
|
@@ -53,6 +53,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
53
53
|
setLoading(true);
|
|
54
54
|
}
|
|
55
55
|
if (!shouldSkipRequest) {
|
|
56
|
+
resetRoute();
|
|
56
57
|
const requestBody = createBestRouteRequestBody({
|
|
57
58
|
fromToken,
|
|
58
59
|
toToken,
|
|
@@ -87,7 +88,8 @@ export function useSwapInput(): UseSwapInput {
|
|
|
87
88
|
useEffect(() => {
|
|
88
89
|
if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
|
|
89
90
|
setLoading(false);
|
|
90
|
-
|
|
91
|
+
cancelFetch();
|
|
92
|
+
return;
|
|
91
93
|
}
|
|
92
94
|
if (shouldSkipRequest) {
|
|
93
95
|
return;
|
|
@@ -98,5 +100,12 @@ export function useSwapInput(): UseSwapInput {
|
|
|
98
100
|
return cancelFetch;
|
|
99
101
|
}, [inputAmount]);
|
|
100
102
|
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (!shouldSkipRequest) {
|
|
105
|
+
fetch();
|
|
106
|
+
}
|
|
107
|
+
return cancelFetch;
|
|
108
|
+
}, [disabledLiquiditySources.length]);
|
|
109
|
+
|
|
101
110
|
return { fetch, loading, error };
|
|
102
111
|
}
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -1,87 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { WidgetTheme } from '../types';
|
|
2
|
+
|
|
3
|
+
import { createTheme, darkTheme, lightTheme } from '@rango-dev/ui';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
|
|
3
6
|
import { useMetaStore } from '../store/meta';
|
|
4
7
|
import { useSettingsStore } from '../store/settings';
|
|
5
|
-
import {
|
|
6
|
-
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_PRIMARY_RADIUS,
|
|
10
|
+
DEFAULT_SECONDARY_RADIUS,
|
|
11
|
+
} from '../utils/configs';
|
|
7
12
|
|
|
8
13
|
export function useTheme({
|
|
9
14
|
// colors,
|
|
10
15
|
fontFamily = 'Roboto',
|
|
11
|
-
|
|
16
|
+
borderRadius = DEFAULT_PRIMARY_RADIUS,
|
|
17
|
+
secondaryBorderRadius = DEFAULT_SECONDARY_RADIUS,
|
|
12
18
|
mode = 'auto',
|
|
13
19
|
}: WidgetTheme) {
|
|
14
20
|
const theme = useSettingsStore.use.theme();
|
|
15
21
|
const fetchMeta = useMetaStore.use.fetchMeta();
|
|
16
22
|
const setTheme = useSettingsStore.use.setTheme();
|
|
17
|
-
// const light = themeColors?.light;
|
|
18
|
-
// const dark = themeColors?.dark;
|
|
19
|
-
// const neutral = light?.neutral || '#fafafa';
|
|
20
|
-
// const background = light?.background || '#fff';
|
|
21
|
-
// const foreground = light?.foreground || '#000';
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// };
|
|
24
|
+
const customTheme = createTheme({
|
|
25
|
+
radii: {
|
|
26
|
+
primary: `${borderRadius}px`,
|
|
27
|
+
secondary: `${secondaryBorderRadius}px`,
|
|
28
|
+
},
|
|
29
|
+
fonts: {
|
|
30
|
+
widget: fontFamily,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// ...generateRangeColors('primary', 'light', light?.primary || '#5FA425'),
|
|
37
|
-
// ...generateRangeColors('error', 'light', light?.error || '#FF0000'),
|
|
38
|
-
// ...generateRangeColors('warning', 'light', light?.warning || '#F5A623'),
|
|
39
|
-
// ...generateRangeColors('success', 'light', light?.success || '#0070F3'),
|
|
40
|
-
// ...generateRangeColors('neutral', 'light', neutral),
|
|
41
|
-
// background,
|
|
42
|
-
// foreground,
|
|
43
|
-
// };
|
|
34
|
+
const lightClassName = `${customTheme.className} ${lightTheme.className}`;
|
|
35
|
+
const darkClassName = `${customTheme.className} ${darkTheme.className}`;
|
|
44
36
|
|
|
45
|
-
// const customLightTheme = createTheme({
|
|
46
|
-
// colors: lightColors,
|
|
47
|
-
// radii: {
|
|
48
|
-
// xs: `${borderRadius}px`,
|
|
49
|
-
// },
|
|
50
|
-
// shadows: {
|
|
51
|
-
// s: `0px 3px 5px 3px ${light?.neutral || '#f0f2f5'} ,0px 6px 10px 3px ${
|
|
52
|
-
// light?.neutral || '#f0f2f5'
|
|
53
|
-
// }, 0px 1px 18px 3px ${light?.neutral || '#f0f2f5'}`,
|
|
54
|
-
// },
|
|
55
|
-
// });
|
|
56
|
-
|
|
57
|
-
// const customDarkTheme = createTheme({
|
|
58
|
-
// colors: {
|
|
59
|
-
// ...lightColors,
|
|
60
|
-
// ...generateRangeColors('neutral', 'dark', '#111111'),
|
|
61
|
-
// foreground: background,
|
|
62
|
-
// background: foreground,
|
|
63
|
-
// surface: '#000',
|
|
64
|
-
// ...JSON.parse(JSON.stringify(darkColors)),
|
|
65
|
-
// },
|
|
66
|
-
// radii: {
|
|
67
|
-
// xs: `${borderRadius}px`,
|
|
68
|
-
// },
|
|
69
|
-
// shadows: {
|
|
70
|
-
// s: `0px 3px 5px 3px ${dark?.neutral || '#222'}, 0px 6px 10px 3px ${
|
|
71
|
-
// dark?.neutral || '#222'
|
|
72
|
-
// }, 0px 1px 18px 3px ${dark?.neutral || '#222'}`,
|
|
73
|
-
// },
|
|
74
|
-
// });
|
|
75
37
|
const [OSTheme, setOSTheme] = useState('light');
|
|
76
38
|
|
|
77
39
|
useEffect(() => {
|
|
78
|
-
|
|
40
|
+
const fetchData = async () => {
|
|
79
41
|
await fetchMeta();
|
|
80
|
-
}
|
|
42
|
+
};
|
|
43
|
+
void fetchData();
|
|
81
44
|
|
|
82
45
|
const switchTheme = (event: MediaQueryListEvent) => {
|
|
83
|
-
if (event.matches)
|
|
84
|
-
|
|
46
|
+
if (event.matches) {
|
|
47
|
+
setOSTheme('dark');
|
|
48
|
+
} else {
|
|
49
|
+
setOSTheme('light');
|
|
50
|
+
}
|
|
85
51
|
};
|
|
86
52
|
|
|
87
53
|
if (
|
|
@@ -101,20 +67,16 @@ export function useTheme({
|
|
|
101
67
|
};
|
|
102
68
|
}, []);
|
|
103
69
|
useEffect(() => {
|
|
104
|
-
if (mode !== 'auto')
|
|
70
|
+
if (mode !== 'auto') {
|
|
71
|
+
setTheme(mode);
|
|
72
|
+
}
|
|
105
73
|
}, [mode]);
|
|
106
|
-
const prevFont = usePrevious(fontFamily);
|
|
107
|
-
|
|
108
|
-
useLayoutEffect(() => {
|
|
109
|
-
const { classList } = document.body;
|
|
110
|
-
|
|
111
|
-
if (prevFont) classList.remove(`font_${prevFont.replace(/ /g, '')}`);
|
|
112
|
-
classList.add(`font_${fontFamily.replace(/ /g, '')}`);
|
|
113
|
-
}, [fontFamily]);
|
|
114
74
|
|
|
115
75
|
const getActiveTheme = () => {
|
|
116
|
-
if (theme === 'auto')
|
|
117
|
-
|
|
76
|
+
if (theme === 'auto') {
|
|
77
|
+
return OSTheme === 'dark' ? darkClassName : lightClassName;
|
|
78
|
+
}
|
|
79
|
+
return theme === 'dark' ? darkClassName : lightClassName;
|
|
118
80
|
};
|
|
119
81
|
|
|
120
82
|
return { activeTheme: getActiveTheme() };
|