@rango-dev/widget-embedded 0.23.1-next.3 → 0.23.1-next.31

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.
Files changed (197) hide show
  1. package/dist/components/AppRouter.d.ts +1 -6
  2. package/dist/components/AppRouter.d.ts.map +1 -1
  3. package/dist/components/AppRoutes.d.ts.map +1 -1
  4. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -283
  5. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  6. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  7. package/dist/components/HeaderButtons/HeaderButtons.d.ts.map +1 -1
  8. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +489 -1
  9. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  10. package/dist/components/HeaderButtons/InProgressTransactionBadge.d.ts +4 -0
  11. package/dist/components/HeaderButtons/InProgressTransactionBadge.d.ts.map +1 -0
  12. package/dist/components/HeaderButtons/RefreshButton.d.ts.map +1 -1
  13. package/dist/components/HeaderButtons/UnreadNotificationsBadge.d.ts.map +1 -1
  14. package/dist/components/HeaderButtons/WalletButton.d.ts.map +1 -1
  15. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  16. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -1
  17. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
  18. package/dist/components/NoResult/NoResult.d.ts.map +1 -1
  19. package/dist/components/NoResult/NoResult.helpers.d.ts +8 -0
  20. package/dist/components/NoResult/NoResult.helpers.d.ts.map +1 -1
  21. package/dist/components/NoResult/NoResult.styles.d.ts +167 -1
  22. package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
  23. package/dist/components/NoResult/NoResult.types.d.ts +1 -0
  24. package/dist/components/NoResult/NoResult.types.d.ts.map +1 -1
  25. package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
  26. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +165 -0
  27. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
  28. package/dist/components/Quote/Quote.d.ts.map +1 -1
  29. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  30. package/dist/components/Quote/Quote.types.d.ts +1 -0
  31. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  32. package/dist/components/Quote/QuoteTrigger.d.ts.map +1 -1
  33. package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +1 -0
  34. package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
  35. package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.d.ts.map +1 -1
  36. package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +3 -1
  37. package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
  38. package/dist/components/Quotes/Quotes.d.ts.map +1 -1
  39. package/dist/components/Quotes/Quotes.types.d.ts +1 -0
  40. package/dist/components/Quotes/Quotes.types.d.ts.map +1 -1
  41. package/dist/components/Quotes/SelectStrategy.d.ts.map +1 -1
  42. package/dist/components/Slippage/Slippage.d.ts.map +1 -1
  43. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  44. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  45. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  46. package/dist/components/common/ActivateTabAlert/ActivateTabAlert.d.ts.map +1 -1
  47. package/dist/constants/index.d.ts +1 -1
  48. package/dist/constants/index.d.ts.map +1 -1
  49. package/dist/constants/languages.d.ts.map +1 -1
  50. package/dist/constants/navigationRoutes.d.ts +0 -1
  51. package/dist/constants/navigationRoutes.d.ts.map +1 -1
  52. package/dist/constants/searchFor.d.ts +7 -0
  53. package/dist/constants/searchFor.d.ts.map +1 -0
  54. package/dist/constants/settings.d.ts +6 -0
  55. package/dist/constants/settings.d.ts.map +1 -0
  56. package/dist/containers/App/App.d.ts.map +1 -1
  57. package/dist/containers/App/App.styles.d.ts.map +1 -1
  58. package/dist/containers/ExpandedQuotes/ExpandedQuotes.d.ts.map +1 -1
  59. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts +3 -1
  60. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
  61. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  62. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  63. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +1 -0
  64. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
  65. package/dist/containers/Settings/Lists.d.ts +3 -0
  66. package/dist/containers/Settings/Lists.d.ts.map +1 -0
  67. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  68. package/dist/containers/Wallets/Wallets.types.d.ts +13 -2
  69. package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
  70. package/dist/containers/Widget/Widget.d.ts.map +1 -1
  71. package/dist/hooks/useBootstrap/index.d.ts +2 -0
  72. package/dist/hooks/useBootstrap/index.d.ts.map +1 -0
  73. package/dist/hooks/useBootstrap/useBootstrap.d.ts +2 -0
  74. package/dist/hooks/useBootstrap/useBootstrap.d.ts.map +1 -0
  75. package/dist/hooks/useScreenDetect.d.ts +9 -0
  76. package/dist/hooks/useScreenDetect.d.ts.map +1 -0
  77. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  78. package/dist/hooks/useTheme.d.ts.map +1 -1
  79. package/dist/hooks/useWalletList.d.ts.map +1 -1
  80. package/dist/index.js +2 -2
  81. package/dist/index.js.map +4 -4
  82. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  83. package/dist/pages/Home.d.ts.map +1 -1
  84. package/dist/pages/LanguagePage.d.ts.map +1 -1
  85. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  86. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  87. package/dist/pages/SettingsPage.d.ts.map +1 -1
  88. package/dist/store/AppStore.d.ts +2 -2
  89. package/dist/store/app.d.ts +2 -2
  90. package/dist/store/slices/data.d.ts +3 -1
  91. package/dist/store/slices/data.d.ts.map +1 -1
  92. package/dist/store/slices/settings.d.ts.map +1 -1
  93. package/dist/types/config.d.ts +9 -5
  94. package/dist/types/config.d.ts.map +1 -1
  95. package/dist/utils/colors.d.ts +5 -3
  96. package/dist/utils/colors.d.ts.map +1 -1
  97. package/dist/utils/common.d.ts +4 -0
  98. package/dist/utils/common.d.ts.map +1 -1
  99. package/dist/utils/configs.d.ts +2 -1
  100. package/dist/utils/configs.d.ts.map +1 -1
  101. package/dist/utils/meta.d.ts +1 -0
  102. package/dist/utils/meta.d.ts.map +1 -1
  103. package/dist/utils/swap.d.ts +2 -0
  104. package/dist/utils/swap.d.ts.map +1 -1
  105. package/dist/utils/ui.d.ts +5 -2
  106. package/dist/utils/ui.d.ts.map +1 -1
  107. package/dist/utils/wallets.d.ts +1 -1
  108. package/dist/utils/wallets.d.ts.map +1 -1
  109. package/package.json +8 -7
  110. package/src/components/AppRouter.tsx +1 -29
  111. package/src/components/AppRoutes.tsx +0 -5
  112. package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +6 -12
  113. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +7 -11
  114. package/src/components/ConfirmWalletsModal/WalletList.tsx +2 -2
  115. package/src/components/HeaderButtons/HeaderButtons.styles.ts +43 -2
  116. package/src/components/HeaderButtons/HeaderButtons.tsx +2 -0
  117. package/src/components/HeaderButtons/InProgressTransactionBadge.tsx +26 -0
  118. package/src/components/HeaderButtons/RefreshButton.tsx +2 -1
  119. package/src/components/HeaderButtons/UnreadNotificationsBadge.tsx +10 -2
  120. package/src/components/HeaderButtons/WalletButton.tsx +26 -6
  121. package/src/components/Layout/Layout.styles.ts +3 -0
  122. package/src/components/Layout/Layout.tsx +4 -4
  123. package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.ts +1 -1
  124. package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.tsx +4 -4
  125. package/src/components/NoResult/NoResult.helpers.ts +13 -0
  126. package/src/components/NoResult/NoResult.styles.ts +19 -1
  127. package/src/components/NoResult/NoResult.tsx +27 -16
  128. package/src/components/NoResult/NoResult.types.ts +1 -0
  129. package/src/components/NotificationContent/NotificationContent.styles.ts +14 -1
  130. package/src/components/NotificationContent/NotificationContent.tsx +49 -39
  131. package/src/components/Quote/Quote.styles.ts +13 -14
  132. package/src/components/Quote/Quote.tsx +166 -145
  133. package/src/components/Quote/Quote.types.ts +1 -0
  134. package/src/components/Quote/QuoteTrigger.tsx +7 -8
  135. package/src/components/QuoteSkeleton/QuoteSkeleton.styles.ts +10 -2
  136. package/src/components/QuoteSkeleton/QuoteSkeleton.tsx +2 -2
  137. package/src/components/QuoteSkeleton/QuoteSummarySkeleton.styles.ts +2 -2
  138. package/src/components/QuoteSkeleton/QuoteSummarySkeleton.tsx +5 -4
  139. package/src/components/QuoteSkeleton/StepSkeleton.styles.ts +7 -0
  140. package/src/components/QuoteSkeleton/StepSkeleton.tsx +1 -1
  141. package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +1 -1
  142. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +3 -3
  143. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts +1 -1
  144. package/src/components/Quotes/Quotes.tsx +33 -21
  145. package/src/components/Quotes/Quotes.types.ts +1 -0
  146. package/src/components/Quotes/SelectStrategy.tsx +3 -11
  147. package/src/components/Slippage/Slippage.tsx +11 -13
  148. package/src/components/SwapDetails/SwapDetails.tsx +3 -1
  149. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +5 -1
  150. package/src/components/TokenList/TokenList.tsx +9 -8
  151. package/src/components/common/ActivateTabAlert/ActivateTabAlert.tsx +2 -4
  152. package/src/constants/errors.ts +1 -1
  153. package/src/constants/index.ts +1 -1
  154. package/src/constants/languages.ts +27 -1
  155. package/src/constants/navigationRoutes.ts +0 -1
  156. package/src/constants/searchFor.ts +6 -0
  157. package/src/constants/settings.ts +5 -0
  158. package/src/containers/App/App.styles.ts +0 -4
  159. package/src/containers/App/App.tsx +4 -28
  160. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +13 -0
  161. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +5 -0
  162. package/src/containers/Inputs/Inputs.tsx +7 -1
  163. package/src/containers/QuoteInfo/QuoteInfo.tsx +2 -0
  164. package/src/containers/QuoteInfo/QuoteInfo.types.ts +1 -0
  165. package/src/containers/Settings/Lists.tsx +280 -0
  166. package/src/containers/Wallets/Wallets.tsx +27 -10
  167. package/src/containers/Wallets/Wallets.types.ts +13 -2
  168. package/src/containers/Widget/Widget.tsx +13 -13
  169. package/src/hooks/useBootstrap/index.ts +1 -0
  170. package/src/hooks/useBootstrap/useBootstrap.ts +72 -0
  171. package/src/hooks/useScreenDetect.ts +49 -0
  172. package/src/hooks/useSwapInput.ts +7 -2
  173. package/src/hooks/useTheme.ts +1 -8
  174. package/src/hooks/useWalletList.ts +12 -0
  175. package/src/pages/ConfirmSwapPage.tsx +14 -5
  176. package/src/pages/Home.tsx +31 -7
  177. package/src/pages/LanguagePage.tsx +14 -1
  178. package/src/pages/LiquiditySourcePage.tsx +4 -3
  179. package/src/pages/SelectSwapItemsPage.tsx +2 -7
  180. package/src/pages/SettingsPage.tsx +6 -185
  181. package/src/store/slices/config.ts +2 -2
  182. package/src/store/slices/data.ts +82 -34
  183. package/src/store/slices/settings.ts +7 -3
  184. package/src/types/config.ts +9 -5
  185. package/src/utils/colors.ts +106 -75
  186. package/src/utils/common.ts +181 -0
  187. package/src/utils/configs.ts +12 -1
  188. package/src/utils/meta.ts +21 -0
  189. package/src/utils/swap.ts +12 -5
  190. package/src/utils/ui.ts +7 -5
  191. package/src/utils/wallets.ts +5 -47
  192. package/dist/hooks/useMobileDetect.d.ts +0 -3
  193. package/dist/hooks/useMobileDetect.d.ts.map +0 -1
  194. package/dist/pages/ThemePage.d.ts +0 -3
  195. package/dist/pages/ThemePage.d.ts.map +0 -1
  196. package/src/hooks/useMobileDetect.ts +0 -21
  197. package/src/pages/ThemePage.tsx +0 -90
@@ -1,3 +1,5 @@
1
+ import type { SelectedQuote } from '../types';
2
+
1
3
  import { i18n } from '@lingui/core';
2
4
  import { Button, Divider, styled, WarningIcon } from '@rango-dev/ui';
3
5
  import React, { useEffect, useState } from 'react';
@@ -10,19 +12,23 @@ import { navigationRoutes } from '../constants/navigationRoutes';
10
12
  import { ExpandedQuotes } from '../containers/ExpandedQuotes';
11
13
  import { Inputs } from '../containers/Inputs';
12
14
  import { QuoteInfo } from '../containers/QuoteInfo';
13
- import useMobileDetect from '../hooks/useMobileDetect';
15
+ import useScreenDetect from '../hooks/useScreenDetect';
14
16
  import { useSwapInput } from '../hooks/useSwapInput';
15
17
  import { useAppStore } from '../store/AppStore';
16
18
  import { useQuoteStore } from '../store/quote';
17
19
  import { useUiStore } from '../store/ui';
18
20
  import { useWalletsStore } from '../store/wallets';
19
- import { getSwapButtonState } from '../utils/swap';
21
+ import { isVariantExpandable } from '../utils/configs';
22
+ import { getSwapButtonState, isTokensIdentical } from '../utils/swap';
20
23
 
21
24
  const MainContainer = styled('div', {
22
25
  display: 'grid',
23
26
  gridTemplateColumns: 'auto auto',
24
27
  alignItems: 'flex-start',
25
- height: 700,
28
+ maxHeight: 700,
29
+ '& .footer__alert': {
30
+ paddingTop: '0',
31
+ },
26
32
  });
27
33
  export const TIME_TO_NAVIGATE_ANOTHER_PAGE = 300;
28
34
 
@@ -43,7 +49,7 @@ export function Home() {
43
49
  updateQuotePartialState,
44
50
  } = useQuoteStore();
45
51
  const [isVisibleExpanded, setIsVisibleExpanded] = useState<boolean>(false);
46
- const isMobile = useMobileDetect();
52
+ const { isLargeScreen, isExtraLargeScreen } = useScreenDetect();
47
53
 
48
54
  const { fetch: fetchQuote, loading } = useSwapInput({ refetchQuote });
49
55
  const { config, fetchStatus: fetchMetaStatus } = useAppStore();
@@ -64,9 +70,20 @@ export function Home() {
64
70
  warning: quoteWarning,
65
71
  needsToWarnEthOnPath,
66
72
  });
67
- const isExpandable = config?.variant === 'expandable' && !isMobile;
73
+
74
+ const isExpandable = isVariantExpandable(
75
+ isLargeScreen,
76
+ isExtraLargeScreen,
77
+ config?.variant
78
+ );
79
+
68
80
  const hasInputs =
69
- !!inputAmount && !!fromToken && !!toToken && inputAmount !== '0';
81
+ !!inputAmount &&
82
+ !!fromToken &&
83
+ !!toToken &&
84
+ inputAmount !== '0' &&
85
+ !isTokensIdentical(fromToken, toToken);
86
+
70
87
  const fetchingQuote = hasInputs && fetchMetaStatus === 'success' && loading;
71
88
 
72
89
  const hasValidQuotes =
@@ -99,6 +116,13 @@ export function Home() {
99
116
  }
100
117
  };
101
118
 
119
+ const onClickOnQuote = (quote: SelectedQuote) => {
120
+ if (selectedQuote?.requestId !== quote.requestId) {
121
+ setShowQuoteWarningModal(false);
122
+ setSelectedQuote(quote);
123
+ }
124
+ };
125
+
102
126
  return (
103
127
  <MainContainer>
104
128
  <Layout
@@ -200,7 +224,7 @@ export function Home() {
200
224
  {isExpandable ? (
201
225
  <ExpandedQuotes
202
226
  loading={fetchingQuote}
203
- onClickOnQuote={(quote) => setSelectedQuote(quote)}
227
+ onClickOnQuote={onClickOnQuote}
204
228
  fetch={fetchQuote}
205
229
  onClickRefresh={onClickRefresh}
206
230
  isVisible={isVisibleExpanded}
@@ -1,5 +1,7 @@
1
1
  import { i18n } from '@lingui/core';
2
2
  import {
3
+ Alert,
4
+ Divider,
3
5
  List,
4
6
  ListItemButton,
5
7
  Radio,
@@ -10,9 +12,11 @@ import React from 'react';
10
12
 
11
13
  import { Layout, PageContainer } from '../components/Layout';
12
14
  import { useLanguage } from '../hooks/useLanguage';
15
+ import { useNavigateBack } from '../hooks/useNavigateBack';
13
16
 
14
17
  export function LanguagePage() {
15
18
  const { activeLanguage, changeLanguage, languages } = useLanguage();
19
+ const navigateBack = useNavigateBack();
16
20
 
17
21
  const languageList = languages.map((languageItem) => {
18
22
  const { local, label, SVGFlag } = languageItem;
@@ -24,7 +28,10 @@ export function LanguagePage() {
24
28
  {label}
25
29
  </Typography>
26
30
  ),
27
- onClick: () => changeLanguage(languageItem.local),
31
+ onClick: () => {
32
+ changeLanguage(languageItem.local);
33
+ navigateBack();
34
+ },
28
35
  end: <Radio value={local} />,
29
36
  start: <SVGFlag />,
30
37
  };
@@ -36,6 +43,12 @@ export function LanguagePage() {
36
43
  title: i18n.t('Language'),
37
44
  }}>
38
45
  <PageContainer>
46
+ <Alert
47
+ type="warning"
48
+ variant="alarm"
49
+ title="Important Notice: Machine translations are in use"
50
+ />
51
+ <Divider size={'8'} />
39
52
  <RadioRoot value={activeLanguage}>
40
53
  <List
41
54
  type={
@@ -44,8 +44,7 @@ export function LiquiditySourcePage({ sourceType }: PropTypes) {
44
44
  validTypes.push('DEX');
45
45
  }
46
46
  if (sourceType === 'Bridges') {
47
- validTypes.push('BRIDGE');
48
- validTypes.push('AGGREGATOR');
47
+ validTypes.push('BRIDGE', 'AGGREGATOR', 'OFF_CHAIN');
49
48
  }
50
49
 
51
50
  const liquiditySources = supportedUniqueSwappersGroups.filter((uniqueItem) =>
@@ -136,11 +135,13 @@ export function LiquiditySourcePage({ sourceType }: PropTypes) {
136
135
  fetchStatus === 'success' && (
137
136
  <LiquiditySourceList disabled={campaignMode}>
138
137
  {filteredList.map((sourceItem) => {
138
+ const { groupTitle, ...otherProps } = sourceItem;
139
+
139
140
  return (
140
141
  <React.Fragment key={sourceItem.id}>
141
142
  <ListItemButton
142
143
  style={{ height: '61px' }}
143
- {...sourceItem}
144
+ {...otherProps}
144
145
  selected={false}
145
146
  hasDivider
146
147
  />
@@ -14,7 +14,6 @@ import { useNavigateBack } from '../hooks/useNavigateBack';
14
14
  import { useAppStore } from '../store/AppStore';
15
15
  import { useQuoteStore } from '../store/quote';
16
16
  import { useWalletsStore } from '../store/wallets';
17
- import { sortTokens } from '../utils/wallets';
18
17
 
19
18
  interface PropTypes {
20
19
  type: 'source' | 'destination';
@@ -34,7 +33,6 @@ export function SelectSwapItemsPage(props: PropTypes) {
34
33
  } = useQuoteStore();
35
34
  const getBalanceFor = useWalletsStore.use.getBalanceFor();
36
35
  const [searchedFor, setSearchedFor] = useState<string>('');
37
- const { isTokenPinned } = useAppStore();
38
36
 
39
37
  const selectedBlockchain = type === 'source' ? fromBlockchain : toBlockchain;
40
38
  const selectedBlockchainName = selectedBlockchain?.name ?? '';
@@ -47,12 +45,9 @@ export function SelectSwapItemsPage(props: PropTypes) {
47
45
  type,
48
46
  blockchain: selectedBlockchainName,
49
47
  searchFor: searchedFor,
48
+ getBalanceFor: getBalanceFor,
50
49
  });
51
50
 
52
- const checkIsTokenPinned = (token: Token) => isTokenPinned(token, type);
53
-
54
- const tokensList = sortTokens(tokens, getBalanceFor, checkIsTokenPinned);
55
-
56
51
  const updateBlockchain = (blockchain: BlockchainMeta) => {
57
52
  if (type === 'source') {
58
53
  setFromBlockchain(blockchain);
@@ -101,7 +96,7 @@ export function SelectSwapItemsPage(props: PropTypes) {
101
96
  />
102
97
  <Divider size={16} />
103
98
  <TokenList
104
- list={tokensList}
99
+ list={tokens}
105
100
  selectedBlockchain={selectedBlockchainName}
106
101
  searchedFor={searchedFor}
107
102
  type={type}
@@ -1,194 +1,21 @@
1
1
  import { i18n } from '@lingui/core';
2
- import {
3
- Alert,
4
- Button,
5
- ChevronRightIcon,
6
- Divider,
7
- InfoIcon,
8
- List,
9
- ListItemButton,
10
- Skeleton,
11
- styled,
12
- Switch,
13
- Tooltip,
14
- Typography,
15
- } from '@rango-dev/ui';
2
+ import { Alert, Button, styled } from '@rango-dev/ui';
16
3
  import React from 'react';
17
- import {
18
- useInRouterContext,
19
- useNavigate,
20
- useSearchParams,
21
- } from 'react-router-dom';
4
+ import { useInRouterContext, useSearchParams } from 'react-router-dom';
22
5
 
23
6
  import { Layout, PageContainer } from '../components/Layout';
24
7
  import { Slippage } from '../components/Slippage';
25
- import { SlippageTooltipContainer as TooltipContainer } from '../components/Slippage/Slippage.styles';
26
- import { navigationRoutes } from '../constants/navigationRoutes';
27
8
  import { SearchParams } from '../constants/searchParams';
9
+ import { SettingsLists } from '../containers/Settings/Lists';
28
10
  import { useAppStore } from '../store/AppStore';
29
- import { getContainer } from '../utils/common';
30
- import { getUniqueSwappersGroups, isFeatureHidden } from '../utils/settings';
31
11
 
32
12
  const ResetAction = styled('div', {
33
13
  paddingLeft: '$8',
34
14
  });
35
15
 
36
16
  export function SettingsPage() {
37
- const navigate = useNavigate();
38
- const { theme } = useAppStore().config;
39
- const fetchStatus = useAppStore().fetchStatus;
40
- const swappers = useAppStore().swappers();
41
- const disabledLiquiditySources = useAppStore().getDisabledLiquiditySources();
42
- const {
43
- config: { features },
44
- isInCampaignMode,
45
- updateCampaignMode,
46
- } = useAppStore();
17
+ const { isInCampaignMode, updateCampaignMode } = useAppStore();
47
18
  const campaignMode = isInCampaignMode();
48
- const isThemeHidden = isFeatureHidden('theme', features);
49
-
50
- const isLiquidityHidden = isFeatureHidden('liquiditySource', features);
51
-
52
- const isLanguageHidden = isFeatureHidden('language', features);
53
-
54
- const infiniteApprove = useAppStore().infiniteApprove;
55
- const toggleInfiniteApprove = useAppStore().toggleInfiniteApprove;
56
-
57
- const supportedUniqueSwappersGroups = getUniqueSwappersGroups(
58
- swappers,
59
- disabledLiquiditySources
60
- );
61
-
62
- const bridgeSources = supportedUniqueSwappersGroups.filter(
63
- (uniqueItem) =>
64
- uniqueItem.type === 'BRIDGE' || uniqueItem.type === 'AGGREGATOR'
65
- );
66
- const totalBridgeSources = bridgeSources.length;
67
- const totalSelectedBridgeSources = bridgeSources.filter(
68
- (uniqueItem) => uniqueItem.selected
69
- ).length;
70
-
71
- const exchangeSources = supportedUniqueSwappersGroups.filter(
72
- (uniqueItem) => uniqueItem.type === 'DEX'
73
- );
74
- const totalExchangeSources = exchangeSources.length;
75
- const totalSelectedExchangeSources = exchangeSources.filter(
76
- (uniqueItem) => uniqueItem.selected
77
- ).length;
78
-
79
- const handleEndItem = (totalSelected: number, total: number) => {
80
- switch (fetchStatus) {
81
- case 'loading':
82
- return <Skeleton variant="text" size="medium" width={50} />;
83
- case 'failed':
84
- return (
85
- <Typography variant="body" size="medium" color="$error500">
86
- {i18n.t('Loading failed')}
87
- </Typography>
88
- );
89
- default:
90
- return (
91
- <Typography variant="body" size="medium">
92
- {`${totalSelected} / ${total}`}
93
- </Typography>
94
- );
95
- }
96
- };
97
-
98
- const bridgeItem = {
99
- id: 'bridge-item',
100
- title: (
101
- <Typography variant="title" size="xmedium">
102
- {i18n.t('Enabled bridges')}
103
- </Typography>
104
- ),
105
- end: (
106
- <>
107
- {handleEndItem(totalSelectedBridgeSources, totalBridgeSources)}
108
- <Divider direction="horizontal" size={8} />
109
- <ChevronRightIcon color="black" />
110
- </>
111
- ),
112
- onClick: () => navigate(navigationRoutes.bridges),
113
- };
114
-
115
- const exchangeItem = {
116
- id: 'exchange-item',
117
- title: (
118
- <Typography variant="title" size="xmedium">
119
- {i18n.t('Enabled exchanges')}
120
- </Typography>
121
- ),
122
- end: (
123
- <>
124
- {handleEndItem(totalSelectedExchangeSources, totalExchangeSources)}
125
- <Divider direction="horizontal" size={8} />
126
- <ChevronRightIcon color="gray" />
127
- </>
128
- ),
129
- onClick: () => navigate(navigationRoutes.exchanges),
130
- };
131
-
132
- const languageItem = {
133
- id: 'language-item',
134
- title: (
135
- <Typography variant="title" size="xmedium">
136
- {i18n.t('Language')}
137
- </Typography>
138
- ),
139
- end: <ChevronRightIcon color="gray" />,
140
- onClick: () => navigate(navigationRoutes.languages),
141
- };
142
-
143
- const themeItem = {
144
- id: 'theme-item',
145
- title: (
146
- <Typography variant="title" size="xmedium">
147
- {i18n.t('Theme')}
148
- </Typography>
149
- ),
150
- end: <ChevronRightIcon color="gray" />,
151
- onClick: () => navigate(navigationRoutes.themes),
152
- };
153
-
154
- const infiniteApprovalItem = {
155
- id: 'infinite-approval-item',
156
- title: (
157
- <>
158
- <Typography variant="title" size="xmedium">
159
- {i18n.t('Infinite approval')}
160
- </Typography>
161
- <Divider direction="horizontal" size={4} />
162
- <Tooltip
163
- side="top"
164
- sideOffset={4}
165
- container={getContainer()}
166
- content={
167
- <TooltipContainer>
168
- <Typography variant="label" size="medium" color="neutral700">
169
- {i18n.t(
170
- "Enabling the 'Infinite approval' mode grants unrestricted access to smart contracts of DEXes/Bridges, allowing them to utilize the approved token amount without limitations."
171
- )}
172
- </Typography>
173
- </TooltipContainer>
174
- }>
175
- <InfoIcon color="gray" />
176
- </Tooltip>
177
- </>
178
- ),
179
- end: <Switch checked={infiniteApprove} />,
180
- onClick: toggleInfiniteApprove,
181
- };
182
-
183
- const settingItems = isLiquidityHidden ? [] : [bridgeItem, exchangeItem];
184
-
185
- if (!isLanguageHidden) {
186
- settingItems.push(languageItem);
187
- }
188
- if (!theme?.singleTheme && !isThemeHidden) {
189
- settingItems.push(themeItem);
190
- }
191
- settingItems.push(infiniteApprovalItem);
192
19
 
193
20
  const [, setSearchParams] = useSearchParams();
194
21
  const isRouterInContext = useInRouterContext();
@@ -205,7 +32,6 @@ export function SettingsPage() {
205
32
  updateCampaignMode('liquiditySources', undefined);
206
33
  }
207
34
  };
208
-
209
35
  return (
210
36
  <Layout
211
37
  header={{
@@ -222,19 +48,14 @@ export function SettingsPage() {
222
48
  action={
223
49
  <ResetAction>
224
50
  <Button type="secondary" size="small" onClick={onClick}>
225
- Reset
51
+ {i18n.t('Reset')}
226
52
  </Button>
227
53
  </ResetAction>
228
54
  }
229
55
  />
230
56
  )}
231
57
  <Slippage />
232
- <List
233
- type={
234
- <ListItemButton title="_" id="_" onClick={() => console.log()} />
235
- }
236
- items={settingItems}
237
- />
58
+ <SettingsLists />
238
59
  </PageContainer>
239
60
  </Layout>
240
61
  );
@@ -6,7 +6,7 @@ export const DEFAULT_CONFIG: WidgetConfig = {
6
6
  apiKey: '',
7
7
  title: undefined,
8
8
  multiWallets: true,
9
- enableNewLiquiditySources: true,
9
+ excludeLiquiditySources: true,
10
10
  customDestination: true,
11
11
  };
12
12
 
@@ -72,7 +72,7 @@ export const createConfigSlice: StateCreatorWithInitialData<
72
72
  const { config, campaignMode } = get();
73
73
  return campaignMode.liquiditySources?.length
74
74
  ? false
75
- : !!config.enableNewLiquiditySources;
75
+ : !!config.excludeLiquiditySources;
76
76
  },
77
77
  isInCampaignMode: () => {
78
78
  const { campaignMode } = get();
@@ -1,14 +1,16 @@
1
1
  // We keep all the received data from server in this slice
2
2
 
3
3
  import type { ConfigSlice } from './config';
4
+ import type { Balance } from '../../types';
4
5
  import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
5
6
  import type { StateCreator } from 'zustand';
6
7
 
7
8
  import { httpService as sdk } from '../../services/httpService';
8
- import { containsText } from '../../utils/common';
9
+ import { compareWithSearchFor, containsText } from '../../utils/common';
9
10
  import { isTokenExcludedInConfig } from '../../utils/configs';
11
+ import { isTokenNative } from '../../utils/meta';
10
12
  import { sortLiquiditySourcesByGroupTitle } from '../../utils/settings';
11
- import { areTokensEqual } from '../../utils/wallets';
13
+ import { areTokensEqual, compareTokenBalance } from '../../utils/wallets';
12
14
 
13
15
  type BlockchainOptions = {
14
16
  type?: 'source' | 'destination';
@@ -19,10 +21,12 @@ type TokenOptions = {
19
21
  // filter by an specific blockchain
20
22
  blockchain?: string;
21
23
  searchFor?: string;
24
+ getBalanceFor?: (token: Token) => Balance | null;
22
25
  };
26
+
23
27
  export type FetchStatus = 'loading' | 'success' | 'failed';
24
28
  export interface DataSlice {
25
- _blockchains: BlockchainMeta[];
29
+ _blockchainsMapByName: Map<string, BlockchainMeta>;
26
30
  _tokens: Token[];
27
31
  _popularTokens: Token[];
28
32
  _swappers: SwapperMeta[];
@@ -31,7 +35,6 @@ export interface DataSlice {
31
35
  tokens: (options?: TokenOptions) => Token[];
32
36
  swappers: () => SwapperMeta[];
33
37
  isTokenPinned: (token: Token, type: 'source' | 'destination') => boolean;
34
-
35
38
  fetch: () => Promise<void>;
36
39
  }
37
40
 
@@ -42,14 +45,17 @@ export const createDataSlice: StateCreator<
42
45
  DataSlice
43
46
  > = (set, get) => ({
44
47
  // State
45
- _blockchains: [],
48
+ _blockchainsMapByName: new Map<string, BlockchainMeta>(),
46
49
  _tokens: [],
47
50
  _popularTokens: [],
48
51
  _swappers: [],
49
52
  fetchStatus: 'loading',
50
53
  // Selectors
51
54
  blockchains: (options) => {
52
- const blockchainsFromState = get()._blockchains;
55
+ const blockchainsMapByName = get()._blockchainsMapByName;
56
+ const blockchainsFromState = Array.from(
57
+ blockchainsMapByName?.values() || []
58
+ );
53
59
 
54
60
  if (!options || !options?.type) {
55
61
  return blockchainsFromState;
@@ -76,6 +82,7 @@ export const createDataSlice: StateCreator<
76
82
  },
77
83
  tokens: (options) => {
78
84
  const tokensFromState = get()._tokens;
85
+ const blockchainsMapByName = get()._blockchainsMapByName;
79
86
 
80
87
  if (!options || !options?.type) {
81
88
  return tokensFromState;
@@ -127,29 +134,62 @@ export const createDataSlice: StateCreator<
127
134
 
128
135
  return true;
129
136
  })
130
- .sort((a, b) => {
131
- // Check pinned tokens
132
- if (get().isTokenPinned(a, options.type)) {
133
- return -1;
137
+ .sort((tokenA, tokenB) => {
138
+ //1. sort by pinned tokens
139
+ const isToken1Pinned = get().isTokenPinned(tokenA, options.type);
140
+ const isToken2Pinned = get().isTokenPinned(tokenB, options.type);
141
+ if (isToken1Pinned !== isToken2Pinned) {
142
+ return isToken1Pinned ? -1 : 1;
134
143
  }
135
- if (get().isTokenPinned(b, options.type)) {
136
- return 1;
144
+
145
+ //2. sort by balance
146
+ if (options.getBalanceFor) {
147
+ const token1Balance = options.getBalanceFor(tokenA);
148
+ const token2Balance = options.getBalanceFor(tokenB);
149
+ const balanceCompare = compareTokenBalance(
150
+ token1Balance,
151
+ token2Balance
152
+ );
153
+ if (balanceCompare !== 0) {
154
+ return balanceCompare;
155
+ }
137
156
  }
138
157
 
139
- // Check secondary coins
140
- if (a.isSecondaryCoin) {
141
- return 1;
158
+ //3. sort by token popularity
159
+ if (tokenA.isPopular !== tokenB.isPopular) {
160
+ return tokenA.isPopular ? -1 : 1;
142
161
  }
143
- if (b.isSecondaryCoin) {
144
- return -1;
162
+
163
+ //4. sort by search phrase
164
+ if (options.searchFor) {
165
+ const symbolSearchForCompare = compareWithSearchFor(
166
+ tokenA,
167
+ tokenB,
168
+ options.searchFor
169
+ );
170
+ if (symbolSearchForCompare) {
171
+ return symbolSearchForCompare;
172
+ }
145
173
  }
146
174
 
147
- // Check it has an address or not.
148
- if (!a.address && b.address) {
149
- return -1;
175
+ const blockChainA = blockchainsMapByName.get(tokenA.blockchain);
176
+ const blockChainB = blockchainsMapByName.get(tokenB.blockchain);
177
+
178
+ //5. sort by native token
179
+ const isNativeTokenA = isTokenNative(tokenA, blockChainA);
180
+ const isNativeTokenB = isTokenNative(tokenB, blockChainB);
181
+ if (isNativeTokenA !== isNativeTokenB) {
182
+ return isNativeTokenA ? -1 : 1;
150
183
  }
151
- if (a.address && !b.address) {
152
- return 1;
184
+
185
+ //6. sort by token isSecondary
186
+ if (tokenA.isSecondaryCoin !== tokenB.isSecondaryCoin) {
187
+ return tokenA.isSecondaryCoin ? 1 : -1;
188
+ }
189
+
190
+ //7. sort by blockchain order
191
+ if (!!blockChainA && !!blockChainB) {
192
+ return blockChainA.sort - blockChainB.sort;
153
193
  }
154
194
 
155
195
  return 0;
@@ -177,12 +217,12 @@ export const createDataSlice: StateCreator<
177
217
  const liquiditySources =
178
218
  campaignModeLiquiditySource ?? config.liquiditySources;
179
219
 
180
- const enableNewLiquiditySources = campaignModeLiquiditySource
220
+ const excludeLiquiditySources = campaignModeLiquiditySource
181
221
  ? false
182
- : config.enableNewLiquiditySources;
222
+ : config.excludeLiquiditySources;
183
223
 
184
224
  /*
185
- * If the enableNewLiquiditySources flag is set to true, we return all swappers that are not included in the config.
225
+ * If the excludeLiquiditySources flag is set to true, we return all swappers that are not included in the config.
186
226
  * Otherwise, we return all swappers that are included in the config.
187
227
  */
188
228
  const swappers = get()._swappers.filter((swapper) => {
@@ -191,7 +231,7 @@ export const createDataSlice: StateCreator<
191
231
  );
192
232
 
193
233
  const shouldExcludeLiquiditySources =
194
- enableNewLiquiditySources ||
234
+ excludeLiquiditySources ||
195
235
  !liquiditySources ||
196
236
  liquiditySources.length === 0;
197
237
 
@@ -207,10 +247,17 @@ export const createDataSlice: StateCreator<
207
247
  // Actions
208
248
  fetch: async () => {
209
249
  try {
210
- const response = await sdk().getAllMetadata();
250
+ const { enableCentralizedSwappers } = get().config;
251
+ const response = await sdk().getAllMetadata({
252
+ enableCentralizedSwappers,
253
+ });
211
254
 
212
255
  set({ fetchStatus: 'success' });
213
- const blockchains: BlockchainMeta[] = [];
256
+ const blockchainsMapByName: Map<string, BlockchainMeta> = new Map<
257
+ string,
258
+ BlockchainMeta
259
+ >();
260
+
214
261
  const tokens: Token[] = [];
215
262
  const popularTokens: Token[] = response.popularTokens;
216
263
  const swappers: SwapperMeta[] = response.swappers;
@@ -223,20 +270,21 @@ export const createDataSlice: StateCreator<
223
270
  tokens.push(token);
224
271
  });
225
272
 
226
- response.blockchains.forEach((blockchain) => {
273
+ const sortedBlockchain = response.blockchains.sort(
274
+ (a, b) => a.sort - b.sort
275
+ );
276
+
277
+ sortedBlockchain.forEach((blockchain) => {
227
278
  if (
228
279
  blockchain.enabled &&
229
280
  blockchainsWithAtLeastOneToken.has(blockchain.name)
230
281
  ) {
231
- blockchains.push(blockchain);
282
+ blockchainsMapByName.set(blockchain.name, blockchain);
232
283
  }
233
284
  });
234
285
 
235
- // Sort
236
- blockchains.sort((a, b) => a.sort - b.sort);
237
-
238
286
  set({
239
- _blockchains: blockchains,
287
+ _blockchainsMapByName: blockchainsMapByName,
240
288
  _tokens: tokens,
241
289
  _popularTokens: popularTokens,
242
290
  _swappers: swappers,
@@ -160,9 +160,13 @@ export const createSettingsSlice: StateCreator<
160
160
  const isLiquidityHidden = isFeatureHidden('liquiditySource', features);
161
161
 
162
162
  set({
163
- ...(isThemeHidden && { theme: 'auto' }),
164
- ...(isLanguageHidden && { language: DEFAULT_LANGUAGE }),
165
- ...(isLiquidityHidden && { disabledLiquiditySources: [] }),
163
+ ...(isThemeHidden && { theme: nextConfig.theme?.mode || 'auto' }),
164
+ ...(isLanguageHidden && {
165
+ language: nextConfig.language || DEFAULT_LANGUAGE,
166
+ }),
167
+ ...(isLiquidityHidden && {
168
+ disabledLiquiditySources: nextConfig.liquiditySources || [],
169
+ }),
166
170
  });
167
171
  },
168
172
  });