@rango-dev/widget-embedded 0.14.1-next.2 → 0.14.1-next.21

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 (167) hide show
  1. package/dist/Widget.d.ts.map +1 -1
  2. package/dist/components/BlockchainList/BlockchainList.styles.d.ts +8 -0
  3. package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
  4. package/dist/components/BlockchainsSection/BlockchainsSection.d.ts.map +1 -1
  5. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +4 -0
  6. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
  7. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +60 -0
  8. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  9. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  10. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  11. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +12 -0
  12. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
  13. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +16 -0
  14. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  15. package/dist/components/Layout/Layout.styles.d.ts +12 -0
  16. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  17. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +4 -0
  18. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
  19. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +12 -0
  20. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
  21. package/dist/components/NoRoutes/NoRoutes.styles.d.ts +12 -0
  22. package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
  23. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +16 -0
  24. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
  25. package/dist/components/RouteErrors/RouteErrors.styles.d.ts +16 -0
  26. package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
  27. package/dist/components/SearchInput/SearchInput.styles.d.ts +4 -0
  28. package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
  29. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +16 -0
  30. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
  31. package/dist/components/Slippage/Slippage.styles.d.ts +16 -0
  32. package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
  33. package/dist/components/SwapDetails/SwapDetails.Placeholder.d.ts.map +1 -1
  34. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  35. package/dist/components/SwapDetails/SwapDetails.styles.d.ts +24 -0
  36. package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
  37. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +4 -0
  38. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
  39. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +4 -0
  40. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
  41. package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +16 -0
  42. package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
  43. package/dist/components/TokenList/TokenList.styles.d.ts +40 -0
  44. package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
  45. package/dist/components/WalletModal/WalletModalContent.styles.d.ts +16 -0
  46. package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
  47. package/dist/constants/configs.d.ts +2 -0
  48. package/dist/constants/configs.d.ts.map +1 -0
  49. package/dist/constants/errors.d.ts +1 -1
  50. package/dist/constants/errors.d.ts.map +1 -1
  51. package/dist/constants/fonts.d.ts +2 -0
  52. package/dist/constants/fonts.d.ts.map +1 -0
  53. package/dist/{constants.d.ts → constants/index.d.ts} +1 -1
  54. package/dist/constants/index.d.ts.map +1 -0
  55. package/dist/constants/languages.d.ts +11 -0
  56. package/dist/constants/languages.d.ts.map +1 -0
  57. package/dist/constants/messages.d.ts +1 -1
  58. package/dist/constants/messages.d.ts.map +1 -1
  59. package/dist/hooks/useLanguage.d.ts +11 -0
  60. package/dist/hooks/useLanguage.d.ts.map +1 -0
  61. package/dist/hooks/usePrepareBlockchainList/index.d.ts +2 -0
  62. package/dist/hooks/usePrepareBlockchainList/index.d.ts.map +1 -0
  63. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts +2 -0
  64. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts.map +1 -0
  65. package/dist/hooks/{usePrepareBlockchainList.d.ts → usePrepareBlockchainList/usePrepareBlockchainList.d.ts} +1 -9
  66. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.d.ts.map +1 -0
  67. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +10 -0
  68. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts.map +1 -0
  69. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts +3 -0
  70. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts.map +1 -0
  71. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.d.ts +2 -0
  72. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.d.ts.map +1 -0
  73. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts +11 -0
  74. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts.map +1 -0
  75. package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
  76. package/dist/hooks/useTheme.d.ts +2 -2
  77. package/dist/hooks/useTheme.d.ts.map +1 -1
  78. package/dist/index.d.ts +9 -6
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +1 -1
  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/store/bestRoute.d.ts.map +1 -1
  86. package/dist/store/settings.d.ts +15 -6
  87. package/dist/store/settings.d.ts.map +1 -1
  88. package/dist/types/config.d.ts +11 -13
  89. package/dist/types/config.d.ts.map +1 -1
  90. package/dist/utils/colors.d.ts +11 -0
  91. package/dist/utils/colors.d.ts.map +1 -0
  92. package/dist/utils/common.d.ts +0 -4
  93. package/dist/utils/common.d.ts.map +1 -1
  94. package/dist/utils/configs.d.ts +2 -0
  95. package/dist/utils/configs.d.ts.map +1 -1
  96. package/dist/utils/hash.d.ts +2 -0
  97. package/dist/utils/hash.d.ts.map +1 -0
  98. package/dist/utils/meta.d.ts +3 -1
  99. package/dist/utils/meta.d.ts.map +1 -1
  100. package/dist/utils/routing.d.ts +8 -1
  101. package/dist/utils/routing.d.ts.map +1 -1
  102. package/dist/utils/swap.d.ts.map +1 -1
  103. package/dist/utils/time.d.ts.map +1 -1
  104. package/dist/utils/ui.d.ts +13 -0
  105. package/dist/utils/ui.d.ts.map +1 -0
  106. package/dist/utils/wallets.d.ts +0 -1
  107. package/dist/utils/wallets.d.ts.map +1 -1
  108. package/package.json +6 -6
  109. package/src/Widget.tsx +15 -3
  110. package/src/components/BlockchainsSection/BlockchainsSection.tsx +21 -6
  111. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -11
  112. package/src/components/ConfirmWalletsModal/WalletList.tsx +35 -24
  113. package/src/components/Layout/Layout.styles.ts +7 -2
  114. package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +1 -1
  115. package/src/components/NoRoutes/NoRoutes.helper.ts +4 -4
  116. package/src/components/NoRoutes/NoRoutes.tsx +2 -2
  117. package/src/components/NotificationContent/NotificationContent.tsx +1 -1
  118. package/src/components/NotificationContent/NotificationNotFound.tsx +1 -1
  119. package/src/components/RouteErrors/RouteErrors.tsx +2 -2
  120. package/src/components/RouteErrors/RouteErrorsModal.tsx +6 -6
  121. package/src/components/RouteErrors/RouteErrorsModalItem.tsx +1 -1
  122. package/src/components/Slippage/SlippageTooltipContent.tsx +1 -1
  123. package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +5 -6
  124. package/src/components/SwapDetails/SwapDetails.tsx +6 -10
  125. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +1 -1
  126. package/src/components/SwapsGroup/SwapsGroup.tsx +2 -2
  127. package/src/components/TokenList/TokenList.styles.ts +1 -1
  128. package/src/components/TokenList/TokenList.tsx +2 -2
  129. package/src/constants/configs.ts +1 -0
  130. package/src/constants/errors.ts +44 -41
  131. package/src/constants/fonts.ts +1 -0
  132. package/src/constants/languages.ts +19 -0
  133. package/src/constants/messages.ts +7 -5
  134. package/src/hooks/useConfirmSwap.ts +1 -1
  135. package/src/hooks/useLanguage.ts +27 -0
  136. package/src/hooks/usePrepareBlockchainList/index.ts +1 -0
  137. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.ts +1 -0
  138. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.ts +108 -0
  139. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.ts +3101 -0
  140. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.ts +273 -0
  141. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.ts +38 -0
  142. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.ts +12 -0
  143. package/src/hooks/useSyncStoresWithConfig.ts +49 -1
  144. package/src/hooks/useTheme.ts +44 -26
  145. package/src/index.ts +33 -26
  146. package/src/pages/ConfirmSwapPage.tsx +9 -18
  147. package/src/pages/Home.tsx +6 -7
  148. package/src/pages/LanguagePage.tsx +16 -39
  149. package/src/pages/SettingsPage.tsx +1 -1
  150. package/src/store/bestRoute.ts +12 -38
  151. package/src/store/settings.ts +46 -4
  152. package/src/types/config.ts +10 -12
  153. package/src/utils/colors.ts +109 -0
  154. package/src/utils/common.ts +0 -49
  155. package/src/utils/configs.ts +3 -0
  156. package/src/utils/hash.ts +27 -0
  157. package/src/utils/meta.ts +11 -1
  158. package/src/utils/routing.ts +58 -0
  159. package/src/utils/settings.ts +1 -1
  160. package/src/utils/swap.ts +15 -20
  161. package/src/utils/time.ts +2 -4
  162. package/src/utils/ui.ts +72 -0
  163. package/src/utils/wallets.ts +4 -25
  164. package/dist/constants.d.ts.map +0 -1
  165. package/dist/hooks/usePrepareBlockchainList.d.ts.map +0 -1
  166. package/src/hooks/usePrepareBlockchainList.ts +0 -125
  167. /package/src/{constants.ts → constants/index.ts} +0 -0
@@ -6,57 +6,34 @@ import {
6
6
  RadioRoot,
7
7
  Typography,
8
8
  } from '@rango-dev/ui';
9
- import React, { useState } from 'react';
9
+ import React from 'react';
10
10
 
11
11
  import { Layout } from '../components/Layout';
12
12
  import { SettingsContainer } from '../components/SettingsContainer';
13
13
  import { navigationRoutes } from '../constants/navigationRoutes';
14
+ import { useLanguage } from '../hooks/useLanguage';
14
15
  import { useNavigateBack } from '../hooks/useNavigateBack';
15
16
 
16
- enum Languages {
17
- ENGLISH = 'english',
18
- FRENCH = 'french',
19
- SPANISH = 'spanish',
20
- }
21
17
  export function LanguagePage() {
22
18
  const { navigateBackFrom } = useNavigateBack();
23
- const [language, setLanguage] = useState(Languages.ENGLISH);
24
19
 
25
- const languageList = [
26
- {
27
- id: Languages.ENGLISH,
28
- value: Languages.ENGLISH,
29
- title: (
30
- <Typography variant="title" size="xmedium">
31
- {i18n.t('English')}
32
- </Typography>
33
- ),
34
- onClick: () => setLanguage(Languages.ENGLISH),
35
- end: <Radio value={Languages.ENGLISH} />,
36
- },
37
- {
38
- id: Languages.FRENCH,
39
- value: Languages.FRENCH,
40
- title: (
41
- <Typography variant="title" size="xmedium">
42
- {i18n.t('French')}
43
- </Typography>
44
- ),
45
- onClick: () => setLanguage(Languages.FRENCH),
46
- end: <Radio value={Languages.FRENCH} />,
47
- },
48
- {
49
- id: Languages.SPANISH,
50
- value: Languages.SPANISH,
20
+ const { activeLanguage, changeLanguage, languages } = useLanguage();
21
+
22
+ const languageList = languages.map((languageItem) => {
23
+ const { local, label, SVGFlag } = languageItem;
24
+ return {
25
+ id: local,
26
+ value: local,
51
27
  title: (
52
28
  <Typography variant="title" size="xmedium">
53
- {i18n.t('Spanish')}
29
+ {label}
54
30
  </Typography>
55
31
  ),
56
- onClick: () => setLanguage(Languages.SPANISH),
57
- end: <Radio value={Languages.SPANISH} />,
58
- },
59
- ];
32
+ onClick: () => changeLanguage(languageItem.local),
33
+ end: <Radio value={local} />,
34
+ start: <SVGFlag />,
35
+ };
36
+ });
60
37
 
61
38
  return (
62
39
  <Layout
@@ -65,7 +42,7 @@ export function LanguagePage() {
65
42
  title: i18n.t('Language'),
66
43
  }}>
67
44
  <SettingsContainer>
68
- <RadioRoot value={language}>
45
+ <RadioRoot value={activeLanguage}>
69
46
  <List
70
47
  type={
71
48
  <ListItemButton
@@ -147,7 +147,7 @@ export function SettingsPage({ supportedSwappers, singleTheme }: PropTypes) {
147
147
  container={getContainer()}
148
148
  content={
149
149
  <TooltipContainer>
150
- <Typography variant="label" size="medium" color="neutral900">
150
+ <Typography variant="label" size="medium" color="neutral700">
151
151
  {i18n.t(
152
152
  "Enabling the 'Infinite Approval' mode grants unrestricted access to smart contracts of DEXes/Bridges, allowing them to utilize the approved token amount without limitations."
153
153
  )}
@@ -9,9 +9,11 @@ import { subscribeWithSelector } from 'zustand/middleware';
9
9
 
10
10
  import { ZERO } from '../constants/numbers';
11
11
  import { isPositiveNumber } from '../utils/numbers';
12
- import { getBestRouteToTokenUsdPrice } from '../utils/routing';
12
+ import {
13
+ createRetryRoute,
14
+ getBestRouteToTokenUsdPrice,
15
+ } from '../utils/routing';
13
16
  import { calcOutputUsdValue } from '../utils/swap';
14
- import { tokensAreEqual } from '../utils/wallets';
15
17
 
16
18
  import { useMetaStore } from './meta';
17
19
  import createSelectors from './selectors';
@@ -173,49 +175,21 @@ export const useBestRouteStore = createSelectors(
173
175
  },
174
176
  retry: (pendingSwap) => {
175
177
  const { tokens, blockchains } = useMetaStore.getState().meta;
176
- const failedIndex =
177
- pendingSwap.status === 'failed'
178
- ? pendingSwap.steps.findIndex((s) => s.status === 'failed')
179
- : null;
180
178
 
181
- if (failedIndex === null || failedIndex < 0) {
182
- return;
183
- }
184
-
185
- const firstStep = pendingSwap.steps[0];
186
- const lastStep = pendingSwap.steps[pendingSwap.steps.length - 1];
187
- const fromBlockchain =
188
- blockchains.find(
189
- (blockchain) => blockchain.name === firstStep.fromBlockchain
190
- ) || null;
191
- const toBlockchain =
192
- blockchains.find(
193
- (blockchain) => blockchain.name === lastStep.toBlockchain
194
- ) || null;
195
-
196
- const fromToken = tokens.find((token) =>
197
- tokensAreEqual(token, {
198
- blockchain: firstStep.fromBlockchain,
199
- symbol: firstStep.fromSymbol,
200
- address: firstStep.fromSymbolAddress,
201
- })
202
- );
203
-
204
- const toToken = tokens.find((token) =>
205
- tokensAreEqual(token, {
206
- blockchain: lastStep.toBlockchain,
207
- symbol: lastStep.toSymbol,
208
- address: lastStep.toSymbolAddress,
209
- })
210
- );
179
+ const {
180
+ fromBlockchain,
181
+ fromToken,
182
+ toBlockchain,
183
+ toToken,
184
+ inputAmount,
185
+ } = createRetryRoute(pendingSwap, blockchains, tokens);
211
186
 
212
- const inputAmount = pendingSwap.inputAmount;
213
187
  set({
214
188
  fromBlockchain,
215
189
  fromToken,
216
190
  inputAmount,
217
191
  outputAmount: null,
218
- inputUsdValue: getUsdValue(fromToken || null, inputAmount),
192
+ inputUsdValue: getUsdValue(fromToken ?? null, inputAmount),
219
193
  outputUsdValue: new BigNumber(0),
220
194
  toBlockchain,
221
195
  toToken,
@@ -1,40 +1,50 @@
1
+ import { type Language } from '@rango-dev/ui';
1
2
  import { create } from 'zustand';
2
3
  import { persist, subscribeWithSelector } from 'zustand/middleware';
3
4
 
5
+ import { BLOCKCHAIN_LIST_SIZE } from '../constants/configs';
6
+ import { DEFAULT_LANGUAGE } from '../constants/languages';
4
7
  import { DEFAULT_SLIPPAGE } from '../constants/swapSettings';
5
8
  import { removeDuplicateFrom } from '../utils/common';
6
9
 
7
10
  import { useMetaStore } from './meta';
8
11
  import createSelectors from './selectors';
9
12
 
10
- type Theme = 'auto' | 'dark' | 'light';
13
+ export type ThemeMode = 'auto' | 'dark' | 'light';
11
14
 
12
15
  export interface SettingsState {
16
+ /** Keeping a history of blockchains that user has selected (in Swap process) */
17
+ preferredBlockchains: string[];
13
18
  slippage: number;
14
19
  customSlippage: number | null;
15
20
  infiniteApprove: boolean;
16
21
  disabledLiquiditySources: string[];
17
- theme: Theme;
22
+ theme: ThemeMode;
23
+ language: Language;
18
24
  affiliateRef: string | null;
19
25
  affiliatePercent: number | null;
20
26
  affiliateWallets: { [key: string]: string } | null;
27
+
21
28
  setSlippage: (slippage: number) => void;
22
29
  setCustomSlippage: (customSlippage: number | null) => void;
23
30
  toggleInfiniteApprove: () => void;
24
31
  toggleLiquiditySource: (name: string) => void;
25
- setTheme: (theme: Theme) => void;
32
+ setTheme: (theme: ThemeMode) => void;
33
+ setLanguage: (language: Language) => void;
26
34
  toggleAllLiquiditySources: (shouldReset?: boolean) => void;
27
35
  setAffiliateRef: (affiliateRef: string | null) => void;
28
36
  setAffiliatePercent: (affiliatePercent: number | null) => void;
29
37
  setAffiliateWallets: (
30
38
  affiliateWallets: { [key: string]: string } | null
31
39
  ) => void;
40
+ addPreferredBlockchain: (blockchain: string) => void;
32
41
  }
33
42
 
34
43
  export const useSettingsStore = createSelectors(
35
44
  create<SettingsState>()(
36
45
  persist(
37
- subscribeWithSelector((set) => ({
46
+ subscribeWithSelector((set, get) => ({
47
+ preferredBlockchains: [],
38
48
  slippage: DEFAULT_SLIPPAGE,
39
49
  customSlippage: null,
40
50
  infiniteApprove: false,
@@ -43,6 +53,34 @@ export const useSettingsStore = createSelectors(
43
53
  affiliateWallets: null,
44
54
  disabledLiquiditySources: [],
45
55
  theme: 'auto',
56
+ language: DEFAULT_LANGUAGE,
57
+ addPreferredBlockchain: (blockchain) => {
58
+ const currentPreferredBlockchains = get().preferredBlockchains;
59
+
60
+ const noNeedToDoAnything = currentPreferredBlockchains.find(
61
+ (preferredBlockchain, index) => {
62
+ const isSameBlockchain = preferredBlockchain === blockchain;
63
+ const isInVisibleList = index <= BLOCKCHAIN_LIST_SIZE - 1;
64
+
65
+ return isSameBlockchain && isInVisibleList;
66
+ }
67
+ );
68
+
69
+ if (noNeedToDoAnything) {
70
+ return;
71
+ }
72
+
73
+ const nextPreferredBlockchains: string[] =
74
+ currentPreferredBlockchains.filter((preferredBlockchain) => {
75
+ const isSameBlockchain = preferredBlockchain === blockchain;
76
+
77
+ return !isSameBlockchain;
78
+ });
79
+
80
+ set(() => ({
81
+ preferredBlockchains: [blockchain, ...nextPreferredBlockchains],
82
+ }));
83
+ },
46
84
  setSlippage: (slippage) =>
47
85
  set(() => ({
48
86
  slippage: slippage,
@@ -106,6 +144,10 @@ export const useSettingsStore = createSelectors(
106
144
  set(() => ({
107
145
  theme,
108
146
  })),
147
+ setLanguage: (language) =>
148
+ set(() => ({
149
+ language,
150
+ })),
109
151
  })),
110
152
  {
111
153
  name: 'user-settings',
@@ -8,22 +8,17 @@ import type { Asset } from 'rango-sdk';
8
8
  * @property {string} background
9
9
  * @property {string} foreground
10
10
  * @property {string} primary
11
- * @property {string} success
12
- * @property {string} error
13
- * @property {string} warning
14
- * @property {string} surface
15
- * @property {string} neutral
11
+ * @property {string} secondary
16
12
  *
17
13
  */
14
+ export type WidgetColorsKeys = keyof WidgetColors;
18
15
  export type WidgetColors = {
19
16
  background?: string;
20
17
  foreground?: string;
21
- primary?: string;
22
- success?: string;
23
- error?: string;
24
- warning?: string;
25
- surface?: string;
26
18
  neutral?: string;
19
+ primary?: string;
20
+ secondary?: string;
21
+ info?: string;
27
22
  };
28
23
 
29
24
  /**
@@ -32,7 +27,7 @@ export type WidgetColors = {
32
27
  * @property {'auto' | 'light' | 'dark'} mode - The mode property is used to specify the default theme for
33
28
  * the widget.
34
29
  * @property {string} fontFamily - The font family to be used in the widget.
35
- * @property {Colors} colors - The `colors` property is a sub-property of the `WidgetTheme` object that
30
+ * @property {{ light?: WidgetColors; dark?: WidgetColors }} colors - The `colors` property is a sub-property of the `WidgetTheme` object that
36
31
  * defines the color scheme for the widget. It is of type `Colors`, which is likely another object that
37
32
  * contains specific color values for various parts of the widget (e.g. background color, text color,
38
33
  * border color
@@ -47,7 +42,7 @@ export type WidgetColors = {
47
42
  export type WidgetTheme = {
48
43
  mode?: 'auto' | 'light' | 'dark';
49
44
  fontFamily?: string;
50
- colors?: { light: WidgetColors; dark: WidgetColors };
45
+ colors?: { light?: WidgetColors; dark?: WidgetColors };
51
46
  borderRadius?: number;
52
47
  secondaryBorderRadius?: number;
53
48
  width?: number;
@@ -126,6 +121,8 @@ export type BlockchainAndTokenConfig = {
126
121
  * If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
127
122
  * @property {Asset} pinnedTokens - The `pinnedTokens` property is an optional array of `Asset` objects that
128
123
  * you could use to pin tokens of your choice to the top of the token list.
124
+ * @property {boolean} includeNewLiquiditySources - The `includeNewLiquiditySources` property is a boolean value that when you
125
+ * set it to true, whenever a new liquidity source is added, it will be added to your list as well.
129
126
  */
130
127
  export type WidgetConfig = {
131
128
  apiKey: string;
@@ -142,4 +139,5 @@ export type WidgetConfig = {
142
139
  theme?: WidgetTheme;
143
140
  externalWallets?: boolean;
144
141
  pinnedTokens?: Asset[];
142
+ includeNewLiquiditySources?: boolean;
145
143
  };
@@ -0,0 +1,109 @@
1
+ import type { WidgetColors, WidgetColorsKeys } from '../types';
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
+ };
29
+
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 = 32;
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
+ };
61
+ }
62
+ }
63
+ return colors;
64
+ };
65
+ export const generateColors = (
66
+ mainColors: { [x: string]: string },
67
+ reverseNeutralRange: boolean,
68
+ colors?: WidgetColors
69
+ ) => {
70
+ if (!colors || !Object.entries(colors).length) {
71
+ return {};
72
+ }
73
+ let changeColors = false;
74
+ let listOfColors = { ...mainColors };
75
+ for (const colorKey in colors) {
76
+ const color = colors[colorKey as WidgetColorsKeys];
77
+
78
+ if (!!color && color !== mainColors[colorKey]) {
79
+ changeColors = true;
80
+ if (colorKey === 'background' || colorKey === 'foreground') {
81
+ listOfColors = {
82
+ ...listOfColors,
83
+ [colorKey]: color,
84
+ };
85
+ } else if (colorKey === 'neutral' && reverseNeutralRange) {
86
+ const range = generateRangeColors(colorKey, color);
87
+ listOfColors = {
88
+ ...listOfColors,
89
+ // Reverse the neutral shade
90
+ [`${colorKey}100`]: range[`${colorKey}900`],
91
+ [`${colorKey}200`]: range[`${colorKey}800`],
92
+ [`${colorKey}300`]: range[`${colorKey}700`],
93
+ [`${colorKey}400`]: range[`${colorKey}600`],
94
+ [`${colorKey}500`]: range[`${colorKey}500`],
95
+ [`${colorKey}600`]: range[`${colorKey}400`],
96
+ [`${colorKey}700`]: range[`${colorKey}300`],
97
+ [`${colorKey}800`]: range[`${colorKey}200`],
98
+ [`${colorKey}900`]: range[`${colorKey}100`],
99
+ };
100
+ } else {
101
+ listOfColors = {
102
+ ...listOfColors,
103
+ ...generateRangeColors(colorKey, color),
104
+ };
105
+ }
106
+ }
107
+ }
108
+ return changeColors ? listOfColors : {};
109
+ };
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-magic-numbers */
2
1
  export function removeDuplicateFrom<T>(array: T[]): T[] {
3
2
  return Array.from(new Set(array));
4
3
  }
@@ -31,53 +30,5 @@ export function containsText(text: string, searchText: string): boolean {
31
30
  return text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
32
31
  }
33
32
 
34
- export const colorShade = (col: string, amt: number) => {
35
- col = col.replace(/^#/, '');
36
- if (col.length === 3) {
37
- col = col[0] + col[0] + col[1] + col[1] + col[2] + col[2];
38
- }
39
- let [r, g, b]: any = col.match(/.{2}/g);
40
- [r, g, b] = [
41
- parseInt(r, 16) + amt,
42
- parseInt(g, 16) + amt,
43
- parseInt(b, 16) + amt,
44
- ];
45
-
46
- r = Math.max(Math.min(255, r), 0).toString(16);
47
- g = Math.max(Math.min(255, g), 0).toString(16);
48
- b = Math.max(Math.min(255, b), 0).toString(16);
49
-
50
- const rr = (r.length < 2 ? '0' : '') + r;
51
- const gg = (g.length < 2 ? '0' : '') + g;
52
- const bb = (b.length < 2 ? '0' : '') + b;
53
-
54
- return `#${rr}${gg}${bb}`;
55
- };
56
-
57
- export const generateRangeColors = (name: string, color: string) => {
58
- let colors = { [name]: color };
59
- for (let i = 1; i < 10; i++) {
60
- if (i < 5) {
61
- colors = {
62
- ...colors,
63
- [name + i * 100]: colorShade(color, (5 - i) * 32),
64
- };
65
- }
66
- if (i === 5) {
67
- colors = {
68
- ...colors,
69
- [name + i * 100]: color,
70
- };
71
- }
72
- if (i > 5) {
73
- colors = {
74
- ...colors,
75
- [name + i * 100]: colorShade(color, -((i - 5) * 32)),
76
- };
77
- }
78
- }
79
- return colors;
80
- };
81
-
82
33
  export const getContainer = () =>
83
34
  document.getElementById('swap-box') as HTMLElement;
@@ -34,3 +34,6 @@ export function initConfig(nextConfigs: Configs) {
34
34
 
35
35
  export const DEFAULT_PRIMARY_RADIUS = 20;
36
36
  export const DEFAULT_SECONDARY_RADIUS = 25;
37
+ export const DEFAULT_FONT_FAMILY = 'Roboto';
38
+
39
+ export const THEME_CLASS_NAME_PREFIX = `theme-widget`;
@@ -0,0 +1,27 @@
1
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
2
+ // Original Code: https://github.com/stitchesjs/stitches/blob/canary/packages/core/src/convert/toHash.js
3
+
4
+ const toAlphabeticChar = (code: number) =>
5
+ String.fromCharCode(code + (code > 25 ? 39 : 97));
6
+
7
+ const toAlphabeticName = (code: number) => {
8
+ let name = '';
9
+ let x;
10
+
11
+ for (x = Math.abs(code); x > 52; x = (x / 52) | 0) {
12
+ name = toAlphabeticChar(x % 52) + name;
13
+ }
14
+
15
+ return toAlphabeticChar(x % 52) + name;
16
+ };
17
+
18
+ const toPhash = (h: number, x: string) => {
19
+ let i = x.length;
20
+ while (i) {
21
+ h = (h * 33) ^ x.charCodeAt(--i);
22
+ }
23
+ return h;
24
+ };
25
+
26
+ export const toHash = (value: object) =>
27
+ toAlphabeticName(toPhash(5381, JSON.stringify(value)) >>> 0);
package/src/utils/meta.ts CHANGED
@@ -1,4 +1,6 @@
1
- import type { BlockchainMeta } from 'rango-sdk';
1
+ import type { Asset, BlockchainMeta, Token } from 'rango-sdk';
2
+
3
+ import { tokensAreEqual } from './wallets';
2
4
 
3
5
  export function getBlockchainDisplayNameFor(
4
6
  blockchainName: string,
@@ -14,3 +16,11 @@ export function getBlockchainShortNameFor(
14
16
  return blockchains.find((blockchain) => blockchain.name === blockchainName)
15
17
  ?.shortName;
16
18
  }
19
+
20
+ export function findToken(t: Asset, tokens: Token[]) {
21
+ return tokens.find((token) => tokensAreEqual(token, t)) ?? null;
22
+ }
23
+
24
+ export function findBlockchain(name: string, blockchains: BlockchainMeta[]) {
25
+ return blockchains.find((blockchain) => blockchain.name === name) ?? null;
26
+ }
@@ -13,6 +13,7 @@ import type {
13
13
  Token,
14
14
  } from 'rango-sdk';
15
15
 
16
+ import { getLastSuccessfulStep } from '@rango-dev/queue-manager-rango-preset';
16
17
  import BigNumber from 'bignumber.js';
17
18
 
18
19
  import {
@@ -25,6 +26,7 @@ import {
25
26
  } from '../constants/routing';
26
27
 
27
28
  import { areEqual } from './common';
29
+ import { findBlockchain, findToken } from './meta';
28
30
  import { numberToString } from './numbers';
29
31
 
30
32
  export function searchParamsToToken(
@@ -261,3 +263,59 @@ export function findCommonTokens<T extends Asset[], R extends Asset[]>(
261
263
 
262
264
  return listB.filter((token) => set.has(tokenToString(token))) as R;
263
265
  }
266
+
267
+ export function createRetryRoute(
268
+ pendingSwap: PendingSwap,
269
+ blockchains: BlockchainMeta[],
270
+ tokens: Token[]
271
+ ): {
272
+ fromBlockchain: BlockchainMeta | null;
273
+ fromToken: Token | null;
274
+ toBlockchain: BlockchainMeta | null;
275
+ toToken: Token | null;
276
+ inputAmount: string;
277
+ } {
278
+ const firstStep = pendingSwap.steps[0];
279
+ const lastStep = pendingSwap.steps[pendingSwap.steps.length - 1];
280
+ const lastSuccessfulStep = getLastSuccessfulStep(pendingSwap.steps);
281
+
282
+ const toToken = {
283
+ blockchain: lastStep.toBlockchain,
284
+ symbol: lastStep.toSymbol,
285
+ address: lastStep.toSymbolAddress,
286
+ };
287
+
288
+ const fromBlockchainMeta = findBlockchain(
289
+ lastSuccessfulStep
290
+ ? lastSuccessfulStep.toBlockchain
291
+ : firstStep.fromBlockchain,
292
+ blockchains
293
+ );
294
+ const toBlockchainMeta = findBlockchain(lastStep.toBlockchain, blockchains);
295
+ const fromTokenMeta = findToken(
296
+ lastSuccessfulStep
297
+ ? {
298
+ blockchain: fromBlockchainMeta?.name ?? '',
299
+ symbol: lastSuccessfulStep.toSymbol,
300
+ address: lastSuccessfulStep.toSymbolAddress,
301
+ }
302
+ : {
303
+ blockchain: fromBlockchainMeta?.name ?? '',
304
+ symbol: firstStep.fromSymbol,
305
+ address: firstStep.fromSymbolAddress,
306
+ },
307
+ tokens
308
+ );
309
+ const toTokenMeta = findToken(toToken, tokens);
310
+ const inputAmount = lastSuccessfulStep
311
+ ? lastSuccessfulStep.outputAmount ?? ''
312
+ : pendingSwap.inputAmount;
313
+
314
+ return {
315
+ fromBlockchain: fromBlockchainMeta,
316
+ fromToken: fromTokenMeta,
317
+ toBlockchain: toBlockchainMeta,
318
+ toToken: toTokenMeta,
319
+ inputAmount,
320
+ };
321
+ }
@@ -33,7 +33,7 @@ export function getUniqueSwappersGroups(
33
33
  let isSupportedSwapper = true;
34
34
  if (supportedSwappers) {
35
35
  isSupportedSwapper = supportedSwappers.some(
36
- (supportedItem) => supportedItem === swapperItem.title
36
+ (supportedItem) => supportedItem === swapperItem.swapperGroup
37
37
  );
38
38
  }
39
39