@lifi/widget 1.20.3 → 1.22.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/App.d.ts +2 -2
- package/App.js +5 -3
- package/AppDrawer.d.ts +3 -8
- package/AppDrawer.style.d.ts +1 -1
- package/AppProvider.d.ts +2 -5
- package/AppProvider.js +2 -2
- package/AppRoutes.js +5 -0
- package/cjs/App.d.ts +2 -2
- package/cjs/App.js +5 -4
- package/cjs/AppDrawer.d.ts +3 -8
- package/cjs/AppDrawer.style.d.ts +1 -1
- package/cjs/AppProvider.d.ts +2 -5
- package/cjs/AppProvider.js +1 -1
- package/cjs/AppRoutes.js +5 -0
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +1 -1
- package/cjs/components/BottomSheet/BottomSheet.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.d.ts +0 -1
- package/cjs/components/ChainSelect/ChainSelect.js +1 -3
- package/cjs/components/ChainSelect/useChainSelect.d.ts +1 -1
- package/cjs/components/Header/Header.style.d.ts +34 -1
- package/cjs/components/Header/Header.style.js +19 -1
- package/cjs/components/Header/NavigationHeader.js +4 -1
- package/cjs/components/Header/WalletHeader.js +34 -9
- package/cjs/components/Menu.d.ts +1 -0
- package/cjs/components/Menu.js +24 -0
- package/cjs/components/PoweredBy/PoweredBy.style.d.ts +1 -1
- package/cjs/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
- package/cjs/components/SelectChainAndToken.js +6 -1
- package/cjs/components/SelectTokenButton/SelectTokenButton.js +8 -6
- package/cjs/components/SelectTokenButton/SelectTokenButton.style.js +2 -1
- package/cjs/components/SendToWallet/SendToWallet.js +5 -0
- package/cjs/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/cjs/components/SendToWallet/SendToWalletButton.js +5 -1
- package/cjs/components/Step/CircularProgress.d.ts +0 -1
- package/cjs/components/Step/StepProcess.style.d.ts +2 -2
- package/cjs/components/Step/StepTimer.js +1 -1
- package/cjs/components/StepActions/StepActions.js +6 -1
- package/cjs/components/SwapInput/FormPriceHelperText.js +4 -4
- package/cjs/components/SwapInput/SwapInput.js +5 -2
- package/cjs/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputAdornment.d.ts +0 -1
- package/cjs/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +5 -3
- package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/cjs/components/SwapRouteCard/SwapRouteCardSkeleton.js +3 -1
- package/cjs/components/SwapRoutes/SwapRoutes.js +8 -3
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +0 -1
- package/cjs/components/Token/Token.js +6 -5
- package/cjs/components/TokenAvatar/TokenAvatar.d.ts +6 -1
- package/cjs/components/TokenAvatar/TokenAvatar.js +10 -3
- package/cjs/components/TokenList/TokenList.js +2 -23
- package/cjs/components/TokenList/TokenListItem.d.ts +2 -1
- package/cjs/components/TokenList/TokenListItem.js +12 -6
- package/cjs/components/TokenList/index.d.ts +1 -0
- package/cjs/components/TokenList/index.js +1 -0
- package/cjs/components/TokenList/types.d.ts +6 -0
- package/cjs/components/TokenList/useTokenSelect.d.ts +2 -0
- package/cjs/components/TokenList/useTokenSelect.js +33 -0
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useChain.d.ts +2 -2
- package/cjs/hooks/useChains.d.ts +2 -2
- package/cjs/hooks/useExpandableVariant.js +3 -5
- package/cjs/hooks/useProcessMessage.d.ts +2 -2
- package/cjs/hooks/useSwapRoutes.js +11 -7
- package/cjs/i18n/de.json +199 -0
- package/cjs/i18n/{en/translation.json → en.json} +157 -150
- package/cjs/i18n/es.json +199 -0
- package/cjs/i18n/fr.json +199 -0
- package/cjs/i18n/index.d.ts +8 -199
- package/cjs/i18n/index.js +16 -22
- package/cjs/i18n/it.json +199 -0
- package/cjs/i18n/uk.json +200 -0
- package/cjs/i18n/zh.json +199 -0
- package/cjs/index.d.ts +6 -3
- package/cjs/index.js +3 -2
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +0 -1
- package/cjs/pages/SelectChainPage/SelectChainPage.d.ts +1 -1
- package/cjs/pages/SelectChainPage/SelectChainPage.js +2 -5
- package/cjs/pages/SelectNativeTokenPage/SelectNativeTokenPage.d.ts +3 -0
- package/cjs/pages/SelectNativeTokenPage/SelectNativeTokenPage.js +21 -0
- package/cjs/pages/SelectNativeTokenPage/SelectNativeTokenPage.style.d.ts +21 -0
- package/cjs/pages/SelectNativeTokenPage/SelectNativeTokenPage.style.js +20 -0
- package/cjs/pages/SelectNativeTokenPage/index.d.ts +1 -0
- package/cjs/pages/SelectNativeTokenPage/index.js +17 -0
- package/cjs/pages/SelectTokenPage/SearchTokenInput.d.ts +0 -1
- package/cjs/pages/SelectWalletPage/SelectWalletPage.d.ts +0 -1
- package/cjs/pages/SettingsPage/AdvancedPreferences.d.ts +0 -1
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/cjs/pages/SettingsPage/GasPriceSelect.d.ts +0 -1
- package/cjs/pages/SettingsPage/LanguageSelect.d.ts +2 -0
- package/cjs/pages/SettingsPage/LanguageSelect.js +38 -0
- package/cjs/pages/SettingsPage/SettingsPage.d.ts +0 -1
- package/cjs/pages/SettingsPage/SettingsPage.js +2 -1
- package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -2
- package/cjs/pages/SettingsPage/ShowDestinationWallet.js +6 -0
- package/cjs/pages/SettingsPage/SlippageInput.d.ts +0 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +4 -2
- package/cjs/pages/SwapHistoryPage/SwapHistoryItem.js +4 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.js +3 -3
- package/cjs/pages/SwapPage/TokenValueBottomSheet.js +1 -1
- package/cjs/providers/I18nProvider/I18nProvider.d.ts +2 -0
- package/cjs/providers/I18nProvider/I18nProvider.js +62 -0
- package/cjs/providers/I18nProvider/index.d.ts +2 -0
- package/cjs/providers/I18nProvider/index.js +18 -0
- package/cjs/providers/I18nProvider/types.d.ts +16 -0
- package/cjs/providers/I18nProvider/types.js +2 -0
- package/cjs/providers/WidgetProvider/utils.d.ts +1 -1
- package/cjs/providers/WidgetProvider/utils.js +4 -4
- package/cjs/providers/index.d.ts +1 -0
- package/cjs/providers/index.js +1 -0
- package/cjs/stores/settings/types.d.ts +1 -0
- package/cjs/stores/settings/useSettingsStore.d.ts +2 -0
- package/cjs/types/widget.d.ts +30 -8
- package/cjs/types/widget.js +8 -0
- package/cjs/utils/deepMerge.d.ts +1 -0
- package/cjs/utils/deepMerge.js +18 -0
- package/cjs/utils/index.d.ts +1 -0
- package/cjs/utils/index.js +1 -0
- package/cjs/utils/navigationRoutes.d.ts +8 -7
- package/cjs/utils/navigationRoutes.js +10 -7
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +1 -1
- package/components/BottomSheet/BottomSheet.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.d.ts +0 -1
- package/components/ChainSelect/ChainSelect.js +1 -3
- package/components/ChainSelect/useChainSelect.d.ts +1 -1
- package/components/Header/Header.style.d.ts +34 -1
- package/components/Header/Header.style.js +19 -1
- package/components/Header/NavigationHeader.js +4 -1
- package/components/Header/WalletHeader.js +37 -12
- package/components/Menu.d.ts +1 -0
- package/components/Menu.js +21 -0
- package/components/PoweredBy/PoweredBy.style.d.ts +1 -1
- package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
- package/components/SelectChainAndToken.js +7 -2
- package/components/SelectTokenButton/SelectTokenButton.js +9 -7
- package/components/SelectTokenButton/SelectTokenButton.style.js +2 -1
- package/components/SendToWallet/SendToWallet.js +6 -1
- package/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/components/SendToWallet/SendToWalletButton.js +6 -2
- package/components/Step/CircularProgress.d.ts +0 -1
- package/components/Step/StepProcess.style.d.ts +2 -2
- package/components/Step/StepTimer.js +1 -1
- package/components/StepActions/StepActions.js +6 -1
- package/components/SwapInput/FormPriceHelperText.js +4 -4
- package/components/SwapInput/SwapInput.js +6 -3
- package/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/components/SwapInput/SwapInputAdornment.d.ts +0 -1
- package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
- package/components/SwapRouteCard/SwapRouteCard.js +5 -3
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/components/SwapRouteCard/SwapRouteCardSkeleton.js +3 -1
- package/components/SwapRoutes/SwapRoutes.js +8 -3
- package/components/SwapRoutes/SwapRoutesExpanded.d.ts +0 -1
- package/components/Token/Token.js +7 -6
- package/components/TokenAvatar/TokenAvatar.d.ts +6 -1
- package/components/TokenAvatar/TokenAvatar.js +8 -2
- package/components/TokenList/TokenList.js +4 -25
- package/components/TokenList/TokenListItem.d.ts +2 -1
- package/components/TokenList/TokenListItem.js +10 -5
- package/components/TokenList/index.d.ts +1 -0
- package/components/TokenList/index.js +1 -0
- package/components/TokenList/types.d.ts +6 -0
- package/components/TokenList/useTokenSelect.d.ts +2 -0
- package/components/TokenList/useTokenSelect.js +29 -0
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useChain.d.ts +2 -2
- package/hooks/useChains.d.ts +2 -2
- package/hooks/useExpandableVariant.js +3 -5
- package/hooks/useProcessMessage.d.ts +2 -2
- package/hooks/useSwapRoutes.js +12 -8
- package/i18n/de.json +199 -0
- package/i18n/{en/translation.json → en.json} +157 -150
- package/i18n/es.json +199 -0
- package/i18n/fr.json +199 -0
- package/i18n/index.d.ts +8 -199
- package/i18n/index.js +9 -20
- package/i18n/it.json +199 -0
- package/i18n/uk.json +200 -0
- package/i18n/zh.json +199 -0
- package/index.d.ts +6 -3
- package/index.js +3 -2
- package/package.json +18 -17
- package/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +0 -1
- package/pages/SelectChainPage/SelectChainPage.d.ts +1 -1
- package/pages/SelectChainPage/SelectChainPage.js +2 -5
- package/pages/SelectNativeTokenPage/SelectNativeTokenPage.d.ts +3 -0
- package/pages/SelectNativeTokenPage/SelectNativeTokenPage.js +17 -0
- package/pages/SelectNativeTokenPage/SelectNativeTokenPage.style.d.ts +21 -0
- package/pages/SelectNativeTokenPage/SelectNativeTokenPage.style.js +17 -0
- package/pages/SelectNativeTokenPage/index.d.ts +1 -0
- package/pages/SelectNativeTokenPage/index.js +1 -0
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +0 -1
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +0 -1
- package/pages/SettingsPage/AdvancedPreferences.d.ts +0 -1
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/pages/SettingsPage/GasPriceSelect.d.ts +0 -1
- package/pages/SettingsPage/LanguageSelect.d.ts +2 -0
- package/pages/SettingsPage/LanguageSelect.js +34 -0
- package/pages/SettingsPage/SettingsPage.d.ts +0 -1
- package/pages/SettingsPage/SettingsPage.js +2 -1
- package/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -2
- package/pages/SettingsPage/ShowDestinationWallet.js +6 -0
- package/pages/SettingsPage/SlippageInput.d.ts +0 -1
- package/pages/SwapDetailsPage/SwapDetailsPage.js +4 -2
- package/pages/SwapHistoryPage/SwapHistoryItem.js +4 -2
- package/pages/SwapPage/StatusBottomSheet.js +3 -3
- package/pages/SwapPage/TokenValueBottomSheet.js +1 -1
- package/providers/I18nProvider/I18nProvider.d.ts +2 -0
- package/providers/I18nProvider/I18nProvider.js +58 -0
- package/providers/I18nProvider/index.d.ts +2 -0
- package/providers/I18nProvider/index.js +2 -0
- package/providers/I18nProvider/types.d.ts +16 -0
- package/providers/I18nProvider/types.js +1 -0
- package/providers/WidgetProvider/utils.d.ts +1 -1
- package/providers/WidgetProvider/utils.js +4 -4
- package/providers/index.d.ts +1 -0
- package/providers/index.js +1 -0
- package/stores/settings/types.d.ts +1 -0
- package/stores/settings/useSettingsStore.d.ts +2 -0
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +30 -8
- package/types/widget.js +7 -1
- package/utils/deepMerge.d.ts +1 -0
- package/utils/deepMerge.js +14 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/navigationRoutes.d.ts +8 -7
- package/utils/navigationRoutes.js +10 -7
|
@@ -14,6 +14,7 @@ import { AccessTime as AccessTimeIcon, EvStationOutlined as EvStationIcon, Expan
|
|
|
14
14
|
import { Box, Collapse, Tooltip, Typography } from '@mui/material';
|
|
15
15
|
import { useState } from 'react';
|
|
16
16
|
import { useTranslation } from 'react-i18next';
|
|
17
|
+
import { useWidgetConfig } from '../../providers';
|
|
17
18
|
import { Card } from '../Card';
|
|
18
19
|
import { StepActions } from '../StepActions';
|
|
19
20
|
import { Token } from '../Token';
|
|
@@ -23,6 +24,7 @@ export const SwapRouteCard = (_a) => {
|
|
|
23
24
|
var _b;
|
|
24
25
|
var { route, active, variant = 'default', expanded } = _a, other = __rest(_a, ["route", "active", "variant", "expanded"]);
|
|
25
26
|
const { t } = useTranslation();
|
|
27
|
+
const { variant: widgetVariant, useRecommendedRoute } = useWidgetConfig();
|
|
26
28
|
const [cardExpanded, setCardExpanded] = useState(variant === 'default' || expanded);
|
|
27
29
|
const alternativeTag = t(`swap.tags.ALTERNATIVE`);
|
|
28
30
|
const label = ((_b = route.tags) === null || _b === void 0 ? void 0 : _b.length)
|
|
@@ -32,7 +34,7 @@ export const SwapRouteCard = (_a) => {
|
|
|
32
34
|
e.stopPropagation();
|
|
33
35
|
setCardExpanded((expanded) => !expanded);
|
|
34
36
|
};
|
|
35
|
-
return (_jsxs(Card, Object.assign({ dense: variant === 'dense', variant: active ? 'selected' : 'default', selectionColor: "secondary", indented: true }, other, { children: [_jsxs(Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [_jsx(Label, Object.assign({ active: active !== null && active !== void 0 ? active : label !== alternativeTag }, { children: label })), variant === 'stretched' ? (_jsx(SwapRouteCardEssentials, { route: route })) : null] })), _jsxs(Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [_jsx(Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), step: variant === 'stretched' ? route.steps[0] : undefined }), variant === 'stretched' && !expanded ? (_jsx(IconButton, Object.assign({ onClick: handleExpand, size: "small" }, { children: cardExpanded ? _jsx(ExpandLessIcon, {}) : _jsx(ExpandMoreIcon, {}) }))) : null] })), _jsx(Collapse, Object.assign({ timeout: 225, in: cardExpanded, mountOnEnter: true, unmountOnExit: true }, { children: route.steps.map((step) => (_jsx(StepActions, { step: step, mt: 2 }, step.id))) })), variant !== 'stretched' ? (_jsx(SwapRouteCardEssentials, { route: route, dense: true })) : null] })));
|
|
37
|
+
return (_jsxs(Card, Object.assign({ dense: variant === 'dense', variant: active ? 'selected' : 'default', selectionColor: "secondary", indented: true }, other, { children: [widgetVariant !== 'refuel' && !useRecommendedRoute ? (_jsxs(Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [_jsx(Label, Object.assign({ active: active !== null && active !== void 0 ? active : label !== alternativeTag }, { children: label })), variant === 'stretched' ? (_jsx(SwapRouteCardEssentials, { route: route })) : null] }))) : null, _jsxs(Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [_jsx(Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), step: variant === 'stretched' ? route.steps[0] : undefined }), variant === 'stretched' && !expanded ? (_jsx(IconButton, Object.assign({ onClick: handleExpand, size: "small" }, { children: cardExpanded ? _jsx(ExpandLessIcon, {}) : _jsx(ExpandMoreIcon, {}) }))) : null] })), _jsx(Collapse, Object.assign({ timeout: 225, in: cardExpanded, mountOnEnter: true, unmountOnExit: true }, { children: route.steps.map((step) => (_jsx(StepActions, { step: step, mt: 2 }, step.id))) })), variant !== 'stretched' ? (_jsx(SwapRouteCardEssentials, { route: route, dense: true })) : null] })));
|
|
36
38
|
};
|
|
37
39
|
export const SwapRouteCardEssentials = ({ route, dense }) => {
|
|
38
40
|
var _a;
|
|
@@ -44,8 +46,8 @@ export const SwapRouteCardEssentials = ({ route, dense }) => {
|
|
|
44
46
|
const gasCosts = getGasCostsBreakdown(route);
|
|
45
47
|
return (_jsxs(Box, Object.assign({ display: "flex", justifyContent: dense ? 'space-between' : 'flex-end', flex: 1, pl: dense ? 0 : 2, mt: dense ? 2 : 0 }, { children: [_jsx(Tooltip, Object.assign({ title: _jsxs(Box, Object.assign({ component: "span" }, { children: [t(`tooltip.estimatedNetworkFee`), gasCosts.map((gas) => {
|
|
46
48
|
var _a;
|
|
47
|
-
return (_jsxs(Typography, Object.assign({ fontSize: 11 }, { children: [(_a = gas.amount) === null || _a === void 0 ? void 0 : _a.toFixed(6), " ", gas.token.symbol, " (", t(`
|
|
48
|
-
})] })), placement: "top", enterDelay: 400, arrow: true }, { children: _jsxs(Box, Object.assign({ display: "flex", alignItems: "center", mr: dense ? 0 : 2 }, { children: [_jsx(Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: _jsx(EvStationIcon, { fontSize: dense ? 'medium' : 'small' }) })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t(`
|
|
49
|
+
return (_jsxs(Typography, Object.assign({ fontSize: 11 }, { children: [(_a = gas.amount) === null || _a === void 0 ? void 0 : _a.toFixed(6), " ", gas.token.symbol, " (", t(`format.currency`, { value: gas.amountUSD }), ")"] }), `${gas.token.address}${gas.token.symbol}`));
|
|
50
|
+
})] })), placement: "top", enterDelay: 400, arrow: true }, { children: _jsxs(Box, Object.assign({ display: "flex", alignItems: "center", mr: dense ? 0 : 2 }, { children: [_jsx(Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: _jsx(EvStationIcon, { fontSize: dense ? 'medium' : 'small' }) })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t(`format.currency`, { value: gasCostUSD }) }))] })) })), _jsx(Tooltip, Object.assign({ title: t(`tooltip.estimatedTime`), placement: "top", enterDelay: 400, arrow: true }, { children: _jsxs(Box, Object.assign({ display: "flex", alignItems: "center", mr: dense ? 0 : 2 }, { children: [_jsx(Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: _jsx(AccessTimeIcon, { fontSize: dense ? 'medium' : 'small' }) })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t('swap.estimatedTime', {
|
|
49
51
|
value: executionTimeMinutes,
|
|
50
52
|
}) }))] })) })), !dense ? (_jsx(Tooltip, Object.assign({ title: t(`tooltip.numberOfSteps`), placement: "top", enterDelay: 400, arrow: true }, { children: _jsxs(Box, Object.assign({ display: "flex", alignItems: "center" }, { children: [_jsx(Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: _jsx(LayersIcon, { fontSize: dense ? 'medium' : 'small' }) })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: route.steps.length }))] })) }))) : null] })));
|
|
51
53
|
};
|
|
@@ -17,7 +17,7 @@ export declare const Label: import("@emotion/styled").StyledComponent<import("@m
|
|
|
17
17
|
export declare const IconButton: import("@emotion/styled").StyledComponent<{
|
|
18
18
|
children?: import("react").ReactNode;
|
|
19
19
|
classes?: Partial<import("@mui/material").IconButtonClasses> | undefined;
|
|
20
|
-
color?: "inherit" | "default" | "
|
|
20
|
+
color?: "inherit" | "default" | "error" | "success" | "warning" | "primary" | "secondary" | "info" | undefined;
|
|
21
21
|
disabled?: boolean | undefined;
|
|
22
22
|
disableFocusRipple?: boolean | undefined;
|
|
23
23
|
edge?: false | "end" | "start" | undefined;
|
|
@@ -11,8 +11,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Box, Skeleton } from '@mui/material';
|
|
14
|
+
import { useWidgetConfig } from '../../providers';
|
|
14
15
|
import { Card } from '../Card';
|
|
15
16
|
export const SwapRouteCardSkeleton = (_a) => {
|
|
16
17
|
var { variant } = _a, other = __rest(_a, ["variant"]);
|
|
17
|
-
|
|
18
|
+
const { variant: widgetVariant, useRecommendedRoute } = useWidgetConfig();
|
|
19
|
+
return (_jsxs(Card, Object.assign({ dense: variant === 'dense', indented: true }, other, { children: [widgetVariant !== 'refuel' && !useRecommendedRoute ? (_jsxs(Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [_jsx(Skeleton, { variant: "rectangular", width: 118, height: 24, sx: { borderRadius: 0.5 } }), variant === 'stretched' ? (_jsxs(Box, Object.assign({ display: "flex" }, { children: [_jsx(Skeleton, { variant: "text", width: 52, height: 24, sx: { marginRight: 2 } }), _jsx(Skeleton, { variant: "text", width: 44, height: 24, sx: { marginRight: 2 } }), _jsx(Skeleton, { variant: "text", width: 32, height: 24 })] }))) : null] }))) : null, _jsxs(Box, { children: [_jsxs(Box, Object.assign({ display: "flex", alignItems: "center" }, { children: [_jsx(Box, Object.assign({ mr: 2 }, { children: _jsx(Skeleton, { variant: "circular", width: 32, height: 32 }) })), _jsx(Skeleton, { variant: "text", width: 96, height: 32 })] })), _jsxs(Box, Object.assign({ ml: 6, display: "flex", alignItems: "center" }, { children: [_jsx(Skeleton, { variant: "text", width: 102, height: 16, sx: { borderRadius: 0.5 } }), variant === 'stretched' ? (_jsx(Skeleton, { variant: "text", width: 72, height: 16, sx: { marginLeft: 1 } })) : null] }))] }), variant !== 'stretched' ? (_jsxs(Box, Object.assign({ mt: 2, display: "flex", justifyContent: "space-between" }, { children: [_jsx(Skeleton, { variant: "text", width: 48, height: 24 }), _jsx(Skeleton, { variant: "text", width: 48, height: 24 })] }))) : null] })));
|
|
18
20
|
};
|
|
@@ -8,11 +8,13 @@ import { Card, CardTitle } from '../../components/Card';
|
|
|
8
8
|
import { ProgressToNextUpdate } from '../../components/ProgressToNextUpdate';
|
|
9
9
|
import { SwapRouteCard, SwapRouteCardSkeleton, SwapRouteNotFoundCard, } from '../../components/SwapRouteCard';
|
|
10
10
|
import { useSwapRoutes } from '../../hooks';
|
|
11
|
+
import { useWidgetConfig } from '../../providers';
|
|
11
12
|
import { navigationRoutes } from '../../utils';
|
|
12
13
|
import { Stack } from './SwapRoutes.style';
|
|
13
14
|
import { useSetRecommendedRoute } from './useSetRecommendedRoute';
|
|
14
15
|
export const SwapRoutes = (props) => {
|
|
15
16
|
const { t } = useTranslation();
|
|
17
|
+
const { variant, useRecommendedRoute } = useWidgetConfig();
|
|
16
18
|
const navigate = useNavigate();
|
|
17
19
|
const { isValid, isValidating } = useFormState();
|
|
18
20
|
const { routes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = useSwapRoutes();
|
|
@@ -25,13 +27,16 @@ export const SwapRoutes = (props) => {
|
|
|
25
27
|
navigate(navigationRoutes.swapRoutes);
|
|
26
28
|
};
|
|
27
29
|
const routeNotFound = !currentRoute && !isLoading && !isFetching;
|
|
30
|
+
const onlyRecommendedRoute = variant === 'refuel' || useRecommendedRoute;
|
|
28
31
|
return (_jsxs(Card, Object.assign({}, props, { children: [_jsx(CardTitle, { children: t('swap.routes') }), _jsx(ProgressToNextUpdate, { updatedAt: dataUpdatedAt || new Date().getTime(), timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: {
|
|
29
32
|
position: 'absolute',
|
|
30
33
|
top: 8,
|
|
31
34
|
right: 8,
|
|
32
|
-
} }), _jsxs(Box, Object.assign({ sx: { display: 'flex' } }, { children: [_jsx(Stack, Object.assign({ direction: "row", spacing: 2, my: 2, ml: 2, mr: routeNotFound ? 2 : 1, sx: {
|
|
33
|
-
borderRightWidth: !
|
|
35
|
+
} }), _jsxs(Box, Object.assign({ sx: { display: 'flex' } }, { children: [_jsx(Stack, Object.assign({ direction: "row", spacing: 2, my: 2, ml: 2, mr: onlyRecommendedRoute || routeNotFound ? 2 : 1, sx: {
|
|
36
|
+
borderRightWidth: !onlyRecommendedRoute &&
|
|
37
|
+
!routeNotFound &&
|
|
38
|
+
(isFetching || (routes && routes.length > 1))
|
|
34
39
|
? 1
|
|
35
40
|
: 0,
|
|
36
|
-
} }, { children: isLoading || isFetching ? (_jsxs(_Fragment, { children: [_jsx(SwapRouteCardSkeleton, { minWidth:
|
|
41
|
+
} }, { children: isLoading || isFetching ? (_jsxs(_Fragment, { children: [_jsx(SwapRouteCardSkeleton, { minWidth: !onlyRecommendedRoute ? '80%' : '100%', variant: "dense" }), !onlyRecommendedRoute ? (_jsx(SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" })) : null] })) : !currentRoute ? (_jsx(SwapRouteNotFoundCard, {})) : (_jsxs(_Fragment, { children: [_jsx(SwapRouteCard, { minWidth: !onlyRecommendedRoute && routes.length > 1 ? '80%' : '100%', route: currentRoute, variant: "dense", active: true }), !onlyRecommendedRoute && routes.length > 1 ? (_jsx(SwapRouteCard, { minWidth: "80%", route: routes[1], variant: "dense", pointerEvents: "none" })) : null] })) })), _jsx(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: !onlyRecommendedRoute && !routeNotFound ? (_jsx(Box, Object.assign({ py: 1, pr: 1 }, { children: _jsx(IconButton, Object.assign({ onClick: handleCardClick, size: "medium", disabled: isValidating || !isValid }, { children: _jsx(KeyboardArrowRightIcon, {}) })) }))) : null }))] }))] })));
|
|
37
42
|
};
|
|
@@ -12,22 +12,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
13
|
import { Box, Typography } from '@mui/material';
|
|
14
14
|
import { useTranslation } from 'react-i18next';
|
|
15
|
-
import {
|
|
15
|
+
import { useChain } from '../../hooks';
|
|
16
16
|
import { formatTokenAmount } from '../../utils';
|
|
17
17
|
import { SmallAvatar } from '../SmallAvatar';
|
|
18
18
|
import { TextFitter } from '../TextFitter';
|
|
19
19
|
import { TokenAvatar } from '../TokenAvatar';
|
|
20
20
|
import { TextSecondary, TextSecondaryContainer } from './Token.style';
|
|
21
21
|
export const Token = (_a) => {
|
|
22
|
-
var _b;
|
|
23
22
|
var { token, connected, step } = _a, other = __rest(_a, ["token", "connected", "step"]);
|
|
24
23
|
const { t } = useTranslation();
|
|
25
|
-
const {
|
|
26
|
-
return (_jsxs(Box, Object.assign({ flex: 1 }, other, { children: [_jsxs(Box, Object.assign({ display: "flex", flex: 1, alignItems: "center" }, { children: [_jsx(TokenAvatar, { token: token, sx: { marginRight: 2 } }), _jsx(TextFitter, Object.assign({ height: 30, textStyle: {
|
|
24
|
+
const { chain } = useChain(token.chainId);
|
|
25
|
+
return (_jsxs(Box, Object.assign({ flex: 1 }, other, { children: [_jsxs(Box, Object.assign({ display: "flex", flex: 1, alignItems: "center" }, { children: [_jsx(TokenAvatar, { token: token, chain: chain, sx: { marginRight: 2 } }), _jsx(TextFitter, Object.assign({ height: 30, textStyle: {
|
|
27
26
|
fontWeight: 700,
|
|
28
|
-
} }, { children:
|
|
27
|
+
} }, { children: t('format.number', {
|
|
28
|
+
value: formatTokenAmount(token.amount, token.decimals),
|
|
29
|
+
}) }))] })), _jsxs(TextSecondaryContainer, Object.assign({ connected: connected, component: "span" }, { children: [_jsx(TextSecondary, Object.assign({ connected: connected }, { children: t(`swap.tokenOnChain`, {
|
|
29
30
|
tokenSymbol: token.symbol,
|
|
30
|
-
chainName:
|
|
31
|
+
chainName: chain === null || chain === void 0 ? void 0 : chain.name,
|
|
31
32
|
}) })), step ? (_jsxs(_Fragment, { children: [_jsx(Typography, Object.assign({ fontSize: 12, lineHeight: 1, fontWeight: 500, color: "text.secondary", px: 1, mt: 0.5 }, { children: "\u2022" })), _jsxs(Box, Object.assign({ display: "flex", alignItems: "flex-end", height: 12, mt: 0.5 }, { children: [_jsx(Box, Object.assign({ pr: 0.75 }, { children: _jsx(SmallAvatar, Object.assign({ src: step.toolDetails.logoURI, alt: step.toolDetails.name, sx: {
|
|
32
33
|
border: 0,
|
|
33
34
|
marginBottom: -0.25,
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { Token } from '@lifi/sdk';
|
|
2
|
+
import type { Chain, Token } from '@lifi/sdk';
|
|
3
3
|
import type { SxProps, Theme } from '@mui/material';
|
|
4
|
+
export declare const TokenAvatarFallback: React.FC<{
|
|
5
|
+
token: Token;
|
|
6
|
+
sx?: SxProps<Theme>;
|
|
7
|
+
}>;
|
|
4
8
|
export declare const TokenAvatar: React.FC<{
|
|
5
9
|
token: Token;
|
|
10
|
+
chain?: Chain;
|
|
6
11
|
sx?: SxProps<Theme>;
|
|
7
12
|
}>;
|
|
@@ -2,8 +2,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Avatar, Badge } from '@mui/material';
|
|
3
3
|
import { useChain, useToken } from '../../hooks';
|
|
4
4
|
import { SmallAvatar } from '../SmallAvatar';
|
|
5
|
-
export const
|
|
5
|
+
export const TokenAvatarFallback = ({ token, sx }) => {
|
|
6
6
|
const { chain } = useChain(token.chainId);
|
|
7
7
|
const { token: chainToken } = useToken(token.chainId, token.address);
|
|
8
|
-
return
|
|
8
|
+
return _jsx(TokenAvatar, { token: chainToken !== null && chainToken !== void 0 ? chainToken : token, chain: chain, sx: sx });
|
|
9
|
+
};
|
|
10
|
+
export const TokenAvatar = ({ token, chain, sx }) => {
|
|
11
|
+
if (!chain || !token.logoURI) {
|
|
12
|
+
return _jsx(TokenAvatarFallback, { token: token, sx: sx });
|
|
13
|
+
}
|
|
14
|
+
return (_jsx(Badge, Object.assign({ overlap: "circular", anchorOrigin: { vertical: 'bottom', horizontal: 'right' }, badgeContent: chain ? (_jsx(SmallAvatar, Object.assign({ src: chain.logoURI, alt: chain.name }, { children: chain.name[0] }))) : null, sx: sx }, { children: _jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol }, { children: token.symbol[0] })) })));
|
|
9
15
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box } from '@mui/material';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
import { useWatch } from 'react-hook-form';
|
|
5
5
|
import { useDebouncedWatch, useTokenBalances, useTokenSearch, } from '../../hooks';
|
|
6
6
|
import { SwapFormKey, SwapFormKeyHelper, useWallet } from '../../providers';
|
|
7
7
|
import { TokenNotFound } from './TokenNotFound';
|
|
8
|
+
import { useTokenSelect } from './useTokenSelect';
|
|
8
9
|
import { VirtualizedTokenList } from './VirtualizedTokenList';
|
|
9
10
|
export const TokenList = ({ formType, height, onClick, }) => {
|
|
10
11
|
var _a, _b;
|
|
11
12
|
const parentRef = useRef(null);
|
|
12
13
|
const { account } = useWallet();
|
|
13
|
-
const { setValue, getValues } = useFormContext();
|
|
14
14
|
const [selectedChainId] = useWatch({
|
|
15
15
|
name: [SwapFormKeyHelper.getChainKey(formType)],
|
|
16
16
|
});
|
|
@@ -34,27 +34,6 @@ export const TokenList = ({ formType, height, onClick, }) => {
|
|
|
34
34
|
: searchedToken
|
|
35
35
|
? [searchedToken]
|
|
36
36
|
: filteredTokens;
|
|
37
|
-
const handleTokenClick =
|
|
38
|
-
setValue(SwapFormKeyHelper.getTokenKey(formType), tokenAddress, {
|
|
39
|
-
shouldTouch: true,
|
|
40
|
-
});
|
|
41
|
-
// Set chain again to trigger URL builder update
|
|
42
|
-
setValue(SwapFormKeyHelper.getChainKey(formType), selectedChainId, {
|
|
43
|
-
shouldTouch: true,
|
|
44
|
-
});
|
|
45
|
-
setValue(SwapFormKeyHelper.getAmountKey(formType), '');
|
|
46
|
-
const oppositeFormType = formType === 'from' ? 'to' : 'from';
|
|
47
|
-
const [selectedOppositeToken, selectedOppositeChainId] = getValues([
|
|
48
|
-
SwapFormKeyHelper.getTokenKey(oppositeFormType),
|
|
49
|
-
SwapFormKeyHelper.getChainKey(oppositeFormType),
|
|
50
|
-
]);
|
|
51
|
-
if (selectedOppositeToken === tokenAddress &&
|
|
52
|
-
selectedOppositeChainId === selectedChainId) {
|
|
53
|
-
setValue(SwapFormKeyHelper.getTokenKey(oppositeFormType), '', {
|
|
54
|
-
shouldTouch: true,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
58
|
-
}, [formType, getValues, onClick, selectedChainId, setValue]);
|
|
37
|
+
const handleTokenClick = useTokenSelect(formType, onClick);
|
|
59
38
|
return (_jsxs(Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!tokens.length && !isLoading ? (_jsx(TokenNotFound, { formType: formType })) : null, _jsx(VirtualizedTokenList, { tokens: tokens, featuredTokensLength: featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length, scrollElementRef: parentRef, chainId: selectedChainId, isLoading: isLoading, isBalanceLoading: isBalanceLoading, showBalance: account.isActive, showFeatured: !tokenSearchFilter, onClick: handleTokenClick })] })));
|
|
60
39
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { TokenListItemProps } from './types';
|
|
2
|
+
import type { TokenListItemButtonProps, TokenListItemProps } from './types';
|
|
3
3
|
export declare const TokenListItem: React.FC<TokenListItemProps>;
|
|
4
|
+
export declare const TokenListItemButton: React.FC<TokenListItemButtonProps>;
|
|
4
5
|
export declare const TokenListItemSkeleton: () => JSX.Element;
|
|
5
6
|
export declare const TokenAmountSkeleton: React.FC;
|
|
@@ -5,16 +5,21 @@ import { useTranslation } from 'react-i18next';
|
|
|
5
5
|
import { formatTokenPrice } from '../../utils';
|
|
6
6
|
import { ListItem, ListItemButton } from './TokenList.style';
|
|
7
7
|
export const TokenListItem = memo(({ onClick, size, start, token, showBalance, isBalanceLoading, startAdornment, endAdornment, }) => {
|
|
8
|
-
const { t } = useTranslation();
|
|
9
8
|
const handleClick = () => onClick === null || onClick === void 0 ? void 0 : onClick(token.address);
|
|
10
|
-
const tokenPrice = formatTokenPrice(token.amount, token.priceUSD);
|
|
11
9
|
return (_jsxs(ListItem, Object.assign({ disablePadding: true, style: {
|
|
12
10
|
height: `${size}px`,
|
|
13
11
|
transform: `translateY(${start}px)`,
|
|
14
|
-
} }, { children: [startAdornment,
|
|
15
|
-
value: tokenPrice,
|
|
16
|
-
}) }))) : null] })))) : null] })), endAdornment] })));
|
|
12
|
+
} }, { children: [startAdornment, _jsx(TokenListItemButton, { token: token, showBalance: showBalance, isBalanceLoading: isBalanceLoading, onClick: handleClick }), endAdornment] })));
|
|
17
13
|
});
|
|
14
|
+
export const TokenListItemButton = ({ onClick, token, showBalance, isBalanceLoading, }) => {
|
|
15
|
+
const { t } = useTranslation();
|
|
16
|
+
const tokenPrice = formatTokenPrice(token.amount, token.priceUSD);
|
|
17
|
+
return (_jsxs(ListItemButton, Object.assign({ onClick: onClick, dense: true, disableRipple: true }, { children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol }, { children: token.symbol[0] })) }), _jsx(ListItemText, { primary: token.symbol, secondary: token.name }), showBalance ? (isBalanceLoading ? (_jsx(TokenAmountSkeleton, {})) : (_jsxs(Box, Object.assign({ sx: { textAlign: 'right' } }, { children: [Number(token.amount) ? (_jsx(Typography, Object.assign({ variant: "body1", noWrap: true }, { children: t('format.number', {
|
|
18
|
+
value: token.amount,
|
|
19
|
+
}) }))) : null, tokenPrice ? (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: 12, color: "text.secondary", "data-price": token.priceUSD }, { children: t(`format.currency`, {
|
|
20
|
+
value: tokenPrice,
|
|
21
|
+
}) }))) : null] })))) : null] })));
|
|
22
|
+
};
|
|
18
23
|
export const TokenListItemSkeleton = () => {
|
|
19
24
|
return (_jsxs(ListItem, Object.assign({ secondaryAction: _jsx(TokenAmountSkeleton, {}), disablePadding: true, sx: { position: 'relative', flexDirection: 'row', alignItems: 'center' } }, { children: [_jsx(ListItemAvatar, { children: _jsx(Skeleton, { variant: "circular", width: 32, height: 32, sx: { marginLeft: 1.5, marginRight: 2 } }) }), _jsx(ListItemText, { primary: _jsx(Skeleton, { variant: "text", width: 48, height: 20 }), secondary: _jsx(Skeleton, { variant: "text", width: 96, height: 20 }) })] })));
|
|
20
25
|
};
|
|
@@ -30,3 +30,9 @@ export interface TokenListItemProps extends TokenListItemBaseProps {
|
|
|
30
30
|
startAdornment?: React.ReactNode;
|
|
31
31
|
endAdornment?: React.ReactNode;
|
|
32
32
|
}
|
|
33
|
+
export interface TokenListItemButtonProps {
|
|
34
|
+
onClick?(): void;
|
|
35
|
+
showBalance?: boolean;
|
|
36
|
+
token: TokenAmount;
|
|
37
|
+
isBalanceLoading?: boolean;
|
|
38
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useFormContext } from 'react-hook-form';
|
|
3
|
+
import { SwapFormKeyHelper } from '../../providers';
|
|
4
|
+
export const useTokenSelect = (formType, onClick) => {
|
|
5
|
+
const { setValue, getValues } = useFormContext();
|
|
6
|
+
return useCallback((tokenAddress, chainId) => {
|
|
7
|
+
const selectedChainId = chainId !== null && chainId !== void 0 ? chainId : getValues(SwapFormKeyHelper.getChainKey(formType));
|
|
8
|
+
setValue(SwapFormKeyHelper.getTokenKey(formType), tokenAddress, {
|
|
9
|
+
shouldTouch: true,
|
|
10
|
+
});
|
|
11
|
+
// Set chain again to trigger URL builder update
|
|
12
|
+
setValue(SwapFormKeyHelper.getChainKey(formType), selectedChainId, {
|
|
13
|
+
shouldTouch: true,
|
|
14
|
+
});
|
|
15
|
+
setValue(SwapFormKeyHelper.getAmountKey(formType), '');
|
|
16
|
+
const oppositeFormType = formType === 'from' ? 'to' : 'from';
|
|
17
|
+
const [selectedOppositeToken, selectedOppositeChainId] = getValues([
|
|
18
|
+
SwapFormKeyHelper.getTokenKey(oppositeFormType),
|
|
19
|
+
SwapFormKeyHelper.getChainKey(oppositeFormType),
|
|
20
|
+
]);
|
|
21
|
+
if (selectedOppositeToken === tokenAddress &&
|
|
22
|
+
selectedOppositeChainId === selectedChainId) {
|
|
23
|
+
setValue(SwapFormKeyHelper.getTokenKey(oppositeFormType), '', {
|
|
24
|
+
shouldTouch: true,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
28
|
+
}, [formType, getValues, onClick, setValue]);
|
|
29
|
+
};
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "1.
|
|
2
|
+
export declare const version = "1.22.0";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.22.0';
|
package/hooks/useChain.d.ts
CHANGED
package/hooks/useChains.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const useChains: () => {
|
|
2
|
-
chains: import("@lifi/types").
|
|
3
|
-
getChainById: (chainId: number) => import("@lifi/types").
|
|
2
|
+
chains: import("@lifi/types").ExtendedChain[] | undefined;
|
|
3
|
+
getChainById: (chainId: number) => import("@lifi/types").ExtendedChain | undefined;
|
|
4
4
|
isLoading: boolean;
|
|
5
5
|
};
|
|
@@ -2,9 +2,7 @@ import { useMediaQuery } from '@mui/material';
|
|
|
2
2
|
import { useWidgetConfig } from '../providers';
|
|
3
3
|
const defaultExpandableWidth = 852;
|
|
4
4
|
export const useExpandableVariant = () => {
|
|
5
|
-
const { variant } = useWidgetConfig();
|
|
6
|
-
const expandableAllowed = useMediaQuery((theme) =>
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
return variant === 'expandable' && expandableAllowed;
|
|
5
|
+
const { variant, useRecommendedRoute } = useWidgetConfig();
|
|
6
|
+
const expandableAllowed = useMediaQuery((theme) => theme.breakpoints.up(defaultExpandableWidth));
|
|
7
|
+
return variant === 'expandable' && expandableAllowed && !useRecommendedRoute;
|
|
10
8
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { EVMChain, Process, Step } from '@lifi/sdk';
|
|
2
|
-
import type { TFunction } from '
|
|
2
|
+
import type { TFunction } from 'i18next';
|
|
3
3
|
export declare const useProcessMessage: (step?: Step, process?: Process) => {
|
|
4
4
|
title?: string | undefined;
|
|
5
5
|
message?: string | undefined;
|
|
6
6
|
};
|
|
7
|
-
export declare function getProcessMessage(t: TFunction
|
|
7
|
+
export declare function getProcessMessage(t: TFunction, getChainById: (chainId: number) => EVMChain | undefined, step: Step, process: Process): {
|
|
8
8
|
title?: string;
|
|
9
9
|
message?: string;
|
|
10
10
|
};
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -12,12 +12,13 @@ import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
|
12
12
|
import Big from 'big.js';
|
|
13
13
|
import { useWatch } from 'react-hook-form';
|
|
14
14
|
import { useDebouncedWatch, useToken } from '.';
|
|
15
|
-
import { SwapFormKey, useLiFi, useWallet } from '../providers';
|
|
15
|
+
import { SwapFormKey, useLiFi, useWallet, useWidgetConfig } from '../providers';
|
|
16
16
|
import { useSettings } from '../stores';
|
|
17
17
|
const refetchTime = 60000;
|
|
18
18
|
export const useSwapRoutes = () => {
|
|
19
19
|
var _a;
|
|
20
20
|
const lifi = useLiFi();
|
|
21
|
+
const { variant } = useWidgetConfig();
|
|
21
22
|
const { account, provider } = useWallet();
|
|
22
23
|
const queryClient = useQueryClient();
|
|
23
24
|
const { slippage, enabledBridges, enabledExchanges, routePriority } = useSettings([
|
|
@@ -36,13 +37,14 @@ export const useSwapRoutes = () => {
|
|
|
36
37
|
],
|
|
37
38
|
});
|
|
38
39
|
const [fromTokenAmount] = useDebouncedWatch([SwapFormKey.FromAmount], 320);
|
|
39
|
-
const { token } = useToken(fromChainId, fromTokenAddress);
|
|
40
|
+
const { token: fromToken } = useToken(fromChainId, fromTokenAddress);
|
|
41
|
+
const { token: toToken } = useToken(toChainId, toTokenAddress);
|
|
40
42
|
const isEnabled =
|
|
41
43
|
// Boolean(account.address) &&
|
|
42
44
|
!isNaN(fromChainId) &&
|
|
43
45
|
!isNaN(toChainId) &&
|
|
44
|
-
Boolean(
|
|
45
|
-
Boolean(
|
|
46
|
+
Boolean(fromToken === null || fromToken === void 0 ? void 0 : fromToken.address) &&
|
|
47
|
+
Boolean(toToken === null || toToken === void 0 ? void 0 : toToken.address) &&
|
|
46
48
|
!isNaN(fromTokenAmount) &&
|
|
47
49
|
Number(fromTokenAmount) > 0 &&
|
|
48
50
|
!Number.isNaN(slippage);
|
|
@@ -50,21 +52,22 @@ export const useSwapRoutes = () => {
|
|
|
50
52
|
'routes',
|
|
51
53
|
account.address,
|
|
52
54
|
fromChainId,
|
|
53
|
-
|
|
55
|
+
fromToken === null || fromToken === void 0 ? void 0 : fromToken.address,
|
|
54
56
|
fromTokenAmount,
|
|
55
57
|
toChainId,
|
|
56
|
-
|
|
58
|
+
toToken === null || toToken === void 0 ? void 0 : toToken.address,
|
|
57
59
|
toAddress,
|
|
58
60
|
slippage,
|
|
59
61
|
enabledBridges,
|
|
60
62
|
enabledExchanges,
|
|
61
63
|
routePriority,
|
|
64
|
+
variant,
|
|
62
65
|
];
|
|
63
66
|
const previousDataUpdatedAt = (_a = queryClient.getQueryState(queryKey)) === null || _a === void 0 ? void 0 : _a.dataUpdatedAt;
|
|
64
67
|
const refetchInterval = previousDataUpdatedAt
|
|
65
68
|
? Math.min(Math.abs(refetchTime - (Date.now() - previousDataUpdatedAt)), refetchTime)
|
|
66
69
|
: refetchTime;
|
|
67
|
-
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toChainId, toTokenAddress, toAddress, slippage, enabledBridges, enabledExchanges, routePriority,], signal, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toChainId, toTokenAddress, toAddress, slippage, enabledBridges, enabledExchanges, routePriority, variant,], signal, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
71
|
var _b, _c;
|
|
69
72
|
let toWalletAddress;
|
|
70
73
|
try {
|
|
@@ -74,7 +77,7 @@ export const useSwapRoutes = () => {
|
|
|
74
77
|
catch (_d) {
|
|
75
78
|
toWalletAddress = isAddress(toAddress) ? toAddress : fromAddress;
|
|
76
79
|
}
|
|
77
|
-
const fromAmount = Big(Number(fromTokenAmount) * Math.pow(10, ((_c =
|
|
80
|
+
const fromAmount = Big(Number(fromTokenAmount) * Math.pow(10, ((_c = fromToken === null || fromToken === void 0 ? void 0 : fromToken.decimals) !== null && _c !== void 0 ? _c : 0))).toString();
|
|
78
81
|
const formattedSlippage = parseFloat(slippage) / 100;
|
|
79
82
|
return lifi.getRoutes({
|
|
80
83
|
fromChainId,
|
|
@@ -93,6 +96,7 @@ export const useSwapRoutes = () => {
|
|
|
93
96
|
allow: enabledExchanges,
|
|
94
97
|
},
|
|
95
98
|
order: routePriority,
|
|
99
|
+
allowSwitchChain: variant !== 'refuel',
|
|
96
100
|
},
|
|
97
101
|
}, { signal });
|
|
98
102
|
}), {
|