@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.
- package/dist/components/AppRouter.d.ts +1 -6
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -283
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +489 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/InProgressTransactionBadge.d.ts +4 -0
- package/dist/components/HeaderButtons/InProgressTransactionBadge.d.ts.map +1 -0
- package/dist/components/HeaderButtons/RefreshButton.d.ts.map +1 -1
- package/dist/components/HeaderButtons/UnreadNotificationsBadge.d.ts.map +1 -1
- package/dist/components/HeaderButtons/WalletButton.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.helpers.d.ts +8 -0
- package/dist/components/NoResult/NoResult.helpers.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.styles.d.ts +167 -1
- package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.types.d.ts +1 -0
- package/dist/components/NoResult/NoResult.types.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +165 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.types.d.ts +1 -0
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteTrigger.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +1 -0
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +3 -1
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.types.d.ts +1 -0
- package/dist/components/Quotes/Quotes.types.d.ts.map +1 -1
- package/dist/components/Quotes/SelectStrategy.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/languages.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +1 -5
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/constants/searchFor.d.ts +7 -0
- package/dist/constants/searchFor.d.ts.map +1 -0
- package/dist/containers/App/App.d.ts.map +1 -1
- package/dist/containers/App/App.styles.d.ts.map +1 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.d.ts.map +1 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts +3 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.types.d.ts +1 -0
- package/dist/containers/Inputs/Inputs.types.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
- package/dist/containers/Settings/Lists.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.types.d.ts +13 -2
- package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
- package/dist/containers/Widget/Widget.d.ts.map +1 -1
- package/dist/hooks/useBootstrap/index.d.ts +2 -0
- package/dist/hooks/useBootstrap/index.d.ts.map +1 -0
- package/dist/hooks/useBootstrap/useBootstrap.d.ts +2 -0
- package/dist/hooks/useBootstrap/useBootstrap.d.ts.map +1 -0
- package/dist/hooks/useScreenDetect.d.ts +9 -0
- package/dist/hooks/useScreenDetect.d.ts.map +1 -0
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LanguagePage.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/store/AppStore.d.ts +2 -2
- package/dist/store/app.d.ts +2 -2
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts +3 -1
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/slices/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +9 -5
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/colors.d.ts +5 -3
- package/dist/utils/colors.d.ts.map +1 -1
- package/dist/utils/common.d.ts +4 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +2 -1
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/meta.d.ts +1 -0
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +2 -0
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/ui.d.ts +5 -2
- package/dist/utils/ui.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/components/AppRouter.tsx +1 -29
- package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +6 -12
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +7 -11
- package/src/components/ConfirmWalletsModal/WalletList.tsx +2 -2
- package/src/components/HeaderButtons/HeaderButtons.styles.ts +43 -2
- package/src/components/HeaderButtons/HeaderButtons.tsx +2 -0
- package/src/components/HeaderButtons/InProgressTransactionBadge.tsx +26 -0
- package/src/components/HeaderButtons/RefreshButton.tsx +2 -1
- package/src/components/HeaderButtons/UnreadNotificationsBadge.tsx +10 -2
- package/src/components/HeaderButtons/WalletButton.tsx +26 -6
- package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.ts +1 -1
- package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.tsx +4 -4
- package/src/components/NoResult/NoResult.helpers.ts +13 -0
- package/src/components/NoResult/NoResult.styles.ts +19 -1
- package/src/components/NoResult/NoResult.tsx +27 -16
- package/src/components/NoResult/NoResult.types.ts +1 -0
- package/src/components/NotificationContent/NotificationContent.styles.ts +14 -1
- package/src/components/NotificationContent/NotificationContent.tsx +49 -39
- package/src/components/Quote/Quote.styles.ts +13 -14
- package/src/components/Quote/Quote.tsx +166 -145
- package/src/components/Quote/Quote.types.ts +1 -0
- package/src/components/Quote/QuoteTrigger.tsx +19 -14
- package/src/components/QuoteSkeleton/QuoteSkeleton.styles.ts +10 -2
- package/src/components/QuoteSkeleton/QuoteSkeleton.tsx +2 -2
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.styles.ts +2 -2
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.tsx +5 -4
- package/src/components/QuoteSkeleton/StepSkeleton.styles.ts +7 -0
- package/src/components/QuoteSkeleton/StepSkeleton.tsx +1 -1
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +1 -1
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +3 -3
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts +1 -1
- package/src/components/Quotes/Quotes.tsx +33 -21
- package/src/components/Quotes/Quotes.types.ts +1 -0
- package/src/components/Quotes/SelectStrategy.tsx +27 -10
- package/src/components/Slippage/Slippage.tsx +11 -13
- package/src/components/SwapDetails/SwapDetails.tsx +3 -1
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +5 -1
- package/src/components/TokenList/TokenList.tsx +9 -8
- package/src/constants/errors.ts +1 -1
- package/src/constants/index.ts +1 -1
- package/src/constants/languages.ts +27 -1
- package/src/constants/quote.ts +1 -24
- package/src/constants/searchFor.ts +6 -0
- package/src/containers/App/App.styles.ts +0 -4
- package/src/containers/App/App.tsx +4 -28
- package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +13 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +5 -0
- package/src/containers/Inputs/Inputs.tsx +2 -3
- package/src/containers/Inputs/Inputs.types.ts +1 -0
- package/src/containers/QuoteInfo/QuoteInfo.tsx +2 -0
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +1 -0
- package/src/containers/Settings/Lists.tsx +28 -13
- package/src/containers/Wallets/Wallets.tsx +27 -10
- package/src/containers/Wallets/Wallets.types.ts +13 -2
- package/src/containers/Widget/Widget.tsx +13 -13
- package/src/hooks/useBootstrap/index.ts +1 -0
- package/src/hooks/useBootstrap/useBootstrap.ts +72 -0
- package/src/hooks/useScreenDetect.ts +49 -0
- package/src/hooks/useSwapInput.ts +7 -2
- package/src/hooks/useTheme.ts +1 -8
- package/src/hooks/useWalletList.ts +12 -0
- package/src/pages/ConfirmSwapPage.tsx +14 -5
- package/src/pages/Home.tsx +29 -7
- package/src/pages/LanguagePage.tsx +14 -1
- package/src/pages/LiquiditySourcePage.tsx +4 -3
- package/src/pages/SelectSwapItemsPage.tsx +2 -7
- package/src/pages/SettingsPage.tsx +0 -1
- package/src/store/slices/config.ts +3 -2
- package/src/store/slices/data.ts +82 -34
- package/src/store/slices/settings.ts +10 -4
- package/src/types/config.ts +9 -5
- package/src/utils/colors.ts +106 -75
- package/src/utils/common.ts +181 -0
- package/src/utils/configs.ts +12 -1
- package/src/utils/meta.ts +21 -0
- package/src/utils/swap.ts +12 -5
- package/src/utils/ui.ts +7 -5
- package/src/utils/wallets.ts +5 -47
- package/dist/hooks/useMobileDetect.d.ts +0 -3
- package/dist/hooks/useMobileDetect.d.ts.map +0 -1
- package/src/hooks/useMobileDetect.ts +0 -21
package/src/utils/common.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/utils/configs.ts
CHANGED
|
@@ -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
|
-
|
|
85
|
+
const { element, key } = item;
|
|
86
|
+
output.push(React.cloneElement(element, { key }));
|
|
86
87
|
if (index < list.length - 1) {
|
|
87
|
-
|
|
88
|
+
const key = `divider-${index}`;
|
|
89
|
+
output.push(React.cloneElement(divider, { key }));
|
|
88
90
|
}
|
|
89
91
|
});
|
|
90
92
|
|
package/src/utils/wallets.ts
CHANGED
|
@@ -381,25 +381,18 @@ export function formatBalance(balance: Balance | null): Balance | null {
|
|
|
381
381
|
return formattedBalance;
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
function
|
|
384
|
+
export function compareTokenBalance(
|
|
385
385
|
token1Balance: Balance | null,
|
|
386
386
|
token2Balance: Balance | null
|
|
387
387
|
): number {
|
|
388
|
-
if (token1Balance?.usdValue
|
|
388
|
+
if (token1Balance?.usdValue || token2Balance?.usdValue) {
|
|
389
389
|
return (
|
|
390
|
-
parseFloat(token2Balance
|
|
390
|
+
parseFloat(token2Balance?.usdValue || '0') -
|
|
391
|
+
parseFloat(token1Balance?.usdValue || '0')
|
|
391
392
|
);
|
|
392
393
|
}
|
|
393
394
|
|
|
394
|
-
if (
|
|
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 +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;
|