@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
@@ -0,0 +1,108 @@
1
+ import type { PrepareListOptions } from './usePrepareBlockchainList.types';
2
+ import type { BlockchainMeta } from 'rango-sdk';
3
+
4
+ import { MOST_USED_BLOCKChAINS } from './usePrepareBlockchainList.constants';
5
+
6
+ export function prepare(
7
+ blockchains: BlockchainMeta[],
8
+ preferredBlockchains: string[],
9
+ options?: PrepareListOptions
10
+ ) {
11
+ /*
12
+ * TODO:
13
+ * We copying the `blockchains` which can causes performance penalties but we should because we are mutating the original object.
14
+ * A better way to solve the problem maybe is using new JS features like Use toSpliced() but
15
+ * we can not use it right now because we need to upgrade our toolings first.
16
+ */
17
+ const list: BlockchainMeta[] = JSON.parse(JSON.stringify(blockchains));
18
+ let more: BlockchainMeta[] = [];
19
+
20
+ list.sort(sortByMostUsedBlockchains);
21
+
22
+ // Checking `limit` has set and it should be more than of the list items.
23
+ if (!!options?.limit && blockchains.length > options.limit) {
24
+ const start = options.limit;
25
+ let preferredBlockchainsWithoutMainList = preferredBlockchains;
26
+
27
+ if (preferredBlockchains.length <= options.limit) {
28
+ /*
29
+ * For first X (limit) numbers, we need to remove them from preferred if exists.
30
+ */
31
+ for (let i = 0; i < options.limit; i++) {
32
+ const blockchain = list[i];
33
+ preferredBlockchainsWithoutMainList =
34
+ preferredBlockchainsWithoutMainList.filter((preferredBlockchain) => {
35
+ return blockchain.name !== preferredBlockchain;
36
+ });
37
+ }
38
+ }
39
+ list.sort(
40
+ generateSortByPreferredBlockchainsFor(preferredBlockchainsWithoutMainList)
41
+ );
42
+
43
+ /*
44
+ * Splice will modify the original list and returns the deleted items
45
+ * We use the deleted items as `more`
46
+ */
47
+ more = list.splice(start);
48
+ }
49
+ return {
50
+ list,
51
+ more,
52
+ };
53
+ }
54
+
55
+ /** There is a hardcoded list of blockchains that we want to show them first in the list. */
56
+ export function sortByMostUsedBlockchains(
57
+ a: BlockchainMeta,
58
+ b: BlockchainMeta
59
+ ) {
60
+ const mostUsed = MOST_USED_BLOCKChAINS;
61
+ const aIndexInMostUsed = mostUsed.findIndex((token) => token === a.name);
62
+ const bIndexInMostUsed = mostUsed.findIndex((token) => token === b.name);
63
+ const aIsMostUsed = aIndexInMostUsed > -1;
64
+ const bIsMostUsed = bIndexInMostUsed > -1;
65
+
66
+ if (aIsMostUsed && bIsMostUsed) {
67
+ return aIndexInMostUsed > bIndexInMostUsed ? 1 : -1;
68
+ }
69
+
70
+ if (aIsMostUsed) {
71
+ return -1;
72
+ }
73
+
74
+ if (bIsMostUsed) {
75
+ return 1;
76
+ }
77
+
78
+ return 0;
79
+ }
80
+
81
+ export function generateSortByPreferredBlockchainsFor(
82
+ preferredBlockchains: string[]
83
+ ) {
84
+ return function sortByPreferred(a: BlockchainMeta, b: BlockchainMeta) {
85
+ const aIndexInPreferred = preferredBlockchains.findIndex(
86
+ (blockchain) => blockchain === a.name
87
+ );
88
+ const bIndexInPreferred = preferredBlockchains.findIndex(
89
+ (blockchain) => blockchain === b.name
90
+ );
91
+
92
+ const aIsPreferred = aIndexInPreferred > -1;
93
+ const bIsPreferred = bIndexInPreferred > -1;
94
+
95
+ if (aIsPreferred && bIsPreferred) {
96
+ return aIndexInPreferred > bIndexInPreferred ? 1 : -1;
97
+ }
98
+
99
+ if (preferredBlockchains.includes(a.name)) {
100
+ return -1;
101
+ }
102
+ if (preferredBlockchains.includes(b.name)) {
103
+ return 1;
104
+ }
105
+
106
+ return 0;
107
+ };
108
+ }