@lifi/widget 1.28.4 → 1.29.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 (170) hide show
  1. package/AppDrawer.style.d.ts +1 -1
  2. package/AppProvider.js +2 -2
  3. package/cjs/AppDrawer.style.d.ts +1 -1
  4. package/cjs/AppProvider.js +2 -2
  5. package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +2 -2
  6. package/cjs/components/AppContainer.d.ts +2 -2
  7. package/cjs/components/BottomSheet/BottomSheet.d.ts +1 -1
  8. package/cjs/components/Card/Card.d.ts +5 -3
  9. package/cjs/components/ChainSelect/ChainSelect.d.ts +0 -1
  10. package/cjs/components/ChainSelect/ChainSelect.style.d.ts +7 -5
  11. package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.style.d.ts +2 -2
  12. package/cjs/components/Header/Header.style.d.ts +3 -3
  13. package/cjs/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
  14. package/cjs/components/SendToWallet/SendToWallet.style.d.ts +1 -1
  15. package/cjs/components/SmallAvatar.d.ts +2 -2
  16. package/cjs/components/Step/CircularProgress.d.ts +0 -1
  17. package/cjs/components/Step/CircularProgress.style.d.ts +2 -2
  18. package/cjs/components/Step/StepList.d.ts +0 -1
  19. package/cjs/components/Step/StepProcess.style.d.ts +1 -1
  20. package/cjs/components/SwapInput/SwapInput.style.d.ts +1 -1
  21. package/cjs/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
  22. package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +0 -1
  23. package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
  24. package/cjs/components/SwapRouteCard/SwapRouteCard.style.js +1 -1
  25. package/cjs/components/SwapRoutes/SwapRoutes.style.d.ts +6 -6
  26. package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +0 -1
  27. package/cjs/components/Switch.js +1 -1
  28. package/cjs/components/Token/Token.style.d.ts +4 -4
  29. package/cjs/components/Token/Token.style.js +3 -1
  30. package/cjs/components/TokenAvatar/TokenAvatar.style.d.ts +4 -4
  31. package/cjs/components/TokenList/TokenList.style.d.ts +1 -1
  32. package/cjs/config/theme.js +22 -27
  33. package/cjs/config/version.d.ts +1 -1
  34. package/cjs/config/version.js +1 -1
  35. package/cjs/hooks/useChains.js +2 -3
  36. package/cjs/hooks/useRouteExecution.js +4 -3
  37. package/cjs/hooks/useTools.js +2 -1
  38. package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +0 -1
  39. package/cjs/pages/SelectTokenPage/SearchTokenInput.d.ts +0 -1
  40. package/cjs/pages/SelectWalletPage/SelectWalletPage.d.ts +0 -1
  41. package/cjs/pages/SettingsPage/AdvancedPreferences.d.ts +0 -1
  42. package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
  43. package/cjs/pages/SettingsPage/GasPriceSelect.d.ts +0 -1
  44. package/cjs/pages/SettingsPage/SettingsPage.d.ts +0 -1
  45. package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +0 -1
  46. package/cjs/pages/SettingsPage/SlippageInput.d.ts +0 -1
  47. package/cjs/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -4
  48. package/cjs/providers/WalletProvider/WalletProvider.js +1 -1
  49. package/cjs/providers/WidgetProvider/WidgetProvider.js +3 -2
  50. package/cjs/stores/StoreProvider.d.ts +3 -0
  51. package/cjs/stores/StoreProvider.js +13 -0
  52. package/cjs/stores/chains/ChainOrderStore.d.ts +9 -0
  53. package/cjs/stores/chains/ChainOrderStore.js +44 -0
  54. package/cjs/stores/chains/createChainOrderStore.d.ts +4 -0
  55. package/cjs/stores/chains/{useChainOrderStore.js → createChainOrderStore.js} +4 -4
  56. package/cjs/stores/chains/index.d.ts +2 -1
  57. package/cjs/stores/chains/index.js +2 -1
  58. package/cjs/stores/chains/types.d.ts +2 -2
  59. package/cjs/stores/chains/useChainOrder.js +2 -2
  60. package/cjs/stores/index.d.ts +1 -0
  61. package/cjs/stores/index.js +1 -0
  62. package/cjs/stores/routes/RouteExecutionStore.d.ts +9 -0
  63. package/cjs/stores/routes/RouteExecutionStore.js +44 -0
  64. package/cjs/stores/routes/createRouteExecutionStore.d.ts +3 -0
  65. package/cjs/stores/routes/{useRouteExecutionStore.js → createRouteExecutionStore.js} +6 -4
  66. package/cjs/stores/routes/index.d.ts +1 -1
  67. package/cjs/stores/routes/index.js +1 -1
  68. package/cjs/stores/routes/types.d.ts +5 -5
  69. package/cjs/stores/routes/useExecutingRoutesIds.js +2 -2
  70. package/cjs/stores/routes/useSetExecutableRoute.js +2 -2
  71. package/cjs/stores/routes/useSwapHistory.js +2 -2
  72. package/cjs/stores/settings/SettingsStore.d.ts +11 -0
  73. package/cjs/stores/settings/SettingsStore.js +58 -0
  74. package/cjs/stores/settings/createSettingsStore.d.ts +5 -0
  75. package/cjs/stores/settings/{useSettingsStore.js → createSettingsStore.js} +4 -19
  76. package/cjs/stores/settings/index.d.ts +1 -1
  77. package/cjs/stores/settings/index.js +1 -1
  78. package/cjs/stores/settings/types.d.ts +4 -4
  79. package/cjs/stores/settings/useAppearance.js +2 -2
  80. package/cjs/stores/settings/useSettings.js +2 -2
  81. package/cjs/stores/types.d.ts +5 -0
  82. package/cjs/stores/types.js +2 -0
  83. package/cjs/types/widget.d.ts +1 -0
  84. package/components/ActiveSwaps/ActiveSwaps.style.d.ts +2 -2
  85. package/components/AppContainer.d.ts +2 -2
  86. package/components/BottomSheet/BottomSheet.d.ts +1 -1
  87. package/components/Card/Card.d.ts +5 -3
  88. package/components/ChainSelect/ChainSelect.d.ts +0 -1
  89. package/components/ChainSelect/ChainSelect.style.d.ts +7 -5
  90. package/components/GasSufficiencyMessage/GasSufficiencyMessage.style.d.ts +2 -2
  91. package/components/Header/Header.style.d.ts +3 -3
  92. package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
  93. package/components/SendToWallet/SendToWallet.style.d.ts +1 -1
  94. package/components/SmallAvatar.d.ts +2 -2
  95. package/components/Step/CircularProgress.d.ts +0 -1
  96. package/components/Step/CircularProgress.style.d.ts +2 -2
  97. package/components/Step/StepList.d.ts +0 -1
  98. package/components/Step/StepProcess.style.d.ts +1 -1
  99. package/components/SwapInput/SwapInput.style.d.ts +1 -1
  100. package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
  101. package/components/SwapInput/SwapInputEndAdornment.d.ts +0 -1
  102. package/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
  103. package/components/SwapRouteCard/SwapRouteCard.style.js +1 -1
  104. package/components/SwapRoutes/SwapRoutes.style.d.ts +6 -6
  105. package/components/SwapRoutes/SwapRoutesExpanded.d.ts +0 -1
  106. package/components/Switch.js +1 -1
  107. package/components/Token/Token.style.d.ts +4 -4
  108. package/components/Token/Token.style.js +4 -2
  109. package/components/TokenAvatar/TokenAvatar.style.d.ts +4 -4
  110. package/components/TokenList/TokenList.style.d.ts +1 -1
  111. package/config/theme.js +22 -27
  112. package/config/version.d.ts +1 -1
  113. package/config/version.js +1 -1
  114. package/hooks/useChains.js +3 -4
  115. package/hooks/useRouteExecution.js +5 -4
  116. package/hooks/useTools.js +3 -2
  117. package/package.json +11 -11
  118. package/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +0 -1
  119. package/pages/SelectTokenPage/SearchTokenInput.d.ts +0 -1
  120. package/pages/SelectWalletPage/SelectWalletPage.d.ts +0 -1
  121. package/pages/SettingsPage/AdvancedPreferences.d.ts +0 -1
  122. package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
  123. package/pages/SettingsPage/GasPriceSelect.d.ts +0 -1
  124. package/pages/SettingsPage/SettingsPage.d.ts +0 -1
  125. package/pages/SettingsPage/ShowDestinationWallet.d.ts +0 -1
  126. package/pages/SettingsPage/SlippageInput.d.ts +0 -1
  127. package/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -4
  128. package/providers/WalletProvider/WalletProvider.js +1 -1
  129. package/providers/WidgetProvider/WidgetProvider.js +4 -3
  130. package/stores/StoreProvider.d.ts +3 -0
  131. package/stores/StoreProvider.js +9 -0
  132. package/stores/chains/ChainOrderStore.d.ts +9 -0
  133. package/stores/chains/ChainOrderStore.js +38 -0
  134. package/stores/chains/createChainOrderStore.d.ts +4 -0
  135. package/stores/chains/{useChainOrderStore.js → createChainOrderStore.js} +2 -3
  136. package/stores/chains/index.d.ts +2 -1
  137. package/stores/chains/index.js +2 -1
  138. package/stores/chains/types.d.ts +2 -2
  139. package/stores/chains/useChainOrder.js +1 -1
  140. package/stores/index.d.ts +1 -0
  141. package/stores/index.js +1 -0
  142. package/stores/routes/RouteExecutionStore.d.ts +9 -0
  143. package/stores/routes/RouteExecutionStore.js +38 -0
  144. package/stores/routes/createRouteExecutionStore.d.ts +3 -0
  145. package/stores/routes/{useRouteExecutionStore.js → createRouteExecutionStore.js} +4 -3
  146. package/stores/routes/index.d.ts +1 -1
  147. package/stores/routes/index.js +1 -1
  148. package/stores/routes/types.d.ts +5 -5
  149. package/stores/routes/useExecutingRoutesIds.js +1 -1
  150. package/stores/routes/useSetExecutableRoute.js +1 -1
  151. package/stores/routes/useSwapHistory.js +1 -1
  152. package/stores/settings/SettingsStore.d.ts +11 -0
  153. package/stores/settings/SettingsStore.js +51 -0
  154. package/stores/settings/createSettingsStore.d.ts +5 -0
  155. package/stores/settings/{useSettingsStore.js → createSettingsStore.js} +2 -17
  156. package/stores/settings/index.d.ts +1 -1
  157. package/stores/settings/index.js +1 -1
  158. package/stores/settings/types.d.ts +4 -4
  159. package/stores/settings/useAppearance.js +1 -1
  160. package/stores/settings/useSettings.js +1 -1
  161. package/stores/types.d.ts +5 -0
  162. package/stores/types.js +1 -0
  163. package/tsconfig.cjs.tsbuildinfo +1 -1
  164. package/types/widget.d.ts +1 -0
  165. package/cjs/stores/chains/useChainOrderStore.d.ts +0 -17
  166. package/cjs/stores/routes/useRouteExecutionStore.d.ts +0 -16
  167. package/cjs/stores/settings/useSettingsStore.d.ts +0 -44
  168. package/stores/chains/useChainOrderStore.d.ts +0 -17
  169. package/stores/routes/useRouteExecutionStore.d.ts +0 -16
  170. package/stores/settings/useSettingsStore.d.ts +0 -44
@@ -0,0 +1,3 @@
1
+ import type { PropsWithChildren } from 'react';
2
+ import type { PersistStoreProviderProps } from './types';
3
+ export declare const StoreProvider: React.FC<PropsWithChildren<PersistStoreProviderProps>>;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ChainOrderStoreProvider } from './chains';
3
+ import { RouteExecutionStoreProvider } from './routes';
4
+ import { SettingsStoreProvider } from './settings';
5
+ export const StoreProvider = ({ children, namePrefix }) => {
6
+ return (_jsx(RouteExecutionStoreProvider, Object.assign({ namePrefix: namePrefix }, { children: _jsx(SettingsStoreProvider
7
+ // namePrefix={namePrefix}
8
+ , { children: _jsx(ChainOrderStoreProvider, Object.assign({ namePrefix: namePrefix }, { children: children })) }) })));
9
+ };
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { StoreApi, UseBoundStore } from 'zustand';
3
+ import type { PersistStoreProviderProps } from '../types';
4
+ import type { ChainOrderState } from './types';
5
+ export type ChainOrderStore = UseBoundStore<StoreApi<ChainOrderState>>;
6
+ export declare const ChainOrderStoreContext: import("react").Context<ChainOrderStore | null>;
7
+ export declare function ChainOrderStoreProvider({ children, ...props }: PersistStoreProviderProps): JSX.Element;
8
+ export declare function useChainOrderStore<T>(selector: (state: ChainOrderState) => T, equalityFn?: (left: T, right: T) => boolean): T;
9
+ export declare function useChainOrderStoreContext(): ChainOrderStore;
@@ -0,0 +1,38 @@
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
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ /* eslint-disable no-underscore-dangle */
14
+ import { createContext, useContext, useRef } from 'react';
15
+ import { createChainOrderStore } from './createChainOrderStore';
16
+ export const ChainOrderStoreContext = createContext(null);
17
+ export function ChainOrderStoreProvider(_a) {
18
+ var { children } = _a, props = __rest(_a, ["children"]);
19
+ const storeRef = useRef();
20
+ if (!storeRef.current) {
21
+ storeRef.current = createChainOrderStore(props);
22
+ }
23
+ return (_jsx(ChainOrderStoreContext.Provider, Object.assign({ value: storeRef.current }, { children: children })));
24
+ }
25
+ export function useChainOrderStore(selector, equalityFn) {
26
+ const useStore = useContext(ChainOrderStoreContext);
27
+ if (!useStore) {
28
+ throw new Error(`You forgot to wrap your component in <${ChainOrderStoreProvider.name}>.`);
29
+ }
30
+ return useStore(selector, equalityFn);
31
+ }
32
+ export function useChainOrderStoreContext() {
33
+ const useStore = useContext(ChainOrderStoreContext);
34
+ if (!useStore) {
35
+ throw new Error(`You forgot to wrap your component in <${ChainOrderStoreProvider.name}>.`);
36
+ }
37
+ return useStore;
38
+ }
@@ -0,0 +1,4 @@
1
+ import type { PersistStoreProps } from '../types';
2
+ import type { ChainOrderState } from './types';
3
+ export declare const maxChainToOrder = 9;
4
+ export declare const createChainOrderStore: ({ namePrefix }: PersistStoreProps) => import("zustand").UseBoundStore<import("zustand").StoreApi<ChainOrderState>>;
@@ -1,8 +1,7 @@
1
- /* eslint-disable no-underscore-dangle */
2
1
  import { create } from 'zustand';
3
2
  import { persist } from 'zustand/middleware';
4
3
  export const maxChainToOrder = 9;
5
- export const useChainOrderStore = create()(persist((set, get) => ({
4
+ export const createChainOrderStore = ({ namePrefix }) => create(persist((set, get) => ({
6
5
  chainOrder: [],
7
6
  availableChains: [],
8
7
  initializeChains: (chainIds) => {
@@ -44,7 +43,7 @@ export const useChainOrderStore = create()(persist((set, get) => ({
44
43
  });
45
44
  },
46
45
  }), {
47
- name: 'li.fi-widget-chains-order',
46
+ name: `${namePrefix || 'li.fi'}-widget-chains-order`,
48
47
  version: 0,
49
48
  partialize: (state) => ({ chainOrder: state.chainOrder }),
50
49
  }));
@@ -1,3 +1,4 @@
1
+ export * from './ChainOrderStore';
2
+ export * from './createChainOrderStore';
1
3
  export * from './types';
2
4
  export * from './useChainOrder';
3
- export * from './useChainOrderStore';
@@ -1,3 +1,4 @@
1
+ export * from './ChainOrderStore';
2
+ export * from './createChainOrderStore';
1
3
  export * from './types';
2
4
  export * from './useChainOrder';
3
- export * from './useChainOrderStore';
@@ -1,8 +1,8 @@
1
- export interface ChainOrderState {
1
+ export interface ChainOrderProps {
2
2
  chainOrder: number[];
3
3
  availableChains: number[];
4
4
  }
5
- export interface ChainOrderStore extends ChainOrderState {
5
+ export interface ChainOrderState extends ChainOrderProps {
6
6
  initializeChains(chainIds: number[]): number[];
7
7
  setChain(chainId: number): void;
8
8
  }
@@ -1,5 +1,5 @@
1
1
  import { shallow } from 'zustand/shallow';
2
- import { useChainOrderStore } from './useChainOrderStore';
2
+ import { useChainOrderStore } from './ChainOrderStore';
3
3
  export const useChainOrder = () => {
4
4
  return useChainOrderStore((state) => [state.chainOrder, state.setChain], shallow);
5
5
  };
package/stores/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './chains';
2
2
  export * from './routes';
3
3
  export * from './settings';
4
+ export * from './StoreProvider';
package/stores/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './chains';
2
2
  export * from './routes';
3
3
  export * from './settings';
4
+ export * from './StoreProvider';
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { StoreApi, UseBoundStore } from 'zustand';
3
+ import type { PersistStoreProviderProps } from '../types';
4
+ import type { RouteExecutionState } from './types';
5
+ export type RouteExecutionStore = UseBoundStore<StoreApi<RouteExecutionState>>;
6
+ export declare const RouteExecutionStoreContext: import("react").Context<RouteExecutionStore | null>;
7
+ export declare function RouteExecutionStoreProvider({ children, ...props }: PersistStoreProviderProps): JSX.Element;
8
+ export declare function useRouteExecutionStore<T>(selector: (state: RouteExecutionState) => T, equalityFn?: (left: T, right: T) => boolean): T;
9
+ export declare function useRouteExecutionStoreContext(): RouteExecutionStore;
@@ -0,0 +1,38 @@
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
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ /* eslint-disable no-underscore-dangle */
14
+ import { createContext, useContext, useRef } from 'react';
15
+ import { createRouteExecutionStore } from './createRouteExecutionStore';
16
+ export const RouteExecutionStoreContext = createContext(null);
17
+ export function RouteExecutionStoreProvider(_a) {
18
+ var { children } = _a, props = __rest(_a, ["children"]);
19
+ const storeRef = useRef();
20
+ if (!storeRef.current) {
21
+ storeRef.current = createRouteExecutionStore(props);
22
+ }
23
+ return (_jsx(RouteExecutionStoreContext.Provider, Object.assign({ value: storeRef.current }, { children: children })));
24
+ }
25
+ export function useRouteExecutionStore(selector, equalityFn) {
26
+ const useStore = useContext(RouteExecutionStoreContext);
27
+ if (!useStore) {
28
+ throw new Error(`You forgot to wrap your component in <${RouteExecutionStoreProvider.name}>.`);
29
+ }
30
+ return useStore(selector, equalityFn);
31
+ }
32
+ export function useRouteExecutionStoreContext() {
33
+ const useStore = useContext(RouteExecutionStoreContext);
34
+ if (!useStore) {
35
+ throw new Error(`You forgot to wrap your component in <${RouteExecutionStoreProvider.name}>.`);
36
+ }
37
+ return useStore;
38
+ }
@@ -0,0 +1,3 @@
1
+ import type { PersistStoreProps } from '../types';
2
+ import type { RouteExecutionState } from './types';
3
+ export declare const createRouteExecutionStore: ({ namePrefix }: PersistStoreProps) => import("zustand").UseBoundStore<import("zustand").StoreApi<RouteExecutionState>>;
@@ -3,7 +3,7 @@ import { persist } from 'zustand/middleware';
3
3
  import { hasEnumFlag } from '../../utils';
4
4
  import { RouteExecutionStatus } from './types';
5
5
  import { isRouteDone, isRouteFailed, isRoutePartiallyDone, isRouteRefunded, } from './utils';
6
- export const useRouteExecutionStore = create()(persist((set, get) => ({
6
+ export const createRouteExecutionStore = ({ namePrefix }) => create(persist((set, get) => ({
7
7
  routes: {},
8
8
  setExecutableRoute: (route) => {
9
9
  if (!get().routes[route.id]) {
@@ -37,7 +37,8 @@ export const useRouteExecutionStore = create()(persist((set, get) => ({
37
37
  }
38
38
  const isDone = isRouteDone(route);
39
39
  if (isDone) {
40
- updatedState.routes[route.id].status = RouteExecutionStatus.Done;
40
+ updatedState.routes[route.id].status =
41
+ RouteExecutionStatus.Done;
41
42
  if (isRoutePartiallyDone(route)) {
42
43
  updatedState.routes[route.id].status |=
43
44
  RouteExecutionStatus.Partial;
@@ -90,7 +91,7 @@ export const useRouteExecutionStore = create()(persist((set, get) => ({
90
91
  };
91
92
  }),
92
93
  }), {
93
- name: 'li.fi-widget-routes',
94
+ name: `${namePrefix || 'li.fi'}-widget-routes`,
94
95
  version: 1,
95
96
  partialize: (state) => ({ routes: state.routes }),
96
97
  merge: (persistedState, currentState) => {
@@ -1,7 +1,7 @@
1
+ export * from './RouteExecutionStore';
1
2
  export * from './types';
2
3
  export * from './useExecutingRoutesIds';
3
4
  export * from './useRecommendedRouteStore';
4
- export * from './useRouteExecutionStore';
5
5
  export * from './useSetExecutableRoute';
6
6
  export * from './useSwapHistory';
7
7
  export * from './utils';
@@ -1,7 +1,7 @@
1
+ export * from './RouteExecutionStore';
1
2
  export * from './types';
2
3
  export * from './useExecutingRoutesIds';
3
4
  export * from './useRecommendedRouteStore';
4
- export * from './useRouteExecutionStore';
5
5
  export * from './useSetExecutableRoute';
6
6
  export * from './useSwapHistory';
7
7
  export * from './utils';
@@ -1,5 +1,9 @@
1
1
  import type { Route } from '@lifi/sdk';
2
- export interface RouteExecutionStore {
2
+ export interface RouteExecution {
3
+ route: Route;
4
+ status: RouteExecutionStatus;
5
+ }
6
+ export interface RouteExecutionState {
3
7
  routes: Partial<Record<string, RouteExecution>>;
4
8
  setExecutableRoute: (route: Route) => void;
5
9
  updateRoute: (route: Route) => void;
@@ -15,10 +19,6 @@ export declare enum RouteExecutionStatus {
15
19
  Partial = 8,
16
20
  Refunded = 16
17
21
  }
18
- export interface RouteExecution {
19
- route: Route;
20
- status: RouteExecutionStatus;
21
- }
22
22
  export interface RecommendedRouteStore {
23
23
  recommendedRoute?: Route;
24
24
  setRecommendedRoute: (route?: Route) => void;
@@ -1,6 +1,6 @@
1
1
  import { shallow } from 'zustand/shallow';
2
+ import { useRouteExecutionStore } from './RouteExecutionStore';
2
3
  import { RouteExecutionStatus } from './types';
3
- import { useRouteExecutionStore } from './useRouteExecutionStore';
4
4
  export const useExecutingRoutesIds = (address) => {
5
5
  return useRouteExecutionStore((state) => Object.values(state.routes)
6
6
  .filter((item) => item.route.fromAddress === address &&
@@ -1,4 +1,4 @@
1
- import { useRouteExecutionStore } from './useRouteExecutionStore';
1
+ import { useRouteExecutionStore } from './RouteExecutionStore';
2
2
  export const useSetExecutableRoute = () => {
3
3
  return useRouteExecutionStore((state) => state.setExecutableRoute);
4
4
  };
@@ -1,7 +1,7 @@
1
1
  import { shallow } from 'zustand/shallow';
2
2
  import { hasEnumFlag } from '../../utils';
3
+ import { useRouteExecutionStore } from './RouteExecutionStore';
3
4
  import { RouteExecutionStatus } from './types';
4
- import { useRouteExecutionStore } from './useRouteExecutionStore';
5
5
  export const useSwapHistory = (address) => {
6
6
  return useRouteExecutionStore((state) => Object.values(state.routes)
7
7
  .filter((item) => (item === null || item === void 0 ? void 0 : item.route.fromAddress) === address &&
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import type { WidgetConfig } from '@lifi/widget';
3
+ import type { StoreApi, UseBoundStore } from 'zustand';
4
+ import type { PersistStoreProviderProps } from '../types';
5
+ import type { SettingsState } from './types';
6
+ export type SettingsStore = UseBoundStore<StoreApi<SettingsState>>;
7
+ export declare const SettingsStoreContext: import("react").Context<SettingsStore | null>;
8
+ export declare function SettingsStoreProvider({ children, ...props }: PersistStoreProviderProps): JSX.Element;
9
+ export declare function useSettingsStore<T>(selector: (state: SettingsState) => T, equalityFn?: (left: T, right: T) => boolean): T;
10
+ export declare function useSettingsStoreContext(): SettingsStore;
11
+ export declare const setDefaultSettings: (useSettingsStore: SettingsStore, config?: WidgetConfig) => void;
@@ -0,0 +1,51 @@
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
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { createContext, useContext, useRef } from 'react';
14
+ import { createSettingsStore, defaultConfigurableSettings, } from './createSettingsStore';
15
+ export const SettingsStoreContext = createContext(null);
16
+ export function SettingsStoreProvider(_a) {
17
+ var { children } = _a, props = __rest(_a, ["children"]);
18
+ const storeRef = useRef();
19
+ if (!storeRef.current) {
20
+ storeRef.current = createSettingsStore(props);
21
+ }
22
+ return (_jsx(SettingsStoreContext.Provider, Object.assign({ value: storeRef.current }, { children: children })));
23
+ }
24
+ export function useSettingsStore(selector, equalityFn) {
25
+ const useStore = useContext(SettingsStoreContext);
26
+ if (!useStore) {
27
+ throw new Error(`You forgot to wrap your component in <${SettingsStoreProvider.name}>.`);
28
+ }
29
+ return useStore(selector, equalityFn);
30
+ }
31
+ export function useSettingsStoreContext() {
32
+ const useStore = useContext(SettingsStoreContext);
33
+ if (!useStore) {
34
+ throw new Error(`You forgot to wrap your component in <${SettingsStoreProvider.name}>.`);
35
+ }
36
+ return useStore;
37
+ }
38
+ export const setDefaultSettings = (useSettingsStore, config) => {
39
+ var _a, _b, _c, _d, _e;
40
+ const { slippage, routePriority, setValue } = useSettingsStore.getState();
41
+ const defaultSlippage = ((config === null || config === void 0 ? void 0 : config.slippage) ||
42
+ ((_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) ||
43
+ 0) * 100;
44
+ 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);
45
+ if (!slippage) {
46
+ setValue('slippage', (_e = (defaultSlippage || defaultConfigurableSettings.slippage)) === null || _e === void 0 ? void 0 : _e.toString());
47
+ }
48
+ if (!routePriority) {
49
+ setValue('routePriority', defaultRoutePriority || defaultConfigurableSettings.routePriority);
50
+ }
51
+ };
@@ -0,0 +1,5 @@
1
+ import type { PersistStoreProps } from '../types';
2
+ import type { SettingsProps, SettingsState } from './types';
3
+ export declare const defaultConfigurableSettings: Pick<SettingsState, 'routePriority' | 'slippage'>;
4
+ export declare const defaultSettings: SettingsProps;
5
+ export declare const createSettingsStore: ({ namePrefix }: PersistStoreProps) => import("zustand").UseBoundStore<import("zustand").StoreApi<SettingsState>>;
@@ -9,7 +9,6 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- /* eslint-disable no-underscore-dangle */
13
12
  import { create } from 'zustand';
14
13
  import { persist } from 'zustand/middleware';
15
14
  import { SettingsToolTypes } from './types';
@@ -23,7 +22,7 @@ export const defaultSettings = {
23
22
  advancedPreferences: false,
24
23
  showDestinationWallet: true,
25
24
  };
26
- export const useSettingsStore = create()(persist((set) => (Object.assign(Object.assign({}, defaultSettings), { setValue: (key, value) => set(() => ({
25
+ export const createSettingsStore = ({ namePrefix }) => create(persist((set) => (Object.assign(Object.assign({}, defaultSettings), { setValue: (key, value) => set(() => ({
27
26
  [key]: value,
28
27
  })), setValues: (values) => set((state) => {
29
28
  const updatedState = Object.assign({}, state);
@@ -68,7 +67,7 @@ export const useSettingsStore = create()(persist((set) => (Object.assign(Object.
68
67
  return values;
69
68
  }, {}),
70
69
  })) })), {
71
- name: 'li.fi-widget-settings',
70
+ name: `${namePrefix || 'li.fi'}-widget-settings`,
72
71
  version: 2,
73
72
  partialize: (state) => {
74
73
  const { enabledBridges, enabledExchanges } = state, partializedState = __rest(state, ["enabledBridges", "enabledExchanges"]);
@@ -93,17 +92,3 @@ export const useSettingsStore = create()(persist((set) => (Object.assign(Object.
93
92
  return persistedState;
94
93
  },
95
94
  }));
96
- export const setDefaultSettings = (config) => {
97
- var _a, _b, _c, _d, _e;
98
- const { slippage, routePriority, setValue } = useSettingsStore.getState();
99
- const defaultSlippage = ((config === null || config === void 0 ? void 0 : config.slippage) ||
100
- ((_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) ||
101
- 0) * 100;
102
- 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);
103
- if (!slippage) {
104
- setValue('slippage', (_e = (defaultSlippage || defaultConfigurableSettings.slippage)) === null || _e === void 0 ? void 0 : _e.toString());
105
- }
106
- if (!routePriority) {
107
- setValue('routePriority', defaultRoutePriority || defaultConfigurableSettings.routePriority);
108
- }
109
- };
@@ -1,5 +1,5 @@
1
+ export * from './SettingsStore';
1
2
  export * from './types';
2
3
  export * from './useAppearance';
3
4
  export * from './useSendToWalletStore';
4
5
  export * from './useSettings';
5
- export * from './useSettingsStore';
@@ -1,5 +1,5 @@
1
+ export * from './SettingsStore';
1
2
  export * from './types';
2
3
  export * from './useAppearance';
3
4
  export * from './useSendToWalletStore';
4
5
  export * from './useSettings';
5
- export * from './useSettingsStore';
@@ -4,7 +4,7 @@ export type ValueSetter<S> = <K extends keyof S>(key: K, value: S[Extract<K, str
4
4
  export type ValuesSetter<S> = <K extends keyof S>(values: Record<K, S[Extract<K, string>]>) => void;
5
5
  export type SettingsToolType = 'Bridges' | 'Exchanges';
6
6
  export declare const SettingsToolTypes: SettingsToolType[];
7
- export interface SettingsState {
7
+ export interface SettingsProps {
8
8
  advancedPreferences: boolean;
9
9
  appearance: Appearance;
10
10
  gasPrice?: string;
@@ -17,9 +17,9 @@ export interface SettingsState {
17
17
  enabledExchanges?: string[];
18
18
  _enabledExchanges?: Record<string, boolean>;
19
19
  }
20
- export interface SettingsStore extends SettingsState {
21
- setValue: ValueSetter<SettingsState>;
22
- setValues: ValuesSetter<SettingsState>;
20
+ export interface SettingsState extends SettingsProps {
21
+ setValue: ValueSetter<SettingsProps>;
22
+ setValues: ValuesSetter<SettingsProps>;
23
23
  initializeTools(toolType: SettingsToolType, tools: string[]): void;
24
24
  setTools(toolType: SettingsToolType, tools: string[], availableTools: (Pick<Bridge, 'key'> | Pick<Exchange, 'key'>)[]): void;
25
25
  }
@@ -1,5 +1,5 @@
1
1
  import { shallow } from 'zustand/shallow';
2
- import { useSettingsStore } from './useSettingsStore';
2
+ import { useSettingsStore } from './SettingsStore';
3
3
  export const useAppearance = () => {
4
4
  const [appearance, setValue] = useSettingsStore((state) => [state.appearance, state.setValue], shallow);
5
5
  const setAppearance = (appearance) => {
@@ -1,5 +1,5 @@
1
1
  import { shallow } from 'zustand/shallow';
2
- import { useSettingsStore } from './useSettingsStore';
2
+ import { useSettingsStore } from './SettingsStore';
3
3
  export const useSettings = (keys) => {
4
4
  return useSettingsStore((state) => keys.reduce((values, key) => {
5
5
  values[key] = state[key];
@@ -0,0 +1,5 @@
1
+ import type { PropsWithChildren } from 'react';
2
+ export interface PersistStoreProps {
3
+ namePrefix?: string;
4
+ }
5
+ export type PersistStoreProviderProps = PropsWithChildren<PersistStoreProps>;
@@ -0,0 +1 @@
1
+ export {};