@rango-dev/widget-embedded 0.23.1-next.3 → 0.23.1-next.31
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/AppRoutes.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/Layout/Layout.styles.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/components/common/ActivateTabAlert/ActivateTabAlert.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/navigationRoutes.d.ts +0 -1
- package/dist/constants/navigationRoutes.d.ts.map +1 -1
- package/dist/constants/searchFor.d.ts +7 -0
- package/dist/constants/searchFor.d.ts.map +1 -0
- package/dist/constants/settings.d.ts +6 -0
- package/dist/constants/settings.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/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 +3 -0
- package/dist/containers/Settings/Lists.d.ts.map +1 -0
- 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/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/AppRoutes.tsx +0 -5
- 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/Layout/Layout.styles.ts +3 -0
- package/src/components/Layout/Layout.tsx +4 -4
- 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 +7 -8
- 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 +3 -11
- 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/components/common/ActivateTabAlert/ActivateTabAlert.tsx +2 -4
- package/src/constants/errors.ts +1 -1
- package/src/constants/index.ts +1 -1
- package/src/constants/languages.ts +27 -1
- package/src/constants/navigationRoutes.ts +0 -1
- package/src/constants/searchFor.ts +6 -0
- package/src/constants/settings.ts +5 -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 +7 -1
- package/src/containers/QuoteInfo/QuoteInfo.tsx +2 -0
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +1 -0
- package/src/containers/Settings/Lists.tsx +280 -0
- 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 +31 -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 +6 -185
- package/src/store/slices/config.ts +2 -2
- package/src/store/slices/data.ts +82 -34
- package/src/store/slices/settings.ts +7 -3
- 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/dist/pages/ThemePage.d.ts +0 -3
- package/dist/pages/ThemePage.d.ts.map +0 -1
- package/src/hooks/useMobileDetect.ts +0 -21
- package/src/pages/ThemePage.tsx +0 -90
package/src/types/config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
|
3
3
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
4
|
import type { Asset } from 'rango-sdk';
|
|
5
5
|
|
|
6
|
-
export type WidgetVariant = 'default' | '
|
|
6
|
+
export type WidgetVariant = 'default' | 'expanded' | 'full-expanded';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The above type defines a set of optional color properties for a widget.
|
|
@@ -171,8 +171,8 @@ export type Features = Partial<
|
|
|
171
171
|
* that defines the various properties of the theme, such as colors, fonts, and others.
|
|
172
172
|
* @property {boolean} externalWallets
|
|
173
173
|
* If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
|
|
174
|
-
* @property {boolean}
|
|
175
|
-
* set it to true,
|
|
174
|
+
* @property {boolean} excludeLiquiditySources - The `excludeLiquiditySources` property is a boolean value that when you
|
|
175
|
+
* set it to true, the list of liquidity sources provided in `liquiditySources` will be excluded; otherwise, they will be included.
|
|
176
176
|
* @property {Features} features - An optional object for configuring the visibility or enablement of various features.
|
|
177
177
|
* Keys include:
|
|
178
178
|
* - 'notification': Visibility state for the notification icon.
|
|
@@ -182,8 +182,11 @@ export type Features = Partial<
|
|
|
182
182
|
* - 'language': Visibility state for the language.
|
|
183
183
|
* - 'experimentalRoute': Enablement state for the experimental route.
|
|
184
184
|
* @property {WidgetVariant} variant
|
|
185
|
-
* If it is
|
|
185
|
+
* If it is expanded, multiple routes will show up on the home page;
|
|
186
|
+
* If it is full-expanded, multiple routes will show up on the home page with full routes;
|
|
186
187
|
* if not, you will need to go to a different page to see the suggested routes.
|
|
188
|
+
* @property {boolean} enableCentralizedSwappers
|
|
189
|
+
* If you want to enable routing from the centralized protocols like XO Swap, you could set this parameter to true.
|
|
187
190
|
*/
|
|
188
191
|
|
|
189
192
|
export type WidgetConfig = {
|
|
@@ -202,7 +205,8 @@ export type WidgetConfig = {
|
|
|
202
205
|
language?: Language;
|
|
203
206
|
theme?: WidgetTheme;
|
|
204
207
|
externalWallets?: boolean;
|
|
205
|
-
|
|
208
|
+
excludeLiquiditySources?: boolean;
|
|
206
209
|
features?: Features;
|
|
207
210
|
variant?: WidgetVariant;
|
|
211
|
+
enableCentralizedSwappers?: boolean;
|
|
208
212
|
};
|
package/src/utils/colors.ts
CHANGED
|
@@ -1,68 +1,113 @@
|
|
|
1
1
|
import type { WidgetColors, WidgetColorsKeys } from '../types';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let [r, g, b]: any = col.match(/.{2}/g);
|
|
13
|
-
[r, g, b] = [
|
|
14
|
-
parseInt(r, RADIX) + amt,
|
|
15
|
-
parseInt(g, RADIX) + amt,
|
|
16
|
-
parseInt(b, RADIX) + amt,
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
r = Math.max(Math.min(RANGE, r), 0).toString(RADIX);
|
|
20
|
-
g = Math.max(Math.min(RANGE, g), 0).toString(RADIX);
|
|
21
|
-
b = Math.max(Math.min(RANGE, b), 0).toString(RADIX);
|
|
22
|
-
|
|
23
|
-
const rr = (r.length < 2 ? '0' : '') + r;
|
|
24
|
-
const gg = (g.length < 2 ? '0' : '') + g;
|
|
25
|
-
const bb = (b.length < 2 ? '0' : '') + b;
|
|
26
|
-
|
|
27
|
-
return `#${rr}${gg}${bb}`;
|
|
28
|
-
};
|
|
3
|
+
export function generateShades(
|
|
4
|
+
baseColor: string,
|
|
5
|
+
prefix: string,
|
|
6
|
+
reverse?: boolean
|
|
7
|
+
): { [key: string]: string } {
|
|
8
|
+
const BASE_SHADE_INDEX = 100;
|
|
9
|
+
const NUMBER_OF_COLORS = 9;
|
|
10
|
+
const SHADING_INCREMENT_MAX = 10; // For bright colors
|
|
11
|
+
const SHADING_INCREMENT_MIN = 6; // For dark colors
|
|
29
12
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(HALF_NUMBER_OF_COLORS - i) * AMT
|
|
44
|
-
),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
if (i === HALF_NUMBER_OF_COLORS) {
|
|
48
|
-
colors = {
|
|
49
|
-
...colors,
|
|
50
|
-
[name + i * COLOR_SUFFIX]: color,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
if (i > HALF_NUMBER_OF_COLORS) {
|
|
54
|
-
colors = {
|
|
55
|
-
...colors,
|
|
56
|
-
[name + i * COLOR_SUFFIX]: colorShade(
|
|
57
|
-
color,
|
|
58
|
-
-((i - HALF_NUMBER_OF_COLORS) * AMT)
|
|
59
|
-
),
|
|
60
|
-
};
|
|
13
|
+
const HALF_NUMBER_OF_COLORS = 4;
|
|
14
|
+
|
|
15
|
+
const shadeIncrements: number[] = [];
|
|
16
|
+
let increment = 90;
|
|
17
|
+
for (let i = 0; i < NUMBER_OF_COLORS; i++) {
|
|
18
|
+
shadeIncrements.push(increment);
|
|
19
|
+
if (i + 1 === HALF_NUMBER_OF_COLORS) {
|
|
20
|
+
increment = 0;
|
|
21
|
+
} else {
|
|
22
|
+
increment -=
|
|
23
|
+
i >= HALF_NUMBER_OF_COLORS
|
|
24
|
+
? SHADING_INCREMENT_MIN
|
|
25
|
+
: SHADING_INCREMENT_MAX;
|
|
61
26
|
}
|
|
62
27
|
}
|
|
63
28
|
|
|
64
|
-
|
|
65
|
-
|
|
29
|
+
// If 'reverse' is true, that means the color should be from dark to light
|
|
30
|
+
const decrementAmounts = reverse
|
|
31
|
+
? shadeIncrements.slice().reverse()
|
|
32
|
+
: shadeIncrements;
|
|
33
|
+
|
|
34
|
+
const shades: { [key: string]: string } = {};
|
|
35
|
+
|
|
36
|
+
// Generate shades
|
|
37
|
+
for (let i = 0; i < NUMBER_OF_COLORS; i++) {
|
|
38
|
+
const shadeIndex = BASE_SHADE_INDEX + i * BASE_SHADE_INDEX;
|
|
39
|
+
const decrementAmount = decrementAmounts[i];
|
|
40
|
+
|
|
41
|
+
const shade: { [key: string]: string } = {
|
|
42
|
+
[`${prefix}${shadeIndex}`]: generateShade(baseColor, decrementAmount),
|
|
43
|
+
};
|
|
44
|
+
Object.assign(shades, shade);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { ...shades, [prefix]: baseColor };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function generateShade(
|
|
51
|
+
baseColor: string,
|
|
52
|
+
decrementAmount: number
|
|
53
|
+
): string {
|
|
54
|
+
const [r, g, b] = convertToRGB(baseColor);
|
|
55
|
+
return `#${clamp(r + decrementAmount)}${clamp(g + decrementAmount)}${clamp(
|
|
56
|
+
b + decrementAmount
|
|
57
|
+
)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function convertToRGB(baseColor: string): number[] {
|
|
61
|
+
const COLOR_SLICE_START = 1;
|
|
62
|
+
const COLOR_SLICE_END = 3;
|
|
63
|
+
const BASE_COLOR_LENGTH = 7;
|
|
64
|
+
|
|
65
|
+
// Convert the base color to RGB components
|
|
66
|
+
const r: number = parseInt(
|
|
67
|
+
baseColor.slice(COLOR_SLICE_START, COLOR_SLICE_END),
|
|
68
|
+
16
|
|
69
|
+
);
|
|
70
|
+
const g: number = parseInt(
|
|
71
|
+
baseColor.slice(COLOR_SLICE_END, COLOR_SLICE_END + 2),
|
|
72
|
+
16
|
|
73
|
+
);
|
|
74
|
+
const b: number = parseInt(
|
|
75
|
+
baseColor.slice(COLOR_SLICE_END + 2, BASE_COLOR_LENGTH),
|
|
76
|
+
16
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return [r, g, b];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Function to clamp color component to valid range [0, 255] and convert to hex
|
|
83
|
+
function clamp(color: number): string {
|
|
84
|
+
const MAX_COLOR_VALUE = 255;
|
|
85
|
+
const HEX_BASE = 16;
|
|
86
|
+
const HEX_LENGTH = -2;
|
|
87
|
+
return (
|
|
88
|
+
'0' + Math.max(0, Math.min(MAX_COLOR_VALUE, color)).toString(HEX_BASE)
|
|
89
|
+
)
|
|
90
|
+
.slice(HEX_LENGTH)
|
|
91
|
+
.toUpperCase();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function isBright(baseColor: string) {
|
|
95
|
+
const BRIGHTNESS_THRESHOLD = 188;
|
|
96
|
+
const RED_COEFFICIENT = 299;
|
|
97
|
+
const GREEN_COEFFICIENT = 587;
|
|
98
|
+
const BLUE_COEFFICIENT = 114;
|
|
99
|
+
const BRIGHTNESS_DIVISOR = 1000;
|
|
100
|
+
|
|
101
|
+
const [r, g, b] = convertToRGB(baseColor);
|
|
102
|
+
const brightness =
|
|
103
|
+
(r * RED_COEFFICIENT + g * GREEN_COEFFICIENT + b * BLUE_COEFFICIENT) /
|
|
104
|
+
BRIGHTNESS_DIVISOR;
|
|
105
|
+
if (brightness > BRIGHTNESS_THRESHOLD) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
66
111
|
export const generateColors = (
|
|
67
112
|
mainColors: { [x: string]: string },
|
|
68
113
|
reverseNeutralRange: boolean,
|
|
@@ -83,25 +128,11 @@ export const generateColors = (
|
|
|
83
128
|
...listOfColors,
|
|
84
129
|
[colorKey]: color,
|
|
85
130
|
};
|
|
86
|
-
} else if (colorKey === 'neutral' && reverseNeutralRange) {
|
|
87
|
-
const range = generateRangeColors(colorKey, color);
|
|
88
|
-
listOfColors = {
|
|
89
|
-
...listOfColors,
|
|
90
|
-
// Reverse the neutral shade
|
|
91
|
-
[`${colorKey}100`]: range[`${colorKey}900`],
|
|
92
|
-
[`${colorKey}200`]: range[`${colorKey}800`],
|
|
93
|
-
[`${colorKey}300`]: range[`${colorKey}700`],
|
|
94
|
-
[`${colorKey}400`]: range[`${colorKey}600`],
|
|
95
|
-
[`${colorKey}500`]: range[`${colorKey}500`],
|
|
96
|
-
[`${colorKey}600`]: range[`${colorKey}400`],
|
|
97
|
-
[`${colorKey}700`]: range[`${colorKey}300`],
|
|
98
|
-
[`${colorKey}800`]: range[`${colorKey}200`],
|
|
99
|
-
[`${colorKey}900`]: range[`${colorKey}100`],
|
|
100
|
-
};
|
|
101
131
|
} else {
|
|
132
|
+
const reverse = colorKey === 'neutral' && reverseNeutralRange;
|
|
102
133
|
listOfColors = {
|
|
103
134
|
...listOfColors,
|
|
104
|
-
...
|
|
135
|
+
...generateShades(color, colorKey, reverse),
|
|
105
136
|
};
|
|
106
137
|
}
|
|
107
138
|
}
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ThemePage.d.ts","sourceRoot":"","sources":["../../src/pages/ThemePage.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B,wBAAgB,SAAS,sBAiExB"}
|
|
@@ -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;
|