@lifi/widget 2.4.5 → 2.5.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 (54) hide show
  1. package/cjs/components/Card/CardLabel.d.ts +1 -1
  2. package/cjs/components/GasMessage/GasMessage.js +2 -2
  3. package/cjs/config/version.d.ts +1 -1
  4. package/cjs/config/version.js +1 -1
  5. package/cjs/hooks/index.d.ts +1 -1
  6. package/cjs/hooks/index.js +1 -1
  7. package/cjs/hooks/useFromTokenSufficiency.d.ts +5 -0
  8. package/cjs/hooks/{useFundsSufficiency.js → useFromTokenSufficiency.js} +6 -6
  9. package/cjs/hooks/useGasSufficiency.js +14 -8
  10. package/cjs/i18n/en.json +2 -1
  11. package/cjs/i18n/pt.json +2 -1
  12. package/cjs/i18n/tr.json +2 -1
  13. package/cjs/i18n/uk.json +2 -1
  14. package/cjs/pages/SettingsPage/ResetSettingsButton.js +29 -1
  15. package/cjs/pages/SettingsPage/ResetSettingsButton.style.d.ts +4 -0
  16. package/cjs/pages/SettingsPage/ResetSettingsButton.style.js +13 -0
  17. package/cjs/pages/TransactionPage/StartTransactionButton.js +3 -3
  18. package/cjs/providers/SDKProvider/SDKProvider.js +5 -4
  19. package/cjs/stores/StoreProvider.js +3 -1
  20. package/cjs/stores/routes/createRouteExecutionStore.js +1 -1
  21. package/cjs/stores/settings/types.d.ts +4 -3
  22. package/cjs/stores/settings/useSettingsStore.d.ts +1 -1
  23. package/cjs/stores/settings/useSettingsStore.js +7 -3
  24. package/cjs/stores/settings/useSplitSubvariantStore.js +1 -1
  25. package/cjs/types/widget.d.ts +4 -1
  26. package/components/Card/CardLabel.d.ts +1 -1
  27. package/components/GasMessage/GasMessage.js +3 -3
  28. package/config/version.d.ts +1 -1
  29. package/config/version.js +1 -1
  30. package/hooks/index.d.ts +1 -1
  31. package/hooks/index.js +1 -1
  32. package/hooks/useFromTokenSufficiency.d.ts +5 -0
  33. package/hooks/{useFundsSufficiency.js → useFromTokenSufficiency.js} +4 -4
  34. package/hooks/useGasSufficiency.js +14 -8
  35. package/i18n/en.json +2 -1
  36. package/i18n/pt.json +2 -1
  37. package/i18n/tr.json +2 -1
  38. package/i18n/uk.json +2 -1
  39. package/package.json +10 -10
  40. package/pages/SettingsPage/ResetSettingsButton.js +30 -2
  41. package/pages/SettingsPage/ResetSettingsButton.style.d.ts +4 -0
  42. package/pages/SettingsPage/ResetSettingsButton.style.js +10 -0
  43. package/pages/TransactionPage/StartTransactionButton.js +4 -4
  44. package/providers/SDKProvider/SDKProvider.js +5 -4
  45. package/stores/StoreProvider.js +3 -1
  46. package/stores/routes/createRouteExecutionStore.js +1 -1
  47. package/stores/settings/types.d.ts +4 -3
  48. package/stores/settings/useSettingsStore.d.ts +1 -1
  49. package/stores/settings/useSettingsStore.js +7 -3
  50. package/stores/settings/useSplitSubvariantStore.js +1 -1
  51. package/tsconfig.cjs.tsbuildinfo +1 -1
  52. package/types/widget.d.ts +4 -1
  53. package/cjs/hooks/useFundsSufficiency.d.ts +0 -5
  54. package/hooks/useFundsSufficiency.d.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "2.4.5",
3
+ "version": "2.5.0",
4
4
  "description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -43,13 +43,13 @@
43
43
  "@ethersproject/address": "^5.7.0",
44
44
  "@ethersproject/experimental": "^5.7.0",
45
45
  "@ethersproject/providers": "^5.7.2",
46
- "@lifi/sdk": "^2.4.0",
47
- "@lifi/wallet-management": "^2.3.4",
48
- "@mui/icons-material": "^5.14.9",
49
- "@mui/lab": "^5.0.0-alpha.145",
50
- "@mui/material": "^5.14.10",
51
- "@tanstack/react-query": "^4.35.3",
52
- "@tanstack/react-virtual": "^3.0.0-beta.60",
46
+ "@lifi/sdk": "^2.4.1",
47
+ "@lifi/wallet-management": "^2.3.5",
48
+ "@mui/icons-material": "^5.14.11",
49
+ "@mui/lab": "^5.0.0-alpha.146",
50
+ "@mui/material": "^5.14.11",
51
+ "@tanstack/react-query": "^4.35.7",
52
+ "@tanstack/react-virtual": "^3.0.0-beta.61",
53
53
  "big.js": "^6.2.1",
54
54
  "i18next": "^23.5.1",
55
55
  "i18next-browser-languagedetector": "^7.1.0",
@@ -57,13 +57,13 @@
57
57
  "mitt": "^3.0.1",
58
58
  "react": "^18.2.0",
59
59
  "react-dom": "^18.2.0",
60
- "react-hook-form": "^7.46.1",
60
+ "react-hook-form": "^7.47.0",
61
61
  "react-i18next": "^13.2.2",
62
62
  "react-intersection-observer": "^9.5.2",
63
63
  "react-router-dom": "^6.16.0",
64
64
  "react-timer-hook": "^3.0.7",
65
65
  "uuid": "^9.0.1",
66
- "zustand": "^4.4.1"
66
+ "zustand": "^4.4.2"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@types/react": "^18.0.0",
@@ -5,8 +5,18 @@ import { useTranslation } from 'react-i18next';
5
5
  import { Dialog } from '../../components/Dialog';
6
6
  import { useTools } from '../../hooks';
7
7
  import { useWidgetConfig } from '../../providers';
8
- import { useSettingsStore } from '../../stores';
8
+ import { defaultConfigurableSettings, setDefaultSettings, useSettingsStore, } from '../../stores';
9
+ import { ResetButtonContainer } from './ResetSettingsButton.style';
10
+ import { InfoRounded } from '@mui/icons-material';
11
+ import { shallow } from 'zustand/shallow';
9
12
  export const ResetSettingsButton = () => {
13
+ const [enabledBridges, enabledExchanges, routePriority, slippage, gasPrice] = useSettingsStore((state) => [
14
+ state.enabledBridges,
15
+ state.enabledExchanges,
16
+ state.routePriority,
17
+ state.slippage,
18
+ state.gasPrice,
19
+ ], shallow);
10
20
  const { t } = useTranslation();
11
21
  const { tools } = useTools();
12
22
  const config = useWidgetConfig();
@@ -18,8 +28,26 @@ export const ResetSettingsButton = () => {
18
28
  const handleReset = () => {
19
29
  if (tools) {
20
30
  resetSettings(config, tools.bridges.map((tool) => tool.key), tools.exchanges.map((tool) => tool.key));
31
+ setDefaultSettings(config);
21
32
  }
22
33
  toggleDialog();
23
34
  };
24
- return (_jsxs(Box, { px: 3, mt: 1.5, mb: 1, children: [_jsx(Button, { onClick: toggleDialog, fullWidth: true, children: t('button.resetSettings') }), _jsxs(Dialog, { open: open, onClose: toggleDialog, children: [_jsx(DialogTitle, { children: t('warning.title.resetSettings') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('warning.message.resetSettings') }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: toggleDialog, children: t('button.cancel') }), _jsx(Button, { variant: "contained", onClick: handleReset, autoFocus: true, children: t('button.reset') })] })] })] }));
35
+ const isSlippageChanged = config.slippage
36
+ ? Number(slippage) !== config.slippage * 100
37
+ : slippage !== defaultConfigurableSettings.slippage;
38
+ const isRoutePriorityChanged = config.routePriority
39
+ ? routePriority !== config.routePriority
40
+ : routePriority !== defaultConfigurableSettings.routePriority;
41
+ const isGasPriceChanged = gasPrice !== defaultConfigurableSettings.gasPrice;
42
+ const isCustomRouteSettings = tools?.bridges?.length !== enabledBridges?.length ||
43
+ tools?.exchanges?.length !== enabledExchanges?.length ||
44
+ isSlippageChanged ||
45
+ isRoutePriorityChanged ||
46
+ isGasPriceChanged;
47
+ if (!isCustomRouteSettings) {
48
+ return null;
49
+ }
50
+ return (_jsx(Box, { px: 3, mt: 1.5, mb: 1, children: _jsxs(ResetButtonContainer, { children: [_jsxs(Box, { display: "flex", marginBottom: "12px", children: [_jsx(InfoRounded, { sx: {
51
+ marginRight: '8px',
52
+ } }), _jsx(Box, { fontSize: 14, children: t(`settings.resetSettings`) })] }), _jsx(Button, { onClick: toggleDialog, fullWidth: true, children: t('button.resetSettings') }), _jsxs(Dialog, { open: open, onClose: toggleDialog, children: [_jsx(DialogTitle, { children: t('warning.title.resetSettings') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('warning.message.resetSettings') }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: toggleDialog, children: t('button.cancel') }), _jsx(Button, { variant: "contained", onClick: handleReset, autoFocus: true, children: t('button.reset') })] })] })] }) }));
25
53
  };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare const ResetButtonContainer: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
3
+ ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
4
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
@@ -0,0 +1,10 @@
1
+ import { getContrastAlphaColor } from '../../utils';
2
+ import { Box, styled } from '@mui/material';
3
+ export const ResetButtonContainer = styled(Box)(({ theme }) => ({
4
+ background: getContrastAlphaColor(theme.palette.mode, '4%'),
5
+ borderRadius: '16px',
6
+ padding: '16px',
7
+ [`svg`]: {
8
+ fill: getContrastAlphaColor(theme.palette.mode, '40%'),
9
+ },
10
+ }));
@@ -1,15 +1,15 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { DefaultTransactionButton } from '../../components/DefaultTransactionButton';
3
- import { useFundsSufficiency, useGasSufficiency, useRoutes } from '../../hooks';
3
+ import { useFromTokenSufficiency, useGasSufficiency, useRoutes, } from '../../hooks';
4
4
  import { useWidgetConfig } from '../../providers';
5
5
  import { useRouteExecutionStore } from '../../stores';
6
6
  export const StartTransactionButton = ({ onClick, route, text, loading, }) => {
7
7
  const { sdkConfig } = useWidgetConfig();
8
8
  const isMultisigSigner = sdkConfig?.multisigConfig?.isMultisigSigner;
9
9
  const { insufficientGas, isInitialLoading: isGasSufficiencyLoading } = useGasSufficiency(route);
10
- const { insufficientFunds, isInitialLoading: isFundsSufficiencyLoading } = useFundsSufficiency(route);
11
- const shouldDisableButton = !isMultisigSigner && (insufficientFunds || !!insufficientGas?.length);
12
- return (_jsx(DefaultTransactionButton, { onClick: onClick, text: text, disabled: shouldDisableButton, loading: isFundsSufficiencyLoading || isGasSufficiencyLoading || loading }));
10
+ const { insufficientFromToken, isInitialLoading: isFromTokenSufficiencyLoading, } = useFromTokenSufficiency(route);
11
+ const shouldDisableButton = !isMultisigSigner && (insufficientFromToken || !!insufficientGas?.length);
12
+ return (_jsx(DefaultTransactionButton, { onClick: onClick, text: text, disabled: shouldDisableButton, loading: isFromTokenSufficiencyLoading || isGasSufficiencyLoading || loading }));
13
13
  };
14
14
  export const StartInsurableTransactionButton = ({ onClick, text, route, loading, disabled, insurableRouteId }) => {
15
15
  const routeExecution = useRouteExecutionStore((state) => state.routes[insurableRouteId]);
@@ -7,16 +7,17 @@ let lifi;
7
7
  const SDKContext = createContext(null);
8
8
  export const useLiFi = () => useContext(SDKContext);
9
9
  export const SDKProvider = ({ children, }) => {
10
- const { sdkConfig, fee, integrator, referrer, routePriority, slippage } = useWidgetConfig();
10
+ const { sdkConfig, integrator, apiKey, fee, referrer, routePriority, slippage, } = useWidgetConfig();
11
11
  const value = useMemo(() => {
12
12
  const config = {
13
13
  ...sdkConfig,
14
+ apiKey,
14
15
  integrator: integrator ?? window.location.hostname,
15
16
  defaultRouteOptions: {
16
- fee,
17
17
  integrator: integrator ?? window.location.hostname,
18
+ fee,
18
19
  referrer,
19
- routePriority,
20
+ order: routePriority,
20
21
  slippage,
21
22
  ...sdkConfig?.defaultRouteOptions,
22
23
  },
@@ -30,6 +31,6 @@ export const SDKProvider = ({ children, }) => {
30
31
  }
31
32
  lifi.setConfig(config);
32
33
  return lifi;
33
- }, [fee, integrator, referrer, routePriority, sdkConfig, slippage]);
34
+ }, [apiKey, fee, integrator, referrer, routePriority, sdkConfig, slippage]);
34
35
  return _jsx(SDKContext.Provider, { value: value, children: children });
35
36
  };
@@ -4,5 +4,7 @@ import { HeaderStoreProvider } from './header';
4
4
  import { RouteExecutionStoreProvider } from './routes';
5
5
  import { SplitSubvariantStoreProvider } from './settings';
6
6
  export const StoreProvider = ({ children, config, }) => {
7
- return (_jsx(SplitSubvariantStoreProvider, { state: config.subvariant === 'split' ? 'swap' : undefined, children: _jsx(HeaderStoreProvider, { namePrefix: config?.keyPrefix, children: _jsx(ChainOrderStoreProvider, { namePrefix: config?.keyPrefix, children: _jsx(RouteExecutionStoreProvider, { namePrefix: config?.keyPrefix, children: children }) }) }) }));
7
+ return (_jsx(SplitSubvariantStoreProvider, { state: config.subvariant === 'split'
8
+ ? config.subvariantOptions || 'swap'
9
+ : undefined, children: _jsx(HeaderStoreProvider, { namePrefix: config?.keyPrefix, children: _jsx(ChainOrderStoreProvider, { namePrefix: config?.keyPrefix, children: _jsx(RouteExecutionStoreProvider, { namePrefix: config?.keyPrefix, children: children }) }) }) }));
8
10
  };
@@ -151,7 +151,7 @@ export const createRouteExecutionStore = ({ namePrefix }) => createWithEqualityF
151
151
  }
152
152
  }
153
153
  catch (error) {
154
- console.log(error);
154
+ console.error(error);
155
155
  }
156
156
  return state;
157
157
  },
@@ -35,12 +35,13 @@ export interface SendToWalletStore extends SendToWalletState {
35
35
  toggleSendToWallet(): void;
36
36
  setSendToWallet(value: boolean): void;
37
37
  }
38
+ export type SplitSubvariantOptions = 'bridge' | 'swap';
38
39
  export interface SplitSubvariantState {
39
- state?: 'swap' | 'bridge';
40
- setState(state: 'swap' | 'bridge'): void;
40
+ state?: SplitSubvariantOptions;
41
+ setState(state: SplitSubvariantOptions): void;
41
42
  }
42
43
  export type SplitSubvariantStore = UseBoundStoreWithEqualityFn<StoreApi<SplitSubvariantState>>;
43
44
  export interface SplitSubvariantProps {
44
- state?: 'swap' | 'bridge';
45
+ state?: SplitSubvariantOptions;
45
46
  }
46
47
  export type SplitSubvariantProviderProps = PropsWithChildren<SplitSubvariantProps>;
@@ -1,6 +1,6 @@
1
1
  import type { WidgetConfig } from '../../types';
2
2
  import type { SettingsProps, SettingsState } from './types';
3
- export declare const defaultConfigurableSettings: Pick<SettingsState, 'routePriority' | 'slippage'>;
3
+ export declare const defaultConfigurableSettings: Pick<SettingsState, 'routePriority' | 'slippage' | 'gasPrice'>;
4
4
  export declare const defaultSettings: SettingsProps;
5
5
  export declare const useSettingsStore: import("zustand/traditional").UseBoundStoreWithEqualityFn<import("zustand").StoreApi<SettingsState>>;
6
6
  export declare const setDefaultSettings: (config?: WidgetConfig) => void;
@@ -4,6 +4,7 @@ import { SettingsToolTypes } from './types';
4
4
  export const defaultConfigurableSettings = {
5
5
  routePriority: 'RECOMMENDED',
6
6
  slippage: '0.5',
7
+ gasPrice: 'normal',
7
8
  };
8
9
  export const defaultSettings = {
9
10
  appearance: 'auto',
@@ -64,10 +65,10 @@ export const useSettingsStore = createWithEqualityFn(persist((set, get) => ({
64
65
  }, {}),
65
66
  })),
66
67
  reset: (config, bridges, exchanges) => {
68
+ const { appearance, ...restDefaultSettings } = defaultSettings;
67
69
  set(() => ({
68
- ...defaultSettings,
70
+ ...restDefaultSettings,
69
71
  ...defaultConfigurableSettings,
70
- appearance: config.appearance ?? defaultSettings.appearance,
71
72
  }));
72
73
  get().initializeTools('Bridges', bridges, true);
73
74
  get().initializeTools('Exchanges', exchanges, true);
@@ -99,7 +100,7 @@ export const useSettingsStore = createWithEqualityFn(persist((set, get) => ({
99
100
  },
100
101
  }), Object.is);
101
102
  export const setDefaultSettings = (config) => {
102
- const { slippage, routePriority, setValue } = useSettingsStore.getState();
103
+ const { slippage, routePriority, setValue, gasPrice } = useSettingsStore.getState();
103
104
  const defaultSlippage = (config?.slippage ||
104
105
  config?.sdkConfig?.defaultRouteOptions?.slippage ||
105
106
  0) * 100;
@@ -113,4 +114,7 @@ export const setDefaultSettings = (config) => {
113
114
  if (!routePriority) {
114
115
  setValue('routePriority', defaultConfigurableSettings.routePriority);
115
116
  }
117
+ if (!gasPrice) {
118
+ setValue('gasPrice', defaultConfigurableSettings.gasPrice);
119
+ }
116
120
  };
@@ -4,7 +4,7 @@ import { createWithEqualityFn } from 'zustand/traditional';
4
4
  export const SplitSubvariantStoreContext = createContext(null);
5
5
  const shouldRecreateStore = (store, props) => {
6
6
  const { state } = store.getState();
7
- return (!state && props.state) || (state && !props.state);
7
+ return state !== props.state;
8
8
  };
9
9
  export function SplitSubvariantStoreProvider({ children, ...props }) {
10
10
  const storeRef = useRef();