@rango-dev/widget-embedded 0.22.4-next.6 → 0.22.4-next.8
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/AppRoutes.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +3 -0
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +1 -0
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +2 -2
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +15 -0
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +3 -0
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts +4 -0
- package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.d.ts +4 -0
- package/dist/components/HeaderButtons/HeaderButtons.d.ts.map +1 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +5 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.types.d.ts +3 -2
- package/dist/components/HeaderButtons/HeaderButtons.types.d.ts.map +1 -1
- package/dist/components/HeaderButtons/index.d.ts +1 -1
- package/dist/components/HeaderButtons/index.d.ts.map +1 -1
- package/dist/components/HistoryGroupedList/HistoryGroupedList.styles.d.ts +6 -0
- package/dist/components/HistoryGroupedList/HistoryGroupedList.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +3 -0
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.types.d.ts +1 -0
- package/dist/components/Layout/Layout.types.d.ts.map +1 -1
- package/dist/components/Layout/PageContainer.d.ts +1 -0
- package/dist/components/Layout/PageContainer.d.ts.map +1 -1
- package/dist/components/Layout/ScrollableArea.d.ts +1 -0
- package/dist/components/Layout/ScrollableArea.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -0
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +14 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.styles.d.ts +3 -0
- package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +4 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1136 -25
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.types.d.ts +12 -7
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts +5 -0
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
- package/dist/components/Quote/QuoteSummary.styles.d.ts +2 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -1
- package/dist/components/Quote/QuoteTrigger .d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +4 -0
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.types.d.ts +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.types.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts +20 -10
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.types.d.ts +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.types.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +5 -0
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +4 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +1 -0
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +3 -0
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +5 -0
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +13 -0
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +1 -0
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +2 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/index.d.ts +1 -1
- package/dist/components/SwapDetailsModal/index.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +17 -0
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +4 -0
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/constants/navigationRoutes.d.ts +1 -0
- package/dist/constants/navigationRoutes.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +5 -1
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/containers/App/App.styles.d.ts +1 -0
- package/dist/containers/App/App.styles.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +3 -0
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +6 -3
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +5 -4
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +1 -1
- package/dist/hooks/useFetch.d.ts +12 -0
- package/dist/hooks/useFetch.d.ts.map +1 -0
- package/dist/hooks/useFetchAllQuotes.d.ts +4 -0
- package/dist/hooks/useFetchAllQuotes.d.ts.map +1 -0
- package/dist/hooks/useFetchConfirmQuote.d.ts +4 -0
- package/dist/hooks/useFetchConfirmQuote.d.ts.map +1 -0
- package/dist/hooks/useSwapInput.d.ts +5 -5
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.js +2 -2
- 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/pages/Routes.d.ts +3 -0
- package/dist/pages/Routes.d.ts.map +1 -0
- package/dist/store/quote.d.ts +32 -10
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +0 -2
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/quote.d.ts +19 -1
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +12 -9
- package/dist/utils/quote.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +18 -18
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +3 -3
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/AppRoutes.tsx +5 -0
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +3 -3
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +21 -18
- package/src/components/HeaderButtons/{HomeButtons.tsx → HeaderButtons.tsx} +39 -26
- package/src/components/HeaderButtons/HeaderButtons.types.ts +3 -2
- package/src/components/HeaderButtons/index.ts +1 -1
- package/src/components/Layout/Layout.tsx +13 -1
- package/src/components/Layout/Layout.types.ts +1 -0
- package/src/components/Quote/Quote.styles.ts +133 -38
- package/src/components/Quote/Quote.tsx +68 -13
- package/src/components/Quote/Quote.types.ts +13 -7
- package/src/components/Quote/QuoteCostDetails.tsx +9 -4
- package/src/components/Quote/QuoteTrigger .tsx +7 -3
- package/src/components/QuoteSkeleton/QuoteSkeleton.tsx +2 -2
- package/src/components/QuoteSkeleton/QuoteSkeleton.types.ts +1 -1
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.styles.ts +10 -12
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.tsx +28 -9
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.types.ts +1 -1
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +19 -19
- package/src/components/SwapDetails/SwapDetails.tsx +1 -1
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/SwapDetailsModal/index.ts +1 -1
- package/src/constants/navigationRoutes.ts +1 -0
- package/src/constants/quote.ts +17 -1
- package/src/containers/QuoteInfo/QuoteInfo.tsx +32 -7
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +6 -3
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +36 -20
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +76 -78
- package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +1 -1
- package/src/hooks/useFetch.ts +48 -0
- package/src/hooks/useFetchAllQuotes.ts +21 -0
- package/src/hooks/useFetchConfirmQuote.ts +21 -0
- package/src/hooks/useSwapInput.ts +59 -31
- package/src/pages/ConfirmSwapPage.tsx +12 -9
- package/src/pages/Home.tsx +25 -15
- package/src/pages/Routes.tsx +131 -0
- package/src/store/quote.ts +60 -22
- package/src/store/wallets.ts +0 -2
- package/src/types/quote.ts +27 -1
- package/src/utils/quote.ts +129 -67
- package/src/utils/swap.ts +37 -77
- package/src/utils/wallets.ts +10 -9
- package/dist/components/HeaderButtons/HomeButtons.d.ts +0 -4
- package/dist/components/HeaderButtons/HomeButtons.d.ts.map +0 -1
- package/dist/hooks/useFetchQuote.d.ts +0 -9
- package/dist/hooks/useFetchQuote.d.ts.map +0 -1
- package/src/hooks/useFetchQuote.ts +0 -38
package/src/utils/swap.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
2
|
import type { FeesGroup, NameOfFees } from '../constants/quote';
|
|
3
3
|
import type { FetchStatus } from '../store/slices/data';
|
|
4
|
+
import type { ConnectedWallet } from '../store/wallets';
|
|
4
5
|
import type {
|
|
5
6
|
ConvertedToken,
|
|
6
7
|
QuoteError,
|
|
7
8
|
QuoteWarning,
|
|
8
9
|
RecommendedSlippages,
|
|
10
|
+
SelectedQuote,
|
|
9
11
|
SwapButtonState,
|
|
10
12
|
Wallet,
|
|
11
13
|
} from '../types';
|
|
12
14
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
13
15
|
import type {
|
|
14
16
|
BestRouteRequest,
|
|
15
|
-
BestRouteResponse,
|
|
16
17
|
BlockchainMeta,
|
|
17
18
|
RecommendedSlippage,
|
|
18
19
|
SwapFee,
|
|
@@ -36,7 +37,6 @@ import {
|
|
|
36
37
|
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
37
38
|
} from '../constants/routing';
|
|
38
39
|
|
|
39
|
-
import { removeDuplicateFrom } from './common';
|
|
40
40
|
import { getBlockchainShortNameFor } from './meta';
|
|
41
41
|
import { numberToString } from './numbers';
|
|
42
42
|
import { getPriceImpact, getRequiredBalanceOfWallet } from './quote';
|
|
@@ -74,9 +74,9 @@ export function hasHighValueLoss(
|
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export function hasLimitError(
|
|
77
|
+
export function hasLimitError(swaps: SwapResult[]): boolean {
|
|
78
78
|
return (
|
|
79
|
-
(
|
|
79
|
+
(swaps || []).filter((swap) => {
|
|
80
80
|
const minimum = !!swap.fromAmountMinValue
|
|
81
81
|
? new BigNumber(swap.fromAmountMinValue)
|
|
82
82
|
: null;
|
|
@@ -91,12 +91,13 @@ export function hasLimitError(quote: BestRouteResponse | null): boolean {
|
|
|
91
91
|
}).length > 0
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
|
|
95
|
+
export function getLimitErrorMessage(swaps: SwapResult[]): {
|
|
95
96
|
swap: SwapResult;
|
|
96
97
|
fromAmountRangeError: string;
|
|
97
98
|
recommendation: string;
|
|
98
99
|
} {
|
|
99
|
-
const swap = (
|
|
100
|
+
const swap = (swaps || []).filter((swap) => {
|
|
100
101
|
const minimum = !!swap.fromAmountMinValue
|
|
101
102
|
? new BigNumber(swap.fromAmountMinValue)
|
|
102
103
|
: null;
|
|
@@ -184,7 +185,7 @@ export function getSwapButtonState(params: {
|
|
|
184
185
|
anyWalletConnected: boolean;
|
|
185
186
|
fetchingQuote: boolean;
|
|
186
187
|
inputAmount: string;
|
|
187
|
-
quote:
|
|
188
|
+
quote: SelectedQuote | null;
|
|
188
189
|
warning: QuoteWarning | null;
|
|
189
190
|
error: QuoteError | null;
|
|
190
191
|
needsToWarnEthOnPath: boolean;
|
|
@@ -213,14 +214,7 @@ export function getSwapButtonState(params: {
|
|
|
213
214
|
disabled: false,
|
|
214
215
|
};
|
|
215
216
|
}
|
|
216
|
-
if (
|
|
217
|
-
fetchingQuote ||
|
|
218
|
-
!quote ||
|
|
219
|
-
!quote.result ||
|
|
220
|
-
error ||
|
|
221
|
-
!inputAmount ||
|
|
222
|
-
inputAmount === '0'
|
|
223
|
-
) {
|
|
217
|
+
if (fetchingQuote || !quote || error || !inputAmount || inputAmount === '0') {
|
|
224
218
|
return {
|
|
225
219
|
title: swapButtonTitles().swap,
|
|
226
220
|
action: 'confirm-swap',
|
|
@@ -247,24 +241,24 @@ export function getSwapButtonState(params: {
|
|
|
247
241
|
}
|
|
248
242
|
|
|
249
243
|
export function canComputePriceImpact(
|
|
250
|
-
quote:
|
|
244
|
+
quote: SelectedQuote | null,
|
|
251
245
|
inputAmount: string,
|
|
252
246
|
usdValue: BigNumber | null
|
|
253
247
|
) {
|
|
254
248
|
return !(
|
|
255
249
|
(!usdValue || usdValue.lte(ZERO)) &&
|
|
256
|
-
!!quote
|
|
250
|
+
!!quote &&
|
|
257
251
|
!!inputAmount &&
|
|
258
252
|
inputAmount !== '0' &&
|
|
259
253
|
parseFloat(inputAmount || '0') !== 0 &&
|
|
260
|
-
!!quote
|
|
254
|
+
!!quote
|
|
261
255
|
);
|
|
262
256
|
}
|
|
263
257
|
|
|
264
|
-
export function requiredWallets(quote:
|
|
258
|
+
export function requiredWallets(quote: SelectedQuote | null) {
|
|
265
259
|
const wallets: string[] = [];
|
|
266
260
|
|
|
267
|
-
quote?.
|
|
261
|
+
quote?.swaps.forEach((swap) => {
|
|
268
262
|
const currentStepFromBlockchain = swap.from.blockchain;
|
|
269
263
|
const currentStepToBlockchain = swap.to.blockchain;
|
|
270
264
|
let lastAddedWallet = wallets[wallets.length - 1];
|
|
@@ -377,10 +371,10 @@ export function hasSlippageError(
|
|
|
377
371
|
}
|
|
378
372
|
|
|
379
373
|
export function checkSlippageErrors(
|
|
380
|
-
|
|
374
|
+
swaps: SwapResult[]
|
|
381
375
|
): RecommendedSlippages | null {
|
|
382
376
|
const recommendedSlippages: RecommendedSlippages = new Map();
|
|
383
|
-
|
|
377
|
+
swaps.forEach((swap, index) => {
|
|
384
378
|
if (swap.recommendedSlippage?.error) {
|
|
385
379
|
recommendedSlippages.set(index, swap.recommendedSlippage.slippage);
|
|
386
380
|
}
|
|
@@ -392,11 +386,11 @@ export function checkSlippageErrors(
|
|
|
392
386
|
}
|
|
393
387
|
|
|
394
388
|
export function checkSlippageWarnings(
|
|
395
|
-
quote:
|
|
389
|
+
quote: SelectedQuote,
|
|
396
390
|
userSlippage: number
|
|
397
391
|
): RecommendedSlippages | null {
|
|
398
392
|
const recommendedSlippages: RecommendedSlippages = new Map();
|
|
399
|
-
quote
|
|
393
|
+
quote?.swaps.forEach((swap, index) => {
|
|
400
394
|
if (
|
|
401
395
|
swap.recommendedSlippage?.slippage &&
|
|
402
396
|
parseFloat(swap.recommendedSlippage.slippage) > userSlippage
|
|
@@ -410,12 +404,8 @@ export function checkSlippageWarnings(
|
|
|
410
404
|
return null;
|
|
411
405
|
}
|
|
412
406
|
|
|
413
|
-
export function getMinRequiredSlippage(
|
|
414
|
-
|
|
415
|
-
): string | null {
|
|
416
|
-
const slippages = quote.result?.swaps.map(
|
|
417
|
-
(slippage) => slippage.recommendedSlippage
|
|
418
|
-
);
|
|
407
|
+
export function getMinRequiredSlippage(swaps: SwapResult[]): string | null {
|
|
408
|
+
const slippages = swaps.map((slippage) => slippage.recommendedSlippage);
|
|
419
409
|
return (
|
|
420
410
|
slippages
|
|
421
411
|
?.map((s) => s?.slippage || '0')
|
|
@@ -436,7 +426,7 @@ export function hasProperSlippage(
|
|
|
436
426
|
}
|
|
437
427
|
|
|
438
428
|
export function hasEnoughBalance(
|
|
439
|
-
quote:
|
|
429
|
+
quote: SelectedQuote,
|
|
440
430
|
selectedWallets: Wallet[]
|
|
441
431
|
) {
|
|
442
432
|
const fee = quote.validationStatus;
|
|
@@ -463,7 +453,7 @@ export function hasEnoughBalance(
|
|
|
463
453
|
}
|
|
464
454
|
|
|
465
455
|
export function hasEnoughBalanceAndProperSlippage(
|
|
466
|
-
quote:
|
|
456
|
+
quote: SelectedQuote,
|
|
467
457
|
selectedWallets: Wallet[],
|
|
468
458
|
userSlippage: string,
|
|
469
459
|
minRequiredSlippage: string | null
|
|
@@ -478,7 +468,7 @@ export function createQuoteRequestBody(params: {
|
|
|
478
468
|
fromToken: Token;
|
|
479
469
|
toToken: Token;
|
|
480
470
|
inputAmount: string;
|
|
481
|
-
wallets?:
|
|
471
|
+
wallets?: ConnectedWallet[];
|
|
482
472
|
selectedWallets?: Wallet[];
|
|
483
473
|
liquiditySources?: string[];
|
|
484
474
|
excludeLiquiditySources?: boolean;
|
|
@@ -487,7 +477,6 @@ export function createQuoteRequestBody(params: {
|
|
|
487
477
|
affiliateRef: string | null;
|
|
488
478
|
affiliatePercent: number | null;
|
|
489
479
|
affiliateWallets: { [key: string]: string } | null;
|
|
490
|
-
initialQuote?: BestRouteResponse;
|
|
491
480
|
destination?: string;
|
|
492
481
|
}): BestRouteRequest {
|
|
493
482
|
const {
|
|
@@ -503,7 +492,6 @@ export function createQuoteRequestBody(params: {
|
|
|
503
492
|
affiliateRef,
|
|
504
493
|
affiliatePercent,
|
|
505
494
|
affiliateWallets,
|
|
506
|
-
initialQuote,
|
|
507
495
|
destination,
|
|
508
496
|
} = params;
|
|
509
497
|
const selectedWalletsMap = selectedWallets?.reduce(
|
|
@@ -520,46 +508,18 @@ export function createQuoteRequestBody(params: {
|
|
|
520
508
|
const connectedWallets: BestRouteRequest['connectedWallets'] = [];
|
|
521
509
|
|
|
522
510
|
wallets?.forEach((wallet) => {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
chainAndAccounts.addresses.push(wallet.address);
|
|
528
|
-
} else {
|
|
529
|
-
connectedWallets.push({
|
|
530
|
-
blockchain: wallet.chain,
|
|
531
|
-
addresses: [wallet.address],
|
|
532
|
-
});
|
|
533
|
-
}
|
|
511
|
+
connectedWallets.push({
|
|
512
|
+
blockchain: wallet.chain,
|
|
513
|
+
addresses: [wallet.address],
|
|
514
|
+
});
|
|
534
515
|
});
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
const filteredBlockchains = removeDuplicateFrom(
|
|
539
|
-
(initialQuote?.result?.swaps || []).reduce(
|
|
540
|
-
(blockchains: string[], swap) => {
|
|
541
|
-
blockchains.push(swap.from.blockchain, swap.to.blockchain);
|
|
542
|
-
// Check if internalSwaps array exists
|
|
543
|
-
if (swap.internalSwaps && Array.isArray(swap.internalSwaps)) {
|
|
544
|
-
swap.internalSwaps.map((internalSwap) => {
|
|
545
|
-
blockchains.push(
|
|
546
|
-
internalSwap.from.blockchain,
|
|
547
|
-
internalSwap.to.blockchain
|
|
548
|
-
);
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
return blockchains;
|
|
552
|
-
},
|
|
553
|
-
[]
|
|
554
|
-
)
|
|
555
|
-
);
|
|
556
|
-
|
|
516
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
517
|
+
// @ts-ignore
|
|
557
518
|
const requestBody: BestRouteRequest = {
|
|
558
519
|
amount: inputAmount.toString(),
|
|
559
520
|
affiliateRef: affiliateRef ?? undefined,
|
|
560
521
|
affiliatePercent: affiliatePercent ?? undefined,
|
|
561
522
|
affiliateWallets: affiliateWallets ?? undefined,
|
|
562
|
-
checkPrerequisites,
|
|
563
523
|
from: {
|
|
564
524
|
address: fromToken.address,
|
|
565
525
|
blockchain: fromToken.blockchain,
|
|
@@ -584,7 +544,6 @@ export function createQuoteRequestBody(params: {
|
|
|
584
544
|
),
|
|
585
545
|
swappersGroupsExclude: false,
|
|
586
546
|
}),
|
|
587
|
-
...(checkPrerequisites && { blockchains: filteredBlockchains }),
|
|
588
547
|
};
|
|
589
548
|
return requestBody;
|
|
590
549
|
}
|
|
@@ -609,8 +568,8 @@ export function getWalletsForNewSwap(selectedWallets: Wallet[]) {
|
|
|
609
568
|
return wallets;
|
|
610
569
|
}
|
|
611
570
|
|
|
612
|
-
export function getQuoteOutputAmount(quote:
|
|
613
|
-
return quote
|
|
571
|
+
export function getQuoteOutputAmount(quote: SelectedQuote) {
|
|
572
|
+
return quote?.outputAmount || null;
|
|
614
573
|
}
|
|
615
574
|
|
|
616
575
|
export function getPercentageChange(input: string, output: string) {
|
|
@@ -622,8 +581,8 @@ export function getPercentageChange(input: string, output: string) {
|
|
|
622
581
|
}
|
|
623
582
|
|
|
624
583
|
export function isOutputAmountChangedALot(
|
|
625
|
-
oldQuote:
|
|
626
|
-
newQuote:
|
|
584
|
+
oldQuote: SelectedQuote,
|
|
585
|
+
newQuote: SelectedQuote
|
|
627
586
|
) {
|
|
628
587
|
const oldOutputAmount = getQuoteOutputAmount(oldQuote);
|
|
629
588
|
const newOutputAmount = getQuoteOutputAmount(newQuote);
|
|
@@ -639,7 +598,7 @@ export function isOutputAmountChangedALot(
|
|
|
639
598
|
}
|
|
640
599
|
|
|
641
600
|
export function generateBalanceWarnings(
|
|
642
|
-
quote:
|
|
601
|
+
quote: SelectedQuote,
|
|
643
602
|
selectedWallets: Wallet[],
|
|
644
603
|
blockchains: BlockchainMeta[]
|
|
645
604
|
) {
|
|
@@ -650,6 +609,7 @@ export function generateBalanceWarnings(
|
|
|
650
609
|
requiredWallets.indexOf(selectedWallet1.chain) -
|
|
651
610
|
requiredWallets.indexOf(selectedWallet2.chain)
|
|
652
611
|
);
|
|
612
|
+
|
|
653
613
|
return walletsSortedByRequiredWallets
|
|
654
614
|
.flatMap((wallet) => getRequiredBalanceOfWallet(wallet, fee) || [])
|
|
655
615
|
.filter((asset) => !asset.ok)
|
|
@@ -797,8 +757,8 @@ export function shouldRetrySwap(pendingSwap: PendingSwap) {
|
|
|
797
757
|
export function confirmSwapDisabled(
|
|
798
758
|
fetching: boolean,
|
|
799
759
|
showCustomDestination: boolean,
|
|
800
|
-
customDestination: string,
|
|
801
|
-
quote:
|
|
760
|
+
customDestination: string | null,
|
|
761
|
+
quote: SelectedQuote | null,
|
|
802
762
|
selectedWallets: { walletType: string; chain: string }[],
|
|
803
763
|
lastStepToBlockchain?: BlockchainMeta
|
|
804
764
|
) {
|
package/src/utils/wallets.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Balance,
|
|
4
|
+
SelectedQuote,
|
|
5
|
+
TokenHash,
|
|
6
|
+
TokensBalance,
|
|
7
|
+
Wallet,
|
|
8
|
+
} from '../types';
|
|
3
9
|
import type { WalletInfo as ModalWalletInfo } from '@rango-dev/ui';
|
|
4
10
|
import type {
|
|
5
11
|
Asset,
|
|
@@ -9,12 +15,7 @@ import type {
|
|
|
9
15
|
WalletType,
|
|
10
16
|
WalletTypes,
|
|
11
17
|
} from '@rango-dev/wallets-shared';
|
|
12
|
-
import type {
|
|
13
|
-
BestRouteResponse,
|
|
14
|
-
BlockchainMeta,
|
|
15
|
-
Token,
|
|
16
|
-
WalletDetail,
|
|
17
|
-
} from 'rango-sdk';
|
|
18
|
+
import type { BlockchainMeta, Token, WalletDetail } from 'rango-sdk';
|
|
18
19
|
|
|
19
20
|
import { WalletState as WalletStatus } from '@rango-dev/ui';
|
|
20
21
|
import { readAccountAddress } from '@rango-dev/wallets-react';
|
|
@@ -192,10 +193,10 @@ export function prepareAccountsForWalletStore(
|
|
|
192
193
|
return result;
|
|
193
194
|
}
|
|
194
195
|
|
|
195
|
-
export function getRequiredChains(quote:
|
|
196
|
+
export function getRequiredChains(quote: SelectedQuote | null) {
|
|
196
197
|
const wallets: string[] = [];
|
|
197
198
|
|
|
198
|
-
quote?.
|
|
199
|
+
quote?.swaps.forEach((swap) => {
|
|
199
200
|
const currentStepFromBlockchain = swap.from.blockchain;
|
|
200
201
|
const currentStepToBlockchain = swap.to.blockchain;
|
|
201
202
|
if (!wallets.includes(currentStepFromBlockchain)) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HomeButtons.d.ts","sourceRoot":"","sources":["../../../src/components/HeaderButtons/HomeButtons.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAUlE,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,wBAAgB,WAAW,CAAC,KAAK,EAAE,oBAAoB,qBAwDtD"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { BestRouteRequest, BestRouteResponse } from 'rango-sdk';
|
|
2
|
-
interface UseFetchQuote {
|
|
3
|
-
fetch: (requestBody: BestRouteRequest) => Promise<BestRouteResponse>;
|
|
4
|
-
cancelFetch: () => void;
|
|
5
|
-
loading: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare function useFetchQuote(): UseFetchQuote;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=useFetchQuote.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchQuote.d.ts","sourceRoot":"","sources":["../../src/hooks/useFetchQuote.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAMrE,UAAU,aAAa;IACrB,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,aAAa,IAAI,aAAa,CAyB7C"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { BestRouteRequest, BestRouteResponse } from 'rango-sdk';
|
|
2
|
-
|
|
3
|
-
import { useRef, useState } from 'react';
|
|
4
|
-
|
|
5
|
-
import { httpService } from '../services/httpService';
|
|
6
|
-
|
|
7
|
-
interface UseFetchQuote {
|
|
8
|
-
fetch: (requestBody: BestRouteRequest) => Promise<BestRouteResponse>;
|
|
9
|
-
cancelFetch: () => void;
|
|
10
|
-
loading: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function useFetchQuote(): UseFetchQuote {
|
|
14
|
-
const [loading, setLoading] = useState(false);
|
|
15
|
-
const abortController = useRef<AbortController | null>(null);
|
|
16
|
-
const cancel = () => abortController.current?.abort();
|
|
17
|
-
|
|
18
|
-
const fetch: UseFetchQuote['fetch'] = async (requestBody) => {
|
|
19
|
-
cancel();
|
|
20
|
-
abortController.current = new AbortController();
|
|
21
|
-
|
|
22
|
-
setLoading(true);
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const res = await httpService().getBestRoute(requestBody, {
|
|
26
|
-
signal: abortController.current.signal,
|
|
27
|
-
});
|
|
28
|
-
abortController.current = null;
|
|
29
|
-
return res;
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-useless-catch
|
|
31
|
-
} catch (error: any) {
|
|
32
|
-
throw error;
|
|
33
|
-
} finally {
|
|
34
|
-
setLoading(false);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
return { fetch, loading, cancelFetch: cancel };
|
|
38
|
-
}
|