@lifi/widget 1.1.2 → 1.2.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 (93) hide show
  1. package/App.js +9 -1
  2. package/AppProvider.js +7 -2
  3. package/components/Header/Header.js +1 -1
  4. package/components/Header/NavigationHeader.js +5 -3
  5. package/components/Header/WalletHeader.js +19 -3
  6. package/components/Initializer.d.ts +2 -0
  7. package/components/Initializer.js +5 -0
  8. package/components/StepToken.js +1 -1
  9. package/components/SwapButton/SwapButton.js +5 -2
  10. package/components/SwapInProgress/SwapInProgress.js +1 -1
  11. package/components/SwapRoutes/SwapRoutes.js +2 -1
  12. package/components/TextFitter/TextFitter.js +9 -5
  13. package/hooks/index.d.ts +1 -3
  14. package/hooks/index.js +1 -3
  15. package/hooks/useContentHeight.js +18 -10
  16. package/hooks/useHasSufficientBalance.js +1 -1
  17. package/hooks/useInitializer.d.ts +1 -0
  18. package/hooks/useInitializer.js +5 -0
  19. package/hooks/{useRouteExecution/useRouteExecution.d.ts → useRouteExecution.d.ts} +1 -1
  20. package/hooks/{useRouteExecution/useRouteExecution.js → useRouteExecution.js} +5 -5
  21. package/hooks/useSwapRoutes.js +9 -7
  22. package/hooks/useTools.d.ts +1 -0
  23. package/hooks/useTools.js +14 -0
  24. package/i18n/en/translation.json +0 -2
  25. package/i18n/index.d.ts +0 -2
  26. package/package.json +6 -6
  27. package/pages/SelectTokenPage/ChainSelect.js +1 -1
  28. package/pages/SettingsPage/AdvancedPreferences.js +5 -4
  29. package/pages/SettingsPage/ColorSchemeButtonGroup.js +1 -1
  30. package/pages/SettingsPage/EnabledBridgesSelect.js +11 -6
  31. package/pages/SettingsPage/EnabledExchangesSelect.js +10 -6
  32. package/pages/SettingsPage/GasPriceSelect.js +4 -4
  33. package/pages/SettingsPage/RoutePrioritySelect.js +4 -4
  34. package/pages/SettingsPage/SlippageInput.js +7 -10
  35. package/pages/SwapPage/ExecutionItem.js +1 -1
  36. package/pages/SwapPage/StatusBottomSheet.d.ts +1 -1
  37. package/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
  38. package/pages/SwapPage/StepItem.js +1 -1
  39. package/pages/SwapPage/StepTimer.js +3 -2
  40. package/pages/SwapRoutesPage/SwapRoutesPage.js +2 -1
  41. package/providers/SwapFormProvider/SwapFormProvider.d.ts +0 -3
  42. package/providers/SwapFormProvider/SwapFormProvider.js +0 -3
  43. package/providers/SwapFormProvider/types.d.ts +0 -19
  44. package/providers/SwapFormProvider/types.js +0 -9
  45. package/providers/ThemeProvider/ThemeProvider.js +1 -1
  46. package/providers/WalletProvider/WalletProvider.js +46 -13
  47. package/providers/WalletProvider/types.d.ts +2 -1
  48. package/providers/WidgetProvider/types.d.ts +2 -2
  49. package/stores/index.d.ts +2 -0
  50. package/stores/index.js +2 -0
  51. package/stores/route/index.d.ts +5 -0
  52. package/stores/route/index.js +5 -0
  53. package/{hooks/useRouteExecution → stores/route}/types.d.ts +0 -0
  54. package/{hooks/useRouteExecution → stores/route}/types.js +0 -0
  55. package/stores/route/useCurrentRoute.d.ts +2 -0
  56. package/stores/route/useCurrentRoute.js +5 -0
  57. package/stores/route/useExecutingRoutes.d.ts +1 -0
  58. package/stores/route/useExecutingRoutes.js +4 -0
  59. package/{hooks/useRouteExecution → stores/route}/useRouteStore.d.ts +3 -5
  60. package/{hooks/useRouteExecution → stores/route}/useRouteStore.js +16 -26
  61. package/stores/route/useSetExecutableRoute.d.ts +1 -0
  62. package/stores/route/useSetExecutableRoute.js +4 -0
  63. package/stores/settings/index.d.ts +5 -0
  64. package/stores/settings/index.js +5 -0
  65. package/stores/settings/types.d.ts +23 -0
  66. package/stores/settings/types.js +1 -0
  67. package/stores/settings/useAppearance.d.ts +2 -0
  68. package/stores/settings/useAppearance.js +7 -0
  69. package/stores/settings/useSetSettings.d.ts +5 -0
  70. package/stores/settings/useSetSettings.js +5 -0
  71. package/stores/settings/useSettings.d.ts +2 -0
  72. package/stores/settings/useSettings.js +8 -0
  73. package/stores/settings/useSettingsStore.d.ts +25 -0
  74. package/stores/settings/useSettingsStore.js +84 -0
  75. package/types/widget.d.ts +33 -24
  76. package/utils/format.d.ts +1 -1
  77. package/utils/format.js +1 -1
  78. package/utils/routes.d.ts +1 -0
  79. package/utils/routes.js +7 -6
  80. package/hooks/useBridges.d.ts +0 -1
  81. package/hooks/useBridges.js +0 -12
  82. package/hooks/useExchanges.d.ts +0 -1
  83. package/hooks/useExchanges.js +0 -12
  84. package/hooks/useRouteExecution/index.d.ts +0 -3
  85. package/hooks/useRouteExecution/index.js +0 -3
  86. package/hooks/useSettings/index.d.ts +0 -2
  87. package/hooks/useSettings/index.js +0 -2
  88. package/hooks/useSettings/types.d.ts +0 -5
  89. package/hooks/useSettings/types.js +0 -1
  90. package/hooks/useSettings/useSettingsStore.d.ts +0 -13
  91. package/hooks/useSettings/useSettingsStore.js +0 -22
  92. package/pages/MainPage/SendToRecipientForm.d.ts +0 -2
  93. package/pages/MainPage/SendToRecipientForm.js +0 -20
@@ -1,13 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
3
3
  import { FormControl, MenuItem } from '@mui/material';
4
- import { useFormContext } from 'react-hook-form';
5
4
  import { useTranslation } from 'react-i18next';
6
5
  import { CardContainer, CardTitle } from '../../components/Card';
7
6
  import { Select } from '../../components/Select';
8
- import { formDefaultValues, SwapFormKey, } from '../../providers/SwapFormProvider';
7
+ import { useSetSettings, useSettings } from '../../stores';
9
8
  export const GasPriceSelect = () => {
10
9
  const { t } = useTranslation();
11
- const { register } = useFormContext();
12
- return (_jsxs(CardContainer, Object.assign({ flex: 1 }, { children: [_jsx(CardTitle, { children: t(`settings.gasPrice.title`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsxs(Select, Object.assign({ defaultValue: formDefaultValues.gasPrice, MenuProps: { elevation: 2 }, inputProps: Object.assign({}, register(SwapFormKey.GasPrice)), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: [_jsx(MenuItem, Object.assign({ value: "slow" }, { children: t(`settings.gasPrice.slow`) })), _jsx(MenuItem, Object.assign({ value: "normal" }, { children: t(`settings.gasPrice.normal`) })), _jsx(MenuItem, Object.assign({ value: "fast" }, { children: t(`settings.gasPrice.fast`) }))] })) }))] })));
10
+ const [setValue] = useSetSettings();
11
+ const { gasPrice } = useSettings(['gasPrice']);
12
+ return (_jsxs(CardContainer, Object.assign({ flex: 1 }, { children: [_jsx(CardTitle, { children: t(`settings.gasPrice.title`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsxs(Select, Object.assign({ MenuProps: { elevation: 2 }, value: gasPrice, onChange: (event) => setValue('gasPrice', event.target.value), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: [_jsx(MenuItem, Object.assign({ value: "slow" }, { children: t(`settings.gasPrice.slow`) })), _jsx(MenuItem, Object.assign({ value: "normal" }, { children: t(`settings.gasPrice.normal`) })), _jsx(MenuItem, Object.assign({ value: "fast" }, { children: t(`settings.gasPrice.fast`) }))] })) }))] })));
13
13
  };
@@ -2,13 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Orders } from '@lifinance/sdk';
3
3
  import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
4
4
  import { FormControl, MenuItem } from '@mui/material';
5
- import { useFormContext } from 'react-hook-form';
6
5
  import { useTranslation } from 'react-i18next';
7
6
  import { CardContainer, CardTitle } from '../../components/Card';
8
7
  import { Select } from '../../components/Select';
9
- import { formDefaultValues, SwapFormKey, } from '../../providers/SwapFormProvider';
8
+ import { useSetSettings, useSettings } from '../../stores';
10
9
  export const RoutePrioritySelect = () => {
11
10
  const { t } = useTranslation();
12
- const { register } = useFormContext();
13
- return (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.routePriority`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ defaultValue: formDefaultValues.routePriority, MenuProps: { elevation: 2 }, inputProps: Object.assign({}, register(SwapFormKey.RoutePriority)), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: Orders.map((order) => (_jsx(MenuItem, Object.assign({ value: order }, { children: t(`swap.tags.${order.toLowerCase()}`) }), order))) })) }))] }));
11
+ const [setValue] = useSetSettings();
12
+ const { routePriority } = useSettings(['routePriority']);
13
+ return (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.routePriority`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ MenuProps: { elevation: 2 }, value: routePriority, onChange: (event) => setValue('routePriority', event.target.value), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: Orders.map((order) => (_jsx(MenuItem, Object.assign({ value: order }, { children: t(`swap.tags.${order.toLowerCase()}`) }), order))) })) }))] }));
14
14
  };
@@ -1,28 +1,25 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { FormControl, InputAdornment } from '@mui/material';
3
3
  import { useRef } from 'react';
4
- import { useFormContext, useWatch } from 'react-hook-form';
5
4
  import { useTranslation } from 'react-i18next';
6
5
  import { CardContainer, CardTitle } from '../../components/Card';
7
6
  import { Input } from '../../components/Input';
8
- import { SwapFormKey } from '../../providers/SwapFormProvider';
7
+ import { useSetSettings, useSettings } from '../../stores';
9
8
  import { formatSlippage } from '../../utils/format';
10
9
  export const SlippageInput = () => {
11
10
  const { t } = useTranslation();
12
- const { setValue } = useFormContext();
13
- const value = useWatch({
14
- name: SwapFormKey.Slippage,
15
- });
16
- const defaultValue = useRef(value);
11
+ const [setValue] = useSetSettings();
12
+ const { slippage } = useSettings(['slippage']);
13
+ const defaultValue = useRef(slippage);
17
14
  const handleChange = (event) => {
18
15
  const { value } = event.target;
19
- setValue(SwapFormKey.Slippage, formatSlippage(value, defaultValue.current, true));
16
+ setValue('slippage', formatSlippage(value, defaultValue.current, true));
20
17
  };
21
18
  const handleBlur = (event) => {
22
19
  const { value } = event.target;
23
- setValue(SwapFormKey.Slippage, formatSlippage(value, defaultValue.current));
20
+ setValue('slippage', formatSlippage(value, defaultValue.current));
24
21
  };
25
22
  return (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.slippage`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Input, { size: "small", placeholder: t(`settings.slippage`), endAdornment: _jsx(InputAdornment, Object.assign({ position: "end" }, { children: "%" })), autoComplete: "off", inputProps: {
26
23
  inputMode: 'decimal',
27
- }, onChange: handleChange, onBlur: handleBlur, value: value, name: SwapFormKey.Slippage }) }))] }));
24
+ }, onChange: handleChange, onBlur: handleBlur, value: slippage }) }))] }));
28
25
  };
@@ -13,7 +13,7 @@ export const ExecutionItem = ({ step, process }) => {
13
13
  return (_jsxs(Box, Object.assign({ px: 2, py: 1 }, { children: [_jsxs(Box, Object.assign({ sx: {
14
14
  display: 'flex',
15
15
  alignItems: 'center',
16
- } }, { children: [_jsx(CircularProgress, { status: process.status }), _jsx(Typography, Object.assign({ ml: 2, fontWeight: process.error ? 700 : 500 }, { children: title })), process.txLink ? (_jsx(Box, Object.assign({ ml: 2, sx: {
16
+ } }, { children: [_jsx(CircularProgress, { status: process.status }), _jsx(Typography, Object.assign({ ml: 2, fontSize: 14, fontWeight: process.error ? 600 : 400 }, { children: title })), process.txLink ? (_jsx(Box, Object.assign({ ml: 2, sx: {
17
17
  display: 'flex',
18
18
  flex: 1,
19
19
  justifyContent: 'flex-end',
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- import { RouteExecution } from '../../hooks';
2
+ import { RouteExecution } from '../../stores';
3
3
  export declare const StatusBottomSheet: React.FC<RouteExecution>;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Theme } from '@mui/material';
3
- import { RouteExecutionStatus } from '../../hooks';
3
+ import { RouteExecutionStatus } from '../../stores';
4
4
  export declare const IconContainer: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
5
5
  children?: import("react").ReactNode;
6
6
  component?: import("react").ElementType<any> | undefined;
@@ -25,5 +25,5 @@ export const StepItem = ({ step, fromToken, toToken }) => {
25
25
  return (_jsxs(CardContainer, Object.assign({ isError: stepHasError }, { children: [_jsxs(Box, Object.assign({ sx: {
26
26
  display: 'flex',
27
27
  flex: 1,
28
- } }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: getCardTitle() })), _jsx(CardTitle, { children: _jsx(StepTimer, { step: step }) })] })), _jsxs(Box, Object.assign({ py: 1 }, { children: [fromToken ? _jsx(StepToken, { token: fromToken, px: 2, py: 1 }) : null, _jsx(StepActions, { step: step, px: 2, py: 1, dense: true }), (_b = step.execution) === null || _b === void 0 ? void 0 : _b.process.map((process, index) => (_jsx(ExecutionItem, { step: step, process: process }, index))), toToken ? _jsx(StepToken, { token: toToken, px: 2, py: 1 }) : null] }))] })));
28
+ } }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: getCardTitle() })), _jsx(CardTitle, Object.assign({ sx: { fontWeight: 500 } }, { children: _jsx(StepTimer, { step: step }) }))] })), _jsxs(Box, Object.assign({ py: 1 }, { children: [fromToken ? _jsx(StepToken, { token: fromToken, px: 2, py: 1 }) : null, _jsx(StepActions, { step: step, px: 2, py: 1, dense: true }), (_b = step.execution) === null || _b === void 0 ? void 0 : _b.process.map((process, index) => (_jsx(ExecutionItem, { step: step, process: process }, index))), toToken ? _jsx(StepToken, { token: toToken, px: 2, py: 1 }) : null] }))] })));
29
29
  };
@@ -8,7 +8,7 @@ const getExpiryTimestamp = (step) => {
8
8
  step.estimate.executionDuration * 1000);
9
9
  };
10
10
  export const StepTimer = ({ step }) => {
11
- var _a;
11
+ var _a, _b;
12
12
  const { t } = useTranslation();
13
13
  const [isExpired, setExpired] = useState(false);
14
14
  const [isExecutionStarted, setExecutionStarted] = useState(!!step.execution);
@@ -50,7 +50,8 @@ export const StepTimer = ({ step }) => {
50
50
  value: (step.estimate.executionDuration / 60).toFixed(0),
51
51
  }) }));
52
52
  }
53
- if (((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE') {
53
+ if (((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE' ||
54
+ ((_b = step.execution) === null || _b === void 0 ? void 0 : _b.status) === 'FAILED') {
54
55
  return null;
55
56
  }
56
57
  return isExpired ? (_jsx(_Fragment, { children: t('swap.networkIsBusy') })) : (
@@ -2,7 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Skeleton } from '@mui/material';
3
3
  import { useNavigate } from 'react-router-dom';
4
4
  import { SwapRouteCard } from '../../components/SwapRouteCard';
5
- import { useCurrentRoute, useSetExecutableRoute, useSwapRoutes, } from '../../hooks';
5
+ import { useSwapRoutes } from '../../hooks';
6
+ import { useCurrentRoute, useSetExecutableRoute } from '../../stores';
6
7
  import { routes } from '../../utils/routes';
7
8
  import { Stack } from './SwapRoutesPage.style';
8
9
  export const SwapRoutesPage = () => {
@@ -1,9 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export declare const formDefaultValues: {
3
3
  fromAmount: string;
4
- gasPrice: string;
5
- slippage: string;
6
4
  searchTokensFilter: string;
7
- routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
8
5
  };
9
6
  export declare const SwapFormProvider: React.FC<React.PropsWithChildren<{}>>;
@@ -4,10 +4,7 @@ import { useWidgetConfig } from '../WidgetProvider';
4
4
  import { SwapFormKey } from './types';
5
5
  export const formDefaultValues = {
6
6
  [SwapFormKey.FromAmount]: '',
7
- [SwapFormKey.GasPrice]: 'normal',
8
- [SwapFormKey.Slippage]: '3',
9
7
  [SwapFormKey.SearchTokensFilter]: '',
10
- [SwapFormKey.RoutePriority]: 'RECOMMENDED',
11
8
  };
12
9
  export const SwapFormProvider = ({ children, }) => {
13
10
  var _a;
@@ -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();
@@ -20,6 +20,7 @@ const initialContext = {
20
20
  switchChain: stub,
21
21
  addChain: stub,
22
22
  addToken: stub,
23
+ attemptEagerConnect: stub,
23
24
  account: {},
24
25
  };
25
26
  const WalletContext = createContext(initialContext);
@@ -30,35 +31,58 @@ export const WalletProvider = ({ children }) => {
30
31
  const [account, setAccount] = useState({});
31
32
  const connect = useCallback((wallet) => __awaiter(void 0, void 0, void 0, function* () {
32
33
  if (config.disableInternalWalletManagement) {
33
- // TODO
34
+ const signer = yield config.walletCallbacks.connect();
35
+ const account = yield extractAccountFromSigner(signer);
36
+ setAccount(account);
34
37
  return;
35
38
  }
36
39
  yield walletManagementConnect(wallet);
37
- }), [config.disableInternalWalletManagement, walletManagementConnect]);
40
+ }), [
41
+ config.disableInternalWalletManagement,
42
+ config.walletCallbacks,
43
+ walletManagementConnect,
44
+ ]);
38
45
  const disconnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
39
46
  if (config.disableInternalWalletManagement) {
47
+ yield config.walletCallbacks.disconnect();
40
48
  setAccount({});
49
+ return;
41
50
  }
42
51
  yield walletManagementDisconnect();
43
- }), [config.disableInternalWalletManagement, walletManagementDisconnect]);
52
+ }), [
53
+ config.disableInternalWalletManagement,
54
+ config.walletCallbacks,
55
+ walletManagementDisconnect,
56
+ ]);
44
57
  // only for injected wallets
45
58
  const switchChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
46
59
  if (config.disableInternalWalletManagement) {
47
- // TODO
48
- return false;
60
+ const signer = yield config.walletCallbacks.switchChain(chainId);
61
+ const account = yield extractAccountFromSigner(signer);
62
+ setAccount(account);
49
63
  }
50
64
  return walletSwitchChain(chainId);
51
- }), [config.disableInternalWalletManagement]);
65
+ }), [config.disableInternalWalletManagement, config.walletCallbacks]);
52
66
  const addChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
53
- if (!config.disableInternalWalletManagement) {
54
- yield walletAddChain(chainId);
67
+ if (config.disableInternalWalletManagement) {
68
+ return config.walletCallbacks.addChain(chainId);
55
69
  }
56
- }), [config.disableInternalWalletManagement]);
70
+ return walletAddChain(chainId);
71
+ }), [config.disableInternalWalletManagement, config.walletCallbacks]);
57
72
  const addToken = useCallback((chainId, token) => __awaiter(void 0, void 0, void 0, function* () {
58
- if (!config.disableInternalWalletManagement) {
59
- yield switchChainAndAddToken(chainId, token);
73
+ if (config.disableInternalWalletManagement) {
74
+ return config.walletCallbacks.addToken(token, chainId);
60
75
  }
61
- }), [config.disableInternalWalletManagement]);
76
+ return switchChainAndAddToken(chainId, token);
77
+ }), [config.disableInternalWalletManagement, config.walletCallbacks]);
78
+ const attemptEagerConnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
79
+ if (config.disableInternalWalletManagement) {
80
+ const signer = yield config.walletCallbacks.provideSigner();
81
+ const account = yield extractAccountFromSigner(signer);
82
+ console.log(account);
83
+ setAccount((oldAccount) => (Object.assign({}, account)));
84
+ }
85
+ }), [config.disableInternalWalletManagement, config.walletCallbacks]);
62
86
  // keep account information up to date
63
87
  useEffect(() => {
64
88
  const updateAccount = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -75,8 +99,17 @@ export const WalletProvider = ({ children }) => {
75
99
  switchChain,
76
100
  addChain,
77
101
  addToken,
102
+ attemptEagerConnect,
103
+ account,
104
+ }), [
78
105
  account,
79
- }), [account, addChain, addToken, connect, disconnect, switchChain]);
106
+ addChain,
107
+ addToken,
108
+ connect,
109
+ disconnect,
110
+ switchChain,
111
+ attemptEagerConnect,
112
+ ]);
80
113
  return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
81
114
  };
82
115
  const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
@@ -3,11 +3,12 @@ import { Token } from '@lifinance/sdk';
3
3
  import { Signer } from 'ethers';
4
4
  export interface WalletContextProps {
5
5
  account: WalletAccount;
6
- addChain(chainId: number): Promise<void>;
6
+ addChain(chainId: number): Promise<boolean>;
7
7
  addToken(chainId: number, token: Token): Promise<void>;
8
8
  disconnect(): void;
9
9
  switchChain(chainId: number): Promise<boolean>;
10
10
  connect(wallet?: Wallet | undefined): Promise<void>;
11
+ attemptEagerConnect(): Promise<void>;
11
12
  }
12
13
  export interface WalletAccount {
13
14
  address?: string;
@@ -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
+ }>;