@lifi/widget 1.10.0 → 1.10.3
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/AppDrawer.js +8 -1
- package/AppDrawer.style.d.ts +4 -0
- package/AppDrawer.style.js +20 -3
- package/components/StepActions/StepActions.js +5 -2
- package/components/SwapRouteCard/SwapRouteCard.js +2 -2
- package/config/sentry.js +1 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useHasSufficientBalance.js +4 -4
- package/hooks/useSwapRoutes.js +5 -4
- package/hooks/useTelemetry.js +8 -2
- package/i18n/en/translation.json +1 -1
- package/index.js +0 -2
- package/package.json +1 -1
- package/pages/SwapPage/SwapPage.js +1 -1
package/AppDrawer.js
CHANGED
|
@@ -7,6 +7,7 @@ import { AppDefault } from './App';
|
|
|
7
7
|
import { DrawerButton, DrawerButtonTypography } from './AppDrawer.style';
|
|
8
8
|
import { AppProvider } from './AppProvider';
|
|
9
9
|
export const AppDrawer = forwardRef(({ elementRef, open, config }, ref) => {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f;
|
|
10
11
|
const { t } = useTranslation();
|
|
11
12
|
const openRef = useRef(open);
|
|
12
13
|
const [drawerOpen, setDrawerOpen] = useState(open);
|
|
@@ -25,10 +26,16 @@ export const AppDrawer = forwardRef(({ elementRef, open, config }, ref) => {
|
|
|
25
26
|
openDrawer,
|
|
26
27
|
closeDrawer,
|
|
27
28
|
}), [closeDrawer, openDrawer, toggleDrawer]);
|
|
28
|
-
return (_jsxs(AppProvider, Object.assign({ config: config }, { children: [_jsxs(DrawerButton, Object.assign({ variant: "contained", onClick: toggleDrawer, open: drawerOpen, disableElevation: true }, { children: [drawerOpen ? _jsx(KeyboardArrowRightIcon, {}) : _jsx(KeyboardArrowLeftIcon, {}), _jsx(DrawerButtonTypography, { children: drawerOpen ? t('button.hide') : t('button.lifiSwap') })] })), _jsx(Drawer, Object.assign({ ref: elementRef, anchor: "right", open: drawerOpen, onClose: closeDrawer, BackdropProps: {
|
|
29
|
+
return (_jsxs(AppProvider, Object.assign({ config: config }, { children: [_jsxs(DrawerButton, Object.assign({ variant: "contained", onClick: toggleDrawer, open: drawerOpen, drawerProps: config === null || config === void 0 ? void 0 : config.containerStyle, disableElevation: true }, { children: [drawerOpen ? _jsx(KeyboardArrowRightIcon, {}) : _jsx(KeyboardArrowLeftIcon, {}), _jsx(DrawerButtonTypography, { children: drawerOpen ? t('button.hide') : t('button.lifiSwap') })] })), _jsx(Drawer, Object.assign({ ref: elementRef, anchor: "right", open: drawerOpen, onClose: closeDrawer, BackdropProps: {
|
|
29
30
|
sx: {
|
|
30
31
|
backgroundColor: 'rgb(0 0 0 / 48%)',
|
|
31
32
|
backdropFilter: 'blur(3px)',
|
|
32
33
|
},
|
|
34
|
+
}, PaperProps: {
|
|
35
|
+
sx: {
|
|
36
|
+
width: (_b = (_a = config === null || config === void 0 ? void 0 : config.containerStyle) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : '100%',
|
|
37
|
+
minWidth: (_d = (_c = config === null || config === void 0 ? void 0 : config.containerStyle) === null || _c === void 0 ? void 0 : _c.minWidth) !== null && _d !== void 0 ? _d : 375,
|
|
38
|
+
maxWidth: (_f = (_e = config === null || config === void 0 ? void 0 : config.containerStyle) === null || _e === void 0 ? void 0 : _e.maxWidth) !== null && _f !== void 0 ? _f : 392,
|
|
39
|
+
},
|
|
33
40
|
}, keepMounted: true }, { children: _jsx(AppDefault, {}) }))] })));
|
|
34
41
|
});
|
package/AppDrawer.style.d.ts
CHANGED
|
@@ -33,6 +33,10 @@ export declare const DrawerButton: import("@emotion/styled").StyledComponent<{
|
|
|
33
33
|
ref?: ((instance: HTMLButtonElement | null) => void) | import("react").RefObject<HTMLButtonElement> | null | undefined;
|
|
34
34
|
}, keyof import("@mui/material/OverridableComponent").CommonProps | "tabIndex" | "color" | "children" | "action" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "href" | "disableElevation" | "disableFocusRipple" | "endIcon" | "fullWidth" | "size" | "startIcon" | "variant"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
|
|
35
35
|
open?: boolean | undefined;
|
|
36
|
+
drawerProps?: {
|
|
37
|
+
width?: string | number | undefined;
|
|
38
|
+
maxWidth?: string | number | undefined;
|
|
39
|
+
} | undefined;
|
|
36
40
|
}, {}, {}>;
|
|
37
41
|
export declare const DrawerButtonTypography: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
38
42
|
align?: "inherit" | "left" | "right" | "center" | "justify" | undefined;
|
package/AppDrawer.style.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { Button, Typography } from '@mui/material';
|
|
2
2
|
import { styled } from '@mui/material/styles';
|
|
3
|
+
const getButtonTransformWidth = (drawerWidth, drawerMaxWidth) => {
|
|
4
|
+
if (typeof drawerWidth === 'number') {
|
|
5
|
+
return `${drawerWidth}px`;
|
|
6
|
+
}
|
|
7
|
+
if (typeof drawerWidth === 'string' && !drawerWidth.includes('%')) {
|
|
8
|
+
return drawerWidth;
|
|
9
|
+
}
|
|
10
|
+
if (typeof drawerMaxWidth === 'number') {
|
|
11
|
+
return `${drawerMaxWidth}px`;
|
|
12
|
+
}
|
|
13
|
+
if (typeof drawerMaxWidth === 'string' && !drawerMaxWidth.includes('%')) {
|
|
14
|
+
return drawerMaxWidth;
|
|
15
|
+
}
|
|
16
|
+
return '392px';
|
|
17
|
+
};
|
|
3
18
|
export const DrawerButton = styled(Button, {
|
|
4
|
-
shouldForwardProp: (prop) =>
|
|
5
|
-
})(({ theme, open }) => ({
|
|
19
|
+
shouldForwardProp: (prop) => !['open', 'drawerProps'].includes(prop),
|
|
20
|
+
})(({ theme, open, drawerProps }) => ({
|
|
6
21
|
background: theme.palette.mode === 'light'
|
|
7
22
|
? theme.palette.common.black
|
|
8
23
|
: theme.palette.common.white,
|
|
@@ -20,7 +35,9 @@ export const DrawerButton = styled(Button, {
|
|
|
20
35
|
position: 'absolute',
|
|
21
36
|
right: 0,
|
|
22
37
|
top: 'calc(50% - 74px)',
|
|
23
|
-
transform: `translate3d(calc(${open
|
|
38
|
+
transform: `translate3d(calc(${open
|
|
39
|
+
? getButtonTransformWidth(drawerProps === null || drawerProps === void 0 ? void 0 : drawerProps.width, drawerProps === null || drawerProps === void 0 ? void 0 : drawerProps.maxWidth)
|
|
40
|
+
: '0px'} * -1), 0, 0)`,
|
|
24
41
|
transition: theme.transitions.create(['transform'], {
|
|
25
42
|
duration: theme.transitions.duration.enteringScreen,
|
|
26
43
|
easing: theme.transitions.easing.easeOut,
|
|
@@ -26,7 +26,7 @@ export const StepActions = (_a) => {
|
|
|
26
26
|
const isFullView = !dense && ((_b = step.includedSteps) === null || _b === void 0 ? void 0 : _b.length) > 1;
|
|
27
27
|
return (_jsxs(Box, Object.assign({}, other, { children: [_jsxs(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' }, mb: isFullView ? 1 : 0 }, { children: [_jsx(StepAvatar, Object.assign({ variant: step.type === 'lifi' ? 'square' : 'circular', src: step.type !== 'lifi' ? step.toolDetails.logoURI : undefined, alt: step.toolDetails.name }, { children: step.type === 'lifi' ? _jsx(LiFiLogo, {}) : step.toolDetails.name[0] })), _jsx(Typography, Object.assign({ ml: 2, fontSize: 18, fontWeight: "500", textTransform: "capitalize" }, { children: step.type === 'lifi'
|
|
28
28
|
? 'LI.FI Smart Contract'
|
|
29
|
-
: step.toolDetails.name }))] })), isFullView ? (_jsx(Stepper, Object.assign({ orientation: "vertical", connector: _jsx(StepConnector, {}), activeStep: -1 }, { children: step.includedSteps.map((step) => (_jsxs(MuiStep, Object.assign({ expanded: true }, { children: [_jsx(StepLabel, Object.assign({ StepIconComponent: StepIcon }, { children: _jsx(
|
|
29
|
+
: step.toolDetails.name }))] })), isFullView ? (_jsx(Stepper, Object.assign({ orientation: "vertical", connector: _jsx(StepConnector, {}), activeStep: -1 }, { children: step.includedSteps.map((step) => (_jsxs(MuiStep, Object.assign({ expanded: true }, { children: [_jsx(StepLabel, Object.assign({ StepIconComponent: StepIcon }, { children: step.type === 'cross' || step.type === 'lifi' ? (_jsx(CrossStepDetailsLabel, { step: step })) : (_jsx(SwapStepDetailsLabel, { step: step })) })), _jsx(StepContent, { children: _jsx(StepDetailsContent, { step: step }) })] }), step.id))) }))) : (_jsxs(Box, Object.assign({ ml: 6 }, { children: [_jsx(StepDetailsLabel, { step: step }), _jsx(StepDetailsContent, { step: step })] })))] })));
|
|
30
30
|
};
|
|
31
31
|
export const StepDetailsContent = ({ step }) => {
|
|
32
32
|
return (_jsxs(Typography, Object.assign({ fontSize: 12, fontWeight: "500", color: "text.secondary", alignItems: "center", display: "flex" }, { children: [formatTokenAmount(step.estimate.fromAmount, step.action.fromToken.decimals), ' ', step.action.fromToken.symbol, _jsx(ArrowForwardIcon, { sx: { fontSize: 18, paddingX: 0.5 } }), formatTokenAmount(step.estimate.toAmount, step.action.toToken.decimals), ' ', step.action.toToken.symbol] })));
|
|
@@ -42,8 +42,11 @@ export const CrossStepDetailsLabel = ({ step }) => {
|
|
|
42
42
|
}) })));
|
|
43
43
|
};
|
|
44
44
|
export const SwapStepDetailsLabel = ({ step }) => {
|
|
45
|
+
var _a;
|
|
45
46
|
const { t } = useTranslation();
|
|
47
|
+
const { getChainById } = useChains();
|
|
46
48
|
return (_jsx(Typography, Object.assign({ fontSize: 12, fontWeight: "500", color: "text.secondary" }, { children: t('swap.swapStepDetails', {
|
|
47
|
-
|
|
49
|
+
chain: (_a = getChainById(step.action.fromChainId)) === null || _a === void 0 ? void 0 : _a.name,
|
|
50
|
+
tool: step.toolDetails.name,
|
|
48
51
|
}) })));
|
|
49
52
|
};
|
|
@@ -17,7 +17,7 @@ import { StepActions } from '../StepActions';
|
|
|
17
17
|
import { StepToken } from '../StepToken';
|
|
18
18
|
import { Card, Check, Label } from './SwapRouteCard.style';
|
|
19
19
|
export const SwapRouteCard = (_a) => {
|
|
20
|
-
var _b;
|
|
20
|
+
var _b, _c;
|
|
21
21
|
var { route, active, dense } = _a, other = __rest(_a, ["route", "active", "dense"]);
|
|
22
22
|
const { t } = useTranslation();
|
|
23
23
|
const label = ((_b = route.tags) === null || _b === void 0 ? void 0 : _b.length)
|
|
@@ -32,7 +32,7 @@ export const SwapRouteCard = (_a) => {
|
|
|
32
32
|
: null, _jsxs(Box, Object.assign({ sx: {
|
|
33
33
|
display: 'flex',
|
|
34
34
|
justifyContent: 'space-between',
|
|
35
|
-
} }, { children: [_jsxs(Box, { children: [_jsx(Typography, Object.assign({ fontSize: 18, fontWeight: "500" }, { children: t(`swap.currency`, { value: route.gasCostUSD }) })), _jsx(Typography, Object.assign({ fontSize: 12, color: "text.secondary" }, { children: t(`swap.gas`) }))] }), _jsxs(Box, { children: [_jsxs(Typography, Object.assign({ fontSize: 18, fontWeight: "500", display: "flex", justifyContent: "flex-end" }, { children: ["~", (route.steps
|
|
35
|
+
} }, { children: [_jsxs(Box, { children: [_jsx(Typography, Object.assign({ fontSize: 18, fontWeight: "500" }, { children: t(`swap.currency`, { value: (_c = route.gasCostUSD) !== null && _c !== void 0 ? _c : 0 }) })), _jsx(Typography, Object.assign({ fontSize: 12, color: "text.secondary" }, { children: t(`swap.gas`) }))] }), _jsxs(Box, { children: [_jsxs(Typography, Object.assign({ fontSize: 18, fontWeight: "500", display: "flex", justifyContent: "flex-end" }, { children: ["~", (route.steps
|
|
36
36
|
.map((step) => step.estimate.executionDuration)
|
|
37
37
|
.reduce((cumulated, x) => cumulated + x) / 60).toFixed(0)] })), _jsx(Typography, Object.assign({ fontSize: 12, color: "text.secondary", textAlign: "end" }, { children: t(`swap.minutes`) }))] })] }))] }) })));
|
|
38
38
|
};
|
package/config/sentry.js
CHANGED
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "1.10.
|
|
2
|
+
export declare const version = "1.10.3";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '1.10.
|
|
2
|
+
export const version = '1.10.3';
|
|
@@ -23,9 +23,9 @@ export const useHasSufficientBalance = () => {
|
|
|
23
23
|
const { tokens: fromChainTokenBalances } = useTokenBalances(fromChainId);
|
|
24
24
|
const { tokens: toChainTokenBalances } = useTokenBalances((_a = lastStep === null || lastStep === void 0 ? void 0 : lastStep.action.fromChainId) !== null && _a !== void 0 ? _a : toChainId);
|
|
25
25
|
const hasGasOnStartChain = useMemo(() => {
|
|
26
|
-
var _a, _b, _c
|
|
26
|
+
var _a, _b, _c;
|
|
27
27
|
const gasToken = (_a = route === null || route === void 0 ? void 0 : route.steps[0].estimate.gasCosts) === null || _a === void 0 ? void 0 : _a[0].token;
|
|
28
|
-
if (!account.isActive || !gasToken) {
|
|
28
|
+
if (!account.isActive || !gasToken || !fromAmount) {
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
const gasTokenBalance = Big((_c = (_b = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === gasToken.address)) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : 0);
|
|
@@ -34,12 +34,12 @@ export const useHasSufficientBalance = () => {
|
|
|
34
34
|
.reduce((big, step) => { var _a; return big.plus(Big(((_a = step.estimate.gasCosts) === null || _a === void 0 ? void 0 : _a[0].amount) || 0)); }, Big(0))
|
|
35
35
|
.div(Math.pow(10, gasToken.decimals));
|
|
36
36
|
if (route.fromToken.address === gasToken.address) {
|
|
37
|
-
|
|
38
|
-
requiredAmount = requiredAmount.plus(tokenBalance);
|
|
37
|
+
requiredAmount = requiredAmount.plus(Big(fromAmount));
|
|
39
38
|
}
|
|
40
39
|
return gasTokenBalance.gt(0) && gasTokenBalance.gte(requiredAmount);
|
|
41
40
|
}, [
|
|
42
41
|
account.isActive,
|
|
42
|
+
fromAmount,
|
|
43
43
|
fromChainTokenBalances,
|
|
44
44
|
route === null || route === void 0 ? void 0 : route.fromChainId,
|
|
45
45
|
route === null || route === void 0 ? void 0 : route.fromToken.address,
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -44,8 +44,8 @@ export const useSwapRoutes = () => {
|
|
|
44
44
|
!isNaN(toChainId) &&
|
|
45
45
|
Boolean(fromTokenAddress) &&
|
|
46
46
|
Boolean(toTokenAddress) &&
|
|
47
|
-
Boolean(fromTokenAmount) &&
|
|
48
47
|
!isNaN(fromTokenAmount) &&
|
|
48
|
+
Number(fromTokenAmount) > 0 &&
|
|
49
49
|
!Number.isNaN(slippage);
|
|
50
50
|
const queryKey = [
|
|
51
51
|
'routes',
|
|
@@ -96,11 +96,12 @@ export const useSwapRoutes = () => {
|
|
|
96
96
|
// check that the current route is selected from existing routes
|
|
97
97
|
const isCurrentRouteInSet = data === null || data === void 0 ? void 0 : data.routes.some((route) => route.id === (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.id));
|
|
98
98
|
const recommendedRoute = data === null || data === void 0 ? void 0 : data.routes[0];
|
|
99
|
-
// we don't want to set the current route again if it's already selected from existing routes
|
|
100
|
-
if (!isCurrentRouteInSet
|
|
99
|
+
// we don't want to set the current route again on mount if it's already selected from existing routes
|
|
100
|
+
if (!isCurrentRouteInSet) {
|
|
101
101
|
setCurrentRoute(recommendedRoute);
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
104
|
+
}, [data === null || data === void 0 ? void 0 : data.routes, setCurrentRoute]);
|
|
104
105
|
return {
|
|
105
106
|
routes: data === null || data === void 0 ? void 0 : data.routes,
|
|
106
107
|
isLoading: isEnabled && isLoading,
|
package/hooks/useTelemetry.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
/* eslint-disable consistent-return */
|
|
1
2
|
import { useEffect } from 'react';
|
|
2
3
|
import { initSentry } from '../config/sentry';
|
|
3
4
|
export const useTelemetry = (disabled) => {
|
|
4
5
|
useEffect(() => {
|
|
5
|
-
if (
|
|
6
|
+
if (disabled) {
|
|
6
7
|
console.warn('Enable crash reports and diagnostic data to be collected. This helps us to better understand how the widget is performing and where improvements need to be made.');
|
|
7
|
-
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
initSentry(true);
|
|
11
|
+
return () => {
|
|
12
|
+
initSentry(false);
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
15
|
}, [disabled]);
|
|
10
16
|
};
|
package/i18n/en/translation.json
CHANGED
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"estimatedTime": "~{{value}} min.",
|
|
53
53
|
"networkIsBusy": "Network is busy...",
|
|
54
54
|
"crossStepDetails": "Bridge {{from}} to {{to}} via {{tool}}",
|
|
55
|
-
"swapStepDetails": "Swap on {{
|
|
55
|
+
"swapStepDetails": "Swap on {{chain}} via {{tool}}",
|
|
56
56
|
"tags": {
|
|
57
57
|
"recommended": "Recommended",
|
|
58
58
|
"fastest": "Fast",
|
package/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { App } from './App';
|
|
2
2
|
import { AppDrawer } from './AppDrawer';
|
|
3
|
-
import { initSentry } from './config/sentry';
|
|
4
3
|
import './fonts/inter.css';
|
|
5
4
|
import { configureReactI18next } from './i18n';
|
|
6
5
|
export * from './types';
|
|
7
|
-
initSentry(true);
|
|
8
6
|
configureReactI18next();
|
|
9
7
|
// ClassNameGenerator.configure((componentName) => componentName.replace('Mui', ''));
|
|
10
8
|
export const LiFiWidget = App;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.3",
|
|
4
4
|
"description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./index.js",
|
|
@@ -38,5 +38,5 @@ export const SwapPage = () => {
|
|
|
38
38
|
};
|
|
39
39
|
return (_jsxs(Container, { children: [route === null || route === void 0 ? void 0 : route.steps.map((step, index, steps) => (_jsxs(Fragment, { children: [_jsx(StepItem, { step: step, fromToken: index === 0
|
|
40
40
|
? Object.assign(Object.assign({}, route.fromToken), { amount: route.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
41
|
-
? Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id))), _jsx(InsufficientGasOrFundsMessage, { mt: 2 }), status === 'idle' || status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SwapButton, { onClick: handleSwapClick, text: getSwapButtonText() }) }))) : null, status === 'error' ? (_jsx(Button, Object.assign({ variant: "outlined", disableElevation: true, fullWidth: true, onClick: handleRemoveRoute }, { children: t('button.removeSwap') }))) : null, _jsx(StatusBottomSheet, { status: status, route: route })] }));
|
|
41
|
+
? Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id))), status === 'idle' ? _jsx(InsufficientGasOrFundsMessage, { mt: 2 }) : null, status === 'idle' || status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SwapButton, { onClick: handleSwapClick, text: getSwapButtonText() }) }))) : null, status === 'error' ? (_jsx(Button, Object.assign({ variant: "outlined", disableElevation: true, fullWidth: true, onClick: handleRemoveRoute }, { children: t('button.removeSwap') }))) : null, _jsx(StatusBottomSheet, { status: status, route: route })] }));
|
|
42
42
|
};
|