@rango-dev/widget-embedded 0.23.1-next.8 → 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 +8 -7
  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
@@ -1,4 +1,13 @@
1
+ import type { Token } from 'rango-sdk';
2
+
1
3
  import { WIDGET_UI_ID } from '../constants';
4
+ import {
5
+ MIN_LENGTH_SYMBOL_CONTAINS,
6
+ MIN_LENGTH_SYMBOL_START_WITH,
7
+ MIN_LENGTH_TOKEN_ADDRESS_CONTAINS,
8
+ MIN_LENGTH_TOKEN_NAME_CONTAINS,
9
+ MIN_LENGTH_TOKEN_NAME_EXACT_MATCH,
10
+ } from '../constants/searchFor';
2
11
 
3
12
  export function removeDuplicateFrom<T>(array: T[]): T[] {
4
13
  return Array.from(new Set(array));
@@ -32,8 +41,180 @@ export function containsText(text: string, searchText: string): boolean {
32
41
  return text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
33
42
  }
34
43
 
44
+ export function exactText(text: string, searchText: string): boolean {
45
+ return text.toLowerCase() === searchText.toLowerCase();
46
+ }
47
+
48
+ export function startWithText(text: string, searchText: string): boolean {
49
+ return text.toLowerCase().startsWith(searchText.toLowerCase());
50
+ }
51
+
35
52
  export const getContainer = () =>
36
53
  document.getElementById(WIDGET_UI_ID.SWAP_BOX_ID) as HTMLElement;
37
54
 
38
55
  export const getExpanded = () =>
39
56
  document.getElementById(WIDGET_UI_ID.EXPANDED_BOX_ID) as HTMLElement;
57
+
58
+ function compareExactMatchText(
59
+ searchFor: string,
60
+ textA: string | null,
61
+ textB: string | null
62
+ ) {
63
+ const exactMatchA = !!textA && exactText(textA, searchFor);
64
+ const exactMatchB = !!textB && exactText(textB, searchFor);
65
+ if (exactMatchA !== exactMatchB) {
66
+ return exactMatchA ? -1 : 1;
67
+ }
68
+
69
+ return 0;
70
+ }
71
+
72
+ function compareContainsText(
73
+ searchFor: string,
74
+ textA: string | null,
75
+ textB: string | null
76
+ ) {
77
+ const textContainsA = !!textA && containsText(textA, searchFor);
78
+ const textContainsB = !!textB && containsText(textB, searchFor);
79
+ if (textContainsA !== textContainsB) {
80
+ return textContainsA ? -1 : 1;
81
+ }
82
+
83
+ // If both texts contains the searched term, The shorter one has priority
84
+ if (textContainsA && textContainsB && textA?.length !== textB?.length) {
85
+ return textA?.length - textB?.length;
86
+ }
87
+
88
+ return 0;
89
+ }
90
+
91
+ function compareStartWithText(
92
+ searchFor: string,
93
+ textA: string | null,
94
+ textB: string | null
95
+ ) {
96
+ const textStartWithA = !!textA && startWithText(textA, searchFor);
97
+ const textStartWithB = !!textB && startWithText(textB, searchFor);
98
+ if (textStartWithA !== textStartWithB) {
99
+ return textStartWithA ? -1 : 1;
100
+ }
101
+
102
+ // If both texts start with the searched term, The shorter one has priority
103
+ if (textStartWithA && textStartWithB && textA?.length !== textB?.length) {
104
+ return textA?.length - textB?.length;
105
+ }
106
+
107
+ return 0;
108
+ }
109
+
110
+ export function compareWithSearchFor(
111
+ tokenA: Token,
112
+ tokenB: Token,
113
+ searchFor?: string
114
+ ): number {
115
+ if (!searchFor) {
116
+ return 0;
117
+ }
118
+
119
+ // 1: Check the order to exact match the symbol
120
+ const symbolExactMatchCompare = compareExactMatchText(
121
+ searchFor,
122
+ tokenA.symbol,
123
+ tokenB.symbol
124
+ );
125
+ if (symbolExactMatchCompare) {
126
+ return symbolExactMatchCompare;
127
+ }
128
+
129
+ // 2: Check the order to exact match the token name
130
+ if (searchFor.length >= MIN_LENGTH_TOKEN_NAME_EXACT_MATCH) {
131
+ const tokenNameExactMatchCompare = compareExactMatchText(
132
+ searchFor,
133
+ tokenA.name,
134
+ tokenB.name
135
+ );
136
+ if (tokenNameExactMatchCompare) {
137
+ return tokenNameExactMatchCompare;
138
+ }
139
+ }
140
+
141
+ // 3: Check symbol start with searchFor
142
+ if (searchFor.length >= MIN_LENGTH_SYMBOL_START_WITH) {
143
+ const symbolStartWithCompare = compareStartWithText(
144
+ searchFor,
145
+ tokenA.symbol,
146
+ tokenB.symbol
147
+ );
148
+
149
+ if (symbolStartWithCompare) {
150
+ return symbolStartWithCompare;
151
+ }
152
+ }
153
+
154
+ // 4: Check symbol Contains searchFor
155
+ if (searchFor.length >= MIN_LENGTH_SYMBOL_CONTAINS) {
156
+ const symbolContainsCompare = compareContainsText(
157
+ searchFor,
158
+ tokenA.symbol,
159
+ tokenB.symbol
160
+ );
161
+
162
+ if (symbolContainsCompare) {
163
+ return symbolContainsCompare;
164
+ }
165
+ }
166
+
167
+ // 5: Check token name start with searchFor
168
+ if (searchFor.length >= MIN_LENGTH_TOKEN_NAME_CONTAINS) {
169
+ const tokenNameStartWithCompare = compareStartWithText(
170
+ searchFor,
171
+ tokenA.name,
172
+ tokenB.name
173
+ );
174
+
175
+ if (tokenNameStartWithCompare) {
176
+ return tokenNameStartWithCompare;
177
+ }
178
+ }
179
+
180
+ // 6: Check token name Contains searchFor
181
+ if (searchFor.length >= MIN_LENGTH_TOKEN_NAME_CONTAINS) {
182
+ const tokenNameContainsCompare = compareContainsText(
183
+ searchFor,
184
+ tokenA.name,
185
+ tokenB.name
186
+ );
187
+
188
+ if (tokenNameContainsCompare !== 0) {
189
+ return tokenNameContainsCompare;
190
+ }
191
+ }
192
+
193
+ // 7: Check address start with searchFor
194
+ if (searchFor.length >= MIN_LENGTH_TOKEN_ADDRESS_CONTAINS) {
195
+ const addressStartWithCompare = compareStartWithText(
196
+ searchFor,
197
+ tokenA.address,
198
+ tokenB.address
199
+ );
200
+
201
+ if (addressStartWithCompare) {
202
+ return addressStartWithCompare;
203
+ }
204
+ }
205
+
206
+ // 8: Check address Contains searchFor
207
+ if (searchFor.length >= MIN_LENGTH_TOKEN_ADDRESS_CONTAINS) {
208
+ const addressContainCompare = compareContainsText(
209
+ searchFor,
210
+ tokenA.address,
211
+ tokenB.address
212
+ );
213
+
214
+ if (addressContainCompare !== 0) {
215
+ return addressContainCompare;
216
+ }
217
+ }
218
+
219
+ return 0;
220
+ }
@@ -1,4 +1,4 @@
1
- import type { Tokens } from '../types';
1
+ import type { Tokens, WidgetVariant } from '../types';
2
2
  import type { Asset, BlockchainMeta, Token } from 'rango-sdk';
3
3
 
4
4
  import { RANGO_PUBLIC_API_KEY } from '../constants';
@@ -79,3 +79,14 @@ export const isBlockchainExcludedInConfig = (
79
79
  !blockchainsConfig.includes(blockchain.name)
80
80
  );
81
81
  };
82
+
83
+ export const isVariantExpandable = (
84
+ isLargeScreen: boolean,
85
+ isExtraLargeScreen: boolean,
86
+ variant?: WidgetVariant
87
+ ) => {
88
+ return (
89
+ (variant === 'expanded' && (isLargeScreen || isExtraLargeScreen)) ||
90
+ (variant === 'full-expanded' && isExtraLargeScreen)
91
+ );
92
+ };
package/src/utils/meta.ts CHANGED
@@ -31,3 +31,24 @@ export function findToken(t: Asset, tokens: Token[]) {
31
31
  export function findBlockchain(name: string, blockchains: BlockchainMeta[]) {
32
32
  return blockchains.find((blockchain) => blockchain.name === name) ?? null;
33
33
  }
34
+
35
+ export function isTokenNative(
36
+ token: Token,
37
+ blockchain: BlockchainMeta | undefined
38
+ ) {
39
+ if (!blockchain || !token) {
40
+ return false;
41
+ }
42
+
43
+ for (const feeAsset of blockchain.feeAssets) {
44
+ if (
45
+ token?.blockchain === feeAsset?.blockchain &&
46
+ token?.symbol === feeAsset?.symbol &&
47
+ token?.address === feeAsset?.address
48
+ ) {
49
+ return true;
50
+ }
51
+ }
52
+
53
+ return false;
54
+ }
package/src/utils/swap.ts CHANGED
@@ -478,6 +478,7 @@ export function createQuoteRequestBody(params: {
478
478
  affiliatePercent: number | null;
479
479
  affiliateWallets: { [key: string]: string } | null;
480
480
  destination?: string;
481
+ enableCentralizedSwappers?: boolean;
481
482
  }): BestRouteRequest {
482
483
  const {
483
484
  fromToken,
@@ -493,6 +494,7 @@ export function createQuoteRequestBody(params: {
493
494
  affiliatePercent,
494
495
  affiliateWallets,
495
496
  destination,
497
+ enableCentralizedSwappers,
496
498
  } = params;
497
499
  const selectedWalletsMap = selectedWallets?.reduce(
498
500
  (
@@ -544,6 +546,7 @@ export function createQuoteRequestBody(params: {
544
546
  ),
545
547
  swappersGroupsExclude: false,
546
548
  }),
549
+ enableCentralizedSwappers,
547
550
  };
548
551
  return requestBody;
549
552
  }
@@ -747,11 +750,7 @@ export function getLastConvertedTokenInFailedSwap(
747
750
  }
748
751
 
749
752
  export function shouldRetrySwap(pendingSwap: PendingSwap) {
750
- return (
751
- pendingSwap.status === 'failed' &&
752
- !!pendingSwap.finishTime &&
753
- new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000
754
- );
753
+ return pendingSwap.status === 'failed';
755
754
  }
756
755
 
757
756
  export function confirmSwapDisabled(
@@ -775,3 +774,11 @@ export function confirmSwapDisabled(
775
774
  !isValidAddress(lastStepToBlockchain, customDestination))
776
775
  );
777
776
  }
777
+
778
+ export function isTokensIdentical(tokenA: Token, tokenB: Token) {
779
+ return (
780
+ tokenA.blockchain === tokenB.blockchain &&
781
+ tokenA.symbol === tokenB.symbol &&
782
+ tokenA.address === tokenB.address
783
+ );
784
+ }
package/src/utils/ui.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/no-magic-numbers */
2
2
  import type { WidgetTheme } from '../types';
3
3
  import type { createTheme } from '@rango-dev/ui';
4
- import type React from 'react';
5
4
 
6
5
  import {
7
6
  theme as baseThemeTokens,
8
7
  darkColors as defaultDarkColors,
9
8
  } from '@rango-dev/ui';
9
+ import React from 'react';
10
10
 
11
11
  import { generateColors } from '../utils/colors';
12
12
  import { toHash } from '../utils/hash';
@@ -73,18 +73,20 @@ export function customizedThemeTokens(
73
73
  }
74
74
 
75
75
  export function joinList(
76
- list: React.JSX.Element[],
76
+ list: { element: React.JSX.Element; key: string }[],
77
77
  divider: React.JSX.Element
78
78
  ) {
79
79
  if (list.length <= 1) {
80
- return list;
80
+ return list.map(({ element, key }) => React.cloneElement(element, { key }));
81
81
  }
82
82
 
83
83
  const output: React.JSX.Element[] = [];
84
84
  list.forEach((item, index) => {
85
- output.push(item);
85
+ const { element, key } = item;
86
+ output.push(React.cloneElement(element, { key }));
86
87
  if (index < list.length - 1) {
87
- output.push(divider);
88
+ const key = `divider-${index}`;
89
+ output.push(React.cloneElement(divider, { key }));
88
90
  }
89
91
  });
90
92
 
@@ -381,25 +381,18 @@ export function formatBalance(balance: Balance | null): Balance | null {
381
381
  return formattedBalance;
382
382
  }
383
383
 
384
- function sortTokensByBalance(
384
+ export function compareTokenBalance(
385
385
  token1Balance: Balance | null,
386
386
  token2Balance: Balance | null
387
387
  ): number {
388
- if (token1Balance?.usdValue && token2Balance?.usdValue) {
388
+ if (token1Balance?.usdValue || token2Balance?.usdValue) {
389
389
  return (
390
- parseFloat(token2Balance.usdValue) - parseFloat(token1Balance.usdValue)
390
+ parseFloat(token2Balance?.usdValue || '0') -
391
+ parseFloat(token1Balance?.usdValue || '0')
391
392
  );
392
393
  }
393
394
 
394
- if (!token1Balance?.usdValue && token2Balance?.usdValue) {
395
- return 1;
396
- }
397
-
398
- if (token1Balance?.usdValue && !token2Balance?.usdValue) {
399
- return -1;
400
- }
401
-
402
- if (!token1Balance?.usdValue && !token2Balance?.usdValue) {
395
+ if (token1Balance?.amount || token2Balance?.amount) {
403
396
  return (
404
397
  parseFloat(token2Balance?.amount || '0') -
405
398
  parseFloat(token1Balance?.amount || '0')
@@ -409,41 +402,6 @@ function sortTokensByBalance(
409
402
  return 0;
410
403
  }
411
404
 
412
- function sortTokensByPinnedToken(
413
- token1: Token,
414
- token2: Token,
415
- isTokenPinned: (token: Token) => boolean
416
- ): number {
417
- const isToken1Pinned = isTokenPinned(token1);
418
- const isToken2Pinned = isTokenPinned(token2);
419
-
420
- if (isToken1Pinned === isToken2Pinned) {
421
- return 0;
422
- }
423
- if (isToken1Pinned) {
424
- return -1;
425
- }
426
- return 1;
427
- }
428
- export function sortTokens(
429
- tokens: Token[],
430
- getBalanceFor: (token: Token) => Balance | null,
431
- isTokenPinned: (token: Token) => boolean
432
- ) {
433
- tokens.sort((token1, token2) => {
434
- const token1Balance = getBalanceFor(token1);
435
- const token2Balance = getBalanceFor(token2);
436
- // Check pinned tokens
437
- const isTokenPin = sortTokensByPinnedToken(token1, token2, isTokenPinned);
438
-
439
- return isTokenPin !== 0
440
- ? isTokenPin
441
- : sortTokensByBalance(token1Balance, token2Balance);
442
- });
443
-
444
- return tokens;
445
- }
446
-
447
405
  export function areTokensEqual(
448
406
  tokenA: Pick<Token, 'blockchain' | 'symbol' | 'address'> | null,
449
407
  tokenB: Pick<Token, 'blockchain' | 'symbol' | 'address'> | null
@@ -1,3 +0,0 @@
1
- declare const useMobileDetect: () => boolean;
2
- export default useMobileDetect;
3
- //# sourceMappingURL=useMobileDetect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useMobileDetect.d.ts","sourceRoot":"","sources":["../../src/hooks/useMobileDetect.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,eAAe,eAcpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,21 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
-
3
- const MIN_WIDTH_WINDOW = 768;
4
-
5
- const useMobileDetect = () => {
6
- const [isMobile, setIsMobile] = useState(false);
7
-
8
- const handleResize = () => {
9
- setIsMobile(window.innerWidth < MIN_WIDTH_WINDOW);
10
- };
11
-
12
- useEffect(() => {
13
- handleResize(); // Initial check
14
- window.addEventListener('resize', handleResize);
15
- return () => window.removeEventListener('resize', handleResize);
16
- }, []);
17
-
18
- return isMobile;
19
- };
20
-
21
- export default useMobileDetect;