@lifi/widget 1.1.1 → 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/AppDrawer.d.ts +1 -1
- package/AppProvider.d.ts +1 -1
- package/AppProvider.js +7 -2
- package/components/Header/Header.js +1 -1
- package/components/Header/NavigationHeader.js +5 -3
- package/components/Header/WalletHeader.js +1 -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/fonts/Inter-Black.woff +0 -0
- package/fonts/Inter-Black.woff2 +0 -0
- package/fonts/Inter-BlackItalic.woff +0 -0
- package/fonts/Inter-BlackItalic.woff2 +0 -0
- package/fonts/Inter-Bold.woff +0 -0
- package/fonts/Inter-Bold.woff2 +0 -0
- package/fonts/Inter-BoldItalic.woff +0 -0
- package/fonts/Inter-BoldItalic.woff2 +0 -0
- package/fonts/Inter-ExtraBold.woff +0 -0
- package/fonts/Inter-ExtraBold.woff2 +0 -0
- package/fonts/Inter-ExtraBoldItalic.woff +0 -0
- package/fonts/Inter-ExtraBoldItalic.woff2 +0 -0
- package/fonts/Inter-ExtraLight.woff +0 -0
- package/fonts/Inter-ExtraLight.woff2 +0 -0
- package/fonts/Inter-ExtraLightItalic.woff +0 -0
- package/fonts/Inter-ExtraLightItalic.woff2 +0 -0
- package/fonts/Inter-Italic.woff +0 -0
- package/fonts/Inter-Italic.woff2 +0 -0
- package/fonts/Inter-Light.woff +0 -0
- package/fonts/Inter-Light.woff2 +0 -0
- package/fonts/Inter-LightItalic.woff +0 -0
- package/fonts/Inter-LightItalic.woff2 +0 -0
- package/fonts/Inter-Medium.woff +0 -0
- package/fonts/Inter-Medium.woff2 +0 -0
- package/fonts/Inter-MediumItalic.woff +0 -0
- package/fonts/Inter-MediumItalic.woff2 +0 -0
- package/fonts/Inter-Regular.woff +0 -0
- package/fonts/Inter-Regular.woff2 +0 -0
- package/fonts/Inter-SemiBold.woff +0 -0
- package/fonts/Inter-SemiBold.woff2 +0 -0
- package/fonts/Inter-SemiBoldItalic.woff +0 -0
- package/fonts/Inter-SemiBoldItalic.woff2 +0 -0
- package/fonts/Inter-Thin.woff +0 -0
- package/fonts/Inter-Thin.woff2 +0 -0
- package/fonts/Inter-ThinItalic.woff +0 -0
- package/fonts/Inter-ThinItalic.woff2 +0 -0
- package/fonts/Inter-italic.var.woff2 +0 -0
- package/fonts/Inter-roman.var.woff2 +0 -0
- package/fonts/Inter.var.woff2 +0 -0
- package/fonts/inter.css +200 -0
- package/hooks/index.d.ts +1 -3
- package/hooks/index.js +1 -3
- package/hooks/useContentHeight.js +18 -10
- 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 +134 -136
- package/i18n/index.d.ts +0 -2
- package/icons/LiFiFullLogo.svg +10 -0
- package/icons/LiFiLogo.svg +5 -0
- package/package.json +7 -6
- package/pages/SelectTokenPage/ChainSelect.js +1 -1
- 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/WidgetProvider.js +3 -5
- package/providers/WidgetProvider/types.d.ts +3 -3
- 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/utils/routes.d.ts +1 -0
- package/utils/routes.js +7 -6
- 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/i18n/react-i18next.d.ts +0 -9
- package/pages/MainPage/SendToRecipientForm.d.ts +0 -2
- package/pages/MainPage/SendToRecipientForm.js +0 -20
- package/react-app-env.d.ts +0 -1
|
@@ -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;
|
|
@@ -1,35 +1,16 @@
|
|
|
1
|
-
import { Order } from '@lifinance/sdk';
|
|
2
1
|
export declare enum SwapFormKey {
|
|
3
|
-
BridgePrioritization = "bridgePrioritization",
|
|
4
|
-
EnabledBridges = "enabledBridges",
|
|
5
|
-
EnabledExchanges = "enabledExchanges",
|
|
6
2
|
FromAmount = "fromAmount",
|
|
7
3
|
FromChain = "fromChain",
|
|
8
4
|
FromToken = "fromToken",
|
|
9
|
-
GasPrice = "gasPrice",
|
|
10
|
-
IsAddressConfirmed = "isAddressConfirmed",
|
|
11
|
-
IsSendToRecipient = "isSendToRecipient",
|
|
12
|
-
RecipientsAddress = "recipientsAddress",
|
|
13
|
-
RoutePriority = "routePriority",
|
|
14
5
|
SearchTokensFilter = "searchTokensFilter",
|
|
15
|
-
Slippage = "slippage",
|
|
16
6
|
ToChain = "toChain",
|
|
17
7
|
ToToken = "toToken"
|
|
18
8
|
}
|
|
19
9
|
export declare type SwapFormValues = {
|
|
20
|
-
[SwapFormKey.BridgePrioritization]: string;
|
|
21
|
-
[SwapFormKey.EnabledBridges]: string[];
|
|
22
|
-
[SwapFormKey.EnabledExchanges]: string[];
|
|
23
10
|
[SwapFormKey.FromAmount]: string;
|
|
24
11
|
[SwapFormKey.FromChain]: number;
|
|
25
12
|
[SwapFormKey.FromToken]: string;
|
|
26
|
-
[SwapFormKey.GasPrice]: string;
|
|
27
|
-
[SwapFormKey.IsAddressConfirmed]: boolean;
|
|
28
|
-
[SwapFormKey.IsSendToRecipient]: boolean;
|
|
29
|
-
[SwapFormKey.RecipientsAddress]: string;
|
|
30
|
-
[SwapFormKey.RoutePriority]: Order;
|
|
31
13
|
[SwapFormKey.SearchTokensFilter]: string;
|
|
32
|
-
[SwapFormKey.Slippage]: string;
|
|
33
14
|
[SwapFormKey.ToChain]: number;
|
|
34
15
|
[SwapFormKey.ToToken]: string;
|
|
35
16
|
};
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
export var SwapFormKey;
|
|
2
2
|
(function (SwapFormKey) {
|
|
3
|
-
SwapFormKey["BridgePrioritization"] = "bridgePrioritization";
|
|
4
|
-
SwapFormKey["EnabledBridges"] = "enabledBridges";
|
|
5
|
-
SwapFormKey["EnabledExchanges"] = "enabledExchanges";
|
|
6
3
|
SwapFormKey["FromAmount"] = "fromAmount";
|
|
7
4
|
SwapFormKey["FromChain"] = "fromChain";
|
|
8
5
|
SwapFormKey["FromToken"] = "fromToken";
|
|
9
|
-
SwapFormKey["GasPrice"] = "gasPrice";
|
|
10
|
-
SwapFormKey["IsAddressConfirmed"] = "isAddressConfirmed";
|
|
11
|
-
SwapFormKey["IsSendToRecipient"] = "isSendToRecipient";
|
|
12
|
-
SwapFormKey["RecipientsAddress"] = "recipientsAddress";
|
|
13
|
-
SwapFormKey["RoutePriority"] = "routePriority";
|
|
14
6
|
SwapFormKey["SearchTokensFilter"] = "searchTokensFilter";
|
|
15
|
-
SwapFormKey["Slippage"] = "slippage";
|
|
16
7
|
SwapFormKey["ToChain"] = "toChain";
|
|
17
8
|
SwapFormKey["ToToken"] = "toToken";
|
|
18
9
|
})(SwapFormKey || (SwapFormKey = {}));
|
|
@@ -3,7 +3,7 @@ import { useMediaQuery } from '@mui/material';
|
|
|
3
3
|
import { ThemeProvider as MuiThemeProvider } from '@mui/material/styles';
|
|
4
4
|
import { useEffect, useMemo, useState } from 'react';
|
|
5
5
|
import { createTheme } from '../../config/theme';
|
|
6
|
-
import { useAppearance } from '../../
|
|
6
|
+
import { useAppearance } from '../../stores';
|
|
7
7
|
import { useWidgetConfig } from '../WidgetProvider';
|
|
8
8
|
export const ThemeProvider = ({ children, }) => {
|
|
9
9
|
const { appearance: colorSchemeMode, theme: themeConfig } = useWidgetConfig();
|
|
@@ -21,10 +21,8 @@ const initialContext = {
|
|
|
21
21
|
const WidgetContext = createContext(initialContext);
|
|
22
22
|
export const useWidgetConfig = () => useContext(WidgetContext);
|
|
23
23
|
export const WidgetProvider = (_a) => {
|
|
24
|
-
var { children } = _a, _b = _a.config, { fromChain, toChain } =
|
|
24
|
+
var { children } = _a, _b = _a.config, _c = _b === void 0 ? {} : _b, { fromChain, fromToken, toChain, toToken } = _c, config = __rest(_c, ["fromChain", "fromToken", "toChain", "toToken"]);
|
|
25
25
|
const value = useMemo(() => {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
const config = Object.assign({}, other);
|
|
28
26
|
try {
|
|
29
27
|
return Object.assign(Object.assign({}, config), { fromChain: typeof fromChain === 'number'
|
|
30
28
|
? fromChain
|
|
@@ -34,12 +32,12 @@ export const WidgetProvider = (_a) => {
|
|
|
34
32
|
? toChain
|
|
35
33
|
: typeof toChain === 'string'
|
|
36
34
|
? getChainByKey(toChain.toLowerCase()).id
|
|
37
|
-
: ChainId.ETH, fromToken:
|
|
35
|
+
: ChainId.ETH, fromToken: fromToken === null || fromToken === void 0 ? void 0 : fromToken.toLowerCase(), toToken: toToken === null || toToken === void 0 ? void 0 : toToken.toLowerCase() });
|
|
38
36
|
}
|
|
39
37
|
catch (e) {
|
|
40
38
|
console.warn(e);
|
|
41
39
|
return config;
|
|
42
40
|
}
|
|
43
|
-
}, [fromChain,
|
|
41
|
+
}, [config, fromChain, fromToken, toChain, toToken]);
|
|
44
42
|
return (_jsx(WidgetContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
45
43
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WidgetConfig } from '../../types';
|
|
2
|
-
export
|
|
2
|
+
export declare type WidgetContextProps = WidgetConfig & {
|
|
3
3
|
fromChain?: number;
|
|
4
4
|
toChain?: number;
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
6
|
export interface WidgetProviderProps {
|
|
7
|
-
config
|
|
7
|
+
config?: WidgetConfig;
|
|
8
8
|
}
|
package/stores/index.js
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useExecutingRoutes: () => import("./types").RouteExecution[];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Route } from '@lifinance/sdk';
|
|
2
1
|
import type { RouteExecutionStore } from './types';
|
|
3
|
-
export declare const useRouteStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<RouteExecutionStore>, "persist"> & {
|
|
2
|
+
export declare const useRouteStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<RouteExecutionStore>, "persist"> & {
|
|
4
3
|
persist: {
|
|
5
4
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<RouteExecutionStore, {
|
|
6
5
|
routes: Record<string, import("./types").RouteExecution>;
|
|
@@ -11,7 +10,6 @@ export declare const useRouteStore: import("zustand").UseBoundStore<Omit<import(
|
|
|
11
10
|
onHydrate: (fn: (state: RouteExecutionStore) => void) => () => void;
|
|
12
11
|
onFinishHydration: (fn: (state: RouteExecutionStore) => void) => () => void;
|
|
13
12
|
};
|
|
13
|
+
}, "setState"> & {
|
|
14
|
+
setState(nextStateOrUpdater: RouteExecutionStore | Partial<RouteExecutionStore> | ((state: import("immer/dist/internal").WritableDraft<RouteExecutionStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
14
15
|
}>;
|
|
15
|
-
export declare const useSetExecutableRoute: () => (route: Route) => void;
|
|
16
|
-
export declare const useExecutingRoutes: () => import("./types").RouteExecution[];
|
|
17
|
-
export declare const useCurrentRoute: () => [Route | undefined, (route?: Route) => void];
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import produce from 'immer';
|
|
2
1
|
import create from 'zustand';
|
|
3
2
|
import { persist } from 'zustand/middleware';
|
|
4
|
-
import
|
|
5
|
-
export const useRouteStore = create()(persist((set) => ({
|
|
3
|
+
import { immer } from 'zustand/middleware/immer';
|
|
4
|
+
export const useRouteStore = create()(persist(immer((set) => ({
|
|
6
5
|
routes: {},
|
|
7
|
-
setCurrentRoute: (route) => set(
|
|
6
|
+
setCurrentRoute: (route) => set((state) => {
|
|
8
7
|
state.currentRoute = route;
|
|
9
|
-
})
|
|
10
|
-
setExecutableRoute: (route) => set(
|
|
8
|
+
}),
|
|
9
|
+
setExecutableRoute: (route) => set((state) => {
|
|
11
10
|
if (!state.routes[route.id]) {
|
|
12
11
|
// clean previous idle routes that were not executed
|
|
13
12
|
Object.keys(state.routes)
|
|
@@ -19,8 +18,8 @@ export const useRouteStore = create()(persist((set) => ({
|
|
|
19
18
|
};
|
|
20
19
|
state.currentRoute = route;
|
|
21
20
|
}
|
|
22
|
-
})
|
|
23
|
-
updateRoute: (route) => set(
|
|
21
|
+
}),
|
|
22
|
+
updateRoute: (route) => set((state) => {
|
|
24
23
|
state.routes[route.id].route = route;
|
|
25
24
|
const isFailed = route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
26
25
|
if (isFailed) {
|
|
@@ -36,8 +35,8 @@ export const useRouteStore = create()(persist((set) => ({
|
|
|
36
35
|
if (isLoading) {
|
|
37
36
|
state.routes[route.id].status = 'loading';
|
|
38
37
|
}
|
|
39
|
-
})
|
|
40
|
-
restartRoute: (routeId) => set(
|
|
38
|
+
}),
|
|
39
|
+
restartRoute: (routeId) => set((state) => {
|
|
41
40
|
state.routes[routeId].route.steps.forEach((step) => {
|
|
42
41
|
var _a, _b;
|
|
43
42
|
const stepHasFailed = ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED';
|
|
@@ -50,22 +49,13 @@ export const useRouteStore = create()(persist((set) => ({
|
|
|
50
49
|
}
|
|
51
50
|
});
|
|
52
51
|
state.routes[routeId].status = 'loading';
|
|
53
|
-
})
|
|
54
|
-
removeRoute: (routeId) => set(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
59
|
-
}), {
|
|
52
|
+
}),
|
|
53
|
+
removeRoute: (routeId) => set((state) => {
|
|
54
|
+
// TODO: handle immediate removal
|
|
55
|
+
// delete state.routes[routeId];
|
|
56
|
+
state.routes[routeId].status = 'idle';
|
|
57
|
+
}),
|
|
58
|
+
})), {
|
|
60
59
|
name: 'li.fi-widget-executable-routes',
|
|
61
60
|
partialize: (state) => ({ routes: state.routes }),
|
|
62
61
|
}));
|
|
63
|
-
export const useSetExecutableRoute = () => {
|
|
64
|
-
return useRouteStore((state) => state.setExecutableRoute);
|
|
65
|
-
};
|
|
66
|
-
export const useExecutingRoutes = () => {
|
|
67
|
-
return useRouteStore((state) => Object.values(state.routes).filter((route) => route.status === 'loading' || route.status === 'error'));
|
|
68
|
-
};
|
|
69
|
-
export const useCurrentRoute = () => {
|
|
70
|
-
return useRouteStore((state) => [state.currentRoute, state.setCurrentRoute], shallow);
|
|
71
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSetExecutableRoute: () => (route: import("@lifinance/types").Route) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Bridge, Exchange, Order } from '@lifinance/sdk';
|
|
2
|
+
import { Appearance } from '../../types';
|
|
3
|
+
export declare type ValueSetter<S> = <K extends keyof S>(key: K, value: S[Extract<K, string>]) => void;
|
|
4
|
+
export declare type ValuesSetter<S> = <K extends keyof S>(values: Record<K, S[Extract<K, string>]>) => void;
|
|
5
|
+
export declare type SettingsToolType = 'Bridges' | 'Exchanges';
|
|
6
|
+
export declare const SettingsToolTypes: SettingsToolType[];
|
|
7
|
+
export interface SettingsState {
|
|
8
|
+
advancedPreferences: boolean;
|
|
9
|
+
appearance: Appearance;
|
|
10
|
+
routePriority: Order;
|
|
11
|
+
slippage: string;
|
|
12
|
+
gasPrice: string;
|
|
13
|
+
enabledBridges?: string[];
|
|
14
|
+
_enabledBridges?: Record<string, boolean>;
|
|
15
|
+
enabledExchanges?: string[];
|
|
16
|
+
_enabledExchanges?: Record<string, boolean>;
|
|
17
|
+
}
|
|
18
|
+
export interface SettingsStore extends SettingsState {
|
|
19
|
+
setValue: ValueSetter<SettingsState>;
|
|
20
|
+
setValues: ValuesSetter<SettingsState>;
|
|
21
|
+
initializeTools(toolType: SettingsToolType, tools: string[]): void;
|
|
22
|
+
setTools(toolType: SettingsToolType, tools: string[], availableTools: (Pick<Bridge, 'key'> | Pick<Exchange, 'key'>)[]): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SettingsToolTypes = ['Bridges', 'Exchanges'];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import shallow from 'zustand/shallow';
|
|
2
|
+
import { useSettingsStore } from './useSettingsStore';
|
|
3
|
+
export const useAppearance = () => {
|
|
4
|
+
const [appearance, setValue] = useSettingsStore((state) => [state.appearance, state.setValue], shallow);
|
|
5
|
+
const setAppearance = (appearance) => setValue('appearance', appearance);
|
|
6
|
+
return [appearance, setAppearance];
|
|
7
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import shallow from 'zustand/shallow';
|
|
2
|
+
import { useSettingsStore } from './useSettingsStore';
|
|
3
|
+
export const useSettings = (keys) => {
|
|
4
|
+
return useSettingsStore((state) => keys.reduce((values, key) => {
|
|
5
|
+
values[key] = state[key];
|
|
6
|
+
return values;
|
|
7
|
+
}, {}), shallow);
|
|
8
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SettingsState, SettingsStore } from './types';
|
|
2
|
+
export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
|
|
3
|
+
persist: {
|
|
4
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, {
|
|
5
|
+
setValue: import("./types").ValueSetter<SettingsState>;
|
|
6
|
+
setValues: import("./types").ValuesSetter<SettingsState>;
|
|
7
|
+
initializeTools(toolType: import("./types").SettingsToolType, tools: string[]): void;
|
|
8
|
+
setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifinance/types").Bridge, "key"> | Pick<import("@lifinance/types").Exchange, "key">)[]): void;
|
|
9
|
+
advancedPreferences: boolean;
|
|
10
|
+
appearance: import("../..").Appearance;
|
|
11
|
+
routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
|
|
12
|
+
slippage: string;
|
|
13
|
+
gasPrice: string;
|
|
14
|
+
_enabledBridges?: Record<string, boolean> | undefined;
|
|
15
|
+
_enabledExchanges?: Record<string, boolean> | undefined;
|
|
16
|
+
}>>) => void;
|
|
17
|
+
clearStorage: () => void;
|
|
18
|
+
rehydrate: () => Promise<void>;
|
|
19
|
+
hasHydrated: () => boolean;
|
|
20
|
+
onHydrate: (fn: (state: SettingsStore) => void) => () => void;
|
|
21
|
+
onFinishHydration: (fn: (state: SettingsStore) => void) => () => void;
|
|
22
|
+
};
|
|
23
|
+
}, "setState"> & {
|
|
24
|
+
setState(nextStateOrUpdater: SettingsStore | Partial<SettingsStore> | ((state: import("immer/dist/internal").WritableDraft<SettingsStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
25
|
+
}>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
/* eslint-disable no-underscore-dangle */
|
|
13
|
+
import create from 'zustand';
|
|
14
|
+
import { persist } from 'zustand/middleware';
|
|
15
|
+
import { immer } from 'zustand/middleware/immer';
|
|
16
|
+
import { SettingsToolTypes } from './types';
|
|
17
|
+
export const useSettingsStore = create()(persist(immer((set) => ({
|
|
18
|
+
advancedPreferences: false,
|
|
19
|
+
appearance: 'auto',
|
|
20
|
+
gasPrice: 'normal',
|
|
21
|
+
routePriority: 'RECOMMENDED',
|
|
22
|
+
slippage: '3',
|
|
23
|
+
setValue: (key, value) => set((state) => {
|
|
24
|
+
state[key] = value;
|
|
25
|
+
}),
|
|
26
|
+
setValues: (values) => set((state) => {
|
|
27
|
+
for (const key in values) {
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(state, key)) {
|
|
29
|
+
state[key] = values[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}),
|
|
33
|
+
initializeTools: (toolType, tools) => set((state) => {
|
|
34
|
+
if (!tools.length) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (state[`_enabled${toolType}`]) {
|
|
38
|
+
state[`_enabled${toolType}`] = tools
|
|
39
|
+
.filter((tool) => !Object.prototype.hasOwnProperty.call(state._enabledBridges, tool))
|
|
40
|
+
.reduce((values, tool) => {
|
|
41
|
+
values[tool] = true;
|
|
42
|
+
return values;
|
|
43
|
+
}, state[`_enabled${toolType}`]);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
state[`_enabled${toolType}`] = tools.reduce((values, tool) => {
|
|
47
|
+
values[tool] = true;
|
|
48
|
+
return values;
|
|
49
|
+
}, {});
|
|
50
|
+
}
|
|
51
|
+
state[`enabled${toolType}`] = Object.entries(state[`_enabled${toolType}`])
|
|
52
|
+
.filter(([_, value]) => value)
|
|
53
|
+
.map(([key]) => key);
|
|
54
|
+
}),
|
|
55
|
+
setTools: (toolType, tools, availableTools) => set((state) => {
|
|
56
|
+
state[`enabled${toolType}`] = tools;
|
|
57
|
+
state[`_enabled${toolType}`] = availableTools.reduce((values, tool) => {
|
|
58
|
+
values[tool.key] = tools.includes(tool.key);
|
|
59
|
+
return values;
|
|
60
|
+
}, {});
|
|
61
|
+
}),
|
|
62
|
+
})), {
|
|
63
|
+
name: 'li.fi-widget-settings',
|
|
64
|
+
version: 1,
|
|
65
|
+
partialize: (state) => {
|
|
66
|
+
const { enabledBridges, enabledExchanges } = state, partializedState = __rest(state, ["enabledBridges", "enabledExchanges"]);
|
|
67
|
+
return partializedState;
|
|
68
|
+
},
|
|
69
|
+
merge: (persistedState, currentState) => {
|
|
70
|
+
const state = Object.assign(Object.assign({}, currentState), persistedState);
|
|
71
|
+
SettingsToolTypes.forEach((toolType) => {
|
|
72
|
+
state[`enabled${toolType}`] = Object.entries(persistedState[`_enabled${toolType}`])
|
|
73
|
+
.filter(([_, value]) => value)
|
|
74
|
+
.map(([key]) => key);
|
|
75
|
+
});
|
|
76
|
+
return state;
|
|
77
|
+
},
|
|
78
|
+
migrate: (persistedState, version) => {
|
|
79
|
+
if (version === 0 && persistedState.appearance === 'system') {
|
|
80
|
+
persistedState.appearance = 'auto';
|
|
81
|
+
}
|
|
82
|
+
return persistedState;
|
|
83
|
+
},
|
|
84
|
+
}));
|
package/types/widget.d.ts
CHANGED
|
@@ -9,33 +9,41 @@ export declare type ThemeConfig = {
|
|
|
9
9
|
shape?: Shape;
|
|
10
10
|
typography?: TypographyOptions;
|
|
11
11
|
};
|
|
12
|
-
export interface
|
|
12
|
+
export interface WidgetWalletCallbacks {
|
|
13
|
+
connect(): Signer;
|
|
14
|
+
disconnect(): void;
|
|
15
|
+
provideSigner(): Signer;
|
|
16
|
+
switchChain(): Signer;
|
|
17
|
+
addToken(): void;
|
|
18
|
+
}
|
|
19
|
+
interface WidgetConfigBase {
|
|
13
20
|
fromAmount?: number;
|
|
14
|
-
fromChain?: `${ChainKey}` | number;
|
|
15
|
-
fromToken?: string;
|
|
16
|
-
toChain?: `${ChainKey}` | number;
|
|
17
|
-
toToken?: string;
|
|
18
21
|
disabledChains?: number[];
|
|
19
|
-
disableInternalWalletManagement?: boolean;
|
|
20
|
-
walletCallbacks?: {
|
|
21
|
-
connect: {
|
|
22
|
-
(): Signer;
|
|
23
|
-
};
|
|
24
|
-
disconnect: {
|
|
25
|
-
(): void;
|
|
26
|
-
};
|
|
27
|
-
provideSigner: {
|
|
28
|
-
(): Signer;
|
|
29
|
-
};
|
|
30
|
-
switchChain: {
|
|
31
|
-
(): Signer;
|
|
32
|
-
};
|
|
33
|
-
addToken: {
|
|
34
|
-
(): void;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
22
|
containerStyle?: CSSProperties;
|
|
38
23
|
theme?: ThemeConfig;
|
|
39
24
|
appearance?: Appearance;
|
|
40
25
|
disableAppearance?: boolean;
|
|
41
26
|
}
|
|
27
|
+
declare type WidgetFromTokenConfig = {
|
|
28
|
+
fromChain: `${ChainKey}` | number;
|
|
29
|
+
fromToken?: string;
|
|
30
|
+
} | {
|
|
31
|
+
fromChain?: never;
|
|
32
|
+
fromToken?: never;
|
|
33
|
+
};
|
|
34
|
+
declare type WidgetToTokenConfig = {
|
|
35
|
+
toChain: `${ChainKey}` | number;
|
|
36
|
+
toToken?: string;
|
|
37
|
+
} | {
|
|
38
|
+
toChain?: never;
|
|
39
|
+
toToken?: never;
|
|
40
|
+
};
|
|
41
|
+
declare type WidgetWalletManagementConfig = {
|
|
42
|
+
disableInternalWalletManagement: true;
|
|
43
|
+
walletCallbacks: WidgetWalletCallbacks;
|
|
44
|
+
} | {
|
|
45
|
+
disableInternalWalletManagement?: false;
|
|
46
|
+
walletCallbacks?: never;
|
|
47
|
+
};
|
|
48
|
+
export declare type WidgetConfig = WidgetConfigBase & WidgetFromTokenConfig & WidgetToTokenConfig & WidgetWalletManagementConfig;
|
|
49
|
+
export {};
|
package/utils/format.d.ts
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* @returns formatted amount.
|
|
5
5
|
*/
|
|
6
6
|
export declare const formatTokenAmount: (amount?: string, decimals?: number) => string;
|
|
7
|
-
export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string
|
|
7
|
+
export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string;
|
|
8
8
|
export declare const formatAmount: (amount?: string, returnInitial?: boolean) => string;
|
|
9
9
|
export declare const formatTokenPrice: (amount?: string, price?: string) => number;
|
package/utils/format.js
CHANGED
|
@@ -30,7 +30,7 @@ export const formatSlippage = (slippage = '', defaultValue = '', returnInitial =
|
|
|
30
30
|
}
|
|
31
31
|
const parsedSlippage = parseFloat(slippage);
|
|
32
32
|
if (isNaN(Number(slippage)) && !isNaN(parsedSlippage)) {
|
|
33
|
-
return parsedSlippage;
|
|
33
|
+
return parsedSlippage.toString();
|
|
34
34
|
}
|
|
35
35
|
if (isNaN(parsedSlippage)) {
|
|
36
36
|
return defaultValue;
|
package/utils/routes.d.ts
CHANGED
package/utils/routes.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export const routes = {
|
|
2
2
|
home: '/',
|
|
3
|
-
selectWallet: '
|
|
4
|
-
settings: '
|
|
5
|
-
fromToken: '
|
|
6
|
-
toToken: '
|
|
7
|
-
swapRoutes: '
|
|
8
|
-
swap: '
|
|
3
|
+
selectWallet: 'select-wallet',
|
|
4
|
+
settings: 'settings',
|
|
5
|
+
fromToken: 'select-from-token',
|
|
6
|
+
toToken: 'select-to-token',
|
|
7
|
+
swapRoutes: 'swap-routes',
|
|
8
|
+
swap: 'swap',
|
|
9
9
|
};
|
|
10
|
+
export const routesValues = Object.values(routes);
|
package/hooks/useBridges.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useBridges: () => string[];
|