@lifi/widget 1.1.3 → 1.2.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.js +2 -1
- package/components/Initializer.d.ts +2 -0
- package/components/Initializer.js +5 -0
- package/components/StepToken.js +1 -1
- package/components/SwapButton/SwapButton.js +5 -2
- package/components/SwapInProgress/SwapInProgress.js +1 -1
- package/components/SwapRoutes/SwapRoutes.js +2 -1
- package/components/TextFitter/TextFitter.js +9 -5
- package/hooks/index.d.ts +1 -3
- package/hooks/index.js +1 -3
- package/hooks/useHasSufficientBalance.js +1 -1
- package/hooks/useInitializer.d.ts +1 -0
- package/hooks/useInitializer.js +5 -0
- package/hooks/{useRouteExecution/useRouteExecution.d.ts → useRouteExecution.d.ts} +1 -1
- package/hooks/{useRouteExecution/useRouteExecution.js → useRouteExecution.js} +5 -5
- package/hooks/useSwapRoutes.js +9 -7
- package/hooks/useTools.d.ts +1 -0
- package/hooks/useTools.js +14 -0
- package/i18n/en/translation.json +0 -2
- package/i18n/index.d.ts +0 -2
- package/package.json +5 -5
- package/pages/SettingsPage/AdvancedPreferences.js +5 -4
- package/pages/SettingsPage/ColorSchemeButtonGroup.js +1 -1
- package/pages/SettingsPage/EnabledBridgesSelect.js +11 -6
- package/pages/SettingsPage/EnabledExchangesSelect.js +10 -6
- package/pages/SettingsPage/GasPriceSelect.js +4 -4
- package/pages/SettingsPage/RoutePrioritySelect.js +4 -4
- package/pages/SettingsPage/SlippageInput.js +7 -10
- package/pages/SwapPage/ExecutionItem.js +1 -1
- package/pages/SwapPage/StatusBottomSheet.d.ts +1 -1
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
- package/pages/SwapPage/StepItem.js +1 -1
- package/pages/SwapPage/StepTimer.js +3 -2
- package/pages/SwapRoutesPage/SwapRoutesPage.js +2 -1
- package/providers/SwapFormProvider/SwapFormProvider.d.ts +0 -3
- package/providers/SwapFormProvider/SwapFormProvider.js +0 -3
- package/providers/SwapFormProvider/types.d.ts +0 -19
- package/providers/SwapFormProvider/types.js +0 -9
- package/providers/ThemeProvider/ThemeProvider.js +1 -1
- package/providers/WidgetProvider/types.d.ts +2 -2
- package/stores/index.d.ts +2 -0
- package/stores/index.js +2 -0
- package/stores/route/index.d.ts +5 -0
- package/stores/route/index.js +5 -0
- package/{hooks/useRouteExecution → stores/route}/types.d.ts +0 -0
- package/{hooks/useRouteExecution → stores/route}/types.js +0 -0
- package/stores/route/useCurrentRoute.d.ts +2 -0
- package/stores/route/useCurrentRoute.js +5 -0
- package/stores/route/useExecutingRoutes.d.ts +1 -0
- package/stores/route/useExecutingRoutes.js +4 -0
- package/{hooks/useRouteExecution → stores/route}/useRouteStore.d.ts +3 -5
- package/{hooks/useRouteExecution → stores/route}/useRouteStore.js +16 -26
- package/stores/route/useSetExecutableRoute.d.ts +1 -0
- package/stores/route/useSetExecutableRoute.js +4 -0
- package/stores/settings/index.d.ts +5 -0
- package/stores/settings/index.js +5 -0
- package/stores/settings/types.d.ts +23 -0
- package/stores/settings/types.js +1 -0
- package/stores/settings/useAppearance.d.ts +2 -0
- package/stores/settings/useAppearance.js +7 -0
- package/stores/settings/useSetSettings.d.ts +5 -0
- package/stores/settings/useSetSettings.js +5 -0
- package/stores/settings/useSettings.d.ts +2 -0
- package/stores/settings/useSettings.js +8 -0
- package/stores/settings/useSettingsStore.d.ts +25 -0
- package/stores/settings/useSettingsStore.js +84 -0
- package/types/widget.d.ts +31 -23
- package/utils/format.d.ts +1 -1
- package/utils/format.js +1 -1
- package/hooks/useBridges.d.ts +0 -1
- package/hooks/useBridges.js +0 -12
- package/hooks/useExchanges.d.ts +0 -1
- package/hooks/useExchanges.js +0 -12
- package/hooks/useRouteExecution/index.d.ts +0 -3
- package/hooks/useRouteExecution/index.js +0 -3
- package/hooks/useSettings/index.d.ts +0 -2
- package/hooks/useSettings/index.js +0 -2
- package/hooks/useSettings/types.d.ts +0 -5
- package/hooks/useSettings/types.js +0 -1
- package/hooks/useSettings/useSettingsStore.d.ts +0 -13
- package/hooks/useSettings/useSettingsStore.js +0 -22
- package/pages/MainPage/SendToRecipientForm.d.ts +0 -2
- package/pages/MainPage/SendToRecipientForm.js +0 -20
package/App.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Route, Routes } from 'react-router-dom';
|
|
|
3
3
|
import { AppProvider } from './AppProvider';
|
|
4
4
|
import { AppContainer } from './components/AppContainer';
|
|
5
5
|
import { Header } from './components/Header';
|
|
6
|
+
import { Initializer } from './components/Initializer';
|
|
6
7
|
import { MainPage } from './pages/MainPage';
|
|
7
8
|
import { SelectTokenPage } from './pages/SelectTokenPage';
|
|
8
9
|
import { SelectWalletPage } from './pages/SelectWalletPage';
|
|
@@ -14,5 +15,5 @@ export const App = ({ config }) => {
|
|
|
14
15
|
return (_jsx(AppProvider, Object.assign({ config: config }, { children: _jsx(AppDefault, {}) })));
|
|
15
16
|
};
|
|
16
17
|
export const AppDefault = () => {
|
|
17
|
-
return (_jsxs(AppContainer, { children: [_jsx(Header, {}), _jsxs(Routes, { children: [_jsx(Route, { path: routes.home, element: _jsx(MainPage, {}) }), _jsx(Route, { path: routes.selectWallet, element: _jsx(SelectWalletPage, {}) }), _jsx(Route, { path: routes.settings, element: _jsx(SettingsPage, {}) }), _jsx(Route, { path: routes.fromToken, element: _jsx(SelectTokenPage, { formType: "from" }) }), _jsx(Route, { path: routes.toToken, element: _jsx(SelectTokenPage, { formType: "to" }) }), _jsx(Route, { path: routes.swapRoutes, element: _jsx(SwapRoutesPage, {}) }), _jsx(Route, { path: routes.swap, element: _jsx(SwapPage, {}) })] })] }));
|
|
18
|
+
return (_jsxs(AppContainer, { children: [_jsx(Header, {}), _jsxs(Routes, { children: [_jsx(Route, { path: routes.home, element: _jsx(MainPage, {}) }), _jsx(Route, { path: routes.selectWallet, element: _jsx(SelectWalletPage, {}) }), _jsx(Route, { path: routes.settings, element: _jsx(SettingsPage, {}) }), _jsx(Route, { path: routes.fromToken, element: _jsx(SelectTokenPage, { formType: "from" }) }), _jsx(Route, { path: routes.toToken, element: _jsx(SelectTokenPage, { formType: "to" }) }), _jsx(Route, { path: routes.swapRoutes, element: _jsx(SwapRoutesPage, {}) }), _jsx(Route, { path: `${routes.swapRoutes}/${routes.swap}`, element: _jsx(SwapPage, {}) }), _jsx(Route, { path: routes.swap, element: _jsx(SwapPage, {}) })] }), _jsx(Initializer, {})] }));
|
|
18
19
|
};
|
package/components/StepToken.js
CHANGED
|
@@ -15,7 +15,7 @@ import { formatTokenAmount } from '../utils/format';
|
|
|
15
15
|
import { TextFitter } from './TextFitter';
|
|
16
16
|
export const StepToken = (_a) => {
|
|
17
17
|
var { token } = _a, other = __rest(_a, ["token"]);
|
|
18
|
-
return (_jsxs(Box, Object.assign({ flex: 1 }, other, { children: [_jsxs(Box, Object.assign({ display: "flex", flex: 1 }, { children: [_jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol, sx: { marginRight: 2 } }, { children: token.symbol[0] })), _jsx(TextFitter, Object.assign({
|
|
18
|
+
return (_jsxs(Box, Object.assign({ flex: 1 }, other, { children: [_jsxs(Box, Object.assign({ display: "flex", flex: 1 }, { children: [_jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol, sx: { marginRight: 2 } }, { children: token.symbol[0] })), _jsx(TextFitter, Object.assign({ height: 32, textStyle: {
|
|
19
19
|
fontWeight: 700,
|
|
20
20
|
} }, { children: formatTokenAmount(token.amount, token.decimals) }))] })), _jsx(Typography, Object.assign({ fontSize: 14, lineHeight: 1, fontWeight: "500", color: "text.secondary", mr: 1, ml: 6 }, { children: token.symbol }))] })));
|
|
21
21
|
};
|
|
@@ -12,9 +12,10 @@ import { ChainId } from '@lifinance/sdk';
|
|
|
12
12
|
import { useWatch } from 'react-hook-form';
|
|
13
13
|
import { useTranslation } from 'react-i18next';
|
|
14
14
|
import { useNavigate } from 'react-router-dom';
|
|
15
|
-
import { useChains,
|
|
15
|
+
import { useChains, useHasSufficientBalance, useSwapRoutes } from '../../hooks';
|
|
16
16
|
import { SwapFormKeyHelper } from '../../providers/SwapFormProvider';
|
|
17
17
|
import { useWallet } from '../../providers/WalletProvider';
|
|
18
|
+
import { useCurrentRoute, useSetExecutableRoute } from '../../stores';
|
|
18
19
|
import { routes } from '../../utils/routes';
|
|
19
20
|
import { ButtonTooltip } from './ButtonTooltip';
|
|
20
21
|
import { Button } from './SwapButton.style';
|
|
@@ -43,7 +44,9 @@ export const SwapButton = () => {
|
|
|
43
44
|
else if (currentRoute &&
|
|
44
45
|
(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.some((route) => route.id === currentRoute.id))) {
|
|
45
46
|
setExecutableRoute(currentRoute);
|
|
46
|
-
navigate(routes.swap, {
|
|
47
|
+
navigate(routes.swap, {
|
|
48
|
+
state: { routeId: currentRoute.id },
|
|
49
|
+
});
|
|
47
50
|
}
|
|
48
51
|
});
|
|
49
52
|
const getButtonText = () => {
|
|
@@ -4,7 +4,7 @@ import { AvatarGroup, Box, Stack } from '@mui/material';
|
|
|
4
4
|
import { useCallback } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { useNavigate } from 'react-router-dom';
|
|
7
|
-
import { useExecutingRoutes } from '../../
|
|
7
|
+
import { useExecutingRoutes } from '../../stores';
|
|
8
8
|
import { routes } from '../../utils/routes';
|
|
9
9
|
import { CardTitle } from '../Card';
|
|
10
10
|
import { Card, RouteAvatar, RouteCard } from './SwapInProgress.style';
|
|
@@ -5,7 +5,8 @@ import { Box, IconButton, Skeleton } from '@mui/material';
|
|
|
5
5
|
import { useCallback } from 'react';
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
import { useNavigate } from 'react-router-dom';
|
|
8
|
-
import {
|
|
8
|
+
import { useSwapRoutes } from '../../hooks';
|
|
9
|
+
import { useCurrentRoute } from '../../stores';
|
|
9
10
|
import { routes } from '../../utils/routes';
|
|
10
11
|
import { CardContainer, CardTitle } from '../Card';
|
|
11
12
|
import { SwapRouteCard } from '../SwapRouteCard';
|
|
@@ -11,7 +11,7 @@ export const TextFitter = ({ children, width = '100%', height, maxHeight, preser
|
|
|
11
11
|
const theme = useTheme();
|
|
12
12
|
const textRef = useRef(null);
|
|
13
13
|
const [viewBox, setViewBox] = useState(initialState);
|
|
14
|
-
const [textRect, setTextRect] = useState(initialState);
|
|
14
|
+
// const [textRect, setTextRect] = useState<Partial<DOMRect>>(initialState);
|
|
15
15
|
const calculateBox = useCallback(() => {
|
|
16
16
|
if (!textRef.current) {
|
|
17
17
|
return;
|
|
@@ -25,7 +25,7 @@ export const TextFitter = ({ children, width = '100%', height, maxHeight, preser
|
|
|
25
25
|
box.height -= box.height * cropBottom;
|
|
26
26
|
}
|
|
27
27
|
setViewBox(box);
|
|
28
|
-
setTextRect(textRef.current.getBoundingClientRect());
|
|
28
|
+
// setTextRect(textRef.current.getBoundingClientRect());
|
|
29
29
|
onFit === null || onFit === void 0 ? void 0 : onFit();
|
|
30
30
|
}, [cropBottom, cropTop, onFit]);
|
|
31
31
|
useLayoutEffect(() => {
|
|
@@ -38,7 +38,11 @@ export const TextFitter = ({ children, width = '100%', height, maxHeight, preser
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
}, [calculateBox]);
|
|
41
|
-
return (_jsx("svg", Object.assign({ style: svgStyle, viewBox: `${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`, width: width, height:
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
return (_jsx("svg", Object.assign({ style: svgStyle, viewBox: `${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`, width: width, height: height,
|
|
42
|
+
// height={
|
|
43
|
+
// textRect.height && maxHeight && textRect.height >= maxHeight
|
|
44
|
+
// ? maxHeight
|
|
45
|
+
// : height
|
|
46
|
+
// }
|
|
47
|
+
preserveAspectRatio: preserveAspectRatio, fill: theme.palette.text.primary }, { children: _jsx("text", Object.assign({ x: 0, y: 0, style: textStyle, ref: textRef }, { children: children })) })));
|
|
44
48
|
};
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
export * from './useBridges';
|
|
2
1
|
export * from './useChain';
|
|
3
2
|
export * from './useChains';
|
|
4
3
|
export * from './useContentHeight';
|
|
5
4
|
export * from './useDebouncedWatch';
|
|
6
|
-
export * from './useExchanges';
|
|
7
5
|
export * from './useHasSufficientBalance';
|
|
8
6
|
export * from './useRouteExecution';
|
|
9
7
|
export * from './useScrollableContainer';
|
|
10
|
-
export * from './useSettings';
|
|
11
8
|
export * from './useSwapRoutes';
|
|
12
9
|
export * from './useToken';
|
|
13
10
|
export * from './useTokenBalance';
|
|
14
11
|
export * from './useTokenBalances';
|
|
15
12
|
export * from './useTokens';
|
|
13
|
+
export * from './useTools';
|
package/hooks/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
export * from './useBridges';
|
|
2
1
|
export * from './useChain';
|
|
3
2
|
export * from './useChains';
|
|
4
3
|
export * from './useContentHeight';
|
|
5
4
|
export * from './useDebouncedWatch';
|
|
6
|
-
export * from './useExchanges';
|
|
7
5
|
export * from './useHasSufficientBalance';
|
|
8
6
|
export * from './useRouteExecution';
|
|
9
7
|
export * from './useScrollableContainer';
|
|
10
|
-
export * from './useSettings';
|
|
11
8
|
export * from './useSwapRoutes';
|
|
12
9
|
export * from './useToken';
|
|
13
10
|
export * from './useTokenBalance';
|
|
14
11
|
export * from './useTokenBalances';
|
|
15
12
|
export * from './useTokens';
|
|
13
|
+
export * from './useTools';
|
|
@@ -3,7 +3,7 @@ import Big from 'big.js';
|
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { useWatch } from 'react-hook-form';
|
|
5
5
|
import { SwapFormKeyHelper } from '../providers/SwapFormProvider';
|
|
6
|
-
import { useCurrentRoute } from '
|
|
6
|
+
import { useCurrentRoute } from '../stores';
|
|
7
7
|
import { useTokenBalances } from './useTokenBalances';
|
|
8
8
|
export const useHasSufficientBalance = () => {
|
|
9
9
|
var _a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useInitializer: () => void;
|
|
@@ -10,13 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { useCallback, useEffect } from 'react';
|
|
11
11
|
import { useMutation } from 'react-query';
|
|
12
12
|
import shallow from 'zustand/shallow';
|
|
13
|
-
import { LiFi } from '
|
|
14
|
-
import { useWallet } from '
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { LiFi } from '../lifi';
|
|
14
|
+
import { useWallet } from '../providers/WalletProvider';
|
|
15
|
+
import { useRouteStore } from '../stores';
|
|
16
|
+
import { deepClone } from '../utils/deepClone';
|
|
17
17
|
export const useRouteExecution = (routeId) => {
|
|
18
18
|
const { account, switchChain } = useWallet();
|
|
19
|
-
const { route, status } = useRouteStore((state) => state.routes[routeId]);
|
|
19
|
+
const { route, status } = useRouteStore((state) => { var _a; return (_a = state.routes[routeId]) !== null && _a !== void 0 ? _a : {}; });
|
|
20
20
|
const [updateRoute, restartRoute, removeRoute] = useRouteStore((state) => [state.updateRoute, state.restartRoute, state.removeRoute], shallow);
|
|
21
21
|
const updateCallback = (updatedRoute) => {
|
|
22
22
|
console.log('Route updated.', updatedRoute);
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -14,23 +14,25 @@ import { useDebouncedWatch, useToken } from '.';
|
|
|
14
14
|
import { LiFi } from '../lifi';
|
|
15
15
|
import { SwapFormKey } from '../providers/SwapFormProvider';
|
|
16
16
|
import { useWallet } from '../providers/WalletProvider';
|
|
17
|
-
import { useCurrentRoute } from '
|
|
17
|
+
import { useCurrentRoute, useSettings } from '../stores';
|
|
18
18
|
const refetchTime = 60000;
|
|
19
19
|
export const useSwapRoutes = () => {
|
|
20
20
|
var _a;
|
|
21
21
|
const { account } = useWallet();
|
|
22
22
|
const queryClient = useQueryClient();
|
|
23
23
|
const [currentRoute, setCurrentRoute] = useCurrentRoute();
|
|
24
|
-
const
|
|
24
|
+
const { slippage, enabledBridges, enabledExchanges, routePriority } = useSettings([
|
|
25
|
+
'slippage',
|
|
26
|
+
'routePriority',
|
|
27
|
+
'enabledBridges',
|
|
28
|
+
'enabledExchanges',
|
|
29
|
+
]);
|
|
30
|
+
const [fromChainId, fromTokenAddress, toChainId, toTokenAddress] = useWatch({
|
|
25
31
|
name: [
|
|
26
32
|
SwapFormKey.FromChain,
|
|
27
33
|
SwapFormKey.FromToken,
|
|
28
34
|
SwapFormKey.ToChain,
|
|
29
35
|
SwapFormKey.ToToken,
|
|
30
|
-
SwapFormKey.Slippage,
|
|
31
|
-
SwapFormKey.EnabledBridges,
|
|
32
|
-
SwapFormKey.EnabledExchanges,
|
|
33
|
-
SwapFormKey.RoutePriority,
|
|
34
36
|
],
|
|
35
37
|
});
|
|
36
38
|
const [fromTokenAmount] = useDebouncedWatch([SwapFormKey.FromAmount], 500);
|
|
@@ -42,7 +44,7 @@ export const useSwapRoutes = () => {
|
|
|
42
44
|
Boolean(toTokenAddress) &&
|
|
43
45
|
Boolean(fromTokenAmount) &&
|
|
44
46
|
!isNaN(fromTokenAmount) &&
|
|
45
|
-
!isNaN(slippage);
|
|
47
|
+
!Number.isNaN(slippage);
|
|
46
48
|
const queryKey = [
|
|
47
49
|
'routes',
|
|
48
50
|
account.address,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useTools: () => import("@lifinance/types").ToolsResponse | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
import { useQuery } from 'react-query';
|
|
3
|
+
import { LiFi } from '../lifi';
|
|
4
|
+
import { useSettingsStore } from '../stores';
|
|
5
|
+
export const useTools = () => {
|
|
6
|
+
const initializeTools = useSettingsStore((state) => state.initializeTools);
|
|
7
|
+
const { data } = useQuery(['tools'], ({ signal }) => LiFi.getTools(undefined, { signal }), {
|
|
8
|
+
onSuccess(data) {
|
|
9
|
+
initializeTools('Bridges', data.bridges.map((bridge) => bridge.key));
|
|
10
|
+
initializeTools('Exchanges', data.exchanges.map((exchange) => exchange.key));
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
return data;
|
|
14
|
+
};
|
package/i18n/en/translation.json
CHANGED
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"approximateCurrency": "\u2248 {{value, currency(currency: USD)}}",
|
|
38
38
|
"currency": "{{value, currency(currency: USD)}}",
|
|
39
39
|
"sendToRecipient": "Send to recipient",
|
|
40
|
-
"recipientsAddress": "Recipient's {{chain}} address",
|
|
41
40
|
"addressConfirmation": "I confirm that the address above is correct",
|
|
42
41
|
"gas": "gas fee",
|
|
43
42
|
"minutes": "minutes",
|
|
@@ -126,7 +125,6 @@
|
|
|
126
125
|
"fast": "Fast"
|
|
127
126
|
},
|
|
128
127
|
"advancedPreferences": "Advanced preferences",
|
|
129
|
-
"bridgePrioritization": "Bridge prioritization",
|
|
130
128
|
"enabledBridges": "Enabled bridges",
|
|
131
129
|
"selectEnabledBridges": "Select enabled bridges",
|
|
132
130
|
"enabledExchanges": "Enabled exchanges",
|
package/i18n/index.d.ts
CHANGED
|
@@ -40,7 +40,6 @@ export declare const resources: {
|
|
|
40
40
|
approximateCurrency: string;
|
|
41
41
|
currency: string;
|
|
42
42
|
sendToRecipient: string;
|
|
43
|
-
recipientsAddress: string;
|
|
44
43
|
addressConfirmation: string;
|
|
45
44
|
gas: string;
|
|
46
45
|
minutes: string;
|
|
@@ -129,7 +128,6 @@ export declare const resources: {
|
|
|
129
128
|
fast: string;
|
|
130
129
|
};
|
|
131
130
|
advancedPreferences: string;
|
|
132
|
-
bridgePrioritization: string;
|
|
133
131
|
enabledBridges: string;
|
|
134
132
|
selectEnabledBridges: string;
|
|
135
133
|
enabledExchanges: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"lifi"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@emotion/react": "^11.9.
|
|
41
|
-
"@emotion/styled": "^11.
|
|
40
|
+
"@emotion/react": "^11.9.3",
|
|
41
|
+
"@emotion/styled": "^11.9.3",
|
|
42
42
|
"@ethersproject/experimental": "^5.6.2",
|
|
43
43
|
"@ethersproject/providers": "^5.6.8",
|
|
44
44
|
"@lifi/wallet-management": "^1.0.2",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"immer": "^9.0.14",
|
|
52
52
|
"react": "^18.1.0",
|
|
53
53
|
"react-dom": "^18.1.0",
|
|
54
|
-
"react-hook-form": "^7.
|
|
55
|
-
"react-i18next": "^11.
|
|
54
|
+
"react-hook-form": "^7.32.0",
|
|
55
|
+
"react-i18next": "^11.17.1",
|
|
56
56
|
"react-query": "^4.0.0-beta.23",
|
|
57
57
|
"react-resize-detector": "^7.1.1",
|
|
58
58
|
"react-router-dom": "^6.3.0",
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Typography } from '@mui/material';
|
|
3
|
-
import { useState } from 'react';
|
|
4
3
|
import { useTranslation } from 'react-i18next';
|
|
5
4
|
import { Switch } from '../../components/Switch';
|
|
5
|
+
import { useSetSettings, useSettings } from '../../stores';
|
|
6
6
|
import { EnabledBridgesSelect } from './EnabledBridgesSelect';
|
|
7
7
|
import { EnabledExchangesSelect } from './EnabledExchangesSelect';
|
|
8
8
|
export const AdvancedPreferences = () => {
|
|
9
9
|
const { t } = useTranslation();
|
|
10
|
-
const [
|
|
10
|
+
const [setValue] = useSetSettings();
|
|
11
|
+
const { advancedPreferences } = useSettings(['advancedPreferences']);
|
|
11
12
|
const handleAdvancedPreferences = (_, checked) => {
|
|
12
|
-
|
|
13
|
+
setValue('advancedPreferences', checked);
|
|
13
14
|
};
|
|
14
15
|
return (_jsxs(Box, Object.assign({ p: 3 }, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
15
16
|
display: 'flex',
|
|
16
17
|
justifyContent: 'space-between',
|
|
17
18
|
alignItems: 'center',
|
|
18
|
-
} }, { children: [_jsx(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: _jsx(Typography, Object.assign({ variant: "subtitle1", color: "text.primary", lineHeight: "normal" }, { children: t(`settings.advancedPreferences`) })) })), _jsx(Switch, {
|
|
19
|
+
} }, { children: [_jsx(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: _jsx(Typography, Object.assign({ variant: "subtitle1", color: "text.primary", lineHeight: "normal" }, { children: t(`settings.advancedPreferences`) })) })), _jsx(Switch, { checked: advancedPreferences, onChange: handleAdvancedPreferences })] })), advancedPreferences && (_jsxs(Box, Object.assign({ mt: 3, mb: 1 }, { children: [_jsx(EnabledBridgesSelect, {}), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(EnabledExchangesSelect, {}) }))] })))] })));
|
|
19
20
|
};
|
|
@@ -2,8 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Brightness4 as Brightness4Icon, DarkMode as DarkModeIcon, LightMode as LightModeIcon, } from '@mui/icons-material';
|
|
3
3
|
import { Box, ToggleButtonGroup } from '@mui/material';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import { useAppearance } from '../../hooks';
|
|
6
5
|
import { useWidgetConfig } from '../../providers/WidgetProvider';
|
|
6
|
+
import { useAppearance } from '../../stores';
|
|
7
7
|
import { ToggleButton } from './ColorSchemeButtonGroup.style';
|
|
8
8
|
export const ColorSchemeButtonGroup = () => {
|
|
9
9
|
const { t } = useTranslation();
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
|
|
3
3
|
import { Box, Chip, FormControl, MenuItem, Skeleton } from '@mui/material';
|
|
4
|
-
import { useFormContext } from 'react-hook-form';
|
|
5
4
|
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import shallow from 'zustand/shallow';
|
|
6
6
|
import { CardContainer, CardTitle } from '../../components/Card';
|
|
7
7
|
import { Select } from '../../components/Select';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { useTools } from '../../hooks';
|
|
9
|
+
import { useSettingsStore } from '../../stores';
|
|
10
10
|
export const EnabledBridgesSelect = () => {
|
|
11
|
+
var _a;
|
|
11
12
|
const { t } = useTranslation();
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
return bridges.length ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.enabledBridges`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ multiple: true, placeholder: t(`settings.selectEnabledBridges`),
|
|
13
|
+
const tools = useTools();
|
|
14
|
+
const [enabledBridges, setTools] = useSettingsStore((state) => [state.enabledBridges, state.setTools], shallow);
|
|
15
|
+
return (tools === null || tools === void 0 ? void 0 : tools.bridges.length) ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.enabledBridges`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ multiple: true, placeholder: t(`settings.selectEnabledBridges`), MenuProps: { elevation: 2 }, IconComponent: KeyboardArrowDownIcon, value: enabledBridges !== null && enabledBridges !== void 0 ? enabledBridges : [], onChange: (event) => {
|
|
16
|
+
if (tools === null || tools === void 0 ? void 0 : tools.bridges) {
|
|
17
|
+
setTools('Bridges', event.target.value, tools.bridges);
|
|
18
|
+
}
|
|
19
|
+
}, renderValue: (selected) => (_jsx(Box, Object.assign({ sx: { display: 'flex', flexWrap: 'wrap', gap: 0.5 } }, { children: selected.map((value) => (_jsx(Chip, { label: value }, value))) }))) }, { children: (_a = tools === null || tools === void 0 ? void 0 : tools.bridges) === null || _a === void 0 ? void 0 : _a.map((bridge) => (_jsx(MenuItem, Object.assign({ value: bridge.key }, { children: bridge.key }), bridge.key))) })) }))] })) : (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 134, sx: { borderRadius: 1 } }));
|
|
15
20
|
};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
|
|
3
3
|
import { Box, Chip, FormControl, MenuItem, Skeleton } from '@mui/material';
|
|
4
|
-
import { useFormContext } from 'react-hook-form';
|
|
5
4
|
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import shallow from 'zustand/shallow';
|
|
6
6
|
import { CardContainer, CardTitle } from '../../components/Card';
|
|
7
7
|
import { Select } from '../../components/Select';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { useTools } from '../../hooks';
|
|
9
|
+
import { useSettingsStore } from '../../stores';
|
|
10
10
|
export const EnabledExchangesSelect = () => {
|
|
11
11
|
const { t } = useTranslation();
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
return exchanges.length ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.enabledExchanges`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ multiple: true, placeholder: t(`settings.selectEnabledExchanges`),
|
|
12
|
+
const tools = useTools();
|
|
13
|
+
const [enabledExchanges, setTools] = useSettingsStore((state) => [state.enabledExchanges, state.setTools], shallow);
|
|
14
|
+
return (tools === null || tools === void 0 ? void 0 : tools.exchanges.length) ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.enabledExchanges`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ multiple: true, placeholder: t(`settings.selectEnabledExchanges`), value: enabledExchanges !== null && enabledExchanges !== void 0 ? enabledExchanges : [], onChange: (event) => {
|
|
15
|
+
if (tools === null || tools === void 0 ? void 0 : tools.exchanges) {
|
|
16
|
+
setTools('Exchanges', event.target.value, tools.exchanges);
|
|
17
|
+
}
|
|
18
|
+
}, MenuProps: { elevation: 2 }, IconComponent: KeyboardArrowDownIcon, renderValue: (selected) => (_jsx(Box, Object.assign({ sx: { display: 'flex', flexWrap: 'wrap', gap: 0.5 } }, { children: selected.map((value) => (_jsx(Chip, { label: value }, value))) }))) }, { children: tools === null || tools === void 0 ? void 0 : tools.exchanges.map((exchange) => (_jsx(MenuItem, Object.assign({ value: exchange.key }, { children: exchange.key }), exchange.key))) })) }))] })) : (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 206, sx: { borderRadius: 1 } }));
|
|
15
19
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
|
|
3
3
|
import { FormControl, MenuItem } from '@mui/material';
|
|
4
|
-
import { useFormContext } from 'react-hook-form';
|
|
5
4
|
import { useTranslation } from 'react-i18next';
|
|
6
5
|
import { CardContainer, CardTitle } from '../../components/Card';
|
|
7
6
|
import { Select } from '../../components/Select';
|
|
8
|
-
import {
|
|
7
|
+
import { useSetSettings, useSettings } from '../../stores';
|
|
9
8
|
export const GasPriceSelect = () => {
|
|
10
9
|
const { t } = useTranslation();
|
|
11
|
-
const
|
|
12
|
-
|
|
10
|
+
const [setValue] = useSetSettings();
|
|
11
|
+
const { gasPrice } = useSettings(['gasPrice']);
|
|
12
|
+
return (_jsxs(CardContainer, Object.assign({ flex: 1 }, { children: [_jsx(CardTitle, { children: t(`settings.gasPrice.title`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsxs(Select, Object.assign({ MenuProps: { elevation: 2 }, value: gasPrice, onChange: (event) => setValue('gasPrice', event.target.value), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: [_jsx(MenuItem, Object.assign({ value: "slow" }, { children: t(`settings.gasPrice.slow`) })), _jsx(MenuItem, Object.assign({ value: "normal" }, { children: t(`settings.gasPrice.normal`) })), _jsx(MenuItem, Object.assign({ value: "fast" }, { children: t(`settings.gasPrice.fast`) }))] })) }))] })));
|
|
13
13
|
};
|
|
@@ -2,13 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Orders } from '@lifinance/sdk';
|
|
3
3
|
import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
|
|
4
4
|
import { FormControl, MenuItem } from '@mui/material';
|
|
5
|
-
import { useFormContext } from 'react-hook-form';
|
|
6
5
|
import { useTranslation } from 'react-i18next';
|
|
7
6
|
import { CardContainer, CardTitle } from '../../components/Card';
|
|
8
7
|
import { Select } from '../../components/Select';
|
|
9
|
-
import {
|
|
8
|
+
import { useSetSettings, useSettings } from '../../stores';
|
|
10
9
|
export const RoutePrioritySelect = () => {
|
|
11
10
|
const { t } = useTranslation();
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
const [setValue] = useSetSettings();
|
|
12
|
+
const { routePriority } = useSettings(['routePriority']);
|
|
13
|
+
return (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.routePriority`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ MenuProps: { elevation: 2 }, value: routePriority, onChange: (event) => setValue('routePriority', event.target.value), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: Orders.map((order) => (_jsx(MenuItem, Object.assign({ value: order }, { children: t(`swap.tags.${order.toLowerCase()}`) }), order))) })) }))] }));
|
|
14
14
|
};
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { FormControl, InputAdornment } from '@mui/material';
|
|
3
3
|
import { useRef } from 'react';
|
|
4
|
-
import { useFormContext, useWatch } from 'react-hook-form';
|
|
5
4
|
import { useTranslation } from 'react-i18next';
|
|
6
5
|
import { CardContainer, CardTitle } from '../../components/Card';
|
|
7
6
|
import { Input } from '../../components/Input';
|
|
8
|
-
import {
|
|
7
|
+
import { useSetSettings, useSettings } from '../../stores';
|
|
9
8
|
import { formatSlippage } from '../../utils/format';
|
|
10
9
|
export const SlippageInput = () => {
|
|
11
10
|
const { t } = useTranslation();
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
const defaultValue = useRef(value);
|
|
11
|
+
const [setValue] = useSetSettings();
|
|
12
|
+
const { slippage } = useSettings(['slippage']);
|
|
13
|
+
const defaultValue = useRef(slippage);
|
|
17
14
|
const handleChange = (event) => {
|
|
18
15
|
const { value } = event.target;
|
|
19
|
-
setValue(
|
|
16
|
+
setValue('slippage', formatSlippage(value, defaultValue.current, true));
|
|
20
17
|
};
|
|
21
18
|
const handleBlur = (event) => {
|
|
22
19
|
const { value } = event.target;
|
|
23
|
-
setValue(
|
|
20
|
+
setValue('slippage', formatSlippage(value, defaultValue.current));
|
|
24
21
|
};
|
|
25
22
|
return (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.slippage`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Input, { size: "small", placeholder: t(`settings.slippage`), endAdornment: _jsx(InputAdornment, Object.assign({ position: "end" }, { children: "%" })), autoComplete: "off", inputProps: {
|
|
26
23
|
inputMode: 'decimal',
|
|
27
|
-
}, onChange: handleChange, onBlur: handleBlur, value:
|
|
24
|
+
}, onChange: handleChange, onBlur: handleBlur, value: slippage }) }))] }));
|
|
28
25
|
};
|
|
@@ -13,7 +13,7 @@ export const ExecutionItem = ({ step, process }) => {
|
|
|
13
13
|
return (_jsxs(Box, Object.assign({ px: 2, py: 1 }, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
14
14
|
display: 'flex',
|
|
15
15
|
alignItems: 'center',
|
|
16
|
-
} }, { children: [_jsx(CircularProgress, { status: process.status }), _jsx(Typography, Object.assign({ ml: 2, fontWeight: process.error ?
|
|
16
|
+
} }, { children: [_jsx(CircularProgress, { status: process.status }), _jsx(Typography, Object.assign({ ml: 2, fontSize: 14, fontWeight: process.error ? 600 : 400 }, { children: title })), process.txLink ? (_jsx(Box, Object.assign({ ml: 2, sx: {
|
|
17
17
|
display: 'flex',
|
|
18
18
|
flex: 1,
|
|
19
19
|
justifyContent: 'flex-end',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Theme } from '@mui/material';
|
|
3
|
-
import { RouteExecutionStatus } from '../../
|
|
3
|
+
import { RouteExecutionStatus } from '../../stores';
|
|
4
4
|
export declare const IconContainer: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
|
|
5
5
|
children?: import("react").ReactNode;
|
|
6
6
|
component?: import("react").ElementType<any> | undefined;
|
|
@@ -25,5 +25,5 @@ export const StepItem = ({ step, fromToken, toToken }) => {
|
|
|
25
25
|
return (_jsxs(CardContainer, Object.assign({ isError: stepHasError }, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
26
26
|
display: 'flex',
|
|
27
27
|
flex: 1,
|
|
28
|
-
} }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: getCardTitle() })), _jsx(CardTitle, { children: _jsx(StepTimer, { step: step }) })] })), _jsxs(Box, Object.assign({ py: 1 }, { children: [fromToken ? _jsx(StepToken, { token: fromToken, px: 2, py: 1 }) : null, _jsx(StepActions, { step: step, px: 2, py: 1, dense: true }), (_b = step.execution) === null || _b === void 0 ? void 0 : _b.process.map((process, index) => (_jsx(ExecutionItem, { step: step, process: process }, index))), toToken ? _jsx(StepToken, { token: toToken, px: 2, py: 1 }) : null] }))] })));
|
|
28
|
+
} }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: getCardTitle() })), _jsx(CardTitle, Object.assign({ sx: { fontWeight: 500 } }, { children: _jsx(StepTimer, { step: step }) }))] })), _jsxs(Box, Object.assign({ py: 1 }, { children: [fromToken ? _jsx(StepToken, { token: fromToken, px: 2, py: 1 }) : null, _jsx(StepActions, { step: step, px: 2, py: 1, dense: true }), (_b = step.execution) === null || _b === void 0 ? void 0 : _b.process.map((process, index) => (_jsx(ExecutionItem, { step: step, process: process }, index))), toToken ? _jsx(StepToken, { token: toToken, px: 2, py: 1 }) : null] }))] })));
|
|
29
29
|
};
|
|
@@ -8,7 +8,7 @@ const getExpiryTimestamp = (step) => {
|
|
|
8
8
|
step.estimate.executionDuration * 1000);
|
|
9
9
|
};
|
|
10
10
|
export const StepTimer = ({ step }) => {
|
|
11
|
-
var _a;
|
|
11
|
+
var _a, _b;
|
|
12
12
|
const { t } = useTranslation();
|
|
13
13
|
const [isExpired, setExpired] = useState(false);
|
|
14
14
|
const [isExecutionStarted, setExecutionStarted] = useState(!!step.execution);
|
|
@@ -50,7 +50,8 @@ export const StepTimer = ({ step }) => {
|
|
|
50
50
|
value: (step.estimate.executionDuration / 60).toFixed(0),
|
|
51
51
|
}) }));
|
|
52
52
|
}
|
|
53
|
-
if (((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'
|
|
53
|
+
if (((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE' ||
|
|
54
|
+
((_b = step.execution) === null || _b === void 0 ? void 0 : _b.status) === 'FAILED') {
|
|
54
55
|
return null;
|
|
55
56
|
}
|
|
56
57
|
return isExpired ? (_jsx(_Fragment, { children: t('swap.networkIsBusy') })) : (
|
|
@@ -2,7 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Skeleton } from '@mui/material';
|
|
3
3
|
import { useNavigate } from 'react-router-dom';
|
|
4
4
|
import { SwapRouteCard } from '../../components/SwapRouteCard';
|
|
5
|
-
import {
|
|
5
|
+
import { useSwapRoutes } from '../../hooks';
|
|
6
|
+
import { useCurrentRoute, useSetExecutableRoute } from '../../stores';
|
|
6
7
|
import { routes } from '../../utils/routes';
|
|
7
8
|
import { Stack } from './SwapRoutesPage.style';
|
|
8
9
|
export const SwapRoutesPage = () => {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare const formDefaultValues: {
|
|
3
3
|
fromAmount: string;
|
|
4
|
-
gasPrice: string;
|
|
5
|
-
slippage: string;
|
|
6
4
|
searchTokensFilter: string;
|
|
7
|
-
routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
|
|
8
5
|
};
|
|
9
6
|
export declare const SwapFormProvider: React.FC<React.PropsWithChildren<{}>>;
|
|
@@ -4,10 +4,7 @@ import { useWidgetConfig } from '../WidgetProvider';
|
|
|
4
4
|
import { SwapFormKey } from './types';
|
|
5
5
|
export const formDefaultValues = {
|
|
6
6
|
[SwapFormKey.FromAmount]: '',
|
|
7
|
-
[SwapFormKey.GasPrice]: 'normal',
|
|
8
|
-
[SwapFormKey.Slippage]: '3',
|
|
9
7
|
[SwapFormKey.SearchTokensFilter]: '',
|
|
10
|
-
[SwapFormKey.RoutePriority]: 'RECOMMENDED',
|
|
11
8
|
};
|
|
12
9
|
export const SwapFormProvider = ({ children, }) => {
|
|
13
10
|
var _a;
|