@rango-dev/widget-embedded 0.23.1-next.9 → 0.24.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.
Files changed (187) 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/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -283
  4. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  5. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  6. package/dist/components/HeaderButtons/HeaderButtons.d.ts.map +1 -1
  7. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +489 -1
  8. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  9. package/dist/components/HeaderButtons/InProgressTransactionBadge.d.ts +4 -0
  10. package/dist/components/HeaderButtons/InProgressTransactionBadge.d.ts.map +1 -0
  11. package/dist/components/HeaderButtons/RefreshButton.d.ts.map +1 -1
  12. package/dist/components/HeaderButtons/UnreadNotificationsBadge.d.ts.map +1 -1
  13. package/dist/components/HeaderButtons/WalletButton.d.ts.map +1 -1
  14. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -1
  15. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
  16. package/dist/components/NoResult/NoResult.d.ts.map +1 -1
  17. package/dist/components/NoResult/NoResult.helpers.d.ts +8 -0
  18. package/dist/components/NoResult/NoResult.helpers.d.ts.map +1 -1
  19. package/dist/components/NoResult/NoResult.styles.d.ts +167 -1
  20. package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
  21. package/dist/components/NoResult/NoResult.types.d.ts +1 -0
  22. package/dist/components/NoResult/NoResult.types.d.ts.map +1 -1
  23. package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
  24. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +165 -0
  25. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
  26. package/dist/components/Quote/Quote.d.ts.map +1 -1
  27. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  28. package/dist/components/Quote/Quote.types.d.ts +1 -0
  29. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  30. package/dist/components/Quote/QuoteTrigger.d.ts.map +1 -1
  31. package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +1 -0
  32. package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
  33. package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.d.ts.map +1 -1
  34. package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +3 -1
  35. package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
  36. package/dist/components/Quotes/Quotes.d.ts.map +1 -1
  37. package/dist/components/Quotes/Quotes.types.d.ts +1 -0
  38. package/dist/components/Quotes/Quotes.types.d.ts.map +1 -1
  39. package/dist/components/Quotes/SelectStrategy.d.ts.map +1 -1
  40. package/dist/components/Slippage/Slippage.d.ts.map +1 -1
  41. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  42. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  43. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  44. package/dist/constants/index.d.ts +1 -1
  45. package/dist/constants/index.d.ts.map +1 -1
  46. package/dist/constants/languages.d.ts.map +1 -1
  47. package/dist/constants/quote.d.ts +1 -5
  48. package/dist/constants/quote.d.ts.map +1 -1
  49. package/dist/constants/searchFor.d.ts +7 -0
  50. package/dist/constants/searchFor.d.ts.map +1 -0
  51. package/dist/containers/App/App.d.ts.map +1 -1
  52. package/dist/containers/App/App.styles.d.ts.map +1 -1
  53. package/dist/containers/ExpandedQuotes/ExpandedQuotes.d.ts.map +1 -1
  54. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts +3 -1
  55. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
  56. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  57. package/dist/containers/Inputs/Inputs.types.d.ts +1 -0
  58. package/dist/containers/Inputs/Inputs.types.d.ts.map +1 -1
  59. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  60. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +1 -0
  61. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
  62. package/dist/containers/Settings/Lists.d.ts.map +1 -1
  63. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  64. package/dist/containers/Wallets/Wallets.types.d.ts +13 -2
  65. package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
  66. package/dist/containers/Widget/Widget.d.ts.map +1 -1
  67. package/dist/hooks/useBootstrap/index.d.ts +2 -0
  68. package/dist/hooks/useBootstrap/index.d.ts.map +1 -0
  69. package/dist/hooks/useBootstrap/useBootstrap.d.ts +2 -0
  70. package/dist/hooks/useBootstrap/useBootstrap.d.ts.map +1 -0
  71. package/dist/hooks/useScreenDetect.d.ts +9 -0
  72. package/dist/hooks/useScreenDetect.d.ts.map +1 -0
  73. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  74. package/dist/hooks/useTheme.d.ts.map +1 -1
  75. package/dist/hooks/useWalletList.d.ts.map +1 -1
  76. package/dist/index.js +2 -2
  77. package/dist/index.js.map +4 -4
  78. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  79. package/dist/pages/Home.d.ts.map +1 -1
  80. package/dist/pages/LanguagePage.d.ts.map +1 -1
  81. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  82. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  83. package/dist/pages/SettingsPage.d.ts.map +1 -1
  84. package/dist/store/AppStore.d.ts +2 -2
  85. package/dist/store/app.d.ts +2 -2
  86. package/dist/store/slices/config.d.ts.map +1 -1
  87. package/dist/store/slices/data.d.ts +3 -1
  88. package/dist/store/slices/data.d.ts.map +1 -1
  89. package/dist/store/slices/settings.d.ts.map +1 -1
  90. package/dist/types/config.d.ts +9 -5
  91. package/dist/types/config.d.ts.map +1 -1
  92. package/dist/utils/colors.d.ts +5 -3
  93. package/dist/utils/colors.d.ts.map +1 -1
  94. package/dist/utils/common.d.ts +4 -0
  95. package/dist/utils/common.d.ts.map +1 -1
  96. package/dist/utils/configs.d.ts +2 -1
  97. package/dist/utils/configs.d.ts.map +1 -1
  98. package/dist/utils/meta.d.ts +1 -0
  99. package/dist/utils/meta.d.ts.map +1 -1
  100. package/dist/utils/swap.d.ts +2 -0
  101. package/dist/utils/swap.d.ts.map +1 -1
  102. package/dist/utils/ui.d.ts +5 -2
  103. package/dist/utils/ui.d.ts.map +1 -1
  104. package/dist/utils/wallets.d.ts +1 -1
  105. package/dist/utils/wallets.d.ts.map +1 -1
  106. package/package.json +7 -6
  107. package/src/components/AppRouter.tsx +1 -29
  108. package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +6 -12
  109. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +7 -11
  110. package/src/components/ConfirmWalletsModal/WalletList.tsx +2 -2
  111. package/src/components/HeaderButtons/HeaderButtons.styles.ts +43 -2
  112. package/src/components/HeaderButtons/HeaderButtons.tsx +2 -0
  113. package/src/components/HeaderButtons/InProgressTransactionBadge.tsx +26 -0
  114. package/src/components/HeaderButtons/RefreshButton.tsx +2 -1
  115. package/src/components/HeaderButtons/UnreadNotificationsBadge.tsx +10 -2
  116. package/src/components/HeaderButtons/WalletButton.tsx +26 -6
  117. package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.ts +1 -1
  118. package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.tsx +4 -4
  119. package/src/components/NoResult/NoResult.helpers.ts +13 -0
  120. package/src/components/NoResult/NoResult.styles.ts +19 -1
  121. package/src/components/NoResult/NoResult.tsx +27 -16
  122. package/src/components/NoResult/NoResult.types.ts +1 -0
  123. package/src/components/NotificationContent/NotificationContent.styles.ts +14 -1
  124. package/src/components/NotificationContent/NotificationContent.tsx +49 -39
  125. package/src/components/Quote/Quote.styles.ts +13 -14
  126. package/src/components/Quote/Quote.tsx +166 -145
  127. package/src/components/Quote/Quote.types.ts +1 -0
  128. package/src/components/Quote/QuoteTrigger.tsx +19 -14
  129. package/src/components/QuoteSkeleton/QuoteSkeleton.styles.ts +10 -2
  130. package/src/components/QuoteSkeleton/QuoteSkeleton.tsx +2 -2
  131. package/src/components/QuoteSkeleton/QuoteSummarySkeleton.styles.ts +2 -2
  132. package/src/components/QuoteSkeleton/QuoteSummarySkeleton.tsx +5 -4
  133. package/src/components/QuoteSkeleton/StepSkeleton.styles.ts +7 -0
  134. package/src/components/QuoteSkeleton/StepSkeleton.tsx +1 -1
  135. package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +1 -1
  136. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +3 -3
  137. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts +1 -1
  138. package/src/components/Quotes/Quotes.tsx +33 -21
  139. package/src/components/Quotes/Quotes.types.ts +1 -0
  140. package/src/components/Quotes/SelectStrategy.tsx +27 -10
  141. package/src/components/Slippage/Slippage.tsx +11 -13
  142. package/src/components/SwapDetails/SwapDetails.tsx +3 -1
  143. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +5 -1
  144. package/src/components/TokenList/TokenList.tsx +9 -8
  145. package/src/constants/errors.ts +1 -1
  146. package/src/constants/index.ts +1 -1
  147. package/src/constants/languages.ts +27 -1
  148. package/src/constants/quote.ts +1 -24
  149. package/src/constants/searchFor.ts +6 -0
  150. package/src/containers/App/App.styles.ts +0 -4
  151. package/src/containers/App/App.tsx +4 -28
  152. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +13 -0
  153. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +5 -0
  154. package/src/containers/Inputs/Inputs.tsx +2 -3
  155. package/src/containers/Inputs/Inputs.types.ts +1 -0
  156. package/src/containers/QuoteInfo/QuoteInfo.tsx +2 -0
  157. package/src/containers/QuoteInfo/QuoteInfo.types.ts +1 -0
  158. package/src/containers/Settings/Lists.tsx +28 -13
  159. package/src/containers/Wallets/Wallets.tsx +27 -10
  160. package/src/containers/Wallets/Wallets.types.ts +13 -2
  161. package/src/containers/Widget/Widget.tsx +13 -13
  162. package/src/hooks/useBootstrap/index.ts +1 -0
  163. package/src/hooks/useBootstrap/useBootstrap.ts +72 -0
  164. package/src/hooks/useScreenDetect.ts +49 -0
  165. package/src/hooks/useSwapInput.ts +7 -2
  166. package/src/hooks/useTheme.ts +1 -8
  167. package/src/hooks/useWalletList.ts +12 -0
  168. package/src/pages/ConfirmSwapPage.tsx +14 -5
  169. package/src/pages/Home.tsx +29 -7
  170. package/src/pages/LanguagePage.tsx +14 -1
  171. package/src/pages/LiquiditySourcePage.tsx +4 -3
  172. package/src/pages/SelectSwapItemsPage.tsx +2 -7
  173. package/src/pages/SettingsPage.tsx +0 -1
  174. package/src/store/slices/config.ts +3 -2
  175. package/src/store/slices/data.ts +82 -34
  176. package/src/store/slices/settings.ts +10 -4
  177. package/src/types/config.ts +9 -5
  178. package/src/utils/colors.ts +106 -75
  179. package/src/utils/common.ts +181 -0
  180. package/src/utils/configs.ts +12 -1
  181. package/src/utils/meta.ts +21 -0
  182. package/src/utils/swap.ts +12 -5
  183. package/src/utils/ui.ts +7 -5
  184. package/src/utils/wallets.ts +5 -47
  185. package/dist/hooks/useMobileDetect.d.ts +0 -3
  186. package/dist/hooks/useMobileDetect.d.ts.map +0 -1
  187. package/src/hooks/useMobileDetect.ts +0 -21
@@ -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}
@@ -32,7 +32,6 @@ export function SettingsPage() {
32
32
  updateCampaignMode('liquiditySources', undefined);
33
33
  }
34
34
  };
35
-
36
35
  return (
37
36
  <Layout
38
37
  header={{
@@ -6,8 +6,9 @@ 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
+ variant: 'default',
11
12
  };
12
13
 
13
14
  interface IframeConfigs {
@@ -72,7 +73,7 @@ export const createConfigSlice: StateCreatorWithInitialData<
72
73
  const { config, campaignMode } = get();
73
74
  return campaignMode.liquiditySources?.length
74
75
  ? false
75
- : !!config.enableNewLiquiditySources;
76
+ : !!config.excludeLiquiditySources;
76
77
  },
77
78
  isInCampaignMode: () => {
78
79
  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,
@@ -153,16 +153,22 @@ export const createSettingsSlice: StateCreator<
153
153
  language,
154
154
  })),
155
155
  updateSettings: (nextConfig: WidgetConfig) => {
156
- const { features } = nextConfig;
156
+ const { features, theme } = nextConfig;
157
157
 
158
158
  const isThemeHidden = isFeatureHidden('theme', features);
159
159
  const isLanguageHidden = isFeatureHidden('language', features);
160
160
  const isLiquidityHidden = isFeatureHidden('liquiditySource', features);
161
+ const singleTheme = theme?.singleTheme;
161
162
 
162
163
  set({
163
- ...(isThemeHidden && { theme: 'auto' }),
164
- ...(isLanguageHidden && { language: DEFAULT_LANGUAGE }),
165
- ...(isLiquidityHidden && { disabledLiquiditySources: [] }),
164
+ ...(isThemeHidden && { theme: nextConfig.theme?.mode || 'auto' }),
165
+ ...(singleTheme && { theme: nextConfig.theme?.mode || 'light' }),
166
+ ...(isLanguageHidden && {
167
+ language: nextConfig.language || DEFAULT_LANGUAGE,
168
+ }),
169
+ ...(isLiquidityHidden && {
170
+ disabledLiquiditySources: nextConfig.liquiditySources || [],
171
+ }),
166
172
  });
167
173
  },
168
174
  });
@@ -3,7 +3,7 @@ import type { ProviderInterface } from '@rango-dev/wallets-react';
3
3
  import type { WalletType } from '@rango-dev/wallets-shared';
4
4
  import type { Asset } from 'rango-sdk';
5
5
 
6
- export type WidgetVariant = 'default' | 'expandable';
6
+ export type WidgetVariant = 'default' | 'expanded' | 'full-expanded';
7
7
 
8
8
  /**
9
9
  * The above type defines a set of optional color properties for a widget.
@@ -171,8 +171,8 @@ export type Features = Partial<
171
171
  * that defines the various properties of the theme, such as colors, fonts, and others.
172
172
  * @property {boolean} externalWallets
173
173
  * If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
174
- * @property {boolean} enableNewLiquiditySources - The `enableNewLiquiditySources` property is a boolean value that when you
175
- * set it to true, whenever a new liquidity source is added, it will be added to your list as well.
174
+ * @property {boolean} excludeLiquiditySources - The `excludeLiquiditySources` property is a boolean value that when you
175
+ * set it to true, the list of liquidity sources provided in `liquiditySources` will be excluded; otherwise, they will be included.
176
176
  * @property {Features} features - An optional object for configuring the visibility or enablement of various features.
177
177
  * Keys include:
178
178
  * - 'notification': Visibility state for the notification icon.
@@ -182,8 +182,11 @@ export type Features = Partial<
182
182
  * - 'language': Visibility state for the language.
183
183
  * - 'experimentalRoute': Enablement state for the experimental route.
184
184
  * @property {WidgetVariant} variant
185
- * If it is expandable, multiple routes will show up on the home page;
185
+ * If it is expanded, multiple routes will show up on the home page;
186
+ * If it is full-expanded, multiple routes will show up on the home page with full routes;
186
187
  * if not, you will need to go to a different page to see the suggested routes.
188
+ * @property {boolean} enableCentralizedSwappers
189
+ * If you want to enable routing from the centralized protocols like XO Swap, you could set this parameter to true.
187
190
  */
188
191
 
189
192
  export type WidgetConfig = {
@@ -202,7 +205,8 @@ export type WidgetConfig = {
202
205
  language?: Language;
203
206
  theme?: WidgetTheme;
204
207
  externalWallets?: boolean;
205
- enableNewLiquiditySources?: boolean;
208
+ excludeLiquiditySources?: boolean;
206
209
  features?: Features;
207
210
  variant?: WidgetVariant;
211
+ enableCentralizedSwappers?: boolean;
208
212
  };
@@ -1,68 +1,113 @@
1
1
  import type { WidgetColors, WidgetColorsKeys } from '../types';
2
2
 
3
- export const colorShade = (col: string, amt: number) => {
4
- const RANGE = 255;
5
- const COL = 3;
6
- const RADIX = 16;
7
-
8
- col = col.replace(/^#/, '');
9
- if (col.length === COL) {
10
- col = col[0] + col[0] + col[1] + col[1] + col[2] + col[2];
11
- }
12
- let [r, g, b]: any = col.match(/.{2}/g);
13
- [r, g, b] = [
14
- parseInt(r, RADIX) + amt,
15
- parseInt(g, RADIX) + amt,
16
- parseInt(b, RADIX) + amt,
17
- ];
18
-
19
- r = Math.max(Math.min(RANGE, r), 0).toString(RADIX);
20
- g = Math.max(Math.min(RANGE, g), 0).toString(RADIX);
21
- b = Math.max(Math.min(RANGE, b), 0).toString(RADIX);
22
-
23
- const rr = (r.length < 2 ? '0' : '') + r;
24
- const gg = (g.length < 2 ? '0' : '') + g;
25
- const bb = (b.length < 2 ? '0' : '') + b;
26
-
27
- return `#${rr}${gg}${bb}`;
28
- };
3
+ export function generateShades(
4
+ baseColor: string,
5
+ prefix: string,
6
+ reverse?: boolean
7
+ ): { [key: string]: string } {
8
+ const BASE_SHADE_INDEX = 100;
9
+ const NUMBER_OF_COLORS = 9;
10
+ const SHADING_INCREMENT_MAX = 10; // For bright colors
11
+ const SHADING_INCREMENT_MIN = 6; // For dark colors
29
12
 
30
- export const generateRangeColors = (name: string, color: string) => {
31
- const NUMBER_OF_COLORS = 10;
32
- const HALF_NUMBER_OF_COLORS = 5;
33
- const COLOR_SUFFIX = 100;
34
- const AMT = 25;
35
-
36
- let colors = { [name]: color };
37
- for (let i = 1; i < NUMBER_OF_COLORS; i++) {
38
- if (i < HALF_NUMBER_OF_COLORS) {
39
- colors = {
40
- ...colors,
41
- [name + i * COLOR_SUFFIX]: colorShade(
42
- color,
43
- (HALF_NUMBER_OF_COLORS - i) * AMT
44
- ),
45
- };
46
- }
47
- if (i === HALF_NUMBER_OF_COLORS) {
48
- colors = {
49
- ...colors,
50
- [name + i * COLOR_SUFFIX]: color,
51
- };
52
- }
53
- if (i > HALF_NUMBER_OF_COLORS) {
54
- colors = {
55
- ...colors,
56
- [name + i * COLOR_SUFFIX]: colorShade(
57
- color,
58
- -((i - HALF_NUMBER_OF_COLORS) * AMT)
59
- ),
60
- };
13
+ const HALF_NUMBER_OF_COLORS = 4;
14
+
15
+ const shadeIncrements: number[] = [];
16
+ let increment = 90;
17
+ for (let i = 0; i < NUMBER_OF_COLORS; i++) {
18
+ shadeIncrements.push(increment);
19
+ if (i + 1 === HALF_NUMBER_OF_COLORS) {
20
+ increment = 0;
21
+ } else {
22
+ increment -=
23
+ i >= HALF_NUMBER_OF_COLORS
24
+ ? SHADING_INCREMENT_MIN
25
+ : SHADING_INCREMENT_MAX;
61
26
  }
62
27
  }
63
28
 
64
- return colors;
65
- };
29
+ // If 'reverse' is true, that means the color should be from dark to light
30
+ const decrementAmounts = reverse
31
+ ? shadeIncrements.slice().reverse()
32
+ : shadeIncrements;
33
+
34
+ const shades: { [key: string]: string } = {};
35
+
36
+ // Generate shades
37
+ for (let i = 0; i < NUMBER_OF_COLORS; i++) {
38
+ const shadeIndex = BASE_SHADE_INDEX + i * BASE_SHADE_INDEX;
39
+ const decrementAmount = decrementAmounts[i];
40
+
41
+ const shade: { [key: string]: string } = {
42
+ [`${prefix}${shadeIndex}`]: generateShade(baseColor, decrementAmount),
43
+ };
44
+ Object.assign(shades, shade);
45
+ }
46
+
47
+ return { ...shades, [prefix]: baseColor };
48
+ }
49
+
50
+ export function generateShade(
51
+ baseColor: string,
52
+ decrementAmount: number
53
+ ): string {
54
+ const [r, g, b] = convertToRGB(baseColor);
55
+ return `#${clamp(r + decrementAmount)}${clamp(g + decrementAmount)}${clamp(
56
+ b + decrementAmount
57
+ )}`;
58
+ }
59
+
60
+ export function convertToRGB(baseColor: string): number[] {
61
+ const COLOR_SLICE_START = 1;
62
+ const COLOR_SLICE_END = 3;
63
+ const BASE_COLOR_LENGTH = 7;
64
+
65
+ // Convert the base color to RGB components
66
+ const r: number = parseInt(
67
+ baseColor.slice(COLOR_SLICE_START, COLOR_SLICE_END),
68
+ 16
69
+ );
70
+ const g: number = parseInt(
71
+ baseColor.slice(COLOR_SLICE_END, COLOR_SLICE_END + 2),
72
+ 16
73
+ );
74
+ const b: number = parseInt(
75
+ baseColor.slice(COLOR_SLICE_END + 2, BASE_COLOR_LENGTH),
76
+ 16
77
+ );
78
+
79
+ return [r, g, b];
80
+ }
81
+
82
+ // Function to clamp color component to valid range [0, 255] and convert to hex
83
+ function clamp(color: number): string {
84
+ const MAX_COLOR_VALUE = 255;
85
+ const HEX_BASE = 16;
86
+ const HEX_LENGTH = -2;
87
+ return (
88
+ '0' + Math.max(0, Math.min(MAX_COLOR_VALUE, color)).toString(HEX_BASE)
89
+ )
90
+ .slice(HEX_LENGTH)
91
+ .toUpperCase();
92
+ }
93
+
94
+ export function isBright(baseColor: string) {
95
+ const BRIGHTNESS_THRESHOLD = 188;
96
+ const RED_COEFFICIENT = 299;
97
+ const GREEN_COEFFICIENT = 587;
98
+ const BLUE_COEFFICIENT = 114;
99
+ const BRIGHTNESS_DIVISOR = 1000;
100
+
101
+ const [r, g, b] = convertToRGB(baseColor);
102
+ const brightness =
103
+ (r * RED_COEFFICIENT + g * GREEN_COEFFICIENT + b * BLUE_COEFFICIENT) /
104
+ BRIGHTNESS_DIVISOR;
105
+ if (brightness > BRIGHTNESS_THRESHOLD) {
106
+ return true;
107
+ }
108
+ return false;
109
+ }
110
+
66
111
  export const generateColors = (
67
112
  mainColors: { [x: string]: string },
68
113
  reverseNeutralRange: boolean,
@@ -83,25 +128,11 @@ export const generateColors = (
83
128
  ...listOfColors,
84
129
  [colorKey]: color,
85
130
  };
86
- } else if (colorKey === 'neutral' && reverseNeutralRange) {
87
- const range = generateRangeColors(colorKey, color);
88
- listOfColors = {
89
- ...listOfColors,
90
- // Reverse the neutral shade
91
- [`${colorKey}100`]: range[`${colorKey}900`],
92
- [`${colorKey}200`]: range[`${colorKey}800`],
93
- [`${colorKey}300`]: range[`${colorKey}700`],
94
- [`${colorKey}400`]: range[`${colorKey}600`],
95
- [`${colorKey}500`]: range[`${colorKey}500`],
96
- [`${colorKey}600`]: range[`${colorKey}400`],
97
- [`${colorKey}700`]: range[`${colorKey}300`],
98
- [`${colorKey}800`]: range[`${colorKey}200`],
99
- [`${colorKey}900`]: range[`${colorKey}100`],
100
- };
101
131
  } else {
132
+ const reverse = colorKey === 'neutral' && reverseNeutralRange;
102
133
  listOfColors = {
103
134
  ...listOfColors,
104
- ...generateRangeColors(colorKey, color),
135
+ ...generateShades(color, colorKey, reverse),
105
136
  };
106
137
  }
107
138
  }