@rango-dev/widget-embedded 0.22.4-next.5 → 0.22.4-next.7
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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { SelectedQuote } from '../types';
|
|
2
|
+
import type { MultiRouteSimulationResult } from 'rango-sdk';
|
|
3
|
+
|
|
4
|
+
import { i18n } from '@lingui/core';
|
|
5
|
+
import { Divider } from '@rango-dev/ui';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { useNavigate } from 'react-router-dom';
|
|
8
|
+
|
|
9
|
+
import { HeaderButtons } from '../components/HeaderButtons';
|
|
10
|
+
import { Layout, PageContainer } from '../components/Layout';
|
|
11
|
+
import { QuoteSkeleton } from '../components/QuoteSkeleton';
|
|
12
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
13
|
+
import { QuoteInfo } from '../containers/QuoteInfo';
|
|
14
|
+
import { getQuoteError } from '../hooks/useConfirmSwap/useConfirmSwap.helpers';
|
|
15
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
16
|
+
import { useSwapInput } from '../hooks/useSwapInput';
|
|
17
|
+
import { useAppStore } from '../store/AppStore';
|
|
18
|
+
import { useQuoteStore } from '../store/quote';
|
|
19
|
+
import { generateQuoteWarnings } from '../utils/quote';
|
|
20
|
+
|
|
21
|
+
const ITEM_SKELETON_COUNT = 3;
|
|
22
|
+
export function RoutesPage() {
|
|
23
|
+
const navigate = useNavigate();
|
|
24
|
+
const navigateBack = useNavigateBack();
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
selectedQuote,
|
|
28
|
+
quotes,
|
|
29
|
+
refetchQuote,
|
|
30
|
+
setSelectedQuote,
|
|
31
|
+
updateQuotePartialState,
|
|
32
|
+
fromToken,
|
|
33
|
+
toToken,
|
|
34
|
+
error: quoteError,
|
|
35
|
+
} = useQuoteStore();
|
|
36
|
+
const { slippage, customSlippage } = useAppStore();
|
|
37
|
+
const tokens = useAppStore().tokens();
|
|
38
|
+
|
|
39
|
+
const userSlippage = customSlippage ?? slippage;
|
|
40
|
+
|
|
41
|
+
const { fetch: fetchQuote, loading: fetchingQuote } = useSwapInput({
|
|
42
|
+
refetchQuote,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const onClickOnQuote = (quote: SelectedQuote) => {
|
|
46
|
+
setSelectedQuote(quote);
|
|
47
|
+
updateQuotePartialState('refetchQuote', false);
|
|
48
|
+
navigateBack();
|
|
49
|
+
};
|
|
50
|
+
const getQuoteWarning = (quote: MultiRouteSimulationResult) => {
|
|
51
|
+
if (!fromToken || !toToken || !quotes) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const mergedQuote: SelectedQuote = {
|
|
55
|
+
requestAmount: quotes.requestAmount, // Assuming quotes is an array
|
|
56
|
+
...quote,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return generateQuoteWarnings(mergedQuote, {
|
|
60
|
+
fromToken,
|
|
61
|
+
toToken,
|
|
62
|
+
userSlippage,
|
|
63
|
+
tokens,
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const settings_url = `../${navigationRoutes.settings}`;
|
|
67
|
+
const wallets_url = `../${navigationRoutes.wallets}`;
|
|
68
|
+
return (
|
|
69
|
+
<Layout
|
|
70
|
+
header={{
|
|
71
|
+
onWallet: () => {
|
|
72
|
+
navigate(wallets_url);
|
|
73
|
+
},
|
|
74
|
+
onBack: () => {
|
|
75
|
+
updateQuotePartialState('refetchQuote', false);
|
|
76
|
+
},
|
|
77
|
+
title: i18n.t('Routes'),
|
|
78
|
+
suffix: (
|
|
79
|
+
<HeaderButtons
|
|
80
|
+
onClickRefresh={
|
|
81
|
+
!!selectedQuote || quoteError ? fetchQuote : undefined
|
|
82
|
+
}
|
|
83
|
+
hidden={['notifications', 'history']}
|
|
84
|
+
onClickSettings={() => navigate(settings_url)}
|
|
85
|
+
/>
|
|
86
|
+
),
|
|
87
|
+
}}>
|
|
88
|
+
<PageContainer>
|
|
89
|
+
{fetchingQuote
|
|
90
|
+
? Array.from({ length: ITEM_SKELETON_COUNT }, (_, index) => (
|
|
91
|
+
<React.Fragment key={index}>
|
|
92
|
+
<QuoteSkeleton
|
|
93
|
+
tagHidden={false}
|
|
94
|
+
type="list-item"
|
|
95
|
+
expanded={false}
|
|
96
|
+
/>
|
|
97
|
+
<Divider size={16} />
|
|
98
|
+
</React.Fragment>
|
|
99
|
+
))
|
|
100
|
+
: !!quotes &&
|
|
101
|
+
quotes.results?.map((quote) => {
|
|
102
|
+
const quoteWarning = getQuoteWarning(quote);
|
|
103
|
+
const quoteError = getQuoteError(quote.swaps);
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<React.Fragment key={quote.requestId}>
|
|
107
|
+
<QuoteInfo
|
|
108
|
+
selected={selectedQuote?.requestId === quote.requestId}
|
|
109
|
+
tagHidden={false}
|
|
110
|
+
quote={{ ...quote, requestAmount: quotes.requestAmount }}
|
|
111
|
+
loading={fetchingQuote}
|
|
112
|
+
error={quoteError?.options || null}
|
|
113
|
+
warning={quoteWarning}
|
|
114
|
+
onClick={(quote) => {
|
|
115
|
+
updateQuotePartialState('warning', quoteWarning);
|
|
116
|
+
updateQuotePartialState(
|
|
117
|
+
'error',
|
|
118
|
+
quoteError?.options || null
|
|
119
|
+
);
|
|
120
|
+
onClickOnQuote(quote);
|
|
121
|
+
}}
|
|
122
|
+
type="list-item"
|
|
123
|
+
/>
|
|
124
|
+
<Divider size={16} />
|
|
125
|
+
</React.Fragment>
|
|
126
|
+
);
|
|
127
|
+
})}
|
|
128
|
+
</PageContainer>
|
|
129
|
+
</Layout>
|
|
130
|
+
);
|
|
131
|
+
}
|
package/src/store/quote.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { Wallet } from '../types';
|
|
1
|
+
import type { QuoteError, QuoteWarning, SelectedQuote, Wallet } from '../types';
|
|
2
2
|
import type {
|
|
3
|
-
BestRouteResponse,
|
|
4
3
|
BlockchainMeta,
|
|
5
4
|
MetaResponse,
|
|
5
|
+
MultiRouteResponse,
|
|
6
|
+
PreferenceType,
|
|
6
7
|
Token,
|
|
7
8
|
} from 'rango-sdk';
|
|
8
9
|
import type { PendingSwap } from 'rango-types';
|
|
@@ -30,6 +31,14 @@ export type Meta = Pick<MetaResponse, 'blockchains' | 'tokens'>;
|
|
|
30
31
|
|
|
31
32
|
export type SetTokenParams = { token: Token; meta: Meta } | { token: null };
|
|
32
33
|
|
|
34
|
+
type SomeQuoteState = {
|
|
35
|
+
quotes: MultiRouteResponse | null;
|
|
36
|
+
sortStrategy: PreferenceType;
|
|
37
|
+
refetchQuote: boolean;
|
|
38
|
+
error: QuoteError | null;
|
|
39
|
+
warning: QuoteWarning | null;
|
|
40
|
+
};
|
|
41
|
+
|
|
33
42
|
export interface QuoteState {
|
|
34
43
|
fromBlockchain: BlockchainMeta | null;
|
|
35
44
|
toBlockchain: BlockchainMeta | null;
|
|
@@ -38,27 +47,37 @@ export interface QuoteState {
|
|
|
38
47
|
outputAmount: BigNumber | null;
|
|
39
48
|
outputUsdValue: BigNumber | null;
|
|
40
49
|
fromToken: Token | null;
|
|
50
|
+
sortStrategy: PreferenceType;
|
|
41
51
|
toToken: Token | null;
|
|
42
52
|
quoteWalletsConfirmed: boolean;
|
|
43
53
|
selectedWallets: Wallet[];
|
|
44
54
|
quoteWarningsConfirmed: boolean;
|
|
55
|
+
refetchQuote: boolean;
|
|
56
|
+
selectedQuote: SelectedQuote | null;
|
|
57
|
+
quotes: MultiRouteResponse | null;
|
|
58
|
+
customDestination: string | null;
|
|
59
|
+
error: QuoteError | null;
|
|
60
|
+
warning: QuoteWarning | null;
|
|
45
61
|
resetQuote: () => void;
|
|
62
|
+
resetAlerts: () => void;
|
|
63
|
+
|
|
46
64
|
resetToBlockchain: () => void;
|
|
47
65
|
resetFromBlockchain: () => void;
|
|
48
66
|
setFromBlockchain: (chain: BlockchainMeta | null) => void;
|
|
49
67
|
setToBlockchain: (chian: BlockchainMeta | null) => void;
|
|
50
|
-
|
|
51
68
|
setFromToken: (params: SetTokenParams) => void;
|
|
52
69
|
setToToken: (params: SetTokenParams) => void;
|
|
70
|
+
updateQuotePartialState: <K extends keyof SomeQuoteState>(
|
|
71
|
+
key: K,
|
|
72
|
+
value: SomeQuoteState[K]
|
|
73
|
+
) => void;
|
|
53
74
|
setInputAmount: (amount: string) => void;
|
|
54
|
-
quote:
|
|
55
|
-
setQuote: (quote: BestRouteResponse | null) => void;
|
|
75
|
+
setSelectedQuote: (quote: SelectedQuote | null) => void;
|
|
56
76
|
retry: (pendingSwap: PendingSwap, meta: Meta) => void;
|
|
57
77
|
switchFromAndTo: () => void;
|
|
58
78
|
setQuoteWalletConfirmed: (flag: boolean) => void;
|
|
59
79
|
setSelectedWallets: (wallets: Wallet[]) => void;
|
|
60
|
-
|
|
61
|
-
setCustomDestination: (address: string) => void;
|
|
80
|
+
setCustomDestination: (address: string | null) => void;
|
|
62
81
|
resetQuoteWallets: () => void;
|
|
63
82
|
setQuoteWarningsConfirmed: (flag: boolean) => void;
|
|
64
83
|
}
|
|
@@ -74,12 +93,22 @@ export const useQuoteStore = createSelectors(
|
|
|
74
93
|
outputUsdValue: new BigNumber(0),
|
|
75
94
|
toBlockchain: null,
|
|
76
95
|
toToken: null,
|
|
77
|
-
|
|
96
|
+
refetchQuote: true,
|
|
97
|
+
sortStrategy: 'SMART',
|
|
98
|
+
selectedQuote: null,
|
|
99
|
+
quotes: null,
|
|
100
|
+
error: null,
|
|
101
|
+
warning: null,
|
|
78
102
|
quoteWalletsConfirmed: false,
|
|
79
103
|
selectedWallets: [],
|
|
80
|
-
customDestination:
|
|
104
|
+
customDestination: null,
|
|
81
105
|
quoteWarningsConfirmed: false,
|
|
82
|
-
|
|
106
|
+
updateQuotePartialState: (key, value) =>
|
|
107
|
+
set((state) => ({
|
|
108
|
+
...state,
|
|
109
|
+
[key]: value,
|
|
110
|
+
})),
|
|
111
|
+
setSelectedQuote: (quote) =>
|
|
83
112
|
set((state) => {
|
|
84
113
|
let outputAmount: BigNumber | null = null;
|
|
85
114
|
let outputUsdValue: BigNumber = ZERO;
|
|
@@ -87,27 +116,36 @@ export const useQuoteStore = createSelectors(
|
|
|
87
116
|
return {};
|
|
88
117
|
}
|
|
89
118
|
if (!!quote) {
|
|
90
|
-
outputAmount = !!quote
|
|
91
|
-
? new BigNumber(quote
|
|
119
|
+
outputAmount = !!quote?.outputAmount
|
|
120
|
+
? new BigNumber(quote?.outputAmount)
|
|
92
121
|
: null;
|
|
93
122
|
outputUsdValue = calcOutputUsdValue(
|
|
94
|
-
quote
|
|
123
|
+
quote?.outputAmount,
|
|
95
124
|
getQuoteToTokenUsdPrice(quote) || state.toToken?.usdPrice
|
|
96
125
|
);
|
|
97
126
|
}
|
|
98
127
|
return {
|
|
99
|
-
|
|
128
|
+
selectedQuote: quote,
|
|
100
129
|
...(!!quote && {
|
|
101
130
|
outputAmount,
|
|
102
131
|
outputUsdValue,
|
|
103
132
|
}),
|
|
104
133
|
};
|
|
105
134
|
}),
|
|
135
|
+
resetAlerts: () =>
|
|
136
|
+
set(() => ({
|
|
137
|
+
error: null,
|
|
138
|
+
warning: null,
|
|
139
|
+
})),
|
|
106
140
|
resetQuote: () =>
|
|
107
141
|
set(() => ({
|
|
108
|
-
|
|
142
|
+
selectedQuote: null,
|
|
109
143
|
outputAmount: null,
|
|
110
144
|
outputUsdValue: new BigNumber(0),
|
|
145
|
+
quotes: null,
|
|
146
|
+
refetchQuote: true,
|
|
147
|
+
error: null,
|
|
148
|
+
warning: null,
|
|
111
149
|
})),
|
|
112
150
|
setFromBlockchain: (chain) => {
|
|
113
151
|
set((state) => {
|
|
@@ -118,7 +156,7 @@ export const useQuoteStore = createSelectors(
|
|
|
118
156
|
return {
|
|
119
157
|
fromBlockchain: chain,
|
|
120
158
|
...(state.fromToken && {
|
|
121
|
-
|
|
159
|
+
selectedQuote: null,
|
|
122
160
|
fromToken: null,
|
|
123
161
|
outputAmount: null,
|
|
124
162
|
outputUsdValue: null,
|
|
@@ -149,7 +187,7 @@ export const useQuoteStore = createSelectors(
|
|
|
149
187
|
return {
|
|
150
188
|
toBlockchain: chain,
|
|
151
189
|
...(state.toToken && {
|
|
152
|
-
|
|
190
|
+
selectedQuote: null,
|
|
153
191
|
toToken: null,
|
|
154
192
|
outputAmount: null,
|
|
155
193
|
outputUsdValue: null,
|
|
@@ -174,7 +212,7 @@ export const useQuoteStore = createSelectors(
|
|
|
174
212
|
...(!amount && {
|
|
175
213
|
outputAmount: new BigNumber(0),
|
|
176
214
|
outputUsdValue: new BigNumber(0),
|
|
177
|
-
|
|
215
|
+
selectedQuote: null,
|
|
178
216
|
}),
|
|
179
217
|
...(!!state.fromToken && {
|
|
180
218
|
inputUsdValue: getUsdValue(state.fromToken, amount),
|
|
@@ -199,7 +237,7 @@ export const useQuoteStore = createSelectors(
|
|
|
199
237
|
outputUsdValue: new BigNumber(0),
|
|
200
238
|
toBlockchain,
|
|
201
239
|
toToken,
|
|
202
|
-
|
|
240
|
+
selectedQuote: null,
|
|
203
241
|
});
|
|
204
242
|
},
|
|
205
243
|
switchFromAndTo: () =>
|
|
@@ -220,7 +258,7 @@ export const useQuoteStore = createSelectors(
|
|
|
220
258
|
fromBlockchain: null,
|
|
221
259
|
outputAmount: null,
|
|
222
260
|
outputUsdValue: null,
|
|
223
|
-
|
|
261
|
+
selectedQuote: null,
|
|
224
262
|
})),
|
|
225
263
|
resetToBlockchain: () =>
|
|
226
264
|
set(() => ({
|
|
@@ -228,7 +266,7 @@ export const useQuoteStore = createSelectors(
|
|
|
228
266
|
toBlockchain: null,
|
|
229
267
|
outputAmount: null,
|
|
230
268
|
outputUsdValue: null,
|
|
231
|
-
|
|
269
|
+
selectedQuote: null,
|
|
232
270
|
})),
|
|
233
271
|
setQuoteWalletConfirmed: (flag) =>
|
|
234
272
|
set({
|
|
@@ -240,7 +278,7 @@ export const useQuoteStore = createSelectors(
|
|
|
240
278
|
set({
|
|
241
279
|
quoteWalletsConfirmed: false,
|
|
242
280
|
selectedWallets: [],
|
|
243
|
-
customDestination:
|
|
281
|
+
customDestination: null,
|
|
244
282
|
}),
|
|
245
283
|
setQuoteWarningsConfirmed: (flag) =>
|
|
246
284
|
set({ quoteWarningsConfirmed: flag }),
|
package/src/store/wallets.ts
CHANGED
|
@@ -38,7 +38,6 @@ export interface ConnectedWallet extends Wallet {
|
|
|
38
38
|
interface WalletsStore {
|
|
39
39
|
connectedWallets: ConnectedWallet[];
|
|
40
40
|
balances: TokensBalance;
|
|
41
|
-
customDestination: string;
|
|
42
41
|
loading: boolean;
|
|
43
42
|
connectWallet: (accounts: Wallet[], tokens: Token[]) => void;
|
|
44
43
|
disconnectWallet: (walletType: WalletType) => void;
|
|
@@ -57,7 +56,6 @@ export const useWalletsStore = createSelectors(
|
|
|
57
56
|
subscribeWithSelector((set, get) => ({
|
|
58
57
|
connectedWallets: [],
|
|
59
58
|
balances: {},
|
|
60
|
-
customDestination: '',
|
|
61
59
|
loading: false,
|
|
62
60
|
connectWallet: (accounts, tokens) => {
|
|
63
61
|
const getWalletsDetails = get().getWalletsDetails;
|
package/src/types/quote.ts
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import type { PriceImpactWarningLevel } from '@rango-dev/ui';
|
|
4
4
|
import type BigNumber from 'bignumber.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
BlockchainValidationStatus,
|
|
7
|
+
RouteTag,
|
|
8
|
+
RoutingResultType,
|
|
9
|
+
SwapResult,
|
|
10
|
+
} from 'rango-sdk';
|
|
6
11
|
|
|
7
12
|
export enum QuoteErrorType {
|
|
8
13
|
NO_RESULT,
|
|
@@ -105,3 +110,24 @@ export type ConfirmSwapWarnings = {
|
|
|
105
110
|
quoteUpdate: QuoteUpdateWarning | null;
|
|
106
111
|
balance: { messages: string[] } | null;
|
|
107
112
|
};
|
|
113
|
+
|
|
114
|
+
export type QuoteResponse = {
|
|
115
|
+
requestId: string;
|
|
116
|
+
swaps?: SwapResult[];
|
|
117
|
+
diagnosisMessages: string[] | null;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type SelectedQuote = {
|
|
121
|
+
swaps: SwapResult[];
|
|
122
|
+
requestId: string;
|
|
123
|
+
outputAmount?: string;
|
|
124
|
+
resultType?: RoutingResultType;
|
|
125
|
+
tags?: RouteTag[];
|
|
126
|
+
validationStatus: BlockchainValidationStatus[] | null;
|
|
127
|
+
requestAmount: string;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type QuoteErrorResponse = {
|
|
131
|
+
message: string;
|
|
132
|
+
options: QuoteError;
|
|
133
|
+
};
|
package/src/utils/quote.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import type {
|
|
2
|
+
import type { QuoteWarning, SelectedQuote, Wallet } from '../types';
|
|
3
3
|
import type { PriceImpactWarningLevel, Step } from '@rango-dev/ui';
|
|
4
4
|
import type {
|
|
5
5
|
SimulationAssetAndAmount,
|
|
@@ -7,8 +7,12 @@ import type {
|
|
|
7
7
|
} from '@rango-dev/ui/dist/widget/ui/src/types/swaps';
|
|
8
8
|
import type {
|
|
9
9
|
Asset,
|
|
10
|
-
BestRouteResponse,
|
|
11
10
|
BlockchainMeta,
|
|
11
|
+
MultiRouteResponse,
|
|
12
|
+
MultiRouteSimulationResult,
|
|
13
|
+
PreferenceType,
|
|
14
|
+
RouteTag,
|
|
15
|
+
TagValue,
|
|
12
16
|
Token,
|
|
13
17
|
} from 'rango-sdk';
|
|
14
18
|
import type { PendingSwap } from 'rango-types';
|
|
@@ -16,65 +20,60 @@ import type { PendingSwap } from 'rango-types';
|
|
|
16
20
|
import { getLastSuccessfulStep } from '@rango-dev/queue-manager-rango-preset';
|
|
17
21
|
import BigNumber from 'bignumber.js';
|
|
18
22
|
|
|
23
|
+
import { HIGH_PRIORITY_TAGS } from '../constants/quote';
|
|
19
24
|
import { HIGHT_PRICE_IMPACT, LOW_PRICE_IMPACT } from '../constants/routing';
|
|
20
25
|
import { HIGH_SLIPPAGE } from '../constants/swapSettings';
|
|
21
26
|
import { getUsdValue } from '../store/quote';
|
|
22
|
-
import {
|
|
27
|
+
import { QuoteWarningType } from '../types';
|
|
23
28
|
|
|
24
29
|
import { areEqual } from './common';
|
|
25
30
|
import { findBlockchain, findToken } from './meta';
|
|
26
31
|
import {
|
|
27
|
-
checkSlippageErrors,
|
|
28
32
|
checkSlippageWarnings,
|
|
29
|
-
getLimitErrorMessage,
|
|
30
33
|
getMinRequiredSlippage,
|
|
31
34
|
getPercentageChange,
|
|
32
35
|
getTotalFeeInUsd,
|
|
33
36
|
hasHighValueLoss,
|
|
34
|
-
hasLimitError,
|
|
35
37
|
hasProperSlippage,
|
|
36
38
|
} from './swap';
|
|
37
39
|
|
|
38
40
|
export function getQuoteToTokenUsdPrice(
|
|
39
|
-
quote:
|
|
41
|
+
quote: SelectedQuote | null
|
|
40
42
|
): number | null | undefined {
|
|
41
|
-
|
|
43
|
+
const swaps = quote?.swaps || [];
|
|
44
|
+
return swaps[swaps.length - 1].to.usdPrice;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
export function isNumberOfSwapsChanged(
|
|
45
|
-
quoteA:
|
|
46
|
-
quoteB:
|
|
48
|
+
quoteA: SelectedQuote,
|
|
49
|
+
quoteB: SelectedQuote
|
|
47
50
|
) {
|
|
48
|
-
const quoteASwaps = quoteA
|
|
49
|
-
const quoteBSwaps = quoteB
|
|
51
|
+
const quoteASwaps = quoteA?.swaps || [];
|
|
52
|
+
const quoteBSwaps = quoteB?.swaps || [];
|
|
50
53
|
return quoteASwaps.length !== quoteBSwaps.length;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
export function isQuoteSwappersUpdated(
|
|
54
|
-
quoteA:
|
|
55
|
-
quoteB:
|
|
57
|
+
quoteA: SelectedQuote,
|
|
58
|
+
quoteB: SelectedQuote
|
|
56
59
|
) {
|
|
57
|
-
const quoteASwappers =
|
|
58
|
-
|
|
59
|
-
const quoteBSwappers =
|
|
60
|
-
quoteB.result?.swaps.map((swap) => swap.swapperId) || [];
|
|
60
|
+
const quoteASwappers = quoteA?.swaps.map((swap) => swap.swapperId) || [];
|
|
61
|
+
const quoteBSwappers = quoteB?.swaps.map((swap) => swap.swapperId) || [];
|
|
61
62
|
return !areEqual(quoteASwappers, quoteBSwappers);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
export function isQuoteInternalCoinsUpdated(
|
|
65
|
-
quoteA:
|
|
66
|
-
quoteB:
|
|
66
|
+
quoteA: SelectedQuote,
|
|
67
|
+
quoteB: SelectedQuote
|
|
67
68
|
) {
|
|
68
|
-
const quoteAInternalCoins =
|
|
69
|
-
|
|
70
|
-
const quoteBInternalCoins =
|
|
71
|
-
quoteB.result?.swaps.map((swap) => swap.to.symbol) || [];
|
|
69
|
+
const quoteAInternalCoins = quoteA?.swaps.map((swap) => swap.to.symbol) || [];
|
|
70
|
+
const quoteBInternalCoins = quoteB?.swaps.map((swap) => swap.to.symbol) || [];
|
|
72
71
|
return !areEqual(quoteAInternalCoins, quoteBInternalCoins);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
export function isQuoteChanged(
|
|
76
|
-
quoteA:
|
|
77
|
-
quoteB:
|
|
75
|
+
quoteA: SelectedQuote,
|
|
76
|
+
quoteB: SelectedQuote
|
|
78
77
|
): boolean {
|
|
79
78
|
return (
|
|
80
79
|
isNumberOfSwapsChanged(quoteA, quoteB) ||
|
|
@@ -198,7 +197,7 @@ export function createRetryQuote(
|
|
|
198
197
|
}
|
|
199
198
|
|
|
200
199
|
export function generateQuoteWarnings(
|
|
201
|
-
quote:
|
|
200
|
+
quote: SelectedQuote,
|
|
202
201
|
params: {
|
|
203
202
|
fromToken: Token;
|
|
204
203
|
toToken: Token;
|
|
@@ -208,9 +207,9 @@ export function generateQuoteWarnings(
|
|
|
208
207
|
): QuoteWarning | null {
|
|
209
208
|
const { fromToken, toToken, tokens, userSlippage } = params;
|
|
210
209
|
const inputUsdValue = getUsdValue(fromToken, quote.requestAmount);
|
|
211
|
-
const outputUsdValue = getUsdValue(toToken, quote
|
|
210
|
+
const outputUsdValue = getUsdValue(toToken, quote?.outputAmount ?? '');
|
|
212
211
|
|
|
213
|
-
if (quote
|
|
212
|
+
if (!!quote && inputUsdValue && outputUsdValue) {
|
|
214
213
|
const priceImpact = getPriceImpact(
|
|
215
214
|
inputUsdValue.toString(),
|
|
216
215
|
outputUsdValue.toString()
|
|
@@ -219,7 +218,7 @@ export function generateQuoteWarnings(
|
|
|
219
218
|
!!priceImpact && hasHighValueLoss(inputUsdValue, priceImpact);
|
|
220
219
|
|
|
221
220
|
if (highValueLoss) {
|
|
222
|
-
const totalFee = getTotalFeeInUsd(quote
|
|
221
|
+
const totalFee = getTotalFeeInUsd(quote?.swaps, tokens);
|
|
223
222
|
const warningLevel = getPriceImpactLevel(priceImpact);
|
|
224
223
|
return {
|
|
225
224
|
type: QuoteWarningType.HIGH_VALUE_LOSS,
|
|
@@ -230,11 +229,11 @@ export function generateQuoteWarnings(
|
|
|
230
229
|
warningLevel,
|
|
231
230
|
};
|
|
232
231
|
}
|
|
233
|
-
} else if (quote
|
|
232
|
+
} else if (quote && (!inputUsdValue || !outputUsdValue)) {
|
|
234
233
|
return { type: QuoteWarningType.UNKNOWN_PRICE };
|
|
235
234
|
}
|
|
236
235
|
|
|
237
|
-
const minRequiredSlippage = getMinRequiredSlippage(quote);
|
|
236
|
+
const minRequiredSlippage = getMinRequiredSlippage(quote.swaps);
|
|
238
237
|
const highSlippage = userSlippage > HIGH_SLIPPAGE;
|
|
239
238
|
|
|
240
239
|
if (!hasProperSlippage(params.userSlippage.toString(), minRequiredSlippage)) {
|
|
@@ -256,41 +255,6 @@ export function generateQuoteWarnings(
|
|
|
256
255
|
return null;
|
|
257
256
|
}
|
|
258
257
|
|
|
259
|
-
export function generateQuoteErrors(
|
|
260
|
-
quote: BestRouteResponse
|
|
261
|
-
): QuoteError | null {
|
|
262
|
-
if (!quote.result) {
|
|
263
|
-
return {
|
|
264
|
-
type: QuoteErrorType.NO_RESULT,
|
|
265
|
-
diagnosisMessage: quote.diagnosisMessages?.[0],
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
const limitError = hasLimitError(quote);
|
|
269
|
-
if (limitError) {
|
|
270
|
-
const { swap, recommendation, fromAmountRangeError } =
|
|
271
|
-
getLimitErrorMessage(quote);
|
|
272
|
-
return {
|
|
273
|
-
type: QuoteErrorType.BRIDGE_LIMIT,
|
|
274
|
-
swap: swap,
|
|
275
|
-
recommendation,
|
|
276
|
-
fromAmountRangeError,
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const recommendedSlippages = checkSlippageErrors(quote);
|
|
281
|
-
|
|
282
|
-
if (recommendedSlippages) {
|
|
283
|
-
const minRequiredSlippage = getMinRequiredSlippage(quote);
|
|
284
|
-
return {
|
|
285
|
-
type: QuoteErrorType.INSUFFICIENT_SLIPPAGE,
|
|
286
|
-
recommendedSlippages,
|
|
287
|
-
minRequiredSlippage,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
258
|
export function getPriceImpact(
|
|
295
259
|
inputUsdValue: BigNumber | string | null,
|
|
296
260
|
outputUsdValue: BigNumber | string | null
|
|
@@ -326,3 +290,101 @@ export const getUniqueBlockchains = (steps: Step[]) => {
|
|
|
326
290
|
|
|
327
291
|
return result;
|
|
328
292
|
};
|
|
293
|
+
|
|
294
|
+
export const sortQuotesBy = (
|
|
295
|
+
strategy: PreferenceType,
|
|
296
|
+
quotes: MultiRouteResponse['results']
|
|
297
|
+
): MultiRouteResponse['results'] => {
|
|
298
|
+
return quotes.sort((quote1, quote2) => {
|
|
299
|
+
const getScore = (route: MultiRouteSimulationResult) =>
|
|
300
|
+
route.scores?.find((score) => score.preferenceType === strategy)?.score ??
|
|
301
|
+
0;
|
|
302
|
+
|
|
303
|
+
const quote1Score = getScore(quote1);
|
|
304
|
+
const quote2Score = getScore(quote2);
|
|
305
|
+
|
|
306
|
+
if (quote1Score !== quote2Score) {
|
|
307
|
+
return quote2Score - quote1Score;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const lowerQuoteId1 = quote1.requestId.toLowerCase();
|
|
311
|
+
const lowerQuoteId2 = quote2.requestId.toLowerCase();
|
|
312
|
+
|
|
313
|
+
return lowerQuoteId1.localeCompare(lowerQuoteId2);
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export const getDefaultQuote = (
|
|
318
|
+
currentQuote: SelectedQuote | null,
|
|
319
|
+
quotes: MultiRouteSimulationResult[],
|
|
320
|
+
requestAmount: string
|
|
321
|
+
): SelectedQuote | null => {
|
|
322
|
+
if (!quotes.length) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
if (!currentQuote) {
|
|
326
|
+
// Handle the case where currentQuote is null
|
|
327
|
+
return {
|
|
328
|
+
requestAmount: requestAmount,
|
|
329
|
+
...quotes[0], // Return the first quote from the quotes array
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
// Create a set of swapperIds from the currentQuote swaps
|
|
333
|
+
const currentQuoteSwapperIds = new Set(
|
|
334
|
+
currentQuote.swaps.map((swap) => swap.swapperId)
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
// Find a quote that matches the currentQuote's swapperIds
|
|
338
|
+
const matchedQuote = quotes.find((quote) => {
|
|
339
|
+
// Create a set of swapperIds from the quote swaps
|
|
340
|
+
const quoteSwapperIds = new Set(quote.swaps.map((swap) => swap.swapperId));
|
|
341
|
+
|
|
342
|
+
// Check if all swapperIds from the currentQuote are present in the quoteSwapperIds
|
|
343
|
+
return Array.from(currentQuoteSwapperIds).every((swapperId) =>
|
|
344
|
+
quoteSwapperIds.has(swapperId)
|
|
345
|
+
);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// Return the matchedQuote if found, otherwise return the first quote from the quotes array
|
|
349
|
+
return {
|
|
350
|
+
requestAmount: requestAmount,
|
|
351
|
+
...(matchedQuote || quotes[0]),
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
export const sortTags = (tags: RouteTag[]): RouteTag[] => {
|
|
356
|
+
const customSort = (a: RouteTag, b: RouteTag) => {
|
|
357
|
+
const indexA = HIGH_PRIORITY_TAGS.indexOf(a.value);
|
|
358
|
+
const indexB = HIGH_PRIORITY_TAGS.indexOf(b.value);
|
|
359
|
+
|
|
360
|
+
if (indexA !== -1 && indexB !== -1) {
|
|
361
|
+
return indexA - indexB;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (indexA !== -1) {
|
|
365
|
+
return -1;
|
|
366
|
+
} else if (indexB !== -1) {
|
|
367
|
+
return 1;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return 0;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
return tags.sort(customSort);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export const getRouteTagColor = (tag: TagValue): string => {
|
|
377
|
+
switch (tag) {
|
|
378
|
+
case 'FASTEST':
|
|
379
|
+
return '#06C270';
|
|
380
|
+
case 'RECOMMENDED':
|
|
381
|
+
return '#469BF5';
|
|
382
|
+
case 'LOWEST_FEE':
|
|
383
|
+
return '#FF4DAD';
|
|
384
|
+
case 'HIGH_IMPACT':
|
|
385
|
+
return '#FF3B3B';
|
|
386
|
+
case 'CENTRALIZED':
|
|
387
|
+
default:
|
|
388
|
+
return '#FFF1D4';
|
|
389
|
+
}
|
|
390
|
+
};
|