@lifi/widget 1.26.1 → 1.26.3

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.
Files changed (73) hide show
  1. package/AppDrawer.style.d.ts +1 -1
  2. package/cjs/AppDrawer.style.d.ts +1 -1
  3. package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +1 -1
  4. package/cjs/components/BottomSheet/BottomSheet.js +1 -1
  5. package/cjs/components/Header/Header.style.d.ts +1 -1
  6. package/cjs/components/Header/useHeaderActionStore.d.ts +1 -3
  7. package/cjs/components/Header/useHeaderActionStore.js +8 -9
  8. package/cjs/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
  9. package/cjs/components/SendToWallet/SendToWallet.js +1 -1
  10. package/cjs/components/SendToWallet/SendToWallet.style.d.ts +1 -1
  11. package/cjs/components/SendToWallet/store.d.ts +1 -3
  12. package/cjs/components/SendToWallet/store.js +5 -6
  13. package/cjs/components/Step/StepProcess.style.d.ts +1 -1
  14. package/cjs/components/SwapInput/SwapInput.style.d.ts +1 -1
  15. package/cjs/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
  16. package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
  17. package/cjs/config/version.d.ts +1 -1
  18. package/cjs/config/version.js +1 -1
  19. package/cjs/hooks/useRouteExecution.js +2 -0
  20. package/cjs/hooks/useWidgetEvents.d.ts +2 -2
  21. package/cjs/hooks/useWidgetEvents.js +3 -4
  22. package/cjs/index.d.ts +1 -1
  23. package/cjs/index.js +2 -1
  24. package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
  25. package/cjs/pages/SwapPage/ExchangeRateBottomSheet.d.ts +1 -1
  26. package/cjs/pages/SwapPage/ExchangeRateBottomSheet.js +11 -4
  27. package/cjs/pages/SwapPage/SwapPage.js +1 -1
  28. package/cjs/pages/SwapPage/TokenValueBottomSheet.js +3 -3
  29. package/cjs/stores/chains/useChainOrderStore.d.ts +1 -3
  30. package/cjs/stores/chains/useChainOrderStore.js +28 -17
  31. package/cjs/stores/routes/useRecommendedRouteStore.d.ts +1 -3
  32. package/cjs/stores/routes/useRecommendedRouteStore.js +6 -7
  33. package/cjs/stores/routes/useRouteExecutionStore.d.ts +1 -3
  34. package/cjs/stores/routes/useRouteExecutionStore.js +75 -47
  35. package/cjs/stores/settings/useSettingsStore.d.ts +1 -3
  36. package/cjs/stores/settings/useSettingsStore.js +36 -31
  37. package/components/ActiveSwaps/ActiveSwaps.style.d.ts +1 -1
  38. package/components/BottomSheet/BottomSheet.js +2 -2
  39. package/components/Header/Header.style.d.ts +1 -1
  40. package/components/Header/useHeaderActionStore.d.ts +1 -3
  41. package/components/Header/useHeaderActionStore.js +8 -9
  42. package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
  43. package/components/SendToWallet/SendToWallet.js +1 -1
  44. package/components/SendToWallet/SendToWallet.style.d.ts +1 -1
  45. package/components/SendToWallet/store.d.ts +1 -3
  46. package/components/SendToWallet/store.js +5 -6
  47. package/components/Step/StepProcess.style.d.ts +1 -1
  48. package/components/SwapInput/SwapInput.style.d.ts +1 -1
  49. package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
  50. package/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
  51. package/config/version.d.ts +1 -1
  52. package/config/version.js +1 -1
  53. package/hooks/useRouteExecution.js +3 -1
  54. package/hooks/useWidgetEvents.d.ts +2 -2
  55. package/hooks/useWidgetEvents.js +2 -3
  56. package/index.d.ts +1 -1
  57. package/index.js +1 -1
  58. package/package.json +9 -10
  59. package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
  60. package/pages/SwapPage/ExchangeRateBottomSheet.d.ts +1 -1
  61. package/pages/SwapPage/ExchangeRateBottomSheet.js +12 -5
  62. package/pages/SwapPage/StatusBottomSheet.js +3 -3
  63. package/pages/SwapPage/SwapPage.js +2 -2
  64. package/pages/SwapPage/TokenValueBottomSheet.js +4 -4
  65. package/stores/chains/useChainOrderStore.d.ts +1 -3
  66. package/stores/chains/useChainOrderStore.js +28 -17
  67. package/stores/routes/useRecommendedRouteStore.d.ts +1 -3
  68. package/stores/routes/useRecommendedRouteStore.js +6 -7
  69. package/stores/routes/useRouteExecutionStore.d.ts +1 -3
  70. package/stores/routes/useRouteExecutionStore.js +75 -47
  71. package/stores/settings/useSettingsStore.d.ts +1 -3
  72. package/stores/settings/useSettingsStore.js +36 -31
  73. package/tsconfig.cjs.tsbuildinfo +1 -1
@@ -1,16 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /* eslint-disable consistent-return */
3
- import { Done as DoneIcon, ErrorRounded as ErrorIcon, InfoRounded as InfoIcon, WarningRounded as WarningIcon } from '@mui/icons-material';
3
+ import { Done as DoneIcon, ErrorRounded as ErrorIcon, InfoRounded as InfoIcon, WarningRounded as WarningIcon, } from '@mui/icons-material';
4
4
  import { Box, Button, Typography } from '@mui/material';
5
5
  import { useEffect, useRef } from 'react';
6
6
  import { useFormContext } from 'react-hook-form';
7
7
  import { useTranslation } from 'react-i18next';
8
8
  import { BottomSheet } from '../../components/BottomSheet';
9
9
  import { Token } from '../../components/Token';
10
- import { getProcessMessage, useChains, useNavigateBack, useTokenBalance } from '../../hooks';
10
+ import { getProcessMessage, useChains, useNavigateBack, useTokenBalance, } from '../../hooks';
11
11
  import { SwapFormKey } from '../../providers';
12
12
  import { RouteExecutionStatus } from '../../stores';
13
- import { formatTokenAmount, hasEnumFlag, navigationRoutes, shortenWalletAddress } from '../../utils';
13
+ import { formatTokenAmount, hasEnumFlag, navigationRoutes, shortenWalletAddress, } from '../../utils';
14
14
  import { IconCircle, IconContainer } from './StatusBottomSheet.style';
15
15
  export const StatusBottomSheet = ({ status, route, }) => {
16
16
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
@@ -23,7 +23,7 @@ import { RouteExecutionStatus } from '../../stores';
23
23
  import { ExchangeRateBottomSheet } from './ExchangeRateBottomSheet';
24
24
  import { StatusBottomSheet } from './StatusBottomSheet';
25
25
  import { Container } from './SwapPage.style';
26
- import { getTokenValueLossThreshold, TokenValueBottomSheet } from './TokenValueBottomSheet';
26
+ import { getTokenValueLossThreshold, TokenValueBottomSheet, } from './TokenValueBottomSheet';
27
27
  export const SwapPage = () => {
28
28
  var _a;
29
29
  const { t } = useTranslation();
@@ -79,5 +79,5 @@ export const SwapPage = () => {
79
79
  enableLoading: true }), status === RouteExecutionStatus.Failed ? (_jsx(Tooltip, Object.assign({ title: t('button.removeSwap'), placement: "bottom-end", enterDelay: 400, arrow: true }, { children: _jsx(Button, Object.assign({ onClick: handleRemoveRoute, sx: {
80
80
  minWidth: 48,
81
81
  marginLeft: 1,
82
- } }, { children: _jsx(DeleteIcon, {}) })) }))) : null] }))] })) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null, route ? (_jsx(TokenValueBottomSheet, { route: route, ref: tokenValueBottomSheetRef, onContinue: handleExecuteRoute })) : null, route ? _jsx(ExchangeRateBottomSheet, { ref: exchangeRateBottomSheetRef }) : null] }));
82
+ } }, { children: _jsx(DeleteIcon, {}) })) }))) : null] }))] })) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null, route ? (_jsx(TokenValueBottomSheet, { route: route, ref: tokenValueBottomSheetRef, onContinue: handleExecuteRoute })) : null, route ? (_jsx(ExchangeRateBottomSheet, { ref: exchangeRateBottomSheetRef })) : null] }));
83
83
  };
@@ -2,18 +2,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { WarningRounded as WarningIcon } from '@mui/icons-material';
3
3
  import { Box, Button, Typography } from '@mui/material';
4
4
  import Big from 'big.js';
5
- import { forwardRef, useCallback, useRef } from 'react';
5
+ import { forwardRef, useRef } from 'react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { BottomSheet } from '../../components/BottomSheet';
8
8
  import { useSetContentHeight } from '../../hooks';
9
9
  import { IconCircle, IconContainer } from './StatusBottomSheet.style';
10
10
  export const TokenValueBottomSheet = forwardRef(({ route, onContinue, onCancel }, ref) => {
11
- const handleCancel = useCallback(() => {
11
+ const handleCancel = () => {
12
12
  var _a;
13
13
  (_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
14
14
  onCancel === null || onCancel === void 0 ? void 0 : onCancel();
15
- }, []);
16
- return (_jsx(BottomSheet, Object.assign({ ref: ref, onClose: handleCancel }, { children: _jsx(TokenValueBottomSheetContent, { route: route, onContinue: onContinue, onCancel: handleCancel }) })));
15
+ };
16
+ return (_jsx(BottomSheet, Object.assign({ ref: ref, onClose: onCancel }, { children: _jsx(TokenValueBottomSheetContent, { route: route, onContinue: onContinue, onCancel: handleCancel }) })));
17
17
  });
18
18
  const TokenValueBottomSheetContent = ({ route, onCancel, onContinue, }) => {
19
19
  const { t } = useTranslation();
@@ -1,6 +1,6 @@
1
1
  import type { ChainOrderStore } from './types';
2
2
  export declare const maxChainToOrder = 9;
3
- export declare const useChainOrderStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<ChainOrderStore>, "persist"> & {
3
+ export declare const useChainOrderStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<ChainOrderStore>, "persist"> & {
4
4
  persist: {
5
5
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ChainOrderStore, {
6
6
  chainOrder: number[];
@@ -14,6 +14,4 @@ export declare const useChainOrderStore: import("zustand").UseBoundStore<Omit<Om
14
14
  chainOrder: number[];
15
15
  }>>;
16
16
  };
17
- }, "setState"> & {
18
- setState(nextStateOrUpdater: ChainOrderStore | Partial<ChainOrderStore> | ((state: import("immer/dist/internal").WritableDraft<ChainOrderStore>) => void), shouldReplace?: boolean | undefined): void;
19
17
  }>;
@@ -1,38 +1,49 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
2
  import create from 'zustand';
3
3
  import { persist } from 'zustand/middleware';
4
- import { immer } from 'zustand/middleware/immer';
5
4
  export const maxChainToOrder = 9;
6
- export const useChainOrderStore = create()(persist(immer((set, get) => ({
5
+ export const useChainOrderStore = create()(persist((set, get) => ({
7
6
  chainOrder: [],
8
7
  availableChains: [],
9
8
  initializeChains: (chainIds) => {
10
9
  set((state) => {
11
- state.availableChains = chainIds;
12
- state.chainOrder = state.chainOrder.filter((chainId) => chainIds.includes(chainId));
13
- const chainsToAdd = chainIds.filter((chainId) => !state.chainOrder.includes(chainId));
14
- if (state.chainOrder.length === maxChainToOrder ||
15
- !chainsToAdd.length) {
16
- return;
10
+ const chainOrder = state.chainOrder.filter((chainId) => chainIds.includes(chainId));
11
+ const chainsToAdd = chainIds.filter((chainId) => !chainOrder.includes(chainId));
12
+ if (chainOrder.length === maxChainToOrder || !chainsToAdd.length) {
13
+ return {
14
+ availableChains: chainIds,
15
+ chainOrder,
16
+ };
17
17
  }
18
- const chainsToAddLength = maxChainToOrder - state.chainOrder.length;
18
+ const chainsToAddLength = maxChainToOrder - chainOrder.length;
19
19
  for (let index = 0; index < chainsToAddLength; index++) {
20
- state.chainOrder.push(chainsToAdd[index]);
20
+ chainOrder.push(chainsToAdd[index]);
21
21
  }
22
+ return {
23
+ availableChains: chainIds,
24
+ chainOrder,
25
+ };
22
26
  });
23
27
  return get().chainOrder;
24
28
  },
25
- setChain: (chainId) => set((state) => {
29
+ setChain: (chainId) => {
30
+ const state = get();
26
31
  if (state.chainOrder.includes(chainId) ||
27
32
  !state.availableChains.includes(chainId)) {
28
33
  return;
29
34
  }
30
- state.chainOrder.unshift(chainId);
31
- if (state.chainOrder.length > maxChainToOrder) {
32
- state.chainOrder.pop();
33
- }
34
- }),
35
- })), {
35
+ set((state) => {
36
+ const chainOrder = state.chainOrder.slice();
37
+ chainOrder.unshift(chainId);
38
+ if (chainOrder.length > maxChainToOrder) {
39
+ chainOrder.pop();
40
+ }
41
+ return {
42
+ chainOrder,
43
+ };
44
+ });
45
+ },
46
+ }), {
36
47
  name: 'li.fi-widget-chains-order',
37
48
  version: 0,
38
49
  partialize: (state) => ({ chainOrder: state.chainOrder }),
@@ -1,4 +1,2 @@
1
1
  import type { RecommendedRouteStore } from './types';
2
- export declare const useRecommendedRouteStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<RecommendedRouteStore>, "setState"> & {
3
- setState(nextStateOrUpdater: RecommendedRouteStore | Partial<RecommendedRouteStore> | ((state: import("immer/dist/internal").WritableDraft<RecommendedRouteStore>) => void), shouldReplace?: boolean | undefined): void;
4
- }>;
2
+ export declare const useRecommendedRouteStore: import("zustand").UseBoundStore<import("zustand").StoreApi<RecommendedRouteStore>>;
@@ -1,9 +1,8 @@
1
1
  import create from 'zustand';
2
- import { immer } from 'zustand/middleware/immer';
3
- export const useRecommendedRouteStore = create()(immer((set) => ({
4
- setRecommendedRoute: (route) => {
5
- set((state) => {
6
- state.recommendedRoute = route;
7
- });
2
+ export const useRecommendedRouteStore = create((set) => ({
3
+ setRecommendedRoute: (recommendedRoute) => {
4
+ set(() => ({
5
+ recommendedRoute,
6
+ }));
8
7
  },
9
- })));
8
+ }));
@@ -1,5 +1,5 @@
1
1
  import type { RouteExecutionStore } from './types';
2
- export declare const useRouteExecutionStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<RouteExecutionStore>, "persist"> & {
2
+ export declare const useRouteExecutionStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<RouteExecutionStore>, "persist"> & {
3
3
  persist: {
4
4
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<RouteExecutionStore, {
5
5
  routes: Partial<Record<string, import("./types").RouteExecution>>;
@@ -13,6 +13,4 @@ export declare const useRouteExecutionStore: import("zustand").UseBoundStore<Omi
13
13
  routes: Partial<Record<string, import("./types").RouteExecution>>;
14
14
  }>>;
15
15
  };
16
- }, "setState"> & {
17
- setState(nextStateOrUpdater: RouteExecutionStore | Partial<RouteExecutionStore> | ((state: import("immer/dist/internal").WritableDraft<RouteExecutionStore>) => void), shouldReplace?: boolean | undefined): void;
18
16
  }>;
@@ -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(immer((set) => ({
6
+ export const useRouteExecutionStore = create()(persist((set, get) => ({
8
7
  routes: {},
9
- setExecutableRoute: (route) => set((state) => {
10
- if (!state.routes[route.id]) {
11
- // clean previous idle routes that were not executed
12
- Object.keys(state.routes)
13
- .filter((routeId) => { var _a; return ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === RouteExecutionStatus.Idle; })
14
- .forEach((routeId) => delete state.routes[routeId]);
15
- state.routes[route.id] = {
16
- route,
17
- status: RouteExecutionStatus.Idle,
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) => set((state) => {
22
- if (state.routes[route.id]) {
23
- state.routes[route.id].route = route;
24
- const isFailed = isRouteFailed(route);
25
- if (isFailed) {
26
- state.routes[route.id].status = RouteExecutionStatus.Failed;
27
- return;
28
- }
29
- const isDone = isRouteDone(route);
30
- if (isDone) {
31
- state.routes[route.id].status = RouteExecutionStatus.Done;
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
- else if (isRouteRefunded(route)) {
36
- state.routes[route.id].status |= RouteExecutionStatus.Refunded;
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
- return;
39
- }
40
- const isLoading = route.steps.some((step) => step.execution);
41
- if (isLoading) {
42
- state.routes[route.id].status = RouteExecutionStatus.Pending;
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) => set((state) => {
47
- state.routes[routeId].status = RouteExecutionStatus.Pending;
48
- }),
49
- deleteRoute: (routeId) => set((state) => {
50
- if (state.routes[routeId]) {
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.keys(state.routes)
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 = 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);
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 state.routes[routeId]);
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<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
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(immer((set) => (Object.assign(Object.assign({}, defaultSettings), { setValue: (key, value) => set((state) => {
28
- state[key] = value;
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
31
  if (Object.prototype.hasOwnProperty.call(state, key)) {
32
- state[key] = values[key];
32
+ updatedState[key] = values[key];
33
33
  }
34
34
  }
35
- }), initializeTools: (toolType, tools) => set((state) => {
35
+ return updatedState;
36
+ }), initializeTools: (toolType, tools) => {
36
37
  if (!tools.length) {
37
38
  return;
38
39
  }
39
- if (state[`_enabled${toolType}`]) {
40
- // Add a new tools
41
- const enabledTools = tools
42
- .filter((tool) => !Object.prototype.hasOwnProperty.call(state[`_enabled${toolType}`], tool))
43
- .reduce((values, tool) => {
44
- values[tool] = true;
45
- return values;
46
- }, state[`_enabled${toolType}`]);
47
- // Filter tools we no longer have
48
- state[`_enabled${toolType}`] = Object.fromEntries(Object.entries(enabledTools).filter(([key]) => tools.includes(key)));
49
- }
50
- else {
51
- state[`_enabled${toolType}`] = tools.reduce((values, tool) => {
52
- values[tool] = true;
53
- return values;
54
- }, {});
55
- }
56
- state[`enabled${toolType}`] = Object.entries(state[`_enabled${toolType}`])
57
- .filter(([_, value]) => value)
58
- .map(([key]) => key);
59
- }), setTools: (toolType, tools, availableTools) => set((state) => {
60
- state[`enabled${toolType}`] = tools;
61
- state[`_enabled${toolType}`] = availableTools.reduce((values, tool) => {
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.prototype.hasOwnProperty.call(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) => {