@rango-dev/widget-embedded 0.17.1-next.2 → 0.17.1-next.4
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/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +1 -3
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.d.ts +4 -0
- package/dist/components/NoResult/NoResult.d.ts.map +1 -0
- package/dist/components/NoResult/NoResult.helpers.d.ts +4 -0
- package/dist/components/NoResult/NoResult.helpers.d.ts.map +1 -0
- package/dist/components/{NoRoutes/NoRoutes.styles.d.ts → NoResult/NoResult.styles.d.ts} +1 -1
- package/dist/components/{NoRoutes/NoRoutes.styles.d.ts.map → NoResult/NoResult.styles.d.ts.map} +1 -1
- package/dist/components/{NoRoutes/NoRoutes.types.d.ts → NoResult/NoResult.types.d.ts} +3 -3
- package/dist/components/NoResult/NoResult.types.d.ts.map +1 -0
- package/dist/components/NoResult/index.d.ts +2 -0
- package/dist/components/NoResult/index.d.ts.map +1 -0
- package/dist/components/Quote/Quote.d.ts +4 -0
- package/dist/components/Quote/Quote.d.ts.map +1 -0
- package/dist/components/Quote/Quote.styles.d.ts +1429 -0
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -0
- package/dist/components/Quote/Quote.types.d.ts +22 -0
- package/dist/components/Quote/Quote.types.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.d.ts +4 -0
- package/dist/components/Quote/QuoteSkeleton.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts +319 -0
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.types.d.ts +6 -0
- package/dist/components/Quote/QuoteSkeleton.types.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSummary.d.ts +11 -0
- package/dist/components/Quote/QuoteSummary.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts +158 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -0
- package/dist/components/Quote/index.d.ts +4 -0
- package/dist/components/Quote/index.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts +4 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts +4 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts +9 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -0
- package/dist/components/{RouteErrors/RouteErrors.styles.d.ts → QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts} +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +22 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/index.d.ts +2 -0
- package/dist/components/QuoteWarningsAndErrors/index.d.ts.map +1 -0
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/WidgetEvents.d.ts.map +1 -1
- package/dist/constants/errors.d.ts +4 -4
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/constants/messages.d.ts +1 -1
- package/dist/constants/warnings.d.ts +2 -2
- package/dist/constants/warnings.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts +4 -0
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +472 -0
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +17 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/index.d.ts +2 -0
- package/dist/containers/QuoteInfo/index.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/index.d.ts +2 -0
- package/dist/hooks/useConfirmSwap/index.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts +3 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +16 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -0
- package/dist/hooks/{useConfirmSwap.d.ts → useConfirmSwap/useConfirmSwap.types.d.ts} +5 -7
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +1 -0
- package/dist/hooks/{useFetchBestRoute.d.ts → useFetchQuote.d.ts} +3 -3
- package/dist/hooks/useFetchQuote.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
- package/dist/hooks/useSwapInput.d.ts +4 -2
- package/dist/hooks/useSwapInput.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/store/app.d.ts +2 -2
- package/dist/store/{bestRoute.d.ts → quote.d.ts} +25 -20
- package/dist/store/quote.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/quote.d.ts +82 -0
- package/dist/types/quote.d.ts.map +1 -0
- package/dist/utils/numbers.d.ts +1 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/{routing.d.ts → quote.d.ts} +16 -12
- package/dist/utils/quote.d.ts.map +1 -0
- package/dist/utils/settings.d.ts +1 -1
- package/dist/utils/swap.d.ts +22 -20
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +1 -1
- package/package.json +3 -3
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +3 -3
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +2 -64
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +23 -26
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +1 -1
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +3 -3
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +6 -6
- package/src/components/{NoRoutes/NoRoutes.helper.ts → NoResult/NoResult.helpers.ts} +16 -9
- package/src/components/{NoRoutes/NoRoutes.styles.ts → NoResult/NoResult.styles.ts} +2 -0
- package/src/components/{NoRoutes/NoRoutes.tsx → NoResult/NoResult.tsx} +7 -12
- package/src/components/{NoRoutes/NoRoutes.types.ts → NoResult/NoResult.types.ts} +3 -2
- package/src/components/NoResult/index.ts +1 -0
- package/src/components/Quote/Quote.styles.ts +212 -0
- package/src/components/Quote/Quote.tsx +347 -0
- package/src/components/Quote/Quote.types.ts +16 -0
- package/src/components/Quote/QuoteSkeleton.styles.ts +110 -0
- package/src/components/Quote/QuoteSkeleton.tsx +108 -0
- package/src/components/Quote/QuoteSkeleton.types.ts +5 -0
- package/src/components/Quote/QuoteSummary.styles.ts +15 -0
- package/src/components/Quote/QuoteSummary.tsx +46 -0
- package/src/components/Quote/index.ts +3 -0
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +107 -0
- package/src/components/{RouteErrors/RouteErrorsModalItem.tsx → QuoteWarningsAndErrors/QuoteErrorsModalItem.tsx} +3 -3
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +67 -0
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +103 -0
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +24 -0
- package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +77 -0
- package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +38 -0
- package/src/components/QuoteWarningsAndErrors/index.ts +1 -0
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +13 -16
- package/src/components/SwitchFromAndTo.tsx +2 -2
- package/src/components/UpdateUrl.tsx +12 -12
- package/src/components/WidgetEvents.tsx +2 -3
- package/src/constants/errors.ts +8 -10
- package/src/constants/messages.ts +1 -1
- package/src/constants/warnings.ts +7 -7
- package/src/containers/QuoteInfo/QuoteInfo.styles.ts +15 -0
- package/src/containers/QuoteInfo/QuoteInfo.tsx +97 -0
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +17 -0
- package/src/containers/QuoteInfo/index.ts +1 -0
- package/src/hooks/useConfirmSwap/index.ts +1 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +168 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +136 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +19 -0
- package/src/hooks/{useFetchBestRoute.ts → useFetchQuote.ts} +3 -3
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/hooks/useSwapInput.ts +57 -23
- package/src/hooks/useSyncStoresWithConfig.ts +2 -2
- package/src/pages/ConfirmSwapPage.tsx +58 -227
- package/src/pages/HistoryPage.tsx +1 -1
- package/src/pages/Home.tsx +52 -241
- package/src/pages/LanguagePage.tsx +1 -1
- package/src/pages/LiquiditySourcePage.tsx +1 -1
- package/src/pages/SelectBlockchainPage.tsx +3 -3
- package/src/pages/SelectSwapItemsPage.tsx +2 -2
- package/src/pages/SettingsPage.tsx +1 -1
- package/src/pages/ThemePage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +1 -1
- package/src/store/{bestRoute.ts → quote.ts} +42 -38
- package/src/types/index.ts +1 -1
- package/src/types/quote.ts +107 -0
- package/src/utils/numbers.ts +1 -1
- package/src/utils/quote.ts +338 -0
- package/src/utils/swap.ts +99 -69
- package/src/utils/wallets.ts +2 -2
- package/dist/components/NoRoutes/NoRoutes.d.ts +0 -4
- package/dist/components/NoRoutes/NoRoutes.d.ts.map +0 -1
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts +0 -3
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +0 -1
- package/dist/components/NoRoutes/NoRoutes.types.d.ts.map +0 -1
- package/dist/components/NoRoutes/index.d.ts +0 -2
- package/dist/components/NoRoutes/index.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrors.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.types.d.ts +0 -24
- package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts.map +0 -1
- package/dist/components/RouteErrors/index.d.ts +0 -2
- package/dist/components/RouteErrors/index.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +0 -1
- package/dist/hooks/useFetchBestRoute.d.ts.map +0 -1
- package/dist/store/bestRoute.d.ts.map +0 -1
- package/dist/types/routing.d.ts +0 -65
- package/dist/types/routing.d.ts.map +0 -1
- package/dist/utils/routing.d.ts.map +0 -1
- package/src/components/NoRoutes/index.ts +0 -1
- package/src/components/RouteErrors/RouteErrors.tsx +0 -79
- package/src/components/RouteErrors/RouteErrors.types.ts +0 -29
- package/src/components/RouteErrors/RouteErrorsModal.tsx +0 -129
- package/src/components/RouteErrors/index.ts +0 -1
- package/src/hooks/useConfirmSwap.ts +0 -303
- package/src/types/routing.ts +0 -77
- package/src/utils/routing.ts +0 -321
- /package/src/components/{RouteErrors/RouteErrors.styles.ts → QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts} +0 -0
package/src/utils/swap.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
2
|
import type { LoadingStatus } from '../store/meta';
|
|
3
3
|
import type { ConnectedWallet } from '../store/wallets';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
ConvertedToken,
|
|
6
|
+
RecommendedSlippages,
|
|
7
|
+
SwapButtonState,
|
|
8
|
+
Wallet,
|
|
9
|
+
} from '../types';
|
|
5
10
|
import type {
|
|
6
11
|
PendingSwap,
|
|
7
12
|
PendingSwapStep,
|
|
@@ -35,7 +40,7 @@ import { ButtonState } from '../types';
|
|
|
35
40
|
|
|
36
41
|
import { removeDuplicateFrom } from './common';
|
|
37
42
|
import { numberToString } from './numbers';
|
|
38
|
-
import { getRequiredBalanceOfWallet } from './
|
|
43
|
+
import { getRequiredBalanceOfWallet } from './quote';
|
|
39
44
|
import { getRequiredChains } from './wallets';
|
|
40
45
|
|
|
41
46
|
export function getOutputRatio(
|
|
@@ -50,25 +55,29 @@ export function getOutputRatio(
|
|
|
50
55
|
) {
|
|
51
56
|
return 0;
|
|
52
57
|
}
|
|
53
|
-
return outputUsdValue
|
|
58
|
+
return outputUsdValue
|
|
59
|
+
.div(inputUsdValue)
|
|
60
|
+
.minus(1)
|
|
61
|
+
.multipliedBy(100)
|
|
62
|
+
.toNumber();
|
|
54
63
|
}
|
|
55
64
|
|
|
56
|
-
export function
|
|
65
|
+
export function hasHighValueLoss(
|
|
57
66
|
inputUsdValue: BigNumber | null,
|
|
58
|
-
|
|
67
|
+
priceImpact: number
|
|
59
68
|
): boolean {
|
|
60
69
|
return (
|
|
61
|
-
((parseInt(
|
|
70
|
+
((parseInt(priceImpact.toFixed(2) || '0') <= -10 &&
|
|
62
71
|
inputUsdValue?.gte(new BigNumber(400))) ||
|
|
63
|
-
(parseInt(
|
|
72
|
+
(parseInt(priceImpact.toFixed(2) || '0') <= -5 &&
|
|
64
73
|
inputUsdValue?.gte(new BigNumber(1000)))) ??
|
|
65
74
|
false
|
|
66
75
|
);
|
|
67
76
|
}
|
|
68
77
|
|
|
69
|
-
export function hasLimitError(
|
|
78
|
+
export function hasLimitError(quote: BestRouteResponse | null): boolean {
|
|
70
79
|
return (
|
|
71
|
-
(
|
|
80
|
+
(quote?.result?.swaps || []).filter((swap) => {
|
|
72
81
|
const minimum = !!swap.fromAmountMinValue
|
|
73
82
|
? new BigNumber(swap.fromAmountMinValue)
|
|
74
83
|
: null;
|
|
@@ -83,16 +92,12 @@ export function hasLimitError(bestRoute: BestRouteResponse | null): boolean {
|
|
|
83
92
|
}).length > 0
|
|
84
93
|
);
|
|
85
94
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
swap: SwapResult | null;
|
|
95
|
+
export function getLimitErrorMessage(quote: BestRouteResponse): {
|
|
96
|
+
swap: SwapResult;
|
|
89
97
|
fromAmountRangeError: string;
|
|
90
98
|
recommendation: string;
|
|
91
99
|
} {
|
|
92
|
-
|
|
93
|
-
return { swap: null, fromAmountRangeError: '', recommendation: '' };
|
|
94
|
-
}
|
|
95
|
-
const swap = (bestRoute?.result?.swaps || []).filter((swap) => {
|
|
100
|
+
const swap = (quote.result?.swaps || []).filter((swap) => {
|
|
96
101
|
const minimum = !!swap.fromAmountMinValue
|
|
97
102
|
? new BigNumber(swap.fromAmountMinValue)
|
|
98
103
|
: null;
|
|
@@ -105,9 +110,7 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
105
110
|
}
|
|
106
111
|
return minimum?.gt(swap.fromAmount) || maximum?.lt(swap.fromAmount);
|
|
107
112
|
})[0];
|
|
108
|
-
|
|
109
|
-
return { swap: null, fromAmountRangeError: '', recommendation: '' };
|
|
110
|
-
}
|
|
113
|
+
|
|
111
114
|
const minimum = !!swap.fromAmountMinValue
|
|
112
115
|
? new BigNumber(swap.fromAmountMinValue)
|
|
113
116
|
: null;
|
|
@@ -181,7 +184,7 @@ export function getSwapButtonState(
|
|
|
181
184
|
loadingMetaStatus: LoadingStatus,
|
|
182
185
|
connectedWallets: ConnectedWallet[],
|
|
183
186
|
loading: boolean,
|
|
184
|
-
|
|
187
|
+
quote: BestRouteResponse | null,
|
|
185
188
|
hasLimitError: boolean,
|
|
186
189
|
highValueLoss: boolean,
|
|
187
190
|
priceImpactCanNotBeComputed: boolean,
|
|
@@ -204,8 +207,8 @@ export function getSwapButtonState(
|
|
|
204
207
|
}
|
|
205
208
|
if (
|
|
206
209
|
loading ||
|
|
207
|
-
!
|
|
208
|
-
!
|
|
210
|
+
!quote ||
|
|
211
|
+
!quote.result ||
|
|
209
212
|
hasLimitError ||
|
|
210
213
|
!inputAmount ||
|
|
211
214
|
inputAmount === '0'
|
|
@@ -224,7 +227,7 @@ export function getSwapButtonState(
|
|
|
224
227
|
};
|
|
225
228
|
} else if (needsToWarnEthOnPath) {
|
|
226
229
|
return {
|
|
227
|
-
title: swapButtonTitles().
|
|
230
|
+
title: swapButtonTitles().ethWarning,
|
|
228
231
|
disabled: false,
|
|
229
232
|
hasWarning: true,
|
|
230
233
|
state: ButtonState.WARNING,
|
|
@@ -238,24 +241,24 @@ export function getSwapButtonState(
|
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
export function canComputePriceImpact(
|
|
241
|
-
|
|
244
|
+
quote: BestRouteResponse | null,
|
|
242
245
|
inputAmount: string,
|
|
243
246
|
usdValue: BigNumber | null
|
|
244
247
|
) {
|
|
245
248
|
return !(
|
|
246
249
|
(!usdValue || usdValue.lte(ZERO)) &&
|
|
247
|
-
!!
|
|
250
|
+
!!quote?.result &&
|
|
248
251
|
!!inputAmount &&
|
|
249
252
|
inputAmount !== '0' &&
|
|
250
253
|
parseFloat(inputAmount || '0') !== 0 &&
|
|
251
|
-
!!
|
|
254
|
+
!!quote.result
|
|
252
255
|
);
|
|
253
256
|
}
|
|
254
257
|
|
|
255
|
-
export function requiredWallets(
|
|
258
|
+
export function requiredWallets(quote: BestRouteResponse | null) {
|
|
256
259
|
const wallets: string[] = [];
|
|
257
260
|
|
|
258
|
-
|
|
261
|
+
quote?.result?.swaps.forEach((swap) => {
|
|
259
262
|
const currentStepFromBlockchain = swap.from.blockchain;
|
|
260
263
|
const currentStepToBlockchain = swap.to.blockchain;
|
|
261
264
|
let lastAddedWallet = wallets[wallets.length - 1];
|
|
@@ -311,15 +314,13 @@ export function getUsdFeeOfStep(
|
|
|
311
314
|
}
|
|
312
315
|
|
|
313
316
|
export function getTotalFeeInUsd(
|
|
314
|
-
|
|
317
|
+
swaps: SwapResult[],
|
|
315
318
|
allTokens: Token[]
|
|
316
|
-
): BigNumber
|
|
317
|
-
return (
|
|
318
|
-
|
|
319
|
-
(
|
|
320
|
-
|
|
321
|
-
ZERO
|
|
322
|
-
) || null
|
|
319
|
+
): BigNumber {
|
|
320
|
+
return swaps.reduce(
|
|
321
|
+
(totalFee: BigNumber, step) =>
|
|
322
|
+
totalFee.plus(getUsdFeeOfStep(step, allTokens)),
|
|
323
|
+
ZERO
|
|
323
324
|
);
|
|
324
325
|
}
|
|
325
326
|
|
|
@@ -336,10 +337,44 @@ export function hasSlippageError(
|
|
|
336
337
|
return (slippages?.filter((s) => !!s?.error)?.length || 0) > 0;
|
|
337
338
|
}
|
|
338
339
|
|
|
340
|
+
export function checkSlippageErrors(
|
|
341
|
+
quote: BestRouteResponse
|
|
342
|
+
): RecommendedSlippages | null {
|
|
343
|
+
const recommendedSlippages: RecommendedSlippages = new Map();
|
|
344
|
+
quote.result?.swaps.forEach((swap, index) => {
|
|
345
|
+
if (swap.recommendedSlippage?.error) {
|
|
346
|
+
recommendedSlippages.set(index, swap.recommendedSlippage.slippage);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
if (recommendedSlippages.size > 0) {
|
|
350
|
+
return recommendedSlippages;
|
|
351
|
+
}
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function checkSlippageWarnings(
|
|
356
|
+
quote: BestRouteResponse,
|
|
357
|
+
userSlippage: number
|
|
358
|
+
): RecommendedSlippages | null {
|
|
359
|
+
const recommendedSlippages: RecommendedSlippages = new Map();
|
|
360
|
+
quote.result?.swaps.forEach((swap, index) => {
|
|
361
|
+
if (
|
|
362
|
+
swap.recommendedSlippage?.slippage &&
|
|
363
|
+
parseInt(swap.recommendedSlippage?.slippage) > userSlippage
|
|
364
|
+
) {
|
|
365
|
+
recommendedSlippages.set(index, swap.recommendedSlippage.slippage);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
if (recommendedSlippages.size > 0) {
|
|
369
|
+
return recommendedSlippages;
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
|
|
339
374
|
export function getMinRequiredSlippage(
|
|
340
|
-
|
|
375
|
+
quote: BestRouteResponse
|
|
341
376
|
): string | null {
|
|
342
|
-
const slippages =
|
|
377
|
+
const slippages = quote.result?.swaps.map(
|
|
343
378
|
(slippage) => slippage.recommendedSlippage
|
|
344
379
|
);
|
|
345
380
|
return (
|
|
@@ -362,10 +397,10 @@ export function hasProperSlippage(
|
|
|
362
397
|
}
|
|
363
398
|
|
|
364
399
|
export function hasEnoughBalance(
|
|
365
|
-
|
|
400
|
+
quote: BestRouteResponse,
|
|
366
401
|
selectedWallets: Wallet[]
|
|
367
402
|
) {
|
|
368
|
-
const fee =
|
|
403
|
+
const fee = quote.validationStatus;
|
|
369
404
|
|
|
370
405
|
if (fee === null || fee.length === 0) {
|
|
371
406
|
return true;
|
|
@@ -389,18 +424,18 @@ export function hasEnoughBalance(
|
|
|
389
424
|
}
|
|
390
425
|
|
|
391
426
|
export function hasEnoughBalanceAndProperSlippage(
|
|
392
|
-
|
|
427
|
+
quote: BestRouteResponse,
|
|
393
428
|
selectedWallets: Wallet[],
|
|
394
429
|
userSlippage: string,
|
|
395
430
|
minRequiredSlippage: string | null
|
|
396
431
|
): boolean {
|
|
397
432
|
return (
|
|
398
|
-
hasEnoughBalance(
|
|
433
|
+
hasEnoughBalance(quote, selectedWallets) &&
|
|
399
434
|
hasProperSlippage(userSlippage, minRequiredSlippage)
|
|
400
435
|
);
|
|
401
436
|
}
|
|
402
437
|
|
|
403
|
-
export function
|
|
438
|
+
export function createQuoteRequestBody(params: {
|
|
404
439
|
fromToken: Token;
|
|
405
440
|
toToken: Token;
|
|
406
441
|
inputAmount: string;
|
|
@@ -411,7 +446,7 @@ export function createBestRouteRequestBody(params: {
|
|
|
411
446
|
affiliateRef: string | null;
|
|
412
447
|
affiliatePercent: number | null;
|
|
413
448
|
affiliateWallets: { [key: string]: string } | null;
|
|
414
|
-
|
|
449
|
+
initialQuote?: BestRouteResponse;
|
|
415
450
|
destination?: string;
|
|
416
451
|
}): BestRouteRequest {
|
|
417
452
|
const {
|
|
@@ -425,7 +460,7 @@ export function createBestRouteRequestBody(params: {
|
|
|
425
460
|
affiliateRef,
|
|
426
461
|
affiliatePercent,
|
|
427
462
|
affiliateWallets,
|
|
428
|
-
|
|
463
|
+
initialQuote,
|
|
429
464
|
destination,
|
|
430
465
|
} = params;
|
|
431
466
|
const selectedWalletsMap = selectedWallets?.reduce(
|
|
@@ -455,10 +490,10 @@ export function createBestRouteRequestBody(params: {
|
|
|
455
490
|
}
|
|
456
491
|
});
|
|
457
492
|
|
|
458
|
-
const checkPrerequisites = !!
|
|
493
|
+
const checkPrerequisites = !!initialQuote;
|
|
459
494
|
|
|
460
495
|
const filteredBlockchains = removeDuplicateFrom(
|
|
461
|
-
(
|
|
496
|
+
(initialQuote?.result?.swaps || []).reduce(
|
|
462
497
|
(blockchains: string[], swap) => {
|
|
463
498
|
blockchains.push(swap.from.blockchain, swap.to.blockchain);
|
|
464
499
|
// Check if internalSwaps array exists
|
|
@@ -526,29 +561,24 @@ export function getWalletsForNewSwap(selectedWallets: Wallet[]) {
|
|
|
526
561
|
return wallets;
|
|
527
562
|
}
|
|
528
563
|
|
|
529
|
-
export function
|
|
530
|
-
return
|
|
564
|
+
export function getQuoteOutputAmount(quote: BestRouteResponse) {
|
|
565
|
+
return quote.result?.outputAmount || null;
|
|
531
566
|
}
|
|
532
567
|
|
|
533
|
-
export function getPercentageChange(
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
) {
|
|
537
|
-
if (!inputUsdValue || !outputUsdValue) {
|
|
538
|
-
return null;
|
|
539
|
-
}
|
|
540
|
-
return new BigNumber(outputUsdValue)
|
|
541
|
-
.div(new BigNumber(inputUsdValue))
|
|
568
|
+
export function getPercentageChange(input: string, output: string) {
|
|
569
|
+
return new BigNumber(output)
|
|
570
|
+
.div(new BigNumber(input))
|
|
542
571
|
.minus(1)
|
|
543
|
-
.multipliedBy(100)
|
|
572
|
+
.multipliedBy(100)
|
|
573
|
+
.toNumber();
|
|
544
574
|
}
|
|
545
575
|
|
|
546
576
|
export function isOutputAmountChangedALot(
|
|
547
|
-
|
|
548
|
-
|
|
577
|
+
oldQuote: BestRouteResponse,
|
|
578
|
+
newQuote: BestRouteResponse
|
|
549
579
|
) {
|
|
550
|
-
const oldOutputAmount =
|
|
551
|
-
const newOutputAmount =
|
|
580
|
+
const oldOutputAmount = getQuoteOutputAmount(oldQuote);
|
|
581
|
+
const newOutputAmount = getQuoteOutputAmount(newQuote);
|
|
552
582
|
if (!oldOutputAmount || !newOutputAmount) {
|
|
553
583
|
return false;
|
|
554
584
|
}
|
|
@@ -560,15 +590,15 @@ export function isOutputAmountChangedALot(
|
|
|
560
590
|
return true;
|
|
561
591
|
}
|
|
562
592
|
|
|
563
|
-
return percentageChange
|
|
593
|
+
return percentageChange <= -1;
|
|
564
594
|
}
|
|
565
595
|
|
|
566
596
|
export function getBalanceWarnings(
|
|
567
|
-
|
|
597
|
+
quote: BestRouteResponse,
|
|
568
598
|
selectedWallets: Wallet[]
|
|
569
599
|
) {
|
|
570
|
-
const fee =
|
|
571
|
-
const requiredWallets = getRequiredChains(
|
|
600
|
+
const fee = quote.validationStatus;
|
|
601
|
+
const requiredWallets = getRequiredChains(quote);
|
|
572
602
|
const walletsSortedByRequiredWallets = selectedWallets.sort(
|
|
573
603
|
(selectedWallet1, selectedWallet2) =>
|
|
574
604
|
requiredWallets.indexOf(selectedWallet1.chain) -
|
|
@@ -729,14 +759,14 @@ export function confirmSwapDisabled(
|
|
|
729
759
|
fetching: boolean,
|
|
730
760
|
showCustomDestination: boolean,
|
|
731
761
|
customDestination: string,
|
|
732
|
-
|
|
762
|
+
quote: BestRouteResponse | null,
|
|
733
763
|
selectedWallets: { walletType: string; chain: string }[],
|
|
734
764
|
lastStepToBlockchain?: BlockchainMeta
|
|
735
765
|
) {
|
|
736
766
|
return (
|
|
737
767
|
fetching ||
|
|
738
768
|
(!showCustomDestination &&
|
|
739
|
-
!requiredWallets(
|
|
769
|
+
!requiredWallets(quote).every((chain) =>
|
|
740
770
|
selectedWallets.map((wallet) => wallet.chain).includes(chain)
|
|
741
771
|
)) ||
|
|
742
772
|
(!!showCustomDestination && !customDestination) ||
|
package/src/utils/wallets.ts
CHANGED
|
@@ -174,10 +174,10 @@ export function prepareAccountsForWalletStore(
|
|
|
174
174
|
return result;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
export function getRequiredChains(
|
|
177
|
+
export function getRequiredChains(quote: BestRouteResponse | null) {
|
|
178
178
|
const wallets: string[] = [];
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
quote?.result?.swaps.forEach((swap) => {
|
|
181
181
|
const currentStepFromBlockchain = swap.from.blockchain;
|
|
182
182
|
const currentStepToBlockchain = swap.to.blockchain;
|
|
183
183
|
if (!wallets.includes(currentStepFromBlockchain)) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NoRoutes.d.ts","sourceRoot":"","sources":["../../../src/components/NoRoutes/NoRoutes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAUlD,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,qBA6DxC"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Info } from './NoRoutes.types';
|
|
2
|
-
export declare function makeInfo(diagnosisMessage: string | null, disabledLiquiditySources: string[], hasError: boolean, toggleAllLiquiditySources: (shouldReset: boolean) => void, refetchBestRoute: () => void): Info;
|
|
3
|
-
//# sourceMappingURL=NoRoutes.helper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NoRoutes.helper.d.ts","sourceRoot":"","sources":["../../../src/components/NoRoutes/NoRoutes.helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAM7C,wBAAgB,QAAQ,CACtB,gBAAgB,EAAE,MAAM,GAAG,IAAI,EAC/B,wBAAwB,EAAE,MAAM,EAAE,EAClC,QAAQ,EAAE,OAAO,EACjB,yBAAyB,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,EACzD,gBAAgB,EAAE,MAAM,IAAI,GAC3B,IAAI,CAuCN"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NoRoutes.types.d.ts","sourceRoot":"","sources":["../../../src/components/NoRoutes/NoRoutes.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,WAAW,IAAI;IACnB,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/NoRoutes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouteErrors.d.ts","sourceRoot":"","sources":["../../../src/components/RouteErrors/RouteErrors.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,qBAgE3C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouteErrors.styles.d.ts","sourceRoot":"","sources":["../../../src/components/RouteErrors/RouteErrors.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAGjB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAMf,CAAC;AAEH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAMf,CAAC;AAEH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAIjB,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type BigNumber from 'bignumber.js';
|
|
2
|
-
export interface PropTypes {
|
|
3
|
-
openModal: boolean;
|
|
4
|
-
onToggle: (open: boolean) => void;
|
|
5
|
-
totalFeeInUsd: BigNumber | null;
|
|
6
|
-
outputUsdValue: BigNumber | null;
|
|
7
|
-
inputUsdValue: BigNumber | null;
|
|
8
|
-
percentageChange: BigNumber | null;
|
|
9
|
-
highValueLoss: boolean;
|
|
10
|
-
priceImpactCanNotBeComputed: boolean;
|
|
11
|
-
loading: boolean;
|
|
12
|
-
extraSpace: boolean;
|
|
13
|
-
}
|
|
14
|
-
type ModalPropTypesKeys = keyof Omit<PropTypes, 'priceImpactCanNotBeComputed' | 'openModal' | 'extraSpace' | 'loading'>;
|
|
15
|
-
export type ModalPropTypes = Pick<PropTypes, ModalPropTypesKeys> & {
|
|
16
|
-
open: boolean;
|
|
17
|
-
};
|
|
18
|
-
export interface ModalContentData {
|
|
19
|
-
title: string;
|
|
20
|
-
value: string;
|
|
21
|
-
valueColor?: string;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=RouteErrors.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouteErrors.types.d.ts","sourceRoot":"","sources":["../../../src/components/RouteErrors/RouteErrors.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAE1C,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,aAAa,EAAE,SAAS,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,SAAS,GAAG,IAAI,CAAC;IACjC,aAAa,EAAE,SAAS,GAAG,IAAI,CAAC;IAChC,gBAAgB,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,aAAa,EAAE,OAAO,CAAC;IACvB,2BAA2B,EAAE,OAAO,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,KAAK,kBAAkB,GAAG,MAAM,IAAI,CAClC,SAAS,EACT,6BAA6B,GAAG,WAAW,GAAG,YAAY,GAAG,SAAS,CACvE,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,GAAG;IACjE,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouteErrorsModal.d.ts","sourceRoot":"","sources":["../../../src/components/RouteErrors/RouteErrorsModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAW1D,OAAO,KAAK,MAAM,OAAO,CAAC;AAmB1B,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,qBAkGrD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouteErrorsModalItem.d.ts","sourceRoot":"","sources":["../../../src/components/RouteErrors/RouteErrorsModalItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,qBAgB3D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/RouteErrors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useConfirmSwap.d.ts","sourceRoot":"","sources":["../../src/hooks/useConfirmSwap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EAEnB,MAAM,EACP,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAwCzE,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC/B,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC3D,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAEF,KAAK,MAAM,GAAG;IACZ,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAoHF,wBAAgB,cAAc,IAAI,WAAW,CA4H5C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchBestRoute.d.ts","sourceRoot":"","sources":["../../src/hooks/useFetchBestRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAMrE,UAAU,iBAAiB;IACzB,KAAK,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACrE,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,iBAAiB,IAAI,iBAAiB,CAyBrD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bestRoute.d.ts","sourceRoot":"","sources":["../../src/store/bestRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAC;AACrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAE1E,OAAO,SAAS,MAAM,cAAc,CAAC;AAoBrC,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,YAAY,EAAE,cAAc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M,KAAK,IAAI,CAAC;IAChD,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;gCApBV,IAAI;uCACG,IAAI;yCACF,IAAI;yCACJ,cAAc,GAAG,IAAI,KAAK,IAAI;uCAChC,cAAc,GAAG,IAAI,KAAK,IAAI;oCAEjC,KAAK,GAAG,IAAI,KAAK,IAAI;kCACvB,KAAK,GAAG,IAAI,KAAK,IAAI;uCAChB,MAAM,KAAK,IAAI;;oCAElB,iBAAiB,GAAG,IAAI,KAAK,IAAI;mCAClC,WAAW,KAAK,IAAI;qCAClB,IAAI;8CACK,OAAO,KAAK,IAAI;4CAClB,MAAM,EAAE,KAAK,IAAI;;8CAEf,MAAM,KAAK,IAAI;uCACtB,IAAI;;CA4L9B,CAAC"}
|
package/dist/types/routing.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { RouteState } from '../store/bestRoute';
|
|
2
|
-
import type { SettingsState } from '../store/settings';
|
|
3
|
-
interface BestRouteStoreParams {
|
|
4
|
-
fromBlockchain?: RouteState['fromBlockchain'];
|
|
5
|
-
toBlockchain?: RouteState['toBlockchain'];
|
|
6
|
-
fromToken?: RouteState['fromToken'];
|
|
7
|
-
toToken?: RouteState['toToken'];
|
|
8
|
-
inputAmount?: RouteState['inputAmount'];
|
|
9
|
-
}
|
|
10
|
-
interface SettingsStoreParams {
|
|
11
|
-
slippage?: SettingsState['slippage'];
|
|
12
|
-
customSlippage?: SettingsState['customSlippage'];
|
|
13
|
-
disabledLiquiditySources?: SettingsState['disabledLiquiditySources'];
|
|
14
|
-
infiniteApprove?: SettingsState['infiniteApprove'];
|
|
15
|
-
}
|
|
16
|
-
export type BestRouteEqualityParams = {
|
|
17
|
-
store: 'bestRoute';
|
|
18
|
-
prevState: BestRouteStoreParams;
|
|
19
|
-
currentState: BestRouteStoreParams;
|
|
20
|
-
} | {
|
|
21
|
-
store: 'settings';
|
|
22
|
-
prevState: SettingsStoreParams;
|
|
23
|
-
currentState: SettingsStoreParams;
|
|
24
|
-
};
|
|
25
|
-
export declare enum ConfirmSwapErrorTypes {
|
|
26
|
-
NO_ROUTE = 0,
|
|
27
|
-
ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS = 1,
|
|
28
|
-
REQUEST_FAILED = 2,
|
|
29
|
-
REQUEST_CANCELED = 3
|
|
30
|
-
}
|
|
31
|
-
export type ConfirmSwapError = {
|
|
32
|
-
type: ConfirmSwapErrorTypes.NO_ROUTE;
|
|
33
|
-
diagnosisMessage?: string;
|
|
34
|
-
} | {
|
|
35
|
-
type: Exclude<ConfirmSwapErrorTypes, ConfirmSwapErrorTypes.NO_ROUTE>;
|
|
36
|
-
};
|
|
37
|
-
export declare enum RouteWarningType {
|
|
38
|
-
ROUTE_UPDATED = 0,
|
|
39
|
-
ROUTE_SWAPPERS_UPDATED = 1,
|
|
40
|
-
ROUTE_COINS_UPDATED = 2,
|
|
41
|
-
ROUTE_AND_OUTPUT_AMOUNT_UPDATED = 3
|
|
42
|
-
}
|
|
43
|
-
export type RouteWarning = {
|
|
44
|
-
type: RouteWarningType.ROUTE_AND_OUTPUT_AMOUNT_UPDATED;
|
|
45
|
-
newOutputAmount: string;
|
|
46
|
-
percentageChange: string;
|
|
47
|
-
} | {
|
|
48
|
-
type: Exclude<RouteWarningType, RouteWarningType.ROUTE_AND_OUTPUT_AMOUNT_UPDATED>;
|
|
49
|
-
};
|
|
50
|
-
export declare enum SlippageWarningType {
|
|
51
|
-
INSUFFICIENT_SLIPPAGE = 0,
|
|
52
|
-
HIGH_SLIPPAGE = 1
|
|
53
|
-
}
|
|
54
|
-
export type ConfirmSwapWarnings = {
|
|
55
|
-
route: RouteWarning | null;
|
|
56
|
-
balance: {
|
|
57
|
-
messages: string[];
|
|
58
|
-
} | null;
|
|
59
|
-
slippage: {
|
|
60
|
-
type: SlippageWarningType;
|
|
61
|
-
slippage: string | null;
|
|
62
|
-
} | null;
|
|
63
|
-
};
|
|
64
|
-
export {};
|
|
65
|
-
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/types/routing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,UAAU,oBAAoB;IAC5B,cAAc,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC9C,YAAY,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;CACzC;AAED,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACrC,cAAc,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACjD,wBAAwB,CAAC,EAAE,aAAa,CAAC,0BAA0B,CAAC,CAAC;IACrE,eAAe,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;CACpD;AAED,MAAM,MAAM,uBAAuB,GAC/B;IACE,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,oBAAoB,CAAC;IAChC,YAAY,EAAE,oBAAoB,CAAC;CACpC,GACD;IACE,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE,mBAAmB,CAAC;IAC/B,YAAY,EAAE,mBAAmB,CAAC;CACnC,CAAC;AAEN,oBAAY,qBAAqB;IAC/B,QAAQ,IAAA;IACR,kCAAkC,IAAA;IAClC,cAAc,IAAA;IACd,gBAAgB,IAAA;CACjB;AAED,MAAM,MAAM,gBAAgB,GACxB;IACE,IAAI,EA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AC;AAEF,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,GAClB,uBAAuB,CASzB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,KAAK,EAAE,EAAE,CAAC,SAAS,KAAK,EAAE,EACnE,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,CAAC,KAUT;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,cAAc,EAAE,EAC7B,MAAM,EAAE,KAAK,EAAE,GACd;IACD,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,SAAS,EAAE,KAAK,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,cAAc,GAAG,IAAI,CAAC;IACpC,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB,CA4CA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { NoRoutes } from './NoRoutes';
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { PropTypes } from './RouteErrors.types';
|
|
2
|
-
|
|
3
|
-
import { Alert, Divider, InfoIcon } from '@rango-dev/ui';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
|
|
6
|
-
import { errorMessages } from '../../constants/errors';
|
|
7
|
-
import { useBestRouteStore } from '../../store/bestRoute';
|
|
8
|
-
import { hasLimitError, LimitErrorMessage } from '../../utils/swap';
|
|
9
|
-
|
|
10
|
-
import { Action, Alerts } from './RouteErrors.styles';
|
|
11
|
-
import { RouteErrorsModal } from './RouteErrorsModal';
|
|
12
|
-
|
|
13
|
-
const WARNING_LEVEL_LIMIT = -10;
|
|
14
|
-
|
|
15
|
-
export function RouteErrors(props: PropTypes) {
|
|
16
|
-
const { bestRoute } = useBestRouteStore();
|
|
17
|
-
const {
|
|
18
|
-
highValueLoss,
|
|
19
|
-
percentageChange,
|
|
20
|
-
priceImpactCanNotBeComputed,
|
|
21
|
-
openModal,
|
|
22
|
-
onToggle,
|
|
23
|
-
totalFeeInUsd,
|
|
24
|
-
outputUsdValue,
|
|
25
|
-
inputUsdValue,
|
|
26
|
-
loading,
|
|
27
|
-
extraSpace,
|
|
28
|
-
} = props;
|
|
29
|
-
const error = hasLimitError(bestRoute);
|
|
30
|
-
const { recommendation } = LimitErrorMessage(bestRoute);
|
|
31
|
-
|
|
32
|
-
const showWarnings = !error && (highValueLoss || priceImpactCanNotBeComputed);
|
|
33
|
-
const showAlerts = showWarnings || error;
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<>
|
|
37
|
-
{(loading || (extraSpace && !showAlerts)) && <Divider size={20} />}
|
|
38
|
-
{showAlerts && (
|
|
39
|
-
<Alerts>
|
|
40
|
-
{showWarnings && (
|
|
41
|
-
<>
|
|
42
|
-
<Alert
|
|
43
|
-
title={
|
|
44
|
-
highValueLoss
|
|
45
|
-
? errorMessages().highValueLossError.title
|
|
46
|
-
: errorMessages().unknownPriceError.title
|
|
47
|
-
}
|
|
48
|
-
type={
|
|
49
|
-
highValueLoss && !!percentageChange?.lt(WARNING_LEVEL_LIMIT)
|
|
50
|
-
? 'error'
|
|
51
|
-
: 'warning'
|
|
52
|
-
}
|
|
53
|
-
variant="alarm"
|
|
54
|
-
action={
|
|
55
|
-
<Action onClick={() => onToggle(true)}>
|
|
56
|
-
<InfoIcon size={12} color="gray" />
|
|
57
|
-
</Action>
|
|
58
|
-
}
|
|
59
|
-
/>
|
|
60
|
-
</>
|
|
61
|
-
)}
|
|
62
|
-
{error && (
|
|
63
|
-
<Alert type="error" variant="alarm" title={recommendation} />
|
|
64
|
-
)}
|
|
65
|
-
</Alerts>
|
|
66
|
-
)}
|
|
67
|
-
|
|
68
|
-
<RouteErrorsModal
|
|
69
|
-
highValueLoss={highValueLoss}
|
|
70
|
-
open={openModal}
|
|
71
|
-
onToggle={onToggle}
|
|
72
|
-
percentageChange={percentageChange}
|
|
73
|
-
inputUsdValue={inputUsdValue}
|
|
74
|
-
outputUsdValue={outputUsdValue}
|
|
75
|
-
totalFeeInUsd={totalFeeInUsd}
|
|
76
|
-
/>
|
|
77
|
-
</>
|
|
78
|
-
);
|
|
79
|
-
}
|