@lifi/widget 1.23.1 → 1.25.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/AppDrawer.style.d.ts +1 -1
- package/AppProvider.js +1 -1
- package/cjs/AppDrawer.style.d.ts +1 -1
- package/cjs/AppProvider.js +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwapItem.js +2 -1
- package/cjs/components/BottomSheet/types.d.ts +1 -1
- package/cjs/components/Card/Card.d.ts +2 -2
- package/cjs/components/Card/CardTitle.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.js +6 -1
- package/cjs/components/ChainSelect/useChainSelect.d.ts +3 -1
- package/cjs/components/ChainSelect/useChainSelect.js +12 -3
- package/cjs/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/cjs/components/StepActions/StepActions.js +2 -2
- package/cjs/components/SwapInput/FitInputText.d.ts +3 -0
- package/cjs/components/SwapInput/FitInputText.js +19 -0
- package/cjs/components/SwapInput/FormPriceHelperText.d.ts +1 -3
- package/cjs/components/SwapInput/FormPriceHelperText.js +1 -1
- package/cjs/components/SwapInput/SwapInput.js +12 -24
- package/cjs/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +3 -0
- package/cjs/components/SwapInput/{SwapInputAdornment.js → SwapInputEndAdornment.js} +3 -3
- package/cjs/components/SwapInput/SwapInputStartAdornment.d.ts +3 -0
- package/cjs/components/SwapInput/SwapInputStartAdornment.js +21 -0
- package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/cjs/components/SwapRoutes/SwapRoutes.style.d.ts +1 -1
- package/cjs/components/Token/Token.style.d.ts +1 -1
- package/cjs/components/TokenList/useTokenSelect.js +12 -9
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useGasSufficiency.js +1 -1
- package/cjs/hooks/useRouteExecution.js +1 -1
- package/cjs/hooks/useSwapRoutes.js +12 -9
- package/cjs/hooks/useTelemetry.js +3 -1
- package/cjs/hooks/useTools.d.ts +5 -2
- package/cjs/i18n/en.json +3 -1
- package/cjs/i18n/uk.json +11 -6
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +2 -1
- package/cjs/pages/SettingsPage/SlippageInput.js +2 -1
- package/cjs/pages/SwapHistoryPage/SwapHistoryItem.js +4 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.js +63 -15
- package/cjs/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.style.js +5 -2
- package/cjs/pages/SwapPage/SwapPage.js +8 -6
- package/cjs/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
- package/cjs/providers/I18nProvider/types.d.ts +5 -5
- package/cjs/providers/SwapFormProvider/FormUpdater.d.ts +5 -0
- package/cjs/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js} +24 -21
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +12 -7
- package/cjs/providers/SwapFormProvider/types.d.ts +2 -2
- package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -1
- package/cjs/providers/WalletProvider/WalletProvider.js +1 -2
- package/cjs/providers/WalletProvider/types.d.ts +3 -3
- package/cjs/providers/WidgetProvider/WidgetProvider.js +4 -0
- package/cjs/providers/WidgetProvider/types.d.ts +1 -1
- package/cjs/stores/routes/types.d.ts +8 -1
- package/cjs/stores/routes/types.js +10 -0
- package/cjs/stores/routes/useExecutingRoutesIds.js +3 -1
- package/cjs/stores/routes/useRouteExecutionStore.js +53 -18
- package/cjs/stores/routes/useSwapHistory.js +4 -1
- package/cjs/stores/routes/utils.d.ts +3 -1
- package/cjs/stores/routes/utils.js +12 -4
- package/cjs/stores/settings/types.d.ts +6 -6
- package/cjs/stores/settings/useSettingsStore.d.ts +12 -9
- package/cjs/stores/settings/useSettingsStore.js +22 -5
- package/cjs/types/events.d.ts +1 -1
- package/cjs/types/widget.d.ts +13 -8
- package/cjs/utils/enum.d.ts +1 -0
- package/cjs/utils/enum.js +5 -0
- package/cjs/utils/index.d.ts +1 -0
- package/cjs/utils/index.js +1 -0
- package/cjs/utils/navigationRoutes.d.ts +1 -1
- package/components/ActiveSwaps/ActiveSwapItem.js +2 -1
- package/components/BottomSheet/types.d.ts +1 -1
- package/components/Card/Card.d.ts +2 -2
- package/components/Card/CardTitle.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.js +6 -1
- package/components/ChainSelect/useChainSelect.d.ts +3 -1
- package/components/ChainSelect/useChainSelect.js +13 -4
- package/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/components/StepActions/StepActions.js +2 -2
- package/components/SwapInput/FitInputText.d.ts +3 -0
- package/components/SwapInput/FitInputText.js +16 -0
- package/components/SwapInput/FormPriceHelperText.d.ts +1 -3
- package/components/SwapInput/FormPriceHelperText.js +1 -1
- package/components/SwapInput/SwapInput.js +16 -28
- package/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/components/SwapInput/SwapInputEndAdornment.d.ts +3 -0
- package/components/SwapInput/{SwapInputAdornment.js → SwapInputEndAdornment.js} +1 -1
- package/components/SwapInput/SwapInputStartAdornment.d.ts +3 -0
- package/components/SwapInput/SwapInputStartAdornment.js +17 -0
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/components/SwapRoutes/SwapRoutes.style.d.ts +1 -1
- package/components/Token/Token.style.d.ts +1 -1
- package/components/TokenList/useTokenSelect.js +13 -10
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useGasSufficiency.js +2 -2
- package/hooks/useRouteExecution.js +2 -2
- package/hooks/useSwapRoutes.js +12 -9
- package/hooks/useTelemetry.js +3 -1
- package/hooks/useTools.d.ts +5 -2
- package/i18n/en.json +3 -1
- package/i18n/uk.json +11 -6
- package/package.json +13 -13
- package/pages/SettingsPage/RoutePrioritySelect.js +2 -1
- package/pages/SettingsPage/SlippageInput.js +2 -1
- package/pages/SwapHistoryPage/SwapHistoryItem.js +4 -2
- package/pages/SwapPage/StatusBottomSheet.js +64 -16
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -2
- package/pages/SwapPage/StatusBottomSheet.style.js +5 -2
- package/pages/SwapPage/SwapPage.js +8 -6
- package/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
- package/providers/I18nProvider/types.d.ts +5 -5
- package/providers/SwapFormProvider/FormUpdater.d.ts +5 -0
- package/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js} +23 -20
- package/providers/SwapFormProvider/SwapFormProvider.js +12 -7
- package/providers/SwapFormProvider/types.d.ts +2 -2
- package/providers/WalletProvider/WalletProvider.d.ts +1 -1
- package/providers/WalletProvider/WalletProvider.js +2 -3
- package/providers/WalletProvider/types.d.ts +3 -3
- package/providers/WidgetProvider/WidgetProvider.js +5 -1
- package/providers/WidgetProvider/types.d.ts +1 -1
- package/stores/routes/types.d.ts +8 -1
- package/stores/routes/types.js +9 -1
- package/stores/routes/useExecutingRoutesIds.js +3 -1
- package/stores/routes/useRouteExecutionStore.js +51 -16
- package/stores/routes/useSwapHistory.js +4 -1
- package/stores/routes/utils.d.ts +3 -1
- package/stores/routes/utils.js +8 -2
- package/stores/settings/types.d.ts +6 -6
- package/stores/settings/useSettingsStore.d.ts +12 -9
- package/stores/settings/useSettingsStore.js +20 -4
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +1 -1
- package/types/widget.d.ts +13 -8
- package/utils/enum.d.ts +1 -0
- package/utils/enum.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/navigationRoutes.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputAdornment.d.ts +0 -3
- package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +0 -5
- package/components/SwapInput/SwapInputAdornment.d.ts +0 -3
- package/providers/WalletProvider/WalletFormUpdate.d.ts +0 -5
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import create from 'zustand';
|
|
2
2
|
import { persist } from 'zustand/middleware';
|
|
3
3
|
import { immer } from 'zustand/middleware/immer';
|
|
4
|
-
import {
|
|
4
|
+
import { hasEnumFlag } from '../../utils';
|
|
5
|
+
import { RouteExecutionStatus } from './types';
|
|
6
|
+
import { isRouteDone, isRouteFailed, isRoutePartiallyDone, isRouteRefunded, } from './utils';
|
|
5
7
|
export const useRouteExecutionStore = create()(persist(immer((set) => ({
|
|
6
8
|
routes: {},
|
|
7
9
|
setExecutableRoute: (route) => set((state) => {
|
|
8
10
|
if (!state.routes[route.id]) {
|
|
9
11
|
// clean previous idle routes that were not executed
|
|
10
12
|
Object.keys(state.routes)
|
|
11
|
-
.filter((routeId) => { var _a; return ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) ===
|
|
13
|
+
.filter((routeId) => { var _a; return ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === RouteExecutionStatus.Idle; })
|
|
12
14
|
.forEach((routeId) => delete state.routes[routeId]);
|
|
13
15
|
state.routes[route.id] = {
|
|
14
16
|
route,
|
|
15
|
-
status:
|
|
17
|
+
status: RouteExecutionStatus.Idle,
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
}),
|
|
@@ -21,22 +23,28 @@ export const useRouteExecutionStore = create()(persist(immer((set) => ({
|
|
|
21
23
|
state.routes[route.id].route = route;
|
|
22
24
|
const isFailed = isRouteFailed(route);
|
|
23
25
|
if (isFailed) {
|
|
24
|
-
state.routes[route.id].status =
|
|
26
|
+
state.routes[route.id].status = RouteExecutionStatus.Failed;
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
|
-
const isDone =
|
|
29
|
+
const isDone = isRouteDone(route);
|
|
28
30
|
if (isDone) {
|
|
29
|
-
state.routes[route.id].status =
|
|
31
|
+
state.routes[route.id].status = RouteExecutionStatus.Done;
|
|
32
|
+
if (isRoutePartiallyDone(route)) {
|
|
33
|
+
state.routes[route.id].status |= RouteExecutionStatus.Partial;
|
|
34
|
+
}
|
|
35
|
+
else if (isRouteRefunded(route)) {
|
|
36
|
+
state.routes[route.id].status |= RouteExecutionStatus.Refunded;
|
|
37
|
+
}
|
|
30
38
|
return;
|
|
31
39
|
}
|
|
32
40
|
const isLoading = route.steps.some((step) => step.execution);
|
|
33
41
|
if (isLoading) {
|
|
34
|
-
state.routes[route.id].status =
|
|
42
|
+
state.routes[route.id].status = RouteExecutionStatus.Pending;
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
}),
|
|
38
46
|
restartRoute: (routeId) => set((state) => {
|
|
39
|
-
state.routes[routeId].status =
|
|
47
|
+
state.routes[routeId].status = RouteExecutionStatus.Pending;
|
|
40
48
|
}),
|
|
41
49
|
deleteRoute: (routeId) => set((state) => {
|
|
42
50
|
if (state.routes[routeId]) {
|
|
@@ -46,15 +54,16 @@ export const useRouteExecutionStore = create()(persist(immer((set) => ({
|
|
|
46
54
|
deleteRoutes: (type) => set((state) => {
|
|
47
55
|
Object.keys(state.routes)
|
|
48
56
|
.filter((routeId) => {
|
|
49
|
-
var _a, _b;
|
|
57
|
+
var _a, _b, _c, _d;
|
|
50
58
|
return type === 'completed'
|
|
51
|
-
? ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status)
|
|
52
|
-
: ((
|
|
59
|
+
? hasEnumFlag((_b = (_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 0, RouteExecutionStatus.Done)
|
|
60
|
+
: !hasEnumFlag((_d = (_c = state.routes[routeId]) === null || _c === void 0 ? void 0 : _c.status) !== null && _d !== void 0 ? _d : 0, RouteExecutionStatus.Done);
|
|
53
61
|
})
|
|
54
62
|
.forEach((routeId) => delete state.routes[routeId]);
|
|
55
63
|
}),
|
|
56
64
|
})), {
|
|
57
65
|
name: 'li.fi-widget-routes',
|
|
66
|
+
version: 1,
|
|
58
67
|
partialize: (state) => ({ routes: state.routes }),
|
|
59
68
|
merge: (persistedState, currentState) => {
|
|
60
69
|
const state = Object.assign(Object.assign({}, currentState), persistedState);
|
|
@@ -68,21 +77,21 @@ export const useRouteExecutionStore = create()(persist(immer((set) => ({
|
|
|
68
77
|
}
|
|
69
78
|
state.routes[route.id] = {
|
|
70
79
|
route,
|
|
71
|
-
status:
|
|
80
|
+
status: RouteExecutionStatus.Idle,
|
|
72
81
|
};
|
|
73
82
|
const isFailed = isRouteFailed(route);
|
|
74
83
|
if (isFailed) {
|
|
75
|
-
state.routes[route.id].status =
|
|
84
|
+
state.routes[route.id].status = RouteExecutionStatus.Failed;
|
|
76
85
|
return;
|
|
77
86
|
}
|
|
78
|
-
const isDone =
|
|
87
|
+
const isDone = isRouteDone(route);
|
|
79
88
|
if (isDone) {
|
|
80
|
-
state.routes[route.id].status =
|
|
89
|
+
state.routes[route.id].status = RouteExecutionStatus.Done;
|
|
81
90
|
return;
|
|
82
91
|
}
|
|
83
92
|
const isLoading = route.steps.some((step) => step.execution);
|
|
84
93
|
if (isLoading) {
|
|
85
|
-
state.routes[route.id].status =
|
|
94
|
+
state.routes[route.id].status = RouteExecutionStatus.Pending;
|
|
86
95
|
}
|
|
87
96
|
});
|
|
88
97
|
}
|
|
@@ -93,4 +102,30 @@ export const useRouteExecutionStore = create()(persist(immer((set) => ({
|
|
|
93
102
|
}
|
|
94
103
|
return state;
|
|
95
104
|
},
|
|
105
|
+
migrate: (persistedState, version) => {
|
|
106
|
+
if (version === 0) {
|
|
107
|
+
Object.values(persistedState.routes).forEach((route) => {
|
|
108
|
+
if (route) {
|
|
109
|
+
switch (route.status) {
|
|
110
|
+
case 'idle':
|
|
111
|
+
route.status = RouteExecutionStatus.Idle;
|
|
112
|
+
break;
|
|
113
|
+
case 'loading':
|
|
114
|
+
route.status = RouteExecutionStatus.Pending;
|
|
115
|
+
break;
|
|
116
|
+
case 'success':
|
|
117
|
+
case 'warning':
|
|
118
|
+
route.status = RouteExecutionStatus.Done;
|
|
119
|
+
break;
|
|
120
|
+
case 'error':
|
|
121
|
+
route.status = RouteExecutionStatus.Failed;
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return persistedState;
|
|
130
|
+
},
|
|
96
131
|
}));
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import shallow from 'zustand/shallow';
|
|
2
|
+
import { hasEnumFlag } from '../../utils';
|
|
3
|
+
import { RouteExecutionStatus } from './types';
|
|
2
4
|
import { useRouteExecutionStore } from './useRouteExecutionStore';
|
|
3
5
|
export const useSwapHistory = (address) => {
|
|
4
6
|
return useRouteExecutionStore((state) => Object.values(state.routes)
|
|
5
|
-
.filter((item) => (item === null || item === void 0 ? void 0 : item.route.fromAddress) === address &&
|
|
7
|
+
.filter((item) => (item === null || item === void 0 ? void 0 : item.route.fromAddress) === address &&
|
|
8
|
+
hasEnumFlag(item.status, RouteExecutionStatus.Done))
|
|
6
9
|
.sort((a, b) => {
|
|
7
10
|
var _a, _b, _c, _d;
|
|
8
11
|
return ((_b = (_a = b === null || b === void 0 ? void 0 : b.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0) -
|
package/stores/routes/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Process, Route } from '@lifi/sdk';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const isRouteDone: (route: Route) => boolean;
|
|
3
|
+
export declare const isRoutePartiallyDone: (route: Route) => boolean;
|
|
4
|
+
export declare const isRouteRefunded: (route: Route) => boolean;
|
|
3
5
|
export declare const isRouteFailed: (route: Route) => boolean;
|
|
4
6
|
export declare const isRouteActive: (route?: Route) => boolean;
|
|
5
7
|
export declare const getUpdatedProcess: (currentRoute: Route, updatedRoute: Route) => Process | undefined;
|
package/stores/routes/utils.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import microdiff from 'microdiff';
|
|
2
|
-
export const
|
|
2
|
+
export const isRouteDone = (route) => {
|
|
3
3
|
return route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
|
|
4
4
|
};
|
|
5
|
+
export const isRoutePartiallyDone = (route) => {
|
|
6
|
+
return route.steps.some((step) => { var _a; return (_a = step.execution) === null || _a === void 0 ? void 0 : _a.process.some((process) => process.substatus === 'PARTIAL'); });
|
|
7
|
+
};
|
|
8
|
+
export const isRouteRefunded = (route) => {
|
|
9
|
+
return route.steps.some((step) => { var _a; return (_a = step.execution) === null || _a === void 0 ? void 0 : _a.process.some((process) => process.substatus === 'REFUNDED'); });
|
|
10
|
+
};
|
|
5
11
|
export const isRouteFailed = (route) => {
|
|
6
12
|
return route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
7
13
|
};
|
|
@@ -9,7 +15,7 @@ export const isRouteActive = (route) => {
|
|
|
9
15
|
if (!route) {
|
|
10
16
|
return false;
|
|
11
17
|
}
|
|
12
|
-
const isDone =
|
|
18
|
+
const isDone = isRouteDone(route);
|
|
13
19
|
const isFailed = isRouteFailed(route);
|
|
14
20
|
const alreadyStarted = route.steps.some((step) => step.execution);
|
|
15
21
|
return !isDone && !isFailed && alreadyStarted;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Bridge, Exchange, Order } from '@lifi/sdk';
|
|
2
2
|
import type { Appearance } from '../../types';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
3
|
+
export type ValueSetter<S> = <K extends keyof S>(key: K, value: S[Extract<K, string>]) => void;
|
|
4
|
+
export type ValuesSetter<S> = <K extends keyof S>(values: Record<K, S[Extract<K, string>]>) => void;
|
|
5
|
+
export type SettingsToolType = 'Bridges' | 'Exchanges';
|
|
6
6
|
export declare const SettingsToolTypes: SettingsToolType[];
|
|
7
7
|
export interface SettingsState {
|
|
8
8
|
advancedPreferences: boolean;
|
|
9
9
|
appearance: Appearance;
|
|
10
|
-
gasPrice
|
|
10
|
+
gasPrice?: string;
|
|
11
11
|
language?: string;
|
|
12
|
-
routePriority
|
|
12
|
+
routePriority?: Order;
|
|
13
13
|
showDestinationWallet: boolean;
|
|
14
|
-
slippage
|
|
14
|
+
slippage?: string;
|
|
15
15
|
enabledBridges?: string[];
|
|
16
16
|
_enabledBridges?: Record<string, boolean>;
|
|
17
17
|
enabledExchanges?: string[];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { WidgetConfig } from '../../types';
|
|
1
2
|
import type { SettingsState, SettingsStore } from './types';
|
|
2
|
-
export declare const
|
|
3
|
+
export declare const defaultConfigurableSettings: Pick<SettingsState, 'routePriority' | 'slippage'>;
|
|
4
|
+
export declare const defaultSettings: SettingsState;
|
|
3
5
|
export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
|
|
4
6
|
persist: {
|
|
5
7
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, {
|
|
@@ -8,12 +10,12 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
|
|
|
8
10
|
initializeTools(toolType: import("./types").SettingsToolType, tools: string[]): void;
|
|
9
11
|
setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifi/types").Bridge, "key"> | Pick<import("@lifi/types").Exchange, "key">)[]): void;
|
|
10
12
|
advancedPreferences: boolean;
|
|
11
|
-
appearance: import("
|
|
12
|
-
gasPrice
|
|
13
|
+
appearance: import("../../types").Appearance;
|
|
14
|
+
gasPrice?: string | undefined;
|
|
13
15
|
language?: string | undefined;
|
|
14
|
-
routePriority
|
|
16
|
+
routePriority?: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST" | undefined;
|
|
15
17
|
showDestinationWallet: boolean;
|
|
16
|
-
slippage
|
|
18
|
+
slippage?: string | undefined;
|
|
17
19
|
_enabledBridges?: Record<string, boolean> | undefined;
|
|
18
20
|
_enabledExchanges?: Record<string, boolean> | undefined;
|
|
19
21
|
}>>) => void;
|
|
@@ -28,12 +30,12 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
|
|
|
28
30
|
initializeTools(toolType: import("./types").SettingsToolType, tools: string[]): void;
|
|
29
31
|
setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifi/types").Bridge, "key"> | Pick<import("@lifi/types").Exchange, "key">)[]): void;
|
|
30
32
|
advancedPreferences: boolean;
|
|
31
|
-
appearance: import("
|
|
32
|
-
gasPrice
|
|
33
|
+
appearance: import("../../types").Appearance;
|
|
34
|
+
gasPrice?: string | undefined;
|
|
33
35
|
language?: string | undefined;
|
|
34
|
-
routePriority
|
|
36
|
+
routePriority?: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST" | undefined;
|
|
35
37
|
showDestinationWallet: boolean;
|
|
36
|
-
slippage
|
|
38
|
+
slippage?: string | undefined;
|
|
37
39
|
_enabledBridges?: Record<string, boolean> | undefined;
|
|
38
40
|
_enabledExchanges?: Record<string, boolean> | undefined;
|
|
39
41
|
}>>;
|
|
@@ -41,3 +43,4 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
|
|
|
41
43
|
}, "setState"> & {
|
|
42
44
|
setState(nextStateOrUpdater: SettingsStore | Partial<SettingsStore> | ((state: import("immer/dist/internal").WritableDraft<SettingsStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
43
45
|
}>;
|
|
46
|
+
export declare const setDefaultSettings: (config?: WidgetConfig) => void;
|
|
@@ -14,11 +14,13 @@ import create from 'zustand';
|
|
|
14
14
|
import { persist } from 'zustand/middleware';
|
|
15
15
|
import { immer } from 'zustand/middleware/immer';
|
|
16
16
|
import { SettingsToolTypes } from './types';
|
|
17
|
+
export const defaultConfigurableSettings = {
|
|
18
|
+
routePriority: 'RECOMMENDED',
|
|
19
|
+
slippage: '0.5',
|
|
20
|
+
};
|
|
17
21
|
export const defaultSettings = {
|
|
18
22
|
appearance: 'auto',
|
|
19
23
|
gasPrice: 'normal',
|
|
20
|
-
routePriority: 'RECOMMENDED',
|
|
21
|
-
slippage: '0.5',
|
|
22
24
|
advancedPreferences: false,
|
|
23
25
|
showDestinationWallet: true,
|
|
24
26
|
};
|
|
@@ -78,11 +80,25 @@ export const useSettingsStore = create()(persist(immer((set) => (Object.assign(O
|
|
|
78
80
|
},
|
|
79
81
|
migrate: (persistedState, version) => {
|
|
80
82
|
if (version === 0 && persistedState.appearance === 'system') {
|
|
81
|
-
persistedState.appearance =
|
|
83
|
+
persistedState.appearance = defaultSettings.appearance;
|
|
82
84
|
}
|
|
83
85
|
if (version === 1) {
|
|
84
|
-
persistedState.slippage =
|
|
86
|
+
persistedState.slippage = defaultConfigurableSettings.slippage;
|
|
85
87
|
}
|
|
86
88
|
return persistedState;
|
|
87
89
|
},
|
|
88
90
|
}));
|
|
91
|
+
export const setDefaultSettings = (config) => {
|
|
92
|
+
var _a, _b, _c, _d, _e;
|
|
93
|
+
const { slippage, routePriority, setValue } = useSettingsStore.getState();
|
|
94
|
+
const defaultSlippage = ((config === null || config === void 0 ? void 0 : config.slippage) ||
|
|
95
|
+
((_b = (_a = config === null || config === void 0 ? void 0 : config.sdkConfig) === null || _a === void 0 ? void 0 : _a.defaultRouteOptions) === null || _b === void 0 ? void 0 : _b.slippage) ||
|
|
96
|
+
0) * 100;
|
|
97
|
+
const defaultRoutePriority = (config === null || config === void 0 ? void 0 : config.routePriority) || ((_d = (_c = config === null || config === void 0 ? void 0 : config.sdkConfig) === null || _c === void 0 ? void 0 : _c.defaultRouteOptions) === null || _d === void 0 ? void 0 : _d.order);
|
|
98
|
+
if (!slippage) {
|
|
99
|
+
setValue('slippage', (_e = (defaultSlippage || defaultConfigurableSettings.slippage)) === null || _e === void 0 ? void 0 : _e.toString());
|
|
100
|
+
}
|
|
101
|
+
if (!routePriority) {
|
|
102
|
+
setValue('routePriority', defaultRoutePriority || defaultConfigurableSettings.routePriority);
|
|
103
|
+
}
|
|
104
|
+
};
|