@lifi/widget 1.26.2 → 1.26.4
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/cjs/AppDrawer.style.d.ts +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +1 -1
- package/cjs/components/Header/Header.style.d.ts +1 -1
- package/cjs/components/Header/useHeaderActionStore.d.ts +1 -3
- package/cjs/components/Header/useHeaderActionStore.js +8 -9
- package/cjs/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
- package/cjs/components/SendToWallet/SendToWallet.js +1 -1
- package/cjs/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/cjs/components/SendToWallet/store.d.ts +1 -3
- package/cjs/components/SendToWallet/store.js +5 -6
- package/cjs/components/Step/StepProcess.style.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
- package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useWidgetEvents.d.ts +2 -2
- package/cjs/hooks/useWidgetEvents.js +3 -4
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +2 -1
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/cjs/providers/SDKProvider/SDKProvider.js +4 -3
- package/cjs/stores/chains/useChainOrderStore.d.ts +1 -3
- package/cjs/stores/chains/useChainOrderStore.js +28 -17
- package/cjs/stores/routes/useRecommendedRouteStore.d.ts +1 -3
- package/cjs/stores/routes/useRecommendedRouteStore.js +6 -7
- package/cjs/stores/routes/useRouteExecutionStore.d.ts +1 -3
- package/cjs/stores/routes/useRouteExecutionStore.js +75 -47
- package/cjs/stores/settings/useSettingsStore.d.ts +1 -3
- package/cjs/stores/settings/useSettingsStore.js +37 -32
- package/cjs/types/widget.d.ts +1 -0
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +1 -1
- package/components/Header/Header.style.d.ts +1 -1
- package/components/Header/useHeaderActionStore.d.ts +1 -3
- package/components/Header/useHeaderActionStore.js +8 -9
- package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
- package/components/SendToWallet/SendToWallet.js +1 -1
- package/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/components/SendToWallet/store.d.ts +1 -3
- package/components/SendToWallet/store.js +5 -6
- package/components/Step/StepProcess.style.d.ts +1 -1
- package/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useWidgetEvents.d.ts +2 -2
- package/hooks/useWidgetEvents.js +2 -3
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +9 -10
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/providers/SDKProvider/SDKProvider.js +4 -3
- package/stores/chains/useChainOrderStore.d.ts +1 -3
- package/stores/chains/useChainOrderStore.js +28 -17
- package/stores/routes/useRecommendedRouteStore.d.ts +1 -3
- package/stores/routes/useRecommendedRouteStore.js +6 -7
- package/stores/routes/useRouteExecutionStore.d.ts +1 -3
- package/stores/routes/useRouteExecutionStore.js +75 -47
- package/stores/settings/useSettingsStore.d.ts +1 -3
- package/stores/settings/useSettingsStore.js +37 -32
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +1 -0
|
@@ -1,67 +1,95 @@
|
|
|
1
1
|
import create from 'zustand';
|
|
2
2
|
import { persist } from 'zustand/middleware';
|
|
3
|
-
import { immer } from 'zustand/middleware/immer';
|
|
4
3
|
import { hasEnumFlag } from '../../utils';
|
|
5
4
|
import { RouteExecutionStatus } from './types';
|
|
6
5
|
import { isRouteDone, isRouteFailed, isRoutePartiallyDone, isRouteRefunded, } from './utils';
|
|
7
|
-
export const useRouteExecutionStore = create()(persist(
|
|
6
|
+
export const useRouteExecutionStore = create()(persist((set, get) => ({
|
|
8
7
|
routes: {},
|
|
9
|
-
setExecutableRoute: (route) =>
|
|
10
|
-
if (!
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
setExecutableRoute: (route) => {
|
|
9
|
+
if (!get().routes[route.id]) {
|
|
10
|
+
set((state) => {
|
|
11
|
+
const routes = Object.assign({}, state.routes);
|
|
12
|
+
// clean previous idle routes that were not executed
|
|
13
|
+
Object.keys(routes)
|
|
14
|
+
.filter((routeId) => { var _a; return ((_a = routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === RouteExecutionStatus.Idle; })
|
|
15
|
+
.forEach((routeId) => delete routes[routeId]);
|
|
16
|
+
routes[route.id] = {
|
|
17
|
+
route,
|
|
18
|
+
status: RouteExecutionStatus.Idle,
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
routes,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
19
24
|
}
|
|
20
|
-
}
|
|
21
|
-
updateRoute: (route) =>
|
|
22
|
-
if (
|
|
23
|
-
state
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (isRoutePartiallyDone(route)) {
|
|
33
|
-
state.routes[route.id].status |= RouteExecutionStatus.Partial;
|
|
25
|
+
},
|
|
26
|
+
updateRoute: (route) => {
|
|
27
|
+
if (get().routes[route.id]) {
|
|
28
|
+
set((state) => {
|
|
29
|
+
const updatedState = {
|
|
30
|
+
routes: Object.assign(Object.assign({}, state.routes), { [route.id]: Object.assign(Object.assign({}, state.routes[route.id]), { route }) }),
|
|
31
|
+
};
|
|
32
|
+
const isFailed = isRouteFailed(route);
|
|
33
|
+
if (isFailed) {
|
|
34
|
+
updatedState.routes[route.id].status =
|
|
35
|
+
RouteExecutionStatus.Failed;
|
|
36
|
+
return updatedState;
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
const isDone = isRouteDone(route);
|
|
39
|
+
if (isDone) {
|
|
40
|
+
updatedState.routes[route.id].status = RouteExecutionStatus.Done;
|
|
41
|
+
if (isRoutePartiallyDone(route)) {
|
|
42
|
+
updatedState.routes[route.id].status |=
|
|
43
|
+
RouteExecutionStatus.Partial;
|
|
44
|
+
}
|
|
45
|
+
else if (isRouteRefunded(route)) {
|
|
46
|
+
updatedState.routes[route.id].status |=
|
|
47
|
+
RouteExecutionStatus.Refunded;
|
|
48
|
+
}
|
|
49
|
+
return updatedState;
|
|
37
50
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
const isLoading = route.steps.some((step) => step.execution);
|
|
52
|
+
if (isLoading) {
|
|
53
|
+
updatedState.routes[route.id].status =
|
|
54
|
+
RouteExecutionStatus.Pending;
|
|
55
|
+
}
|
|
56
|
+
return updatedState;
|
|
57
|
+
});
|
|
44
58
|
}
|
|
45
|
-
}
|
|
46
|
-
restartRoute: (routeId) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
delete state.routes[routeId];
|
|
59
|
+
},
|
|
60
|
+
restartRoute: (routeId) => {
|
|
61
|
+
if (get().routes[routeId]) {
|
|
62
|
+
set((state) => ({
|
|
63
|
+
routes: Object.assign(Object.assign({}, state.routes), { [routeId]: Object.assign(Object.assign({}, state.routes[routeId]), { status: RouteExecutionStatus.Pending }) }),
|
|
64
|
+
}));
|
|
52
65
|
}
|
|
53
|
-
}
|
|
66
|
+
},
|
|
67
|
+
deleteRoute: (routeId) => {
|
|
68
|
+
if (get().routes[routeId]) {
|
|
69
|
+
set((state) => {
|
|
70
|
+
const routes = Object.assign({}, state.routes);
|
|
71
|
+
delete routes[routeId];
|
|
72
|
+
return {
|
|
73
|
+
routes,
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
},
|
|
54
78
|
deleteRoutes: (type) => set((state) => {
|
|
55
|
-
Object.
|
|
79
|
+
const routes = Object.assign({}, state.routes);
|
|
80
|
+
Object.keys(routes)
|
|
56
81
|
.filter((routeId) => {
|
|
57
82
|
var _a, _b, _c, _d;
|
|
58
83
|
return type === 'completed'
|
|
59
|
-
? hasEnumFlag((_b = (_a =
|
|
60
|
-
: !hasEnumFlag((_d = (_c =
|
|
84
|
+
? hasEnumFlag((_b = (_a = routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 0, RouteExecutionStatus.Done)
|
|
85
|
+
: !hasEnumFlag((_d = (_c = routes[routeId]) === null || _c === void 0 ? void 0 : _c.status) !== null && _d !== void 0 ? _d : 0, RouteExecutionStatus.Done);
|
|
61
86
|
})
|
|
62
|
-
.forEach((routeId) => delete
|
|
87
|
+
.forEach((routeId) => delete routes[routeId]);
|
|
88
|
+
return {
|
|
89
|
+
routes,
|
|
90
|
+
};
|
|
63
91
|
}),
|
|
64
|
-
})
|
|
92
|
+
}), {
|
|
65
93
|
name: 'li.fi-widget-routes',
|
|
66
94
|
version: 1,
|
|
67
95
|
partialize: (state) => ({ routes: state.routes }),
|
|
@@ -2,7 +2,7 @@ import type { WidgetConfig } from '../../types';
|
|
|
2
2
|
import type { SettingsState, SettingsStore } from './types';
|
|
3
3
|
export declare const defaultConfigurableSettings: Pick<SettingsState, 'routePriority' | 'slippage'>;
|
|
4
4
|
export declare const defaultSettings: SettingsState;
|
|
5
|
-
export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<
|
|
5
|
+
export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
|
|
6
6
|
persist: {
|
|
7
7
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, {
|
|
8
8
|
setValue: import("./types").ValueSetter<SettingsState>;
|
|
@@ -40,7 +40,5 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
|
|
|
40
40
|
_enabledExchanges?: Record<string, boolean> | undefined;
|
|
41
41
|
}>>;
|
|
42
42
|
};
|
|
43
|
-
}, "setState"> & {
|
|
44
|
-
setState(nextStateOrUpdater: SettingsStore | Partial<SettingsStore> | ((state: import("immer/dist/internal").WritableDraft<SettingsStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
45
43
|
}>;
|
|
46
44
|
export declare const setDefaultSettings: (config?: WidgetConfig) => void;
|
|
@@ -12,7 +12,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
/* eslint-disable no-underscore-dangle */
|
|
13
13
|
import create from 'zustand';
|
|
14
14
|
import { persist } from 'zustand/middleware';
|
|
15
|
-
import { immer } from 'zustand/middleware/immer';
|
|
16
15
|
import { SettingsToolTypes } from './types';
|
|
17
16
|
export const defaultConfigurableSettings = {
|
|
18
17
|
routePriority: 'RECOMMENDED',
|
|
@@ -24,45 +23,51 @@ export const defaultSettings = {
|
|
|
24
23
|
advancedPreferences: false,
|
|
25
24
|
showDestinationWallet: true,
|
|
26
25
|
};
|
|
27
|
-
export const useSettingsStore = create()(persist(
|
|
28
|
-
|
|
29
|
-
}), setValues: (values) => set((state) => {
|
|
26
|
+
export const useSettingsStore = create()(persist((set) => (Object.assign(Object.assign({}, defaultSettings), { setValue: (key, value) => set(() => ({
|
|
27
|
+
[key]: value,
|
|
28
|
+
})), setValues: (values) => set((state) => {
|
|
29
|
+
const updatedState = Object.assign({}, state);
|
|
30
30
|
for (const key in values) {
|
|
31
|
-
if (Object.
|
|
32
|
-
|
|
31
|
+
if (Object.hasOwn(state, key)) {
|
|
32
|
+
updatedState[key] = values[key];
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
return updatedState;
|
|
36
|
+
}), initializeTools: (toolType, tools) => {
|
|
36
37
|
if (!tools.length) {
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
set((state) => {
|
|
41
|
+
const updatedState = Object.assign({}, state);
|
|
42
|
+
if (updatedState[`_enabled${toolType}`]) {
|
|
43
|
+
// Add a new tools
|
|
44
|
+
const enabledTools = tools
|
|
45
|
+
.filter((tool) => !Object.hasOwn(updatedState[`_enabled${toolType}`], tool))
|
|
46
|
+
.reduce((values, tool) => {
|
|
47
|
+
values[tool] = true;
|
|
48
|
+
return values;
|
|
49
|
+
}, updatedState[`_enabled${toolType}`]);
|
|
50
|
+
// Filter tools we no longer have
|
|
51
|
+
updatedState[`_enabled${toolType}`] = Object.fromEntries(Object.entries(enabledTools).filter(([key]) => tools.includes(key)));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
updatedState[`_enabled${toolType}`] = tools.reduce((values, tool) => {
|
|
55
|
+
values[tool] = true;
|
|
56
|
+
return values;
|
|
57
|
+
}, {});
|
|
58
|
+
}
|
|
59
|
+
updatedState[`enabled${toolType}`] = Object.entries(updatedState[`_enabled${toolType}`])
|
|
60
|
+
.filter(([_, value]) => value)
|
|
61
|
+
.map(([key]) => key);
|
|
62
|
+
return updatedState;
|
|
63
|
+
});
|
|
64
|
+
}, setTools: (toolType, tools, availableTools) => set(() => ({
|
|
65
|
+
[`enabled${toolType}`]: tools,
|
|
66
|
+
[`_enabled${toolType}`]: availableTools.reduce((values, tool) => {
|
|
62
67
|
values[tool.key] = tools.includes(tool.key);
|
|
63
68
|
return values;
|
|
64
|
-
}, {})
|
|
65
|
-
}) }))
|
|
69
|
+
}, {}),
|
|
70
|
+
})) })), {
|
|
66
71
|
name: 'li.fi-widget-settings',
|
|
67
72
|
version: 2,
|
|
68
73
|
partialize: (state) => {
|