@rango-dev/widget-embedded 0.17.1-next.9 → 0.19.0
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/CHANGELOG.md +4 -0
- package/dist/QueueManager.d.ts +1 -2
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/Wallets.d.ts +0 -1
- package/dist/Wallets.d.ts.map +1 -1
- package/dist/Widget.d.ts +1 -1
- package/dist/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +2 -0
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +6 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +3 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +3 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts +4 -1
- package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts.map +1 -1
- package/dist/components/NoRoutes/NoRoutes.d.ts +4 -0
- package/dist/components/NoRoutes/NoRoutes.d.ts.map +1 -0
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts +3 -0
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +1 -0
- package/dist/components/{NoResult/NoResult.styles.d.ts → NoRoutes/NoRoutes.styles.d.ts} +1 -1
- package/dist/components/{NoResult/NoResult.styles.d.ts.map → NoRoutes/NoRoutes.styles.d.ts.map} +1 -1
- package/dist/components/{NoResult/NoResult.types.d.ts → NoRoutes/NoRoutes.types.d.ts} +3 -3
- package/dist/components/NoRoutes/NoRoutes.types.d.ts.map +1 -0
- package/dist/components/NoRoutes/index.d.ts +2 -0
- package/dist/components/NoRoutes/index.d.ts.map +1 -0
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.d.ts +4 -0
- package/dist/components/RouteErrors/RouteErrors.d.ts.map +1 -0
- package/dist/components/{QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts → RouteErrors/RouteErrors.styles.d.ts} +1 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -0
- package/dist/components/RouteErrors/RouteErrors.types.d.ts +24 -0
- package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +1 -0
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts +4 -0
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +1 -0
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts +4 -0
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts.map +1 -0
- package/dist/components/RouteErrors/index.d.ts +2 -0
- package/dist/components/RouteErrors/index.d.ts.map +1 -0
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts +6 -1
- package/dist/components/UpdateUrl.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/searchParams.d.ts +1 -2
- package/dist/constants/searchParams.d.ts.map +1 -1
- package/dist/constants/warnings.d.ts +2 -2
- package/dist/constants/warnings.d.ts.map +1 -1
- package/dist/hooks/{useConfirmSwap/useConfirmSwap.types.d.ts → useConfirmSwap.d.ts} +7 -5
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -0
- package/dist/hooks/{useFetchQuote.d.ts → useFetchBestRoute.d.ts} +3 -3
- package/dist/hooks/useFetchBestRoute.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
- package/dist/hooks/useSwapInput.d.ts +2 -4
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts +2 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts +6 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcePage.d.ts +2 -1
- package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +6 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +8 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/app.d.ts +23 -5
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/{quote.d.ts → bestRoute.d.ts} +27 -39
- package/dist/store/bestRoute.d.ts.map +1 -0
- package/dist/store/meta.d.ts +23 -0
- package/dist/store/meta.d.ts.map +1 -0
- package/dist/store/settings.d.ts +2 -3
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +2 -3
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts +0 -3
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +4 -5
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +5 -5
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/routing.d.ts +65 -0
- package/dist/types/routing.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/{quote.d.ts → routing.d.ts} +12 -16
- package/dist/utils/routing.d.ts.map +1 -0
- package/dist/utils/settings.d.ts +2 -3
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +22 -25
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +2 -2
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/QueueManager.tsx +14 -14
- package/src/Wallets.tsx +15 -35
- package/src/Widget.tsx +24 -11
- package/src/components/AppRouter.tsx +5 -6
- package/src/components/AppRoutes.tsx +39 -6
- package/src/components/BlockchainList/BlockchainList.tsx +4 -4
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +7 -7
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +64 -2
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +40 -28
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +3 -1
- package/src/components/ConfirmWalletsModal/WalletList.tsx +5 -6
- package/src/components/ConfirmWalletsModal/WalletList.type.ts +4 -1
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +3 -3
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +6 -6
- package/src/components/{NoResult/NoResult.helpers.ts → NoRoutes/NoRoutes.helper.ts} +9 -16
- package/src/components/{NoResult/NoResult.styles.ts → NoRoutes/NoRoutes.styles.ts} +0 -2
- package/src/components/{NoResult/NoResult.tsx → NoRoutes/NoRoutes.tsx} +12 -10
- package/src/components/{NoResult/NoResult.types.ts → NoRoutes/NoRoutes.types.ts} +2 -3
- package/src/components/NoRoutes/index.ts +1 -0
- package/src/components/NotificationContent/NotificationContent.tsx +2 -3
- package/src/components/RouteErrors/RouteErrors.tsx +79 -0
- package/src/components/RouteErrors/RouteErrors.types.ts +29 -0
- package/src/components/RouteErrors/RouteErrorsModal.tsx +129 -0
- package/src/components/{QuoteWarningsAndErrors/QuoteErrorsModalItem.tsx → RouteErrors/RouteErrorsModalItem.tsx} +3 -3
- package/src/components/RouteErrors/index.ts +1 -0
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +22 -18
- package/src/components/SwitchFromAndTo.tsx +2 -2
- package/src/components/TokenList/TokenList.tsx +6 -5
- package/src/components/UpdateUrl.tsx +26 -36
- package/src/components/WidgetEvents.tsx +2 -4
- package/src/constants/errors.ts +10 -8
- package/src/constants/messages.ts +1 -1
- package/src/constants/searchParams.ts +0 -1
- package/src/constants/warnings.ts +7 -7
- package/src/hooks/useConfirmSwap.ts +303 -0
- package/src/hooks/{useFetchQuote.ts → useFetchBestRoute.ts} +3 -3
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/hooks/useSwapInput.ts +23 -58
- package/src/hooks/useSyncStoresWithConfig.ts +19 -22
- package/src/hooks/useWalletList.ts +5 -3
- package/src/pages/ConfirmSwapPage.tsx +235 -58
- package/src/pages/HistoryPage.tsx +1 -1
- package/src/pages/Home.tsx +247 -58
- package/src/pages/LanguagePage.tsx +1 -1
- package/src/pages/LiquiditySourcePage.tsx +32 -23
- package/src/pages/SelectBlockchainPage.tsx +7 -6
- package/src/pages/SelectSwapItemsPage.tsx +5 -5
- package/src/pages/SettingsPage.tsx +13 -9
- package/src/pages/SwapDetailsPage.tsx +3 -3
- package/src/pages/ThemePage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +12 -5
- package/src/store/app.ts +6 -18
- package/src/store/{quote.ts → bestRoute.ts} +60 -68
- package/src/store/meta.ts +39 -0
- package/src/store/settings.ts +4 -7
- package/src/store/slices/config.ts +15 -25
- package/src/store/slices/data.ts +29 -64
- package/src/store/wallets.ts +8 -11
- package/src/types/config.ts +5 -5
- package/src/types/index.ts +1 -1
- package/src/types/routing.ts +77 -0
- package/src/utils/numbers.ts +1 -1
- package/src/utils/routing.ts +321 -0
- package/src/utils/settings.ts +7 -8
- package/src/utils/swap.ts +85 -113
- package/src/utils/wallets.ts +17 -29
- package/dist/components/NoResult/NoResult.d.ts +0 -4
- package/dist/components/NoResult/NoResult.d.ts.map +0 -1
- package/dist/components/NoResult/NoResult.helpers.d.ts +0 -4
- package/dist/components/NoResult/NoResult.helpers.d.ts.map +0 -1
- package/dist/components/NoResult/NoResult.types.d.ts.map +0 -1
- package/dist/components/NoResult/index.d.ts +0 -2
- package/dist/components/NoResult/index.d.ts.map +0 -1
- package/dist/components/Quote/Quote.d.ts +0 -4
- package/dist/components/Quote/Quote.d.ts.map +0 -1
- package/dist/components/Quote/Quote.styles.d.ts +0 -1429
- package/dist/components/Quote/Quote.styles.d.ts.map +0 -1
- package/dist/components/Quote/Quote.types.d.ts +0 -22
- package/dist/components/Quote/Quote.types.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSkeleton.d.ts +0 -4
- package/dist/components/Quote/QuoteSkeleton.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts +0 -319
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSkeleton.types.d.ts +0 -6
- package/dist/components/Quote/QuoteSkeleton.types.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSummary.d.ts +0 -11
- package/dist/components/Quote/QuoteSummary.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSummary.styles.d.ts +0 -158
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +0 -1
- package/dist/components/Quote/index.d.ts +0 -4
- package/dist/components/Quote/index.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts +0 -11
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts +0 -4
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts +0 -4
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts +0 -9
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +0 -22
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts +0 -11
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts +0 -11
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/index.d.ts +0 -2
- package/dist/components/QuoteWarningsAndErrors/index.d.ts.map +0 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts +0 -4
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +0 -1
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +0 -472
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +0 -1
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +0 -17
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +0 -1
- package/dist/containers/QuoteInfo/index.d.ts +0 -2
- package/dist/containers/QuoteInfo/index.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap/index.d.ts +0 -2
- package/dist/hooks/useConfirmSwap/index.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts +0 -3
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +0 -16
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +0 -1
- package/dist/hooks/useFetchQuote.d.ts.map +0 -1
- package/dist/hooks/useForceAutoConnect.d.ts +0 -2
- package/dist/hooks/useForceAutoConnect.d.ts.map +0 -1
- package/dist/store/AppStore.d.ts +0 -11
- package/dist/store/AppStore.d.ts.map +0 -1
- package/dist/store/quote.d.ts.map +0 -1
- package/dist/types/quote.d.ts +0 -82
- package/dist/types/quote.d.ts.map +0 -1
- package/dist/utils/quote.d.ts.map +0 -1
- package/src/components/NoResult/index.ts +0 -1
- package/src/components/Quote/Quote.styles.ts +0 -212
- package/src/components/Quote/Quote.tsx +0 -345
- package/src/components/Quote/Quote.types.ts +0 -16
- package/src/components/Quote/QuoteSkeleton.styles.ts +0 -110
- package/src/components/Quote/QuoteSkeleton.tsx +0 -108
- package/src/components/Quote/QuoteSkeleton.types.ts +0 -5
- package/src/components/Quote/QuoteSummary.styles.ts +0 -15
- package/src/components/Quote/QuoteSummary.tsx +0 -46
- package/src/components/Quote/index.ts +0 -3
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +0 -107
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +0 -67
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +0 -103
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +0 -24
- package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +0 -77
- package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +0 -38
- package/src/components/QuoteWarningsAndErrors/index.ts +0 -1
- package/src/containers/QuoteInfo/QuoteInfo.styles.ts +0 -15
- package/src/containers/QuoteInfo/QuoteInfo.tsx +0 -97
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +0 -17
- package/src/containers/QuoteInfo/index.ts +0 -1
- package/src/hooks/useConfirmSwap/index.ts +0 -1
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +0 -168
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +0 -136
- package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +0 -19
- package/src/hooks/useForceAutoConnect.ts +0 -27
- package/src/store/AppStore.tsx +0 -35
- package/src/types/quote.ts +0 -107
- package/src/utils/quote.ts +0 -338
- /package/src/components/{QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts → RouteErrors/RouteErrors.styles.ts} +0 -0
|
@@ -6,7 +6,7 @@ import { SwapDetails } from '../components/SwapDetails';
|
|
|
6
6
|
import { SwapDetailsPlaceholder } from '../components/SwapDetails/SwapDetails.Placeholder';
|
|
7
7
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
8
8
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
9
|
-
import {
|
|
9
|
+
import { useMetaStore } from '../store/meta';
|
|
10
10
|
import { useUiStore } from '../store/ui';
|
|
11
11
|
import { getPendingSwaps } from '../utils/queue';
|
|
12
12
|
|
|
@@ -16,9 +16,9 @@ export function SwapDetailsPage() {
|
|
|
16
16
|
const pendingSwaps = getPendingSwaps(manager);
|
|
17
17
|
const requestId = useUiStore.use.selectedSwapRequestId();
|
|
18
18
|
const { navigateBackFrom } = useNavigateBack();
|
|
19
|
-
const {
|
|
19
|
+
const { loadingStatus } = useMetaStore();
|
|
20
20
|
|
|
21
|
-
const showSkeleton = loading ||
|
|
21
|
+
const showSkeleton = loading || loadingStatus === 'loading';
|
|
22
22
|
|
|
23
23
|
const selectedSwap = pendingSwaps.find(
|
|
24
24
|
({ swap }) => swap.requestId === requestId
|
package/src/pages/ThemePage.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WidgetConfig } from '../types';
|
|
1
2
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
2
3
|
|
|
3
4
|
import { i18n } from '@lingui/core';
|
|
@@ -9,9 +10,15 @@ import { WalletModal } from '../components/WalletModal';
|
|
|
9
10
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
10
11
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
11
12
|
import { useWalletList } from '../hooks/useWalletList';
|
|
12
|
-
import {
|
|
13
|
+
import { useMetaStore } from '../store/meta';
|
|
13
14
|
import { getContainer } from '../utils/common';
|
|
14
15
|
|
|
16
|
+
interface PropTypes {
|
|
17
|
+
supportedWallets: WidgetConfig['wallets'];
|
|
18
|
+
multiWallets: boolean;
|
|
19
|
+
config?: WidgetConfig;
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
const ListContainer = styled('div', {
|
|
16
23
|
display: 'grid',
|
|
17
24
|
gap: '$10',
|
|
@@ -28,8 +35,7 @@ const Container = styled('div', {
|
|
|
28
35
|
export const TIME_TO_CLOSE_MODAL = 3_000;
|
|
29
36
|
export const TIME_TO_IGNORE_MODAL = 300;
|
|
30
37
|
|
|
31
|
-
export function WalletsPage() {
|
|
32
|
-
const { config, fetchStatus: fetchMetaStatus } = useAppStore();
|
|
38
|
+
export function WalletsPage({ config }: PropTypes) {
|
|
33
39
|
const { navigateBackFrom } = useNavigateBack();
|
|
34
40
|
const [openModal, setOpenModal] = useState(false);
|
|
35
41
|
const [selectedWalletType, setSelectedWalletType] = useState<WalletType>('');
|
|
@@ -53,6 +59,7 @@ export function WalletsPage() {
|
|
|
53
59
|
},
|
|
54
60
|
});
|
|
55
61
|
|
|
62
|
+
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
56
63
|
const selectedWallet = list.find(
|
|
57
64
|
(wallet) => wallet.type === selectedWalletType
|
|
58
65
|
);
|
|
@@ -64,7 +71,7 @@ export function WalletsPage() {
|
|
|
64
71
|
<Layout
|
|
65
72
|
header={{
|
|
66
73
|
title: i18n.t('Connect Wallets'),
|
|
67
|
-
onBack: (
|
|
74
|
+
onBack: navigateBackFrom.bind(null, navigationRoutes.wallets),
|
|
68
75
|
}}>
|
|
69
76
|
<Container>
|
|
70
77
|
<Typography variant="title" size="xmedium" align="center">
|
|
@@ -81,7 +88,7 @@ export function WalletsPage() {
|
|
|
81
88
|
onClick={(type) => {
|
|
82
89
|
void handleClick(type);
|
|
83
90
|
}}
|
|
84
|
-
isLoading={
|
|
91
|
+
isLoading={loadingMetaStatus === 'loading'}
|
|
85
92
|
/>
|
|
86
93
|
</Fragment>
|
|
87
94
|
);
|
package/src/store/app.ts
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
import type { ConfigSlice } from './slices/config';
|
|
2
2
|
import type { DataSlice } from './slices/data';
|
|
3
|
-
import type { WidgetConfig } from '../types';
|
|
4
|
-
import type { StateCreator } from 'zustand';
|
|
5
3
|
|
|
6
4
|
import { create } from 'zustand';
|
|
7
5
|
|
|
6
|
+
import createSelectors from './selectors';
|
|
8
7
|
import { createConfigSlice } from './slices/config';
|
|
9
8
|
import { createDataSlice } from './slices/data';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
> = (
|
|
16
|
-
initialData: T | undefined,
|
|
17
|
-
...rest: Parameters<StateCreator<R, [], [], V>>
|
|
18
|
-
) => ReturnType<StateCreator<R, [], [], V>>;
|
|
10
|
+
const store = create<DataSlice & ConfigSlice>()((...a) => ({
|
|
11
|
+
...createDataSlice(...a),
|
|
12
|
+
...createConfigSlice(...a),
|
|
13
|
+
}));
|
|
19
14
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
export function createAppStore(initialData?: WidgetConfig) {
|
|
23
|
-
return create<AppStoreState>()((...a) => ({
|
|
24
|
-
...createDataSlice(...a),
|
|
25
|
-
...createConfigSlice(initialData, ...a),
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
15
|
+
export const useAppStore = createSelectors(store);
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import type { TokenWithBalance } from '../components/TokenList';
|
|
2
2
|
import type { Wallet } from '../types';
|
|
3
3
|
import type { PendingSwap } from '@rango-dev/queue-manager-rango-preset/dist/shared';
|
|
4
|
-
import type {
|
|
5
|
-
BestRouteResponse,
|
|
6
|
-
BlockchainMeta,
|
|
7
|
-
MetaResponse,
|
|
8
|
-
Token,
|
|
9
|
-
} from 'rango-sdk';
|
|
4
|
+
import type { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
|
|
10
5
|
|
|
11
6
|
import BigNumber from 'bignumber.js';
|
|
12
7
|
import { create } from 'zustand';
|
|
@@ -14,24 +9,21 @@ import { subscribeWithSelector } from 'zustand/middleware';
|
|
|
14
9
|
|
|
15
10
|
import { ZERO } from '../constants/numbers';
|
|
16
11
|
import { isPositiveNumber } from '../utils/numbers';
|
|
17
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
createRetryRoute,
|
|
14
|
+
getBestRouteToTokenUsdPrice,
|
|
15
|
+
} from '../utils/routing';
|
|
18
16
|
import { calcOutputUsdValue } from '../utils/swap';
|
|
19
17
|
|
|
18
|
+
import { useMetaStore } from './meta';
|
|
20
19
|
import createSelectors from './selectors';
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
token: Token | null,
|
|
24
|
-
amount: string
|
|
25
|
-
): BigNumber | null =>
|
|
21
|
+
const getUsdValue = (token: Token | null, amount: string): BigNumber | null =>
|
|
26
22
|
token?.usdPrice
|
|
27
23
|
? new BigNumber(amount || ZERO).multipliedBy(token?.usdPrice || 0)
|
|
28
24
|
: null;
|
|
29
25
|
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
export type SetTokenParams = { token: Token; meta: Meta } | { token: null };
|
|
33
|
-
|
|
34
|
-
export interface QuoteState {
|
|
26
|
+
export interface RouteState {
|
|
35
27
|
fromBlockchain: BlockchainMeta | null;
|
|
36
28
|
toBlockchain: BlockchainMeta | null;
|
|
37
29
|
inputAmount: string;
|
|
@@ -40,32 +32,30 @@ export interface QuoteState {
|
|
|
40
32
|
outputUsdValue: BigNumber | null;
|
|
41
33
|
fromToken: TokenWithBalance | null;
|
|
42
34
|
toToken: TokenWithBalance | null;
|
|
43
|
-
|
|
35
|
+
routeWalletsConfirmed: boolean;
|
|
44
36
|
selectedWallets: Wallet[];
|
|
45
|
-
|
|
46
|
-
resetQuote: () => void;
|
|
37
|
+
resetRoute: () => void;
|
|
47
38
|
resetToBlockchain: () => void;
|
|
48
39
|
resetFromBlockchain: () => void;
|
|
49
40
|
setFromBlockchain: (chain: BlockchainMeta | null) => void;
|
|
50
41
|
setToBlockchain: (chian: BlockchainMeta | null) => void;
|
|
51
42
|
|
|
52
|
-
setFromToken: (
|
|
53
|
-
setToToken: (
|
|
43
|
+
setFromToken: (token: Token | null) => void;
|
|
44
|
+
setToToken: (token: Token | null) => void;
|
|
54
45
|
setInputAmount: (amount: string) => void;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
retry: (pendingSwap: PendingSwap
|
|
46
|
+
bestRoute: BestRouteResponse | null;
|
|
47
|
+
setRoute: (bestRoute: BestRouteResponse | null) => void;
|
|
48
|
+
retry: (pendingSwap: PendingSwap) => void;
|
|
58
49
|
switchFromAndTo: () => void;
|
|
59
|
-
|
|
50
|
+
setRouteWalletConfirmed: (flag: boolean) => void;
|
|
60
51
|
setSelectedWallets: (wallets: Wallet[]) => void;
|
|
61
52
|
customDestination: string;
|
|
62
53
|
setCustomDestination: (address: string) => void;
|
|
63
|
-
|
|
64
|
-
setQuoteWarningsConfirmed: (flag: boolean) => void;
|
|
54
|
+
resetRouteWallets: () => void;
|
|
65
55
|
}
|
|
66
56
|
|
|
67
|
-
export const
|
|
68
|
-
create<
|
|
57
|
+
export const useBestRouteStore = createSelectors(
|
|
58
|
+
create<RouteState>()(
|
|
69
59
|
subscribeWithSelector((set) => ({
|
|
70
60
|
fromBlockchain: null,
|
|
71
61
|
fromToken: null,
|
|
@@ -75,38 +65,37 @@ export const useQuoteStore = createSelectors(
|
|
|
75
65
|
outputUsdValue: new BigNumber(0),
|
|
76
66
|
toBlockchain: null,
|
|
77
67
|
toToken: null,
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
bestRoute: null,
|
|
69
|
+
routeWalletsConfirmed: false,
|
|
80
70
|
selectedWallets: [],
|
|
81
71
|
customDestination: '',
|
|
82
|
-
|
|
83
|
-
setQuote: (quote) =>
|
|
72
|
+
setRoute: (bestRoute) =>
|
|
84
73
|
set((state) => {
|
|
85
74
|
let outputAmount: BigNumber | null = null;
|
|
86
75
|
let outputUsdValue: BigNumber = ZERO;
|
|
87
76
|
if (!isPositiveNumber(state.inputAmount)) {
|
|
88
77
|
return {};
|
|
89
78
|
}
|
|
90
|
-
if (!!
|
|
91
|
-
outputAmount = !!
|
|
92
|
-
? new BigNumber(
|
|
79
|
+
if (!!bestRoute) {
|
|
80
|
+
outputAmount = !!bestRoute.result?.outputAmount
|
|
81
|
+
? new BigNumber(bestRoute.result?.outputAmount)
|
|
93
82
|
: null;
|
|
94
83
|
outputUsdValue = calcOutputUsdValue(
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
bestRoute.result?.outputAmount,
|
|
85
|
+
getBestRouteToTokenUsdPrice(bestRoute) || state.toToken?.usdPrice
|
|
97
86
|
);
|
|
98
87
|
}
|
|
99
88
|
return {
|
|
100
|
-
|
|
101
|
-
...(!!
|
|
89
|
+
bestRoute,
|
|
90
|
+
...(!!bestRoute && {
|
|
102
91
|
outputAmount,
|
|
103
92
|
outputUsdValue,
|
|
104
93
|
}),
|
|
105
94
|
};
|
|
106
95
|
}),
|
|
107
|
-
|
|
96
|
+
resetRoute: () =>
|
|
108
97
|
set(() => ({
|
|
109
|
-
|
|
98
|
+
bestRoute: null,
|
|
110
99
|
outputAmount: null,
|
|
111
100
|
outputUsdValue: new BigNumber(0),
|
|
112
101
|
})),
|
|
@@ -119,7 +108,7 @@ export const useQuoteStore = createSelectors(
|
|
|
119
108
|
return {
|
|
120
109
|
fromBlockchain: chain,
|
|
121
110
|
...(state.fromToken && {
|
|
122
|
-
|
|
111
|
+
bestRoute: null,
|
|
123
112
|
fromToken: null,
|
|
124
113
|
outputAmount: null,
|
|
125
114
|
outputUsdValue: null,
|
|
@@ -127,17 +116,18 @@ export const useQuoteStore = createSelectors(
|
|
|
127
116
|
};
|
|
128
117
|
});
|
|
129
118
|
},
|
|
130
|
-
setFromToken: (
|
|
119
|
+
setFromToken: (token) => {
|
|
120
|
+
const { blockchains } = useMetaStore.getState().meta;
|
|
131
121
|
return set((state) => ({
|
|
132
|
-
fromToken:
|
|
133
|
-
...(
|
|
122
|
+
fromToken: token,
|
|
123
|
+
...(token && {
|
|
134
124
|
fromBlockchain:
|
|
135
|
-
|
|
136
|
-
(blockchain) => blockchain.name ===
|
|
125
|
+
blockchains.find(
|
|
126
|
+
(blockchain) => blockchain.name === token.blockchain
|
|
137
127
|
) ?? null,
|
|
138
128
|
}),
|
|
139
129
|
...(!!state.inputAmount && {
|
|
140
|
-
inputUsdValue: getUsdValue(
|
|
130
|
+
inputUsdValue: getUsdValue(token, state.inputAmount),
|
|
141
131
|
}),
|
|
142
132
|
}));
|
|
143
133
|
},
|
|
@@ -150,7 +140,7 @@ export const useQuoteStore = createSelectors(
|
|
|
150
140
|
return {
|
|
151
141
|
toBlockchain: chain,
|
|
152
142
|
...(state.toToken && {
|
|
153
|
-
|
|
143
|
+
bestRoute: null,
|
|
154
144
|
toToken: null,
|
|
155
145
|
outputAmount: null,
|
|
156
146
|
outputUsdValue: null,
|
|
@@ -158,13 +148,14 @@ export const useQuoteStore = createSelectors(
|
|
|
158
148
|
};
|
|
159
149
|
});
|
|
160
150
|
},
|
|
161
|
-
setToToken: (
|
|
151
|
+
setToToken: (token) => {
|
|
152
|
+
const { blockchains } = useMetaStore.getState().meta;
|
|
162
153
|
return set(() => ({
|
|
163
|
-
toToken:
|
|
164
|
-
...(
|
|
154
|
+
toToken: token,
|
|
155
|
+
...(token && {
|
|
165
156
|
toBlockchain:
|
|
166
|
-
|
|
167
|
-
(blockchain) => blockchain.name ===
|
|
157
|
+
blockchains.find(
|
|
158
|
+
(blockchain) => blockchain.name === token.blockchain
|
|
168
159
|
) ?? null,
|
|
169
160
|
}),
|
|
170
161
|
}));
|
|
@@ -175,22 +166,24 @@ export const useQuoteStore = createSelectors(
|
|
|
175
166
|
...(!amount && {
|
|
176
167
|
outputAmount: new BigNumber(0),
|
|
177
168
|
outputUsdValue: new BigNumber(0),
|
|
178
|
-
|
|
169
|
+
bestRoute: null,
|
|
179
170
|
}),
|
|
180
171
|
...(!!state.fromToken && {
|
|
181
172
|
inputUsdValue: getUsdValue(state.fromToken, amount),
|
|
182
173
|
}),
|
|
183
174
|
}));
|
|
184
175
|
},
|
|
185
|
-
retry: (pendingSwap
|
|
186
|
-
const { tokens, blockchains } = meta;
|
|
176
|
+
retry: (pendingSwap) => {
|
|
177
|
+
const { tokens, blockchains } = useMetaStore.getState().meta;
|
|
178
|
+
|
|
187
179
|
const {
|
|
188
180
|
fromBlockchain,
|
|
189
181
|
fromToken,
|
|
190
182
|
toBlockchain,
|
|
191
183
|
toToken,
|
|
192
184
|
inputAmount,
|
|
193
|
-
} =
|
|
185
|
+
} = createRetryRoute(pendingSwap, blockchains, tokens);
|
|
186
|
+
|
|
194
187
|
set({
|
|
195
188
|
fromBlockchain,
|
|
196
189
|
fromToken,
|
|
@@ -200,7 +193,7 @@ export const useQuoteStore = createSelectors(
|
|
|
200
193
|
outputUsdValue: new BigNumber(0),
|
|
201
194
|
toBlockchain,
|
|
202
195
|
toToken,
|
|
203
|
-
|
|
196
|
+
bestRoute: null,
|
|
204
197
|
});
|
|
205
198
|
},
|
|
206
199
|
switchFromAndTo: () =>
|
|
@@ -215,13 +208,14 @@ export const useQuoteStore = createSelectors(
|
|
|
215
208
|
state.outputAmount?.toString() || ''
|
|
216
209
|
),
|
|
217
210
|
})),
|
|
211
|
+
|
|
218
212
|
resetFromBlockchain: () =>
|
|
219
213
|
set(() => ({
|
|
220
214
|
fromToken: null,
|
|
221
215
|
fromBlockchain: null,
|
|
222
216
|
outputAmount: null,
|
|
223
217
|
outputUsdValue: null,
|
|
224
|
-
|
|
218
|
+
bestRoute: null,
|
|
225
219
|
})),
|
|
226
220
|
resetToBlockchain: () =>
|
|
227
221
|
set(() => ({
|
|
@@ -229,22 +223,20 @@ export const useQuoteStore = createSelectors(
|
|
|
229
223
|
toBlockchain: null,
|
|
230
224
|
outputAmount: null,
|
|
231
225
|
outputUsdValue: null,
|
|
232
|
-
|
|
226
|
+
bestRoute: null,
|
|
233
227
|
})),
|
|
234
|
-
|
|
228
|
+
setRouteWalletConfirmed: (flag) =>
|
|
235
229
|
set({
|
|
236
|
-
|
|
230
|
+
routeWalletsConfirmed: flag,
|
|
237
231
|
}),
|
|
238
232
|
setSelectedWallets: (wallets) => set({ selectedWallets: wallets }),
|
|
239
233
|
setCustomDestination: (address) => set({ customDestination: address }),
|
|
240
|
-
|
|
234
|
+
resetRouteWallets: () =>
|
|
241
235
|
set({
|
|
242
|
-
|
|
236
|
+
routeWalletsConfirmed: false,
|
|
243
237
|
selectedWallets: [],
|
|
244
238
|
customDestination: '',
|
|
245
239
|
}),
|
|
246
|
-
setQuoteWarningsConfirmed: (flag) =>
|
|
247
|
-
set({ quoteWarningsConfirmed: flag }),
|
|
248
240
|
}))
|
|
249
241
|
)
|
|
250
242
|
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TokenWithBalance } from '../components/TokenList';
|
|
2
|
+
import type { MetaResponse } from 'rango-sdk';
|
|
3
|
+
|
|
4
|
+
import { create } from 'zustand';
|
|
5
|
+
|
|
6
|
+
import { useAppStore } from './app';
|
|
7
|
+
import createSelectors from './selectors';
|
|
8
|
+
|
|
9
|
+
export type LoadingStatus = 'loading' | 'success' | 'failed';
|
|
10
|
+
|
|
11
|
+
export interface MetaState {
|
|
12
|
+
meta: MetaResponse & { tokens: TokenWithBalance[] };
|
|
13
|
+
loadingStatus: LoadingStatus;
|
|
14
|
+
fetchMeta: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const useMetaStore = createSelectors(
|
|
18
|
+
create<MetaState>()((set) => ({
|
|
19
|
+
meta: { blockchains: [], popularTokens: [], swappers: [], tokens: [] },
|
|
20
|
+
loadingStatus: 'loading',
|
|
21
|
+
fetchMeta: async () => {
|
|
22
|
+
try {
|
|
23
|
+
await useAppStore.getState().fetch();
|
|
24
|
+
|
|
25
|
+
const state = useAppStore.getState();
|
|
26
|
+
const response: MetaResponse = {
|
|
27
|
+
blockchains: state.blockchains(),
|
|
28
|
+
tokens: state.tokens(),
|
|
29
|
+
popularTokens: state._popularTokens,
|
|
30
|
+
swappers: state._swappers,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
set({ meta: response, loadingStatus: 'success' });
|
|
34
|
+
} catch (error) {
|
|
35
|
+
set({ loadingStatus: 'failed' });
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
}))
|
|
39
|
+
);
|
package/src/store/settings.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { SwapperMeta } from 'rango-sdk';
|
|
2
|
-
|
|
3
1
|
import { type Language } from '@rango-dev/ui';
|
|
4
2
|
import { create } from 'zustand';
|
|
5
3
|
import { persist, subscribeWithSelector } from 'zustand/middleware';
|
|
@@ -9,6 +7,7 @@ import { DEFAULT_LANGUAGE } from '../constants/languages';
|
|
|
9
7
|
import { DEFAULT_SLIPPAGE } from '../constants/swapSettings';
|
|
10
8
|
import { removeDuplicateFrom } from '../utils/common';
|
|
11
9
|
|
|
10
|
+
import { useMetaStore } from './meta';
|
|
12
11
|
import createSelectors from './selectors';
|
|
13
12
|
|
|
14
13
|
export type ThemeMode = 'auto' | 'dark' | 'light';
|
|
@@ -32,10 +31,7 @@ export interface SettingsState {
|
|
|
32
31
|
toggleLiquiditySource: (name: string) => void;
|
|
33
32
|
setTheme: (theme: ThemeMode) => void;
|
|
34
33
|
setLanguage: (language: Language) => void;
|
|
35
|
-
toggleAllLiquiditySources: (
|
|
36
|
-
swappers: SwapperMeta[],
|
|
37
|
-
shouldReset?: boolean
|
|
38
|
-
) => void;
|
|
34
|
+
toggleAllLiquiditySources: (shouldReset?: boolean) => void;
|
|
39
35
|
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
40
36
|
setAffiliatePercent: (affiliatePercent: number | null) => void;
|
|
41
37
|
setAffiliateWallets: (
|
|
@@ -106,11 +102,12 @@ export const useSettingsStore = createSelectors(
|
|
|
106
102
|
set(() => ({
|
|
107
103
|
affiliateWallets,
|
|
108
104
|
})),
|
|
109
|
-
toggleAllLiquiditySources: (
|
|
105
|
+
toggleAllLiquiditySources: (shouldReset?: boolean) =>
|
|
110
106
|
set((state) => {
|
|
111
107
|
if (shouldReset) {
|
|
112
108
|
return { disabledLiquiditySources: [] };
|
|
113
109
|
}
|
|
110
|
+
const { swappers } = useMetaStore.getState().meta;
|
|
114
111
|
const swappersGroup = removeDuplicateFrom(
|
|
115
112
|
swappers.map((swapper) => swapper.swapperGroup)
|
|
116
113
|
);
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { WidgetConfig } from '../../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { StateCreator } from 'zustand';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
apiKey: '',
|
|
6
|
-
multiWallets: true,
|
|
7
|
-
enableNewLiquiditySources: true,
|
|
8
|
-
};
|
|
4
|
+
const initConfig: WidgetConfig = { apiKey: '' };
|
|
9
5
|
|
|
10
6
|
export type ConfigSlice = {
|
|
11
7
|
config: WidgetConfig;
|
|
@@ -13,24 +9,18 @@ export type ConfigSlice = {
|
|
|
13
9
|
updateConfig: (config: WidgetConfig) => void;
|
|
14
10
|
};
|
|
15
11
|
|
|
16
|
-
export const createConfigSlice:
|
|
17
|
-
|
|
18
|
-
ConfigSlice,
|
|
19
|
-
ConfigSlice
|
|
20
|
-
> = (initialData, set, get) => {
|
|
21
|
-
return {
|
|
22
|
-
config: { ...DEFAULT_CONFIG, ...initialData },
|
|
12
|
+
export const createConfigSlice: StateCreator<ConfigSlice> = (set, get) => ({
|
|
13
|
+
config: initConfig,
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
// Actions
|
|
16
|
+
updateConfig: (nextConfig: WidgetConfig) => {
|
|
17
|
+
const currentConfig = get().config;
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
19
|
+
set({
|
|
20
|
+
config: {
|
|
21
|
+
...currentConfig,
|
|
22
|
+
...nextConfig,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
});
|
package/src/store/slices/data.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { StateCreator } from 'zustand';
|
|
|
6
6
|
|
|
7
7
|
import { httpService as sdk } from '../../services/httpService';
|
|
8
8
|
import { containsText } from '../../utils/common';
|
|
9
|
-
import { sortLiquiditySourcesByGroupTitle } from '../../utils/settings';
|
|
10
9
|
import { tokensAreEqual } from '../../utils/wallets';
|
|
11
10
|
|
|
12
11
|
type BlockchainOptions = {
|
|
@@ -19,16 +18,15 @@ type TokenOptions = {
|
|
|
19
18
|
blockchain?: string;
|
|
20
19
|
searchFor?: string;
|
|
21
20
|
};
|
|
22
|
-
|
|
21
|
+
|
|
23
22
|
export interface DataSlice {
|
|
24
23
|
_blockchains: BlockchainMeta[];
|
|
25
24
|
_tokens: Token[];
|
|
26
25
|
_popularTokens: Token[];
|
|
27
26
|
_swappers: SwapperMeta[];
|
|
28
|
-
|
|
27
|
+
|
|
29
28
|
blockchains: (options?: BlockchainOptions) => BlockchainMeta[];
|
|
30
29
|
tokens: (options?: TokenOptions) => Token[];
|
|
31
|
-
swappers: () => SwapperMeta[];
|
|
32
30
|
isTokenPinned: (token: Token) => boolean;
|
|
33
31
|
|
|
34
32
|
fetch: () => Promise<void>;
|
|
@@ -45,7 +43,7 @@ export const createDataSlice: StateCreator<
|
|
|
45
43
|
_tokens: [],
|
|
46
44
|
_popularTokens: [],
|
|
47
45
|
_swappers: [],
|
|
48
|
-
|
|
46
|
+
|
|
49
47
|
// Selectors
|
|
50
48
|
blockchains: (options) => {
|
|
51
49
|
const blockchainsFromState = get()._blockchains;
|
|
@@ -165,74 +163,41 @@ export const createDataSlice: StateCreator<
|
|
|
165
163
|
);
|
|
166
164
|
return pinned;
|
|
167
165
|
},
|
|
168
|
-
swappers: () => {
|
|
169
|
-
const {
|
|
170
|
-
config: { enableNewLiquiditySources, liquiditySources },
|
|
171
|
-
} = get();
|
|
172
|
-
|
|
173
|
-
/*
|
|
174
|
-
* If the enableNewLiquiditySources flag is set to true, we return all swappers that are not included in the config.
|
|
175
|
-
* Otherwise, we return all swappers that are included in the config.
|
|
176
|
-
*/
|
|
177
|
-
const swappers = get()._swappers.filter((swapper) => {
|
|
178
|
-
const swapperGroupIncludedInLiquiditySources = liquiditySources?.includes(
|
|
179
|
-
swapper.swapperGroup
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
const shouldExcludeLiquiditySources =
|
|
183
|
-
enableNewLiquiditySources ||
|
|
184
|
-
!liquiditySources ||
|
|
185
|
-
liquiditySources.length === 0;
|
|
186
|
-
|
|
187
|
-
return shouldExcludeLiquiditySources
|
|
188
|
-
? !swapperGroupIncludedInLiquiditySources
|
|
189
|
-
: swapperGroupIncludedInLiquiditySources;
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
const sortedSwappers = swappers.sort(sortLiquiditySourcesByGroupTitle);
|
|
193
166
|
|
|
194
|
-
return sortedSwappers;
|
|
195
|
-
},
|
|
196
167
|
// Actions
|
|
197
168
|
fetch: async () => {
|
|
198
|
-
|
|
199
|
-
const response = await sdk().getAllMetadata();
|
|
169
|
+
const response = await sdk().getAllMetadata();
|
|
200
170
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const swappers: SwapperMeta[] = response.swappers;
|
|
171
|
+
const blockchains: BlockchainMeta[] = [];
|
|
172
|
+
const tokens: Token[] = [];
|
|
173
|
+
const popularTokens: Token[] = response.popularTokens;
|
|
174
|
+
const swappers: SwapperMeta[] = response.swappers;
|
|
206
175
|
|
|
207
|
-
|
|
176
|
+
const blockchainsWithAtLeastOneToken = new Set();
|
|
208
177
|
|
|
209
|
-
|
|
210
|
-
|
|
178
|
+
response.tokens.forEach((token) => {
|
|
179
|
+
blockchainsWithAtLeastOneToken.add(token.blockchain);
|
|
211
180
|
|
|
212
|
-
|
|
213
|
-
|
|
181
|
+
tokens.push(token);
|
|
182
|
+
});
|
|
214
183
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
184
|
+
response.blockchains.forEach((blockchain) => {
|
|
185
|
+
if (
|
|
186
|
+
blockchain.enabled &&
|
|
187
|
+
blockchainsWithAtLeastOneToken.has(blockchain.name)
|
|
188
|
+
) {
|
|
189
|
+
blockchains.push(blockchain);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
223
192
|
|
|
224
|
-
|
|
225
|
-
|
|
193
|
+
// Sort
|
|
194
|
+
blockchains.sort((a, b) => a.sort - b.sort);
|
|
226
195
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
} catch (error) {
|
|
234
|
-
set({ fetchStatus: 'failed' });
|
|
235
|
-
throw error;
|
|
236
|
-
}
|
|
196
|
+
set({
|
|
197
|
+
_blockchains: blockchains,
|
|
198
|
+
_tokens: tokens,
|
|
199
|
+
_popularTokens: popularTokens,
|
|
200
|
+
_swappers: swappers,
|
|
201
|
+
});
|
|
237
202
|
},
|
|
238
203
|
});
|