@lifi/widget 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/App.js +2 -1
  2. package/components/Initializer.d.ts +2 -0
  3. package/components/Initializer.js +5 -0
  4. package/components/StepToken.js +1 -1
  5. package/components/SwapButton/SwapButton.js +5 -2
  6. package/components/SwapInProgress/SwapInProgress.js +1 -1
  7. package/components/SwapRoutes/SwapRoutes.js +2 -1
  8. package/components/TextFitter/TextFitter.js +9 -5
  9. package/hooks/index.d.ts +1 -3
  10. package/hooks/index.js +1 -3
  11. package/hooks/useHasSufficientBalance.js +1 -1
  12. package/hooks/useInitializer.d.ts +1 -0
  13. package/hooks/useInitializer.js +5 -0
  14. package/hooks/{useRouteExecution/useRouteExecution.d.ts → useRouteExecution.d.ts} +1 -1
  15. package/hooks/{useRouteExecution/useRouteExecution.js → useRouteExecution.js} +5 -5
  16. package/hooks/useSwapRoutes.js +9 -7
  17. package/hooks/useTools.d.ts +1 -0
  18. package/hooks/useTools.js +14 -0
  19. package/i18n/en/translation.json +0 -2
  20. package/i18n/index.d.ts +0 -2
  21. package/package.json +5 -5
  22. package/pages/SettingsPage/AdvancedPreferences.js +5 -4
  23. package/pages/SettingsPage/ColorSchemeButtonGroup.js +1 -1
  24. package/pages/SettingsPage/EnabledBridgesSelect.js +11 -6
  25. package/pages/SettingsPage/EnabledExchangesSelect.js +10 -6
  26. package/pages/SettingsPage/GasPriceSelect.js +4 -4
  27. package/pages/SettingsPage/RoutePrioritySelect.js +4 -4
  28. package/pages/SettingsPage/SlippageInput.js +7 -10
  29. package/pages/SwapPage/ExecutionItem.js +1 -1
  30. package/pages/SwapPage/StatusBottomSheet.d.ts +1 -1
  31. package/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
  32. package/pages/SwapPage/StepItem.js +1 -1
  33. package/pages/SwapPage/StepTimer.js +3 -2
  34. package/pages/SwapRoutesPage/SwapRoutesPage.js +2 -1
  35. package/providers/SwapFormProvider/SwapFormProvider.d.ts +0 -3
  36. package/providers/SwapFormProvider/SwapFormProvider.js +0 -3
  37. package/providers/SwapFormProvider/types.d.ts +0 -19
  38. package/providers/SwapFormProvider/types.js +0 -9
  39. package/providers/ThemeProvider/ThemeProvider.js +1 -1
  40. package/providers/WidgetProvider/types.d.ts +2 -2
  41. package/stores/index.d.ts +2 -0
  42. package/stores/index.js +2 -0
  43. package/stores/route/index.d.ts +5 -0
  44. package/stores/route/index.js +5 -0
  45. package/{hooks/useRouteExecution → stores/route}/types.d.ts +0 -0
  46. package/{hooks/useRouteExecution → stores/route}/types.js +0 -0
  47. package/stores/route/useCurrentRoute.d.ts +2 -0
  48. package/stores/route/useCurrentRoute.js +5 -0
  49. package/stores/route/useExecutingRoutes.d.ts +1 -0
  50. package/stores/route/useExecutingRoutes.js +4 -0
  51. package/{hooks/useRouteExecution → stores/route}/useRouteStore.d.ts +3 -5
  52. package/{hooks/useRouteExecution → stores/route}/useRouteStore.js +16 -26
  53. package/stores/route/useSetExecutableRoute.d.ts +1 -0
  54. package/stores/route/useSetExecutableRoute.js +4 -0
  55. package/stores/settings/index.d.ts +5 -0
  56. package/stores/settings/index.js +5 -0
  57. package/stores/settings/types.d.ts +23 -0
  58. package/stores/settings/types.js +1 -0
  59. package/stores/settings/useAppearance.d.ts +2 -0
  60. package/stores/settings/useAppearance.js +7 -0
  61. package/stores/settings/useSetSettings.d.ts +5 -0
  62. package/stores/settings/useSetSettings.js +5 -0
  63. package/stores/settings/useSettings.d.ts +2 -0
  64. package/stores/settings/useSettings.js +8 -0
  65. package/stores/settings/useSettingsStore.d.ts +25 -0
  66. package/stores/settings/useSettingsStore.js +84 -0
  67. package/types/widget.d.ts +31 -23
  68. package/utils/format.d.ts +1 -1
  69. package/utils/format.js +1 -1
  70. package/hooks/useBridges.d.ts +0 -1
  71. package/hooks/useBridges.js +0 -12
  72. package/hooks/useExchanges.d.ts +0 -1
  73. package/hooks/useExchanges.js +0 -12
  74. package/hooks/useRouteExecution/index.d.ts +0 -3
  75. package/hooks/useRouteExecution/index.js +0 -3
  76. package/hooks/useSettings/index.d.ts +0 -2
  77. package/hooks/useSettings/index.js +0 -2
  78. package/hooks/useSettings/types.d.ts +0 -5
  79. package/hooks/useSettings/types.js +0 -1
  80. package/hooks/useSettings/useSettingsStore.d.ts +0 -13
  81. package/hooks/useSettings/useSettingsStore.js +0 -22
  82. package/pages/MainPage/SendToRecipientForm.d.ts +0 -2
  83. package/pages/MainPage/SendToRecipientForm.js +0 -20
@@ -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 '../../hooks';
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();
@@ -1,8 +1,8 @@
1
1
  import { WidgetConfig } from '../../types';
2
- export interface WidgetContextProps extends WidgetConfig {
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
  }
@@ -0,0 +1,2 @@
1
+ export * from './route';
2
+ export * from './settings';
@@ -0,0 +1,2 @@
1
+ export * from './route';
2
+ export * from './settings';
@@ -0,0 +1,5 @@
1
+ export * from './types';
2
+ export * from './useCurrentRoute';
3
+ export * from './useExecutingRoutes';
4
+ export * from './useRouteStore';
5
+ export * from './useSetExecutableRoute';
@@ -0,0 +1,5 @@
1
+ export * from './types';
2
+ export * from './useCurrentRoute';
3
+ export * from './useExecutingRoutes';
4
+ export * from './useRouteStore';
5
+ export * from './useSetExecutableRoute';
@@ -0,0 +1,2 @@
1
+ import { Route } from '@lifinance/sdk';
2
+ export declare const useCurrentRoute: () => [Route | undefined, (route?: Route) => void];
@@ -0,0 +1,5 @@
1
+ import shallow from 'zustand/shallow';
2
+ import { useRouteStore } from './useRouteStore';
3
+ export const useCurrentRoute = () => {
4
+ return useRouteStore((state) => [state.currentRoute, state.setCurrentRoute], shallow);
5
+ };
@@ -0,0 +1 @@
1
+ export declare const useExecutingRoutes: () => import("./types").RouteExecution[];
@@ -0,0 +1,4 @@
1
+ import { useRouteStore } from './useRouteStore';
2
+ export const useExecutingRoutes = () => {
3
+ return useRouteStore((state) => Object.values(state.routes).filter((route) => route.status === 'loading' || route.status === 'error'));
4
+ };
@@ -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 shallow from 'zustand/shallow';
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(produce((state) => {
6
+ setCurrentRoute: (route) => set((state) => {
8
7
  state.currentRoute = route;
9
- })),
10
- setExecutableRoute: (route) => set(produce((state) => {
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(produce((state) => {
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(produce((state) => {
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(produce((state) => {
55
- if (state.routes[routeId]) {
56
- delete state.routes[routeId];
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,4 @@
1
+ import { useRouteStore } from './useRouteStore';
2
+ export const useSetExecutableRoute = () => {
3
+ return useRouteStore((state) => state.setExecutableRoute);
4
+ };
@@ -0,0 +1,5 @@
1
+ export * from './types';
2
+ export * from './useAppearance';
3
+ export * from './useSetSettings';
4
+ export * from './useSettings';
5
+ export * from './useSettingsStore';
@@ -0,0 +1,5 @@
1
+ export * from './types';
2
+ export * from './useAppearance';
3
+ export * from './useSetSettings';
4
+ export * from './useSettings';
5
+ export * from './useSettingsStore';
@@ -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,2 @@
1
+ import { Appearance } from '../../types';
2
+ export declare const useAppearance: () => [Appearance, (appearance: Appearance) => void];
@@ -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,5 @@
1
+ import { SettingsState, ValueSetter, ValuesSetter } from './types';
2
+ export declare const useSetSettings: () => [
3
+ ValueSetter<SettingsState>,
4
+ ValuesSetter<SettingsState>
5
+ ];
@@ -0,0 +1,5 @@
1
+ import shallow from 'zustand/shallow';
2
+ import { useSettingsStore } from './useSettingsStore';
3
+ export const useSetSettings = () => {
4
+ return useSettingsStore((state) => [state.setValue, state.setValues], shallow);
5
+ };
@@ -0,0 +1,2 @@
1
+ import { SettingsState } from '.';
2
+ export declare const useSettings: <K extends keyof SettingsState>(keys: K[]) => Pick<SettingsState, K>;
@@ -0,0 +1,8 @@
1
+ import shallow from 'zustand/shallow';
2
+ import { useSettingsStore } from './useSettingsStore';
3
+ export const useSettings = (keys) => {
4
+ return useSettingsStore((state) => keys.reduce((values, key) => {
5
+ values[key] = state[key];
6
+ return values;
7
+ }, {}), shallow);
8
+ };
@@ -0,0 +1,25 @@
1
+ import { SettingsState, SettingsStore } from './types';
2
+ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
3
+ persist: {
4
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, {
5
+ setValue: import("./types").ValueSetter<SettingsState>;
6
+ setValues: import("./types").ValuesSetter<SettingsState>;
7
+ initializeTools(toolType: import("./types").SettingsToolType, tools: string[]): void;
8
+ setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifinance/types").Bridge, "key"> | Pick<import("@lifinance/types").Exchange, "key">)[]): void;
9
+ advancedPreferences: boolean;
10
+ appearance: import("../..").Appearance;
11
+ routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
12
+ slippage: string;
13
+ gasPrice: string;
14
+ _enabledBridges?: Record<string, boolean> | undefined;
15
+ _enabledExchanges?: Record<string, boolean> | undefined;
16
+ }>>) => void;
17
+ clearStorage: () => void;
18
+ rehydrate: () => Promise<void>;
19
+ hasHydrated: () => boolean;
20
+ onHydrate: (fn: (state: SettingsStore) => void) => () => void;
21
+ onFinishHydration: (fn: (state: SettingsStore) => void) => () => void;
22
+ };
23
+ }, "setState"> & {
24
+ setState(nextStateOrUpdater: SettingsStore | Partial<SettingsStore> | ((state: import("immer/dist/internal").WritableDraft<SettingsStore>) => void), shouldReplace?: boolean | undefined): void;
25
+ }>;
@@ -0,0 +1,84 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ /* eslint-disable no-underscore-dangle */
13
+ import create from 'zustand';
14
+ import { persist } from 'zustand/middleware';
15
+ import { immer } from 'zustand/middleware/immer';
16
+ import { SettingsToolTypes } from './types';
17
+ export const useSettingsStore = create()(persist(immer((set) => ({
18
+ advancedPreferences: false,
19
+ appearance: 'auto',
20
+ gasPrice: 'normal',
21
+ routePriority: 'RECOMMENDED',
22
+ slippage: '3',
23
+ setValue: (key, value) => set((state) => {
24
+ state[key] = value;
25
+ }),
26
+ setValues: (values) => set((state) => {
27
+ for (const key in values) {
28
+ if (Object.prototype.hasOwnProperty.call(state, key)) {
29
+ state[key] = values[key];
30
+ }
31
+ }
32
+ }),
33
+ initializeTools: (toolType, tools) => set((state) => {
34
+ if (!tools.length) {
35
+ return;
36
+ }
37
+ if (state[`_enabled${toolType}`]) {
38
+ state[`_enabled${toolType}`] = tools
39
+ .filter((tool) => !Object.prototype.hasOwnProperty.call(state._enabledBridges, tool))
40
+ .reduce((values, tool) => {
41
+ values[tool] = true;
42
+ return values;
43
+ }, state[`_enabled${toolType}`]);
44
+ }
45
+ else {
46
+ state[`_enabled${toolType}`] = tools.reduce((values, tool) => {
47
+ values[tool] = true;
48
+ return values;
49
+ }, {});
50
+ }
51
+ state[`enabled${toolType}`] = Object.entries(state[`_enabled${toolType}`])
52
+ .filter(([_, value]) => value)
53
+ .map(([key]) => key);
54
+ }),
55
+ setTools: (toolType, tools, availableTools) => set((state) => {
56
+ state[`enabled${toolType}`] = tools;
57
+ state[`_enabled${toolType}`] = availableTools.reduce((values, tool) => {
58
+ values[tool.key] = tools.includes(tool.key);
59
+ return values;
60
+ }, {});
61
+ }),
62
+ })), {
63
+ name: 'li.fi-widget-settings',
64
+ version: 1,
65
+ partialize: (state) => {
66
+ const { enabledBridges, enabledExchanges } = state, partializedState = __rest(state, ["enabledBridges", "enabledExchanges"]);
67
+ return partializedState;
68
+ },
69
+ merge: (persistedState, currentState) => {
70
+ const state = Object.assign(Object.assign({}, currentState), persistedState);
71
+ SettingsToolTypes.forEach((toolType) => {
72
+ state[`enabled${toolType}`] = Object.entries(persistedState[`_enabled${toolType}`])
73
+ .filter(([_, value]) => value)
74
+ .map(([key]) => key);
75
+ });
76
+ return state;
77
+ },
78
+ migrate: (persistedState, version) => {
79
+ if (version === 0 && persistedState.appearance === 'system') {
80
+ persistedState.appearance = 'auto';
81
+ }
82
+ return persistedState;
83
+ },
84
+ }));
package/types/widget.d.ts CHANGED
@@ -9,33 +9,41 @@ export declare type ThemeConfig = {
9
9
  shape?: Shape;
10
10
  typography?: TypographyOptions;
11
11
  };
12
- export interface WidgetConfig {
12
+ export interface WidgetWalletCallbacks {
13
+ connect(): Signer;
14
+ disconnect(): void;
15
+ provideSigner(): Signer;
16
+ switchChain(): Signer;
17
+ addToken(): void;
18
+ }
19
+ interface WidgetConfigBase {
13
20
  fromAmount?: number;
14
- fromChain?: `${ChainKey}` | number;
15
- fromToken?: string;
16
- toChain?: `${ChainKey}` | number;
17
- toToken?: string;
18
21
  disabledChains?: number[];
19
- disableInternalWalletManagement?: boolean;
20
- walletCallbacks?: {
21
- connect: {
22
- (): Signer;
23
- };
24
- disconnect: {
25
- (): void;
26
- };
27
- provideSigner: {
28
- (): Signer;
29
- };
30
- switchChain: {
31
- (): Signer;
32
- };
33
- addToken: {
34
- (): void;
35
- };
36
- };
37
22
  containerStyle?: CSSProperties;
38
23
  theme?: ThemeConfig;
39
24
  appearance?: Appearance;
40
25
  disableAppearance?: boolean;
41
26
  }
27
+ declare type WidgetFromTokenConfig = {
28
+ fromChain: `${ChainKey}` | number;
29
+ fromToken?: string;
30
+ } | {
31
+ fromChain?: never;
32
+ fromToken?: never;
33
+ };
34
+ declare type WidgetToTokenConfig = {
35
+ toChain: `${ChainKey}` | number;
36
+ toToken?: string;
37
+ } | {
38
+ toChain?: never;
39
+ toToken?: never;
40
+ };
41
+ declare type WidgetWalletManagementConfig = {
42
+ disableInternalWalletManagement: true;
43
+ walletCallbacks: WidgetWalletCallbacks;
44
+ } | {
45
+ disableInternalWalletManagement?: false;
46
+ walletCallbacks?: never;
47
+ };
48
+ export declare type WidgetConfig = WidgetConfigBase & WidgetFromTokenConfig & WidgetToTokenConfig & WidgetWalletManagementConfig;
49
+ export {};
package/utils/format.d.ts CHANGED
@@ -4,6 +4,6 @@
4
4
  * @returns formatted amount.
5
5
  */
6
6
  export declare const formatTokenAmount: (amount?: string, decimals?: number) => string;
7
- export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string | number;
7
+ export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string;
8
8
  export declare const formatAmount: (amount?: string, returnInitial?: boolean) => string;
9
9
  export declare const formatTokenPrice: (amount?: string, price?: string) => number;
package/utils/format.js CHANGED
@@ -30,7 +30,7 @@ export const formatSlippage = (slippage = '', defaultValue = '', returnInitial =
30
30
  }
31
31
  const parsedSlippage = parseFloat(slippage);
32
32
  if (isNaN(Number(slippage)) && !isNaN(parsedSlippage)) {
33
- return parsedSlippage;
33
+ return parsedSlippage.toString();
34
34
  }
35
35
  if (isNaN(parsedSlippage)) {
36
36
  return defaultValue;
@@ -1 +0,0 @@
1
- export declare const useBridges: () => string[];
@@ -1,12 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { useQuery } from 'react-query';
3
- import { LiFi } from '../lifi';
4
- export const useBridges = () => {
5
- const { data } = useQuery(['bridges'], ({ signal }) => LiFi.getPossibilities({ include: ['bridges'] }, { signal }));
6
- const bridges = useMemo(() => {
7
- var _a;
8
- const bridges = (_a = data === null || data === void 0 ? void 0 : data.bridges) === null || _a === void 0 ? void 0 : _a.map((bridge) => bridge.tool).map((bridegTool) => bridegTool.split('-')[0]);
9
- return Array.from(new Set(bridges));
10
- }, [data === null || data === void 0 ? void 0 : data.bridges]);
11
- return bridges;
12
- };
@@ -1 +0,0 @@
1
- export declare const useExchanges: () => string[];
@@ -1,12 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { useQuery } from 'react-query';
3
- import { LiFi } from '../lifi';
4
- export const useExchanges = () => {
5
- const { data } = useQuery(['exchanges'], ({ signal }) => LiFi.getPossibilities({ include: ['exchanges'] }, { signal }));
6
- const exchanges = useMemo(() => {
7
- var _a;
8
- const exchanges = (_a = data === null || data === void 0 ? void 0 : data.exchanges) === null || _a === void 0 ? void 0 : _a.map((exchange) => exchange.tool).map((exchangeTool) => exchangeTool.split('-')[0]);
9
- return Array.from(new Set(exchanges));
10
- }, [data === null || data === void 0 ? void 0 : data.exchanges]);
11
- return exchanges;
12
- };
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './useRouteExecution';
3
- export * from './useRouteStore';
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './useRouteExecution';
3
- export * from './useRouteStore';
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './useSettingsStore';
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './useSettingsStore';
@@ -1,5 +0,0 @@
1
- import { Appearance } from '../../types';
2
- export interface SettingsStore {
3
- appearance: Appearance;
4
- setAppearance(appearance: Appearance): void;
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { Appearance } from '../../types';
2
- import { SettingsStore } from './types';
3
- export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
4
- persist: {
5
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, Partial<SettingsStore>>>) => void;
6
- clearStorage: () => void;
7
- rehydrate: () => Promise<void>;
8
- hasHydrated: () => boolean;
9
- onHydrate: (fn: (state: SettingsStore) => void) => () => void;
10
- onFinishHydration: (fn: (state: SettingsStore) => void) => () => void;
11
- };
12
- }>;
13
- export declare const useAppearance: () => [Appearance, (appearance: Appearance) => void];
@@ -1,22 +0,0 @@
1
- import produce from 'immer';
2
- import create from 'zustand';
3
- import { persist } from 'zustand/middleware';
4
- import shallow from 'zustand/shallow';
5
- export const useSettingsStore = create()(persist((set) => ({
6
- appearance: 'auto',
7
- setAppearance: (appearance) => set(produce((state) => {
8
- state.appearance = appearance;
9
- })),
10
- }), {
11
- name: 'li.fi-widget-settings',
12
- version: 1,
13
- migrate: (persistedState, version) => {
14
- if (version === 0 && persistedState.appearance === 'system') {
15
- persistedState.appearance = 'auto';
16
- }
17
- return persistedState;
18
- },
19
- }));
20
- export const useAppearance = () => {
21
- return useSettingsStore((state) => [state.appearance, state.setAppearance], shallow);
22
- };
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const SendToRecipientForm: React.FC;
@@ -1,20 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { HelpOutline as HelpOutlineIcon } from '@mui/icons-material';
3
- import { Box, Checkbox, FormControl, FormControlLabel, Typography, } from '@mui/material';
4
- import { useFormContext, useWatch } from 'react-hook-form';
5
- import { useTranslation } from 'react-i18next';
6
- import { Input } from '../../components/Input';
7
- import { Switch } from '../../components/Switch';
8
- import { SwapFormKey } from '../../providers/SwapFormProvider';
9
- export const SendToRecipientForm = () => {
10
- const { t } = useTranslation();
11
- const { register } = useFormContext();
12
- const sendToRecipientChecked = useWatch({
13
- name: SwapFormKey.IsSendToRecipient,
14
- });
15
- return (_jsxs(_Fragment, { children: [_jsxs(Box, Object.assign({ mb: 2, sx: {
16
- display: 'flex',
17
- justifyContent: 'space-between',
18
- alignItems: 'center',
19
- } }, { children: [_jsxs(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: [_jsx(HelpOutlineIcon, { sx: { color: 'grey.500' } }), _jsx(Typography, Object.assign({ lineHeight: "normal", variant: "subtitle1", color: "text.primary", ml: 1 }, { children: t(`swap.sendToRecipient`) }))] })), _jsx(Switch, Object.assign({}, register(SwapFormKey.IsSendToRecipient)))] })), sendToRecipientChecked ? (_jsxs(_Fragment, { children: [_jsx(FormControl, Object.assign({ variant: "standard", fullWidth: true }, { children: _jsx(Input, { size: "small", placeholder: t(`swap.recipientsAddress`, { chain: 'ETH' }), required: true, inputProps: Object.assign({}, register(SwapFormKey.RecipientsAddress)) }) })), _jsx(Box, Object.assign({ mt: 0.5, mb: 1 }, { children: _jsx(FormControlLabel, { control: _jsx(Checkbox, Object.assign({ required: true }, register(SwapFormKey.IsAddressConfirmed))), label: t(`swap.addressConfirmation`), componentsProps: { typography: { variant: 'body2' } } }) }))] })) : null] }));
20
- };