@lifi/widget 1.1.3 → 1.2.2
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 +9 -1
- package/components/Header/WalletHeader.js +18 -2
- package/components/Initializer.d.ts +2 -0
- package/components/Initializer.js +5 -0
- package/components/StepToken.js +1 -1
- package/components/SwapButton/SwapButton.js +14 -3
- 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 +6 -6
- 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/WalletProvider/WalletProvider.js +74 -13
- package/providers/WalletProvider/types.d.ts +2 -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 +34 -24
- 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
|
@@ -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();
|
|
@@ -20,45 +20,97 @@ const initialContext = {
|
|
|
20
20
|
switchChain: stub,
|
|
21
21
|
addChain: stub,
|
|
22
22
|
addToken: stub,
|
|
23
|
+
attemptEagerConnect: stub,
|
|
23
24
|
account: {},
|
|
24
25
|
};
|
|
25
26
|
const WalletContext = createContext(initialContext);
|
|
26
27
|
export const useWallet = () => useContext(WalletContext);
|
|
27
28
|
export const WalletProvider = ({ children }) => {
|
|
29
|
+
var _a;
|
|
28
30
|
const config = useWidgetConfig();
|
|
29
31
|
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, } = useLifiWalletManagement();
|
|
30
32
|
const [account, setAccount] = useState({});
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
var _a;
|
|
35
|
+
console.log('walletProvider: signer changed', (_a = config.externalWalletManagementSettings) === null || _a === void 0 ? void 0 : _a.signer);
|
|
36
|
+
const updateSigner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
var _b;
|
|
38
|
+
const account = yield extractAccountFromSigner((_b = config.externalWalletManagementSettings) === null || _b === void 0 ? void 0 : _b.signer);
|
|
39
|
+
setAccount(account);
|
|
40
|
+
console.log('walletProvider: signer changed account', account);
|
|
41
|
+
});
|
|
42
|
+
updateSigner();
|
|
43
|
+
}, [(_a = config.externalWalletManagementSettings) === null || _a === void 0 ? void 0 : _a.signer]);
|
|
31
44
|
const connect = useCallback((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
45
|
if (config.disableInternalWalletManagement) {
|
|
33
|
-
|
|
46
|
+
const signer = yield config.externalWalletManagementSettings.connect();
|
|
47
|
+
const account = yield extractAccountFromSigner(signer);
|
|
48
|
+
setAccount(account);
|
|
34
49
|
return;
|
|
35
50
|
}
|
|
36
51
|
yield walletManagementConnect(wallet);
|
|
37
|
-
}), [
|
|
52
|
+
}), [
|
|
53
|
+
config.disableInternalWalletManagement,
|
|
54
|
+
config.externalWalletManagementSettings,
|
|
55
|
+
walletManagementConnect,
|
|
56
|
+
]);
|
|
38
57
|
const disconnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
58
|
if (config.disableInternalWalletManagement) {
|
|
59
|
+
yield config.externalWalletManagementSettings.disconnect();
|
|
40
60
|
setAccount({});
|
|
61
|
+
return;
|
|
41
62
|
}
|
|
42
63
|
yield walletManagementDisconnect();
|
|
43
|
-
}), [
|
|
64
|
+
}), [
|
|
65
|
+
config.disableInternalWalletManagement,
|
|
66
|
+
config.externalWalletManagementSettings,
|
|
67
|
+
walletManagementDisconnect,
|
|
68
|
+
]);
|
|
44
69
|
// only for injected wallets
|
|
45
70
|
const switchChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
71
|
if (config.disableInternalWalletManagement) {
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
const signer = yield config.externalWalletManagementSettings.switchChain(chainId);
|
|
73
|
+
const account = yield extractAccountFromSigner(signer);
|
|
74
|
+
setAccount(account);
|
|
49
75
|
}
|
|
50
76
|
return walletSwitchChain(chainId);
|
|
51
|
-
}), [
|
|
77
|
+
}), [
|
|
78
|
+
config.disableInternalWalletManagement,
|
|
79
|
+
config.externalWalletManagementSettings,
|
|
80
|
+
]);
|
|
52
81
|
const addChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
-
if (
|
|
54
|
-
|
|
82
|
+
if (config.disableInternalWalletManagement) {
|
|
83
|
+
return config.externalWalletManagementSettings.addChain(chainId);
|
|
55
84
|
}
|
|
56
|
-
|
|
85
|
+
return walletAddChain(chainId);
|
|
86
|
+
}), [
|
|
87
|
+
config.disableInternalWalletManagement,
|
|
88
|
+
config.externalWalletManagementSettings,
|
|
89
|
+
]);
|
|
57
90
|
const addToken = useCallback((chainId, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
-
if (
|
|
59
|
-
|
|
91
|
+
if (config.disableInternalWalletManagement) {
|
|
92
|
+
return config.externalWalletManagementSettings.addToken(token, chainId);
|
|
93
|
+
}
|
|
94
|
+
return switchChainAndAddToken(chainId, token);
|
|
95
|
+
}), [
|
|
96
|
+
config.disableInternalWalletManagement,
|
|
97
|
+
config.externalWalletManagementSettings,
|
|
98
|
+
]);
|
|
99
|
+
const attemptEagerConnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
if (config.disableInternalWalletManagement) {
|
|
101
|
+
try {
|
|
102
|
+
const signer = yield config.externalWalletManagementSettings.provideSigner();
|
|
103
|
+
const account = yield extractAccountFromSigner(signer);
|
|
104
|
+
setAccount(() => (Object.assign({}, account)));
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
console.warn('attempted eagerconnect', e);
|
|
108
|
+
}
|
|
60
109
|
}
|
|
61
|
-
}), [
|
|
110
|
+
}), [
|
|
111
|
+
config.disableInternalWalletManagement,
|
|
112
|
+
config.externalWalletManagementSettings,
|
|
113
|
+
]);
|
|
62
114
|
// keep account information up to date
|
|
63
115
|
useEffect(() => {
|
|
64
116
|
const updateAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -75,8 +127,17 @@ export const WalletProvider = ({ children }) => {
|
|
|
75
127
|
switchChain,
|
|
76
128
|
addChain,
|
|
77
129
|
addToken,
|
|
130
|
+
attemptEagerConnect,
|
|
78
131
|
account,
|
|
79
|
-
}), [
|
|
132
|
+
}), [
|
|
133
|
+
account,
|
|
134
|
+
addChain,
|
|
135
|
+
addToken,
|
|
136
|
+
connect,
|
|
137
|
+
disconnect,
|
|
138
|
+
switchChain,
|
|
139
|
+
attemptEagerConnect,
|
|
140
|
+
]);
|
|
80
141
|
return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
81
142
|
};
|
|
82
143
|
const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -3,11 +3,12 @@ import { Token } from '@lifinance/sdk';
|
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
export interface WalletContextProps {
|
|
5
5
|
account: WalletAccount;
|
|
6
|
-
addChain(chainId: number): Promise<
|
|
6
|
+
addChain(chainId: number): Promise<boolean>;
|
|
7
7
|
addToken(chainId: number, token: Token): Promise<void>;
|
|
8
8
|
disconnect(): void;
|
|
9
9
|
switchChain(chainId: number): Promise<boolean>;
|
|
10
10
|
connect(wallet?: Wallet | undefined): Promise<void>;
|
|
11
|
+
attemptEagerConnect(): Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
export interface WalletAccount {
|
|
13
14
|
address?: string;
|
|
@@ -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
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
|
+
}));
|