@lifi/widget 1.24.0 → 1.25.1

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 (138) hide show
  1. package/AppDrawer.style.d.ts +1 -1
  2. package/AppProvider.js +1 -1
  3. package/cjs/AppDrawer.style.d.ts +1 -1
  4. package/cjs/AppProvider.js +1 -1
  5. package/cjs/components/ActiveSwaps/ActiveSwapItem.js +2 -1
  6. package/cjs/components/BottomSheet/types.d.ts +1 -1
  7. package/cjs/components/Card/Card.d.ts +2 -2
  8. package/cjs/components/Card/CardTitle.d.ts +1 -1
  9. package/cjs/components/ChainSelect/ChainSelect.js +6 -1
  10. package/cjs/components/ChainSelect/useChainSelect.d.ts +3 -1
  11. package/cjs/components/ChainSelect/useChainSelect.js +12 -3
  12. package/cjs/components/SendToWallet/SendToWallet.style.d.ts +1 -1
  13. package/cjs/components/SwapInput/FitInputText.d.ts +3 -0
  14. package/cjs/components/SwapInput/FitInputText.js +19 -0
  15. package/cjs/components/SwapInput/FormPriceHelperText.d.ts +1 -3
  16. package/cjs/components/SwapInput/FormPriceHelperText.js +1 -1
  17. package/cjs/components/SwapInput/SwapInput.js +12 -24
  18. package/cjs/components/SwapInput/SwapInput.style.d.ts +1 -1
  19. package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +3 -0
  20. package/cjs/components/SwapInput/{SwapInputAdornment.js → SwapInputEndAdornment.js} +3 -3
  21. package/cjs/components/SwapInput/SwapInputStartAdornment.d.ts +3 -0
  22. package/cjs/components/SwapInput/SwapInputStartAdornment.js +21 -0
  23. package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
  24. package/cjs/components/SwapRoutes/SwapRoutes.style.d.ts +1 -1
  25. package/cjs/components/Token/Token.style.d.ts +1 -1
  26. package/cjs/components/TokenList/useTokenSelect.js +7 -4
  27. package/cjs/config/version.d.ts +1 -1
  28. package/cjs/config/version.js +1 -1
  29. package/cjs/hooks/useGasSufficiency.js +1 -1
  30. package/cjs/hooks/useRouteExecution.js +1 -1
  31. package/cjs/hooks/useSwapRoutes.js +12 -9
  32. package/cjs/hooks/useTools.d.ts +1 -1
  33. package/cjs/i18n/en.json +3 -1
  34. package/cjs/pages/SettingsPage/RoutePrioritySelect.js +2 -1
  35. package/cjs/pages/SettingsPage/SlippageInput.js +2 -1
  36. package/cjs/pages/SwapPage/StatusBottomSheet.js +61 -14
  37. package/cjs/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -2
  38. package/cjs/pages/SwapPage/StatusBottomSheet.style.js +5 -2
  39. package/cjs/pages/SwapPage/SwapPage.js +8 -6
  40. package/cjs/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
  41. package/cjs/providers/I18nProvider/types.d.ts +5 -5
  42. package/cjs/providers/SDKProvider/SDKProvider.js +4 -3
  43. package/cjs/providers/SwapFormProvider/FormUpdater.d.ts +5 -0
  44. package/cjs/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js} +24 -21
  45. package/cjs/providers/SwapFormProvider/SwapFormProvider.js +12 -7
  46. package/cjs/providers/SwapFormProvider/types.d.ts +2 -2
  47. package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -1
  48. package/cjs/providers/WalletProvider/WalletProvider.js +1 -2
  49. package/cjs/providers/WalletProvider/types.d.ts +3 -3
  50. package/cjs/providers/WidgetProvider/WidgetProvider.js +4 -0
  51. package/cjs/providers/WidgetProvider/types.d.ts +1 -1
  52. package/cjs/stores/routes/types.d.ts +8 -1
  53. package/cjs/stores/routes/types.js +10 -0
  54. package/cjs/stores/routes/useExecutingRoutesIds.js +3 -1
  55. package/cjs/stores/routes/useRouteExecutionStore.js +53 -18
  56. package/cjs/stores/routes/useSwapHistory.js +4 -1
  57. package/cjs/stores/routes/utils.d.ts +3 -1
  58. package/cjs/stores/routes/utils.js +12 -4
  59. package/cjs/stores/settings/types.d.ts +6 -6
  60. package/cjs/stores/settings/useSettingsStore.d.ts +12 -9
  61. package/cjs/stores/settings/useSettingsStore.js +22 -5
  62. package/cjs/types/events.d.ts +1 -1
  63. package/cjs/types/widget.d.ts +14 -8
  64. package/cjs/utils/enum.d.ts +1 -0
  65. package/cjs/utils/enum.js +5 -0
  66. package/cjs/utils/index.d.ts +1 -0
  67. package/cjs/utils/index.js +1 -0
  68. package/cjs/utils/navigationRoutes.d.ts +1 -1
  69. package/components/ActiveSwaps/ActiveSwapItem.js +2 -1
  70. package/components/BottomSheet/types.d.ts +1 -1
  71. package/components/Card/Card.d.ts +2 -2
  72. package/components/Card/CardTitle.d.ts +1 -1
  73. package/components/ChainSelect/ChainSelect.js +6 -1
  74. package/components/ChainSelect/useChainSelect.d.ts +3 -1
  75. package/components/ChainSelect/useChainSelect.js +13 -4
  76. package/components/SendToWallet/SendToWallet.style.d.ts +1 -1
  77. package/components/SwapInput/FitInputText.d.ts +3 -0
  78. package/components/SwapInput/FitInputText.js +16 -0
  79. package/components/SwapInput/FormPriceHelperText.d.ts +1 -3
  80. package/components/SwapInput/FormPriceHelperText.js +1 -1
  81. package/components/SwapInput/SwapInput.js +16 -28
  82. package/components/SwapInput/SwapInput.style.d.ts +1 -1
  83. package/components/SwapInput/SwapInputEndAdornment.d.ts +3 -0
  84. package/components/SwapInput/{SwapInputAdornment.js → SwapInputEndAdornment.js} +1 -1
  85. package/components/SwapInput/SwapInputStartAdornment.d.ts +3 -0
  86. package/components/SwapInput/SwapInputStartAdornment.js +17 -0
  87. package/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
  88. package/components/SwapRoutes/SwapRoutes.style.d.ts +1 -1
  89. package/components/Token/Token.style.d.ts +1 -1
  90. package/components/TokenList/useTokenSelect.js +8 -5
  91. package/config/version.d.ts +1 -1
  92. package/config/version.js +1 -1
  93. package/hooks/useGasSufficiency.js +2 -2
  94. package/hooks/useRouteExecution.js +2 -2
  95. package/hooks/useSwapRoutes.js +12 -9
  96. package/hooks/useTools.d.ts +1 -1
  97. package/i18n/en.json +3 -1
  98. package/package.json +13 -13
  99. package/pages/SettingsPage/RoutePrioritySelect.js +2 -1
  100. package/pages/SettingsPage/SlippageInput.js +2 -1
  101. package/pages/SwapPage/StatusBottomSheet.js +62 -15
  102. package/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -2
  103. package/pages/SwapPage/StatusBottomSheet.style.js +5 -2
  104. package/pages/SwapPage/SwapPage.js +8 -6
  105. package/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
  106. package/providers/I18nProvider/types.d.ts +5 -5
  107. package/providers/SDKProvider/SDKProvider.js +4 -3
  108. package/providers/SwapFormProvider/FormUpdater.d.ts +5 -0
  109. package/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js} +23 -20
  110. package/providers/SwapFormProvider/SwapFormProvider.js +12 -7
  111. package/providers/SwapFormProvider/types.d.ts +2 -2
  112. package/providers/WalletProvider/WalletProvider.d.ts +1 -1
  113. package/providers/WalletProvider/WalletProvider.js +2 -3
  114. package/providers/WalletProvider/types.d.ts +3 -3
  115. package/providers/WidgetProvider/WidgetProvider.js +5 -1
  116. package/providers/WidgetProvider/types.d.ts +1 -1
  117. package/stores/routes/types.d.ts +8 -1
  118. package/stores/routes/types.js +9 -1
  119. package/stores/routes/useExecutingRoutesIds.js +3 -1
  120. package/stores/routes/useRouteExecutionStore.js +51 -16
  121. package/stores/routes/useSwapHistory.js +4 -1
  122. package/stores/routes/utils.d.ts +3 -1
  123. package/stores/routes/utils.js +8 -2
  124. package/stores/settings/types.d.ts +6 -6
  125. package/stores/settings/useSettingsStore.d.ts +12 -9
  126. package/stores/settings/useSettingsStore.js +20 -4
  127. package/tsconfig.cjs.tsbuildinfo +1 -1
  128. package/types/events.d.ts +1 -1
  129. package/types/widget.d.ts +14 -8
  130. package/utils/enum.d.ts +1 -0
  131. package/utils/enum.js +1 -0
  132. package/utils/index.d.ts +1 -0
  133. package/utils/index.js +1 -0
  134. package/utils/navigationRoutes.d.ts +1 -1
  135. package/cjs/components/SwapInput/SwapInputAdornment.d.ts +0 -3
  136. package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +0 -5
  137. package/components/SwapInput/SwapInputAdornment.d.ts +0 -3
  138. package/providers/WalletProvider/WalletFormUpdate.d.ts +0 -5
@@ -4,42 +4,50 @@ exports.useRouteExecutionStore = void 0;
4
4
  const zustand_1 = require("zustand");
5
5
  const middleware_1 = require("zustand/middleware");
6
6
  const immer_1 = require("zustand/middleware/immer");
7
- const utils_1 = require("./utils");
7
+ const utils_1 = require("../../utils");
8
+ const types_1 = require("./types");
9
+ const utils_2 = require("./utils");
8
10
  exports.useRouteExecutionStore = (0, zustand_1.default)()((0, middleware_1.persist)((0, immer_1.immer)((set) => ({
9
11
  routes: {},
10
12
  setExecutableRoute: (route) => set((state) => {
11
13
  if (!state.routes[route.id]) {
12
14
  // clean previous idle routes that were not executed
13
15
  Object.keys(state.routes)
14
- .filter((routeId) => { var _a; return ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === 'idle'; })
16
+ .filter((routeId) => { var _a; return ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === types_1.RouteExecutionStatus.Idle; })
15
17
  .forEach((routeId) => delete state.routes[routeId]);
16
18
  state.routes[route.id] = {
17
19
  route,
18
- status: 'idle',
20
+ status: types_1.RouteExecutionStatus.Idle,
19
21
  };
20
22
  }
21
23
  }),
22
24
  updateRoute: (route) => set((state) => {
23
25
  if (state.routes[route.id]) {
24
26
  state.routes[route.id].route = route;
25
- const isFailed = (0, utils_1.isRouteFailed)(route);
27
+ const isFailed = (0, utils_2.isRouteFailed)(route);
26
28
  if (isFailed) {
27
- state.routes[route.id].status = 'error';
29
+ state.routes[route.id].status = types_1.RouteExecutionStatus.Failed;
28
30
  return;
29
31
  }
30
- const isDone = (0, utils_1.isRouteCompleted)(route);
32
+ const isDone = (0, utils_2.isRouteDone)(route);
31
33
  if (isDone) {
32
- state.routes[route.id].status = 'success';
34
+ state.routes[route.id].status = types_1.RouteExecutionStatus.Done;
35
+ if ((0, utils_2.isRoutePartiallyDone)(route)) {
36
+ state.routes[route.id].status |= types_1.RouteExecutionStatus.Partial;
37
+ }
38
+ else if ((0, utils_2.isRouteRefunded)(route)) {
39
+ state.routes[route.id].status |= types_1.RouteExecutionStatus.Refunded;
40
+ }
33
41
  return;
34
42
  }
35
43
  const isLoading = route.steps.some((step) => step.execution);
36
44
  if (isLoading) {
37
- state.routes[route.id].status = 'loading';
45
+ state.routes[route.id].status = types_1.RouteExecutionStatus.Pending;
38
46
  }
39
47
  }
40
48
  }),
41
49
  restartRoute: (routeId) => set((state) => {
42
- state.routes[routeId].status = 'loading';
50
+ state.routes[routeId].status = types_1.RouteExecutionStatus.Pending;
43
51
  }),
44
52
  deleteRoute: (routeId) => set((state) => {
45
53
  if (state.routes[routeId]) {
@@ -49,15 +57,16 @@ exports.useRouteExecutionStore = (0, zustand_1.default)()((0, middleware_1.persi
49
57
  deleteRoutes: (type) => set((state) => {
50
58
  Object.keys(state.routes)
51
59
  .filter((routeId) => {
52
- var _a, _b;
60
+ var _a, _b, _c, _d;
53
61
  return type === 'completed'
54
- ? ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === 'success'
55
- : ((_b = state.routes[routeId]) === null || _b === void 0 ? void 0 : _b.status) !== 'success';
62
+ ? (0, utils_1.hasEnumFlag)((_b = (_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 0, types_1.RouteExecutionStatus.Done)
63
+ : !(0, utils_1.hasEnumFlag)((_d = (_c = state.routes[routeId]) === null || _c === void 0 ? void 0 : _c.status) !== null && _d !== void 0 ? _d : 0, types_1.RouteExecutionStatus.Done);
56
64
  })
57
65
  .forEach((routeId) => delete state.routes[routeId]);
58
66
  }),
59
67
  })), {
60
68
  name: 'li.fi-widget-routes',
69
+ version: 1,
61
70
  partialize: (state) => ({ routes: state.routes }),
62
71
  merge: (persistedState, currentState) => {
63
72
  const state = Object.assign(Object.assign({}, currentState), persistedState);
@@ -71,21 +80,21 @@ exports.useRouteExecutionStore = (0, zustand_1.default)()((0, middleware_1.persi
71
80
  }
72
81
  state.routes[route.id] = {
73
82
  route,
74
- status: 'idle',
83
+ status: types_1.RouteExecutionStatus.Idle,
75
84
  };
76
- const isFailed = (0, utils_1.isRouteFailed)(route);
85
+ const isFailed = (0, utils_2.isRouteFailed)(route);
77
86
  if (isFailed) {
78
- state.routes[route.id].status = 'error';
87
+ state.routes[route.id].status = types_1.RouteExecutionStatus.Failed;
79
88
  return;
80
89
  }
81
- const isDone = (0, utils_1.isRouteCompleted)(route);
90
+ const isDone = (0, utils_2.isRouteDone)(route);
82
91
  if (isDone) {
83
- state.routes[route.id].status = 'success';
92
+ state.routes[route.id].status = types_1.RouteExecutionStatus.Done;
84
93
  return;
85
94
  }
86
95
  const isLoading = route.steps.some((step) => step.execution);
87
96
  if (isLoading) {
88
- state.routes[route.id].status = 'loading';
97
+ state.routes[route.id].status = types_1.RouteExecutionStatus.Pending;
89
98
  }
90
99
  });
91
100
  }
@@ -96,4 +105,30 @@ exports.useRouteExecutionStore = (0, zustand_1.default)()((0, middleware_1.persi
96
105
  }
97
106
  return state;
98
107
  },
108
+ migrate: (persistedState, version) => {
109
+ if (version === 0) {
110
+ Object.values(persistedState.routes).forEach((route) => {
111
+ if (route) {
112
+ switch (route.status) {
113
+ case 'idle':
114
+ route.status = types_1.RouteExecutionStatus.Idle;
115
+ break;
116
+ case 'loading':
117
+ route.status = types_1.RouteExecutionStatus.Pending;
118
+ break;
119
+ case 'success':
120
+ case 'warning':
121
+ route.status = types_1.RouteExecutionStatus.Done;
122
+ break;
123
+ case 'error':
124
+ route.status = types_1.RouteExecutionStatus.Failed;
125
+ break;
126
+ default:
127
+ break;
128
+ }
129
+ }
130
+ });
131
+ }
132
+ return persistedState;
133
+ },
99
134
  }));
@@ -2,10 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useSwapHistory = void 0;
4
4
  const shallow_1 = require("zustand/shallow");
5
+ const utils_1 = require("../../utils");
6
+ const types_1 = require("./types");
5
7
  const useRouteExecutionStore_1 = require("./useRouteExecutionStore");
6
8
  const useSwapHistory = (address) => {
7
9
  return (0, useRouteExecutionStore_1.useRouteExecutionStore)((state) => Object.values(state.routes)
8
- .filter((item) => (item === null || item === void 0 ? void 0 : item.route.fromAddress) === address && (item === null || item === void 0 ? void 0 : item.status) === 'success')
10
+ .filter((item) => (item === null || item === void 0 ? void 0 : item.route.fromAddress) === address &&
11
+ (0, utils_1.hasEnumFlag)(item.status, types_1.RouteExecutionStatus.Done))
9
12
  .sort((a, b) => {
10
13
  var _a, _b, _c, _d;
11
14
  return ((_b = (_a = b === null || b === void 0 ? void 0 : b.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0) -
@@ -1,5 +1,7 @@
1
1
  import type { Process, Route } from '@lifi/sdk';
2
- export declare const isRouteCompleted: (route: Route) => boolean;
2
+ export declare const isRouteDone: (route: Route) => boolean;
3
+ export declare const isRoutePartiallyDone: (route: Route) => boolean;
4
+ export declare const isRouteRefunded: (route: Route) => boolean;
3
5
  export declare const isRouteFailed: (route: Route) => boolean;
4
6
  export declare const isRouteActive: (route?: Route) => boolean;
5
7
  export declare const getUpdatedProcess: (currentRoute: Route, updatedRoute: Route) => Process | undefined;
@@ -1,11 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUpdatedProcess = exports.isRouteActive = exports.isRouteFailed = exports.isRouteCompleted = void 0;
3
+ exports.getUpdatedProcess = exports.isRouteActive = exports.isRouteFailed = exports.isRouteRefunded = exports.isRoutePartiallyDone = exports.isRouteDone = void 0;
4
4
  const microdiff_1 = require("microdiff");
5
- const isRouteCompleted = (route) => {
5
+ const isRouteDone = (route) => {
6
6
  return route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
7
7
  };
8
- exports.isRouteCompleted = isRouteCompleted;
8
+ exports.isRouteDone = isRouteDone;
9
+ const isRoutePartiallyDone = (route) => {
10
+ return route.steps.some((step) => { var _a; return (_a = step.execution) === null || _a === void 0 ? void 0 : _a.process.some((process) => process.substatus === 'PARTIAL'); });
11
+ };
12
+ exports.isRoutePartiallyDone = isRoutePartiallyDone;
13
+ const isRouteRefunded = (route) => {
14
+ return route.steps.some((step) => { var _a; return (_a = step.execution) === null || _a === void 0 ? void 0 : _a.process.some((process) => process.substatus === 'REFUNDED'); });
15
+ };
16
+ exports.isRouteRefunded = isRouteRefunded;
9
17
  const isRouteFailed = (route) => {
10
18
  return route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
11
19
  };
@@ -14,7 +22,7 @@ const isRouteActive = (route) => {
14
22
  if (!route) {
15
23
  return false;
16
24
  }
17
- const isDone = (0, exports.isRouteCompleted)(route);
25
+ const isDone = (0, exports.isRouteDone)(route);
18
26
  const isFailed = (0, exports.isRouteFailed)(route);
19
27
  const alreadyStarted = route.steps.some((step) => step.execution);
20
28
  return !isDone && !isFailed && alreadyStarted;
@@ -1,17 +1,17 @@
1
1
  import type { Bridge, Exchange, Order } from '@lifi/sdk';
2
2
  import type { Appearance } from '../../types';
3
- export 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';
3
+ export type ValueSetter<S> = <K extends keyof S>(key: K, value: S[Extract<K, string>]) => void;
4
+ export type ValuesSetter<S> = <K extends keyof S>(values: Record<K, S[Extract<K, string>]>) => void;
5
+ export type SettingsToolType = 'Bridges' | 'Exchanges';
6
6
  export declare const SettingsToolTypes: SettingsToolType[];
7
7
  export interface SettingsState {
8
8
  advancedPreferences: boolean;
9
9
  appearance: Appearance;
10
- gasPrice: string;
10
+ gasPrice?: string;
11
11
  language?: string;
12
- routePriority: Order;
12
+ routePriority?: Order;
13
13
  showDestinationWallet: boolean;
14
- slippage: string;
14
+ slippage?: string;
15
15
  enabledBridges?: string[];
16
16
  _enabledBridges?: Record<string, boolean>;
17
17
  enabledExchanges?: string[];
@@ -1,5 +1,7 @@
1
+ import type { WidgetConfig } from '../../types';
1
2
  import type { SettingsState, SettingsStore } from './types';
2
- export declare const defaultSettings: Omit<SettingsState, 'enabledBridges' | 'enabledExchanges' | '_enabledBridges' | '_enabledExchanges'>;
3
+ export declare const defaultConfigurableSettings: Pick<SettingsState, 'routePriority' | 'slippage'>;
4
+ export declare const defaultSettings: SettingsState;
3
5
  export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
4
6
  persist: {
5
7
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, {
@@ -8,12 +10,12 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
8
10
  initializeTools(toolType: import("./types").SettingsToolType, tools: string[]): void;
9
11
  setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifi/types").Bridge, "key"> | Pick<import("@lifi/types").Exchange, "key">)[]): void;
10
12
  advancedPreferences: boolean;
11
- appearance: import("../..").Appearance;
12
- gasPrice: string;
13
+ appearance: import("../../types").Appearance;
14
+ gasPrice?: string | undefined;
13
15
  language?: string | undefined;
14
- routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
16
+ routePriority?: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST" | undefined;
15
17
  showDestinationWallet: boolean;
16
- slippage: string;
18
+ slippage?: string | undefined;
17
19
  _enabledBridges?: Record<string, boolean> | undefined;
18
20
  _enabledExchanges?: Record<string, boolean> | undefined;
19
21
  }>>) => void;
@@ -28,12 +30,12 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
28
30
  initializeTools(toolType: import("./types").SettingsToolType, tools: string[]): void;
29
31
  setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifi/types").Bridge, "key"> | Pick<import("@lifi/types").Exchange, "key">)[]): void;
30
32
  advancedPreferences: boolean;
31
- appearance: import("../..").Appearance;
32
- gasPrice: string;
33
+ appearance: import("../../types").Appearance;
34
+ gasPrice?: string | undefined;
33
35
  language?: string | undefined;
34
- routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
36
+ routePriority?: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST" | undefined;
35
37
  showDestinationWallet: boolean;
36
- slippage: string;
38
+ slippage?: string | undefined;
37
39
  _enabledBridges?: Record<string, boolean> | undefined;
38
40
  _enabledExchanges?: Record<string, boolean> | undefined;
39
41
  }>>;
@@ -41,3 +43,4 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
41
43
  }, "setState"> & {
42
44
  setState(nextStateOrUpdater: SettingsStore | Partial<SettingsStore> | ((state: import("immer/dist/internal").WritableDraft<SettingsStore>) => void), shouldReplace?: boolean | undefined): void;
43
45
  }>;
46
+ export declare const setDefaultSettings: (config?: WidgetConfig) => void;
@@ -11,17 +11,19 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.useSettingsStore = exports.defaultSettings = void 0;
14
+ exports.setDefaultSettings = exports.useSettingsStore = exports.defaultSettings = exports.defaultConfigurableSettings = void 0;
15
15
  /* eslint-disable no-underscore-dangle */
16
16
  const zustand_1 = require("zustand");
17
17
  const middleware_1 = require("zustand/middleware");
18
18
  const immer_1 = require("zustand/middleware/immer");
19
19
  const types_1 = require("./types");
20
+ exports.defaultConfigurableSettings = {
21
+ routePriority: 'RECOMMENDED',
22
+ slippage: '0.5',
23
+ };
20
24
  exports.defaultSettings = {
21
25
  appearance: 'auto',
22
26
  gasPrice: 'normal',
23
- routePriority: 'RECOMMENDED',
24
- slippage: '0.5',
25
27
  advancedPreferences: false,
26
28
  showDestinationWallet: true,
27
29
  };
@@ -81,11 +83,26 @@ exports.useSettingsStore = (0, zustand_1.default)()((0, middleware_1.persist)((0
81
83
  },
82
84
  migrate: (persistedState, version) => {
83
85
  if (version === 0 && persistedState.appearance === 'system') {
84
- persistedState.appearance = 'auto';
86
+ persistedState.appearance = exports.defaultSettings.appearance;
85
87
  }
86
88
  if (version === 1) {
87
- persistedState.slippage = '0.5';
89
+ persistedState.slippage = exports.defaultConfigurableSettings.slippage;
88
90
  }
89
91
  return persistedState;
90
92
  },
91
93
  }));
94
+ const setDefaultSettings = (config) => {
95
+ var _a, _b, _c, _d, _e;
96
+ const { slippage, routePriority, setValue } = exports.useSettingsStore.getState();
97
+ const defaultSlippage = ((config === null || config === void 0 ? void 0 : config.slippage) ||
98
+ ((_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) ||
99
+ 0) * 100;
100
+ 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);
101
+ if (!slippage) {
102
+ setValue('slippage', (_e = (defaultSlippage || exports.defaultConfigurableSettings.slippage)) === null || _e === void 0 ? void 0 : _e.toString());
103
+ }
104
+ if (!routePriority) {
105
+ setValue('routePriority', defaultRoutePriority || exports.defaultConfigurableSettings.routePriority);
106
+ }
107
+ };
108
+ exports.setDefaultSettings = setDefaultSettings;
@@ -5,7 +5,7 @@ export declare enum WidgetEvent {
5
5
  RouteExecutionCompleted = "routeExecutionCompleted",
6
6
  RouteExecutionFailed = "routeExecutionFailed"
7
7
  }
8
- export declare type WidgetEvents = {
8
+ export type WidgetEvents = {
9
9
  routeExecutionStarted: Route;
10
10
  routeExecutionUpdated: RouteExecutionUpdate;
11
11
  routeExecutionCompleted: Route;
@@ -1,19 +1,19 @@
1
- import type { ChainKey, ConfigUpdate, Token } from '@lifi/sdk';
1
+ import type { Signer } from '@ethersproject/abstract-signer';
2
+ import type { ChainKey, ConfigUpdate, Order, RouteOptions, Token } from '@lifi/sdk';
2
3
  import type { PaletteMode, PaletteOptions, Shape } from '@mui/material';
3
4
  import type { TypographyOptions } from '@mui/material/styles/createTypography';
4
- import type { Signer } from 'ethers';
5
5
  import type { CSSProperties, RefObject } from 'react';
6
6
  import type { LanguageKey, LanguageResources } from '../providers';
7
- export declare type WidgetVariant = 'default' | 'expandable' | 'drawer' | 'refuel';
7
+ export type WidgetVariant = 'default' | 'expandable' | 'drawer' | 'refuel';
8
8
  export declare enum DisabledUI {
9
9
  FromToken = "fromToken",
10
10
  ToToken = "toToken",
11
11
  FromAmount = "fromAmount",
12
12
  ToAddress = "toAddress"
13
13
  }
14
- export declare type DisabledUIType = `${DisabledUI}`;
15
- export declare type Appearance = PaletteMode | 'auto';
16
- export declare type ThemeConfig = {
14
+ export type DisabledUIType = `${DisabledUI}`;
15
+ export type Appearance = PaletteMode | 'auto';
16
+ export type ThemeConfig = {
17
17
  palette?: Pick<PaletteOptions, 'primary' | 'secondary'>;
18
18
  shape?: Shape;
19
19
  typography?: TypographyOptions;
@@ -26,6 +26,9 @@ export interface WidgetWalletManagement {
26
26
  addChain?(chainId: number): Promise<boolean>;
27
27
  signer?: Signer;
28
28
  }
29
+ export interface SDKConfig extends Omit<ConfigUpdate, 'defaultExecutionSettings' | 'defaultRouteOptions' | 'disableVersionCheck'> {
30
+ defaultRouteOptions?: Omit<RouteOptions, 'bridges' | 'exchanges'>;
31
+ }
29
32
  export interface WidgetConfig {
30
33
  fromChain?: `${ChainKey}` | number;
31
34
  toChain?: `${ChainKey}` | number;
@@ -33,7 +36,10 @@ export interface WidgetConfig {
33
36
  toToken?: string;
34
37
  toAddress?: string;
35
38
  fromAmount?: number | string;
39
+ fee?: number;
36
40
  integrator?: string;
41
+ slippage?: number;
42
+ routePriority?: Order;
37
43
  variant?: WidgetVariant;
38
44
  appearance?: Appearance;
39
45
  theme?: ThemeConfig;
@@ -43,7 +49,7 @@ export interface WidgetConfig {
43
49
  disabledUI?: DisabledUIType[];
44
50
  useRecommendedRoute?: boolean;
45
51
  walletManagement?: WidgetWalletManagement;
46
- sdkConfig?: ConfigUpdate;
52
+ sdkConfig?: SDKConfig;
47
53
  buildSwapUrl?: boolean;
48
54
  bridges?: {
49
55
  allow?: string[];
@@ -74,7 +80,7 @@ export interface WidgetConfig {
74
80
  /** @deprecated Use tokens.featured instead */
75
81
  featuredTokens?: Token[];
76
82
  }
77
- export declare type WidgetProps = {
83
+ export type WidgetProps = {
78
84
  elementRef?: RefObject<HTMLDivElement>;
79
85
  config?: WidgetConfig;
80
86
  open?: boolean;
@@ -0,0 +1 @@
1
+ export declare const hasEnumFlag: <T extends number | bigint>(flags: T, flag: T) => boolean;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasEnumFlag = void 0;
4
+ const hasEnumFlag = (flags, flag) => (flags & flag) === flag;
5
+ exports.hasEnumFlag = hasEnumFlag;
@@ -2,6 +2,7 @@ export * from './colors';
2
2
  export * from './deepClone';
3
3
  export * from './deepMerge';
4
4
  export * from './elements';
5
+ export * from './enum';
5
6
  export * from './format';
6
7
  export * from './input';
7
8
  export * from './navigationRoutes';
@@ -18,6 +18,7 @@ __exportStar(require("./colors"), exports);
18
18
  __exportStar(require("./deepClone"), exports);
19
19
  __exportStar(require("./deepMerge"), exports);
20
20
  __exportStar(require("./elements"), exports);
21
+ __exportStar(require("./enum"), exports);
21
22
  __exportStar(require("./format"), exports);
22
23
  __exportStar(require("./input"), exports);
23
24
  __exportStar(require("./navigationRoutes"), exports);
@@ -16,4 +16,4 @@ export declare const navigationRoutes: {
16
16
  export declare const navigationRoutesValues: string[];
17
17
  export declare const stickyHeaderRoutes: string[];
18
18
  export declare const backButtonRoutes: string[];
19
- export declare type NavigationRouteType = keyof typeof navigationRoutes;
19
+ export type NavigationRouteType = keyof typeof navigationRoutes;
@@ -3,6 +3,7 @@ import { ArrowForward as ArrowForwardIcon, Info as InfoIcon, Warning as WarningI
3
3
  import { ListItemAvatar, ListItemText, Typography } from '@mui/material';
4
4
  import { useNavigate } from 'react-router-dom';
5
5
  import { useProcessMessage, useRouteExecution } from '../../hooks';
6
+ import { RouteExecutionStatus } from '../../stores';
6
7
  import { navigationRoutes } from '../../utils';
7
8
  import { StepTimer } from '../Step/StepTimer';
8
9
  import { TokenAvatar, TokenAvatarGroup } from '../TokenAvatar';
@@ -37,5 +38,5 @@ export const ActiveSwapItem = ({ routeId, dense }) => {
37
38
  alignItems: 'center',
38
39
  marginLeft: 2,
39
40
  height: 16,
40
- } }, { children: [route.fromToken.symbol, _jsx(ArrowForwardIcon, { sx: { paddingX: 0.5 } }), route.toToken.symbol] })), secondary: status !== 'success' ? (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: 12, color: "text.secondary", lineHeight: 1, mt: 0.75, ml: 2 }, { children: title }))) : null }), getStatusComponent()] })));
41
+ } }, { children: [route.fromToken.symbol, _jsx(ArrowForwardIcon, { sx: { paddingX: 0.5 } }), route.toToken.symbol] })), secondary: status !== RouteExecutionStatus.Done ? (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: 12, color: "text.secondary", lineHeight: 1, mt: 0.75, ml: 2 }, { children: title }))) : null }), getStatusComponent()] })));
41
42
  };
@@ -1,6 +1,6 @@
1
1
  import type { DrawerProps } from '@mui/material';
2
2
  import type { RefObject } from 'react';
3
- export declare type BottomSheetProps = DrawerProps & {
3
+ export type BottomSheetProps = DrawerProps & {
4
4
  elementRef?: RefObject<HTMLDivElement>;
5
5
  };
6
6
  export interface BottomSheetBase {
@@ -1,7 +1,7 @@
1
1
  import type { BoxProps, Theme } from '@mui/material';
2
2
  import type { MouseEventHandler } from 'react';
3
- declare type CardVariant = 'default' | 'selected' | 'error';
4
- export declare type CardProps = {
3
+ type CardVariant = 'default' | 'selected' | 'error';
4
+ export type CardProps = {
5
5
  variant?: CardVariant;
6
6
  selectionColor?: 'primary' | 'secondary';
7
7
  dense?: boolean;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export declare const CardTitle: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
3
- align?: "inherit" | "left" | "right" | "center" | "justify" | undefined;
3
+ align?: "left" | "right" | "inherit" | "center" | "justify" | undefined;
4
4
  children?: import("react").ReactNode;
5
5
  classes?: Partial<import("@mui/material").TypographyClasses> | undefined;
6
6
  gutterBottom?: boolean | undefined;
@@ -10,10 +10,15 @@ import { useChainSelect } from './useChainSelect';
10
10
  export const ChainSelect = ({ formType }) => {
11
11
  var _a;
12
12
  const navigate = useNavigate();
13
- const { chains, getChains, setCurrentChain, isLoading } = useChainSelect(formType);
13
+ const { chainOrder, chains, getChains, isLoading, setChainOrder, setCurrentChain, } = useChainSelect(formType);
14
14
  const [chainId] = useWatch({
15
15
  name: [SwapFormKeyHelper.getChainKey(formType)],
16
16
  });
17
+ const hasChainInOrderedList = chainOrder.includes(chainId);
18
+ // If we don't have a chain in the ordered chain list we should add it.
19
+ if (!hasChainInOrderedList) {
20
+ setChainOrder(chainId);
21
+ }
17
22
  const showAllChains = () => {
18
23
  navigate(navigationRoutes[`${formType}Chain`]);
19
24
  };
@@ -1,8 +1,10 @@
1
1
  import type { EVMChain } from '@lifi/sdk';
2
2
  import type { SwapFormType } from '../../providers';
3
3
  export declare const useChainSelect: (formType: SwapFormType) => {
4
+ chainOrder: number[];
4
5
  chains: import("@lifi/sdk").ExtendedChain[] | undefined;
5
6
  getChains: () => EVMChain[];
6
- setCurrentChain: (chainId: number) => void;
7
7
  isLoading: boolean;
8
+ setChainOrder: (chainId: number) => void;
9
+ setCurrentChain: (chainId: number) => void;
8
10
  };
@@ -1,12 +1,13 @@
1
- import { useFormContext } from 'react-hook-form';
1
+ import { useController, useFormContext } from 'react-hook-form';
2
2
  import { useChains } from '../../hooks';
3
3
  import { SwapFormKey, SwapFormKeyHelper } from '../../providers';
4
4
  import { useChainOrder } from '../../stores';
5
5
  export const useChainSelect = (formType) => {
6
+ const chainKey = SwapFormKeyHelper.getChainKey(formType);
7
+ const { field: { onChange, onBlur }, } = useController({ name: chainKey });
6
8
  const { setValue } = useFormContext();
7
9
  const { chains, isLoading } = useChains();
8
10
  const [chainOrder, setChainOrder] = useChainOrder();
9
- const chainKey = SwapFormKeyHelper.getChainKey(formType);
10
11
  const getChains = () => {
11
12
  if (!chains) {
12
13
  return [];
@@ -17,11 +18,19 @@ export const useChainSelect = (formType) => {
17
18
  return selectedChains;
18
19
  };
19
20
  const setCurrentChain = (chainId) => {
20
- setValue(chainKey, chainId, { shouldTouch: true });
21
+ onChange(chainId);
22
+ onBlur();
21
23
  setValue(SwapFormKeyHelper.getTokenKey(formType), '');
22
24
  setValue(SwapFormKeyHelper.getAmountKey(formType), '');
23
25
  setValue(SwapFormKey.TokenSearchFilter, '');
24
26
  setChainOrder(chainId);
25
27
  };
26
- return { chains, getChains, setCurrentChain, isLoading };
28
+ return {
29
+ chainOrder,
30
+ chains,
31
+ getChains,
32
+ isLoading,
33
+ setChainOrder,
34
+ setCurrentChain,
35
+ };
27
36
  };
@@ -8,7 +8,7 @@ export declare const FormControl: import("@emotion/styled").StyledComponent<{
8
8
  fullWidth?: boolean | undefined;
9
9
  focused?: boolean | undefined;
10
10
  hiddenLabel?: boolean | undefined;
11
- margin?: "none" | "normal" | "dense" | undefined;
11
+ margin?: "normal" | "none" | "dense" | undefined;
12
12
  required?: boolean | undefined;
13
13
  size?: "small" | "medium" | undefined;
14
14
  sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { SwapFormTypeProps } from '../../providers';
3
+ export declare const FitInputText: import("react").ForwardRefExoticComponent<SwapFormTypeProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,16 @@
1
+ import { forwardRef, useLayoutEffect } from 'react';
2
+ import { useWatch } from 'react-hook-form';
3
+ import { SwapFormKeyHelper } from '../../providers';
4
+ import { fitInputText } from '../../utils';
5
+ import { maxInputFontSize, minInputFontSize } from './SwapInput.style';
6
+ export const FitInputText = forwardRef(({ formType }, ref) => {
7
+ const amountKey = SwapFormKeyHelper.getAmountKey(formType);
8
+ const [amount] = useWatch({
9
+ name: [amountKey],
10
+ });
11
+ useLayoutEffect(() => {
12
+ fitInputText(maxInputFontSize, minInputFontSize, ref
13
+ .current);
14
+ }, [amount, ref]);
15
+ return null;
16
+ });
@@ -1,5 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import type { SwapFormTypeProps } from '../../providers';
3
- export declare const FormPriceHelperText: React.FC<SwapFormTypeProps & {
4
- selected: boolean;
5
- }>;
3
+ export declare const FormPriceHelperText: React.FC<SwapFormTypeProps>;
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
5
5
  import { useTokenAddressBalance } from '../../hooks';
6
6
  import { SwapFormKeyHelper } from '../../providers';
7
7
  import { formatTokenPrice } from '../../utils';
8
- export const FormPriceHelperText = ({ formType, selected }) => {
8
+ export const FormPriceHelperText = ({ formType, }) => {
9
9
  const { t } = useTranslation();
10
10
  const [amount, chainId, tokenAddress] = useWatch({
11
11
  name: [