@lifi/widget 1.1.3 → 1.2.2

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 (86) hide show
  1. package/App.js +9 -1
  2. package/components/Header/WalletHeader.js +18 -2
  3. package/components/Initializer.d.ts +2 -0
  4. package/components/Initializer.js +5 -0
  5. package/components/StepToken.js +1 -1
  6. package/components/SwapButton/SwapButton.js +14 -3
  7. package/components/SwapInProgress/SwapInProgress.js +1 -1
  8. package/components/SwapRoutes/SwapRoutes.js +2 -1
  9. package/components/TextFitter/TextFitter.js +9 -5
  10. package/hooks/index.d.ts +1 -3
  11. package/hooks/index.js +1 -3
  12. package/hooks/useHasSufficientBalance.js +1 -1
  13. package/hooks/useInitializer.d.ts +1 -0
  14. package/hooks/useInitializer.js +5 -0
  15. package/hooks/{useRouteExecution/useRouteExecution.d.ts → useRouteExecution.d.ts} +1 -1
  16. package/hooks/{useRouteExecution/useRouteExecution.js → useRouteExecution.js} +5 -5
  17. package/hooks/useSwapRoutes.js +9 -7
  18. package/hooks/useTools.d.ts +1 -0
  19. package/hooks/useTools.js +14 -0
  20. package/i18n/en/translation.json +0 -2
  21. package/i18n/index.d.ts +0 -2
  22. package/package.json +6 -6
  23. package/pages/SettingsPage/AdvancedPreferences.js +5 -4
  24. package/pages/SettingsPage/ColorSchemeButtonGroup.js +1 -1
  25. package/pages/SettingsPage/EnabledBridgesSelect.js +11 -6
  26. package/pages/SettingsPage/EnabledExchangesSelect.js +10 -6
  27. package/pages/SettingsPage/GasPriceSelect.js +4 -4
  28. package/pages/SettingsPage/RoutePrioritySelect.js +4 -4
  29. package/pages/SettingsPage/SlippageInput.js +7 -10
  30. package/pages/SwapPage/ExecutionItem.js +1 -1
  31. package/pages/SwapPage/StatusBottomSheet.d.ts +1 -1
  32. package/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
  33. package/pages/SwapPage/StepItem.js +1 -1
  34. package/pages/SwapPage/StepTimer.js +3 -2
  35. package/pages/SwapRoutesPage/SwapRoutesPage.js +2 -1
  36. package/providers/SwapFormProvider/SwapFormProvider.d.ts +0 -3
  37. package/providers/SwapFormProvider/SwapFormProvider.js +0 -3
  38. package/providers/SwapFormProvider/types.d.ts +0 -19
  39. package/providers/SwapFormProvider/types.js +0 -9
  40. package/providers/ThemeProvider/ThemeProvider.js +1 -1
  41. package/providers/WalletProvider/WalletProvider.js +74 -13
  42. package/providers/WalletProvider/types.d.ts +2 -1
  43. package/providers/WidgetProvider/types.d.ts +2 -2
  44. package/stores/index.d.ts +2 -0
  45. package/stores/index.js +2 -0
  46. package/stores/route/index.d.ts +5 -0
  47. package/stores/route/index.js +5 -0
  48. package/{hooks/useRouteExecution → stores/route}/types.d.ts +0 -0
  49. package/{hooks/useRouteExecution → stores/route}/types.js +0 -0
  50. package/stores/route/useCurrentRoute.d.ts +2 -0
  51. package/stores/route/useCurrentRoute.js +5 -0
  52. package/stores/route/useExecutingRoutes.d.ts +1 -0
  53. package/stores/route/useExecutingRoutes.js +4 -0
  54. package/{hooks/useRouteExecution → stores/route}/useRouteStore.d.ts +3 -5
  55. package/{hooks/useRouteExecution → stores/route}/useRouteStore.js +16 -26
  56. package/stores/route/useSetExecutableRoute.d.ts +1 -0
  57. package/stores/route/useSetExecutableRoute.js +4 -0
  58. package/stores/settings/index.d.ts +5 -0
  59. package/stores/settings/index.js +5 -0
  60. package/stores/settings/types.d.ts +23 -0
  61. package/stores/settings/types.js +1 -0
  62. package/stores/settings/useAppearance.d.ts +2 -0
  63. package/stores/settings/useAppearance.js +7 -0
  64. package/stores/settings/useSetSettings.d.ts +5 -0
  65. package/stores/settings/useSetSettings.js +5 -0
  66. package/stores/settings/useSettings.d.ts +2 -0
  67. package/stores/settings/useSettings.js +8 -0
  68. package/stores/settings/useSettingsStore.d.ts +25 -0
  69. package/stores/settings/useSettingsStore.js +84 -0
  70. package/types/widget.d.ts +34 -24
  71. package/utils/format.d.ts +1 -1
  72. package/utils/format.js +1 -1
  73. package/hooks/useBridges.d.ts +0 -1
  74. package/hooks/useBridges.js +0 -12
  75. package/hooks/useExchanges.d.ts +0 -1
  76. package/hooks/useExchanges.js +0 -12
  77. package/hooks/useRouteExecution/index.d.ts +0 -3
  78. package/hooks/useRouteExecution/index.js +0 -3
  79. package/hooks/useSettings/index.d.ts +0 -2
  80. package/hooks/useSettings/index.js +0 -2
  81. package/hooks/useSettings/types.d.ts +0 -5
  82. package/hooks/useSettings/types.js +0 -1
  83. package/hooks/useSettings/useSettingsStore.d.ts +0 -13
  84. package/hooks/useSettings/useSettingsStore.js +0 -22
  85. package/pages/MainPage/SendToRecipientForm.d.ts +0 -2
  86. package/pages/MainPage/SendToRecipientForm.js +0 -20
package/types/widget.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ChainKey } from '@lifinance/sdk';
1
+ import { ChainKey, Token } from '@lifinance/sdk';
2
2
  import { PaletteMode, PaletteOptions, Shape } from '@mui/material';
3
3
  import { TypographyOptions } from '@mui/material/styles/createTypography';
4
4
  import { Signer } from 'ethers';
@@ -9,33 +9,43 @@ export declare type ThemeConfig = {
9
9
  shape?: Shape;
10
10
  typography?: TypographyOptions;
11
11
  };
12
- export interface WidgetConfig {
12
+ export interface WidgetWalletCallbacks {
13
+ connect(): Promise<Signer>;
14
+ disconnect(): Promise<void>;
15
+ provideSigner(): Promise<Signer | undefined>;
16
+ switchChain(reqChainId: number): Promise<Signer>;
17
+ addToken(token: Token, chainId: number): Promise<void>;
18
+ addChain(chainId: number): Promise<boolean>;
19
+ signer?: Signer;
20
+ }
21
+ interface WidgetConfigBase {
13
22
  fromAmount?: number;
14
- fromChain?: `${ChainKey}` | number;
15
- fromToken?: string;
16
- toChain?: `${ChainKey}` | number;
17
- toToken?: string;
18
23
  disabledChains?: number[];
19
- disableInternalWalletManagement?: boolean;
20
- walletCallbacks?: {
21
- connect: {
22
- (): Signer;
23
- };
24
- disconnect: {
25
- (): void;
26
- };
27
- provideSigner: {
28
- (): Signer;
29
- };
30
- switchChain: {
31
- (): Signer;
32
- };
33
- addToken: {
34
- (): void;
35
- };
36
- };
37
24
  containerStyle?: CSSProperties;
38
25
  theme?: ThemeConfig;
39
26
  appearance?: Appearance;
40
27
  disableAppearance?: boolean;
41
28
  }
29
+ declare type WidgetFromTokenConfig = {
30
+ fromChain: `${ChainKey}` | number;
31
+ fromToken?: string;
32
+ } | {
33
+ fromChain?: never;
34
+ fromToken?: never;
35
+ };
36
+ declare type WidgetToTokenConfig = {
37
+ toChain: `${ChainKey}` | number;
38
+ toToken?: string;
39
+ } | {
40
+ toChain?: never;
41
+ toToken?: never;
42
+ };
43
+ declare type WidgetWalletManagementConfig = {
44
+ disableInternalWalletManagement: true;
45
+ externalWalletManagementSettings: WidgetWalletCallbacks;
46
+ } | {
47
+ disableInternalWalletManagement?: false;
48
+ externalWalletManagementSettings?: never;
49
+ };
50
+ export declare type WidgetConfig = WidgetConfigBase & WidgetFromTokenConfig & WidgetToTokenConfig & WidgetWalletManagementConfig;
51
+ export {};
package/utils/format.d.ts CHANGED
@@ -4,6 +4,6 @@
4
4
  * @returns formatted amount.
5
5
  */
6
6
  export declare const formatTokenAmount: (amount?: string, decimals?: number) => string;
7
- export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string | number;
7
+ export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string;
8
8
  export declare const formatAmount: (amount?: string, returnInitial?: boolean) => string;
9
9
  export declare const formatTokenPrice: (amount?: string, price?: string) => number;
package/utils/format.js CHANGED
@@ -30,7 +30,7 @@ export const formatSlippage = (slippage = '', defaultValue = '', returnInitial =
30
30
  }
31
31
  const parsedSlippage = parseFloat(slippage);
32
32
  if (isNaN(Number(slippage)) && !isNaN(parsedSlippage)) {
33
- return parsedSlippage;
33
+ return parsedSlippage.toString();
34
34
  }
35
35
  if (isNaN(parsedSlippage)) {
36
36
  return defaultValue;
@@ -1 +0,0 @@
1
- export declare const useBridges: () => string[];
@@ -1,12 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { useQuery } from 'react-query';
3
- import { LiFi } from '../lifi';
4
- export const useBridges = () => {
5
- const { data } = useQuery(['bridges'], ({ signal }) => LiFi.getPossibilities({ include: ['bridges'] }, { signal }));
6
- const bridges = useMemo(() => {
7
- var _a;
8
- const bridges = (_a = data === null || data === void 0 ? void 0 : data.bridges) === null || _a === void 0 ? void 0 : _a.map((bridge) => bridge.tool).map((bridegTool) => bridegTool.split('-')[0]);
9
- return Array.from(new Set(bridges));
10
- }, [data === null || data === void 0 ? void 0 : data.bridges]);
11
- return bridges;
12
- };
@@ -1 +0,0 @@
1
- export declare const useExchanges: () => string[];
@@ -1,12 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { useQuery } from 'react-query';
3
- import { LiFi } from '../lifi';
4
- export const useExchanges = () => {
5
- const { data } = useQuery(['exchanges'], ({ signal }) => LiFi.getPossibilities({ include: ['exchanges'] }, { signal }));
6
- const exchanges = useMemo(() => {
7
- var _a;
8
- const exchanges = (_a = data === null || data === void 0 ? void 0 : data.exchanges) === null || _a === void 0 ? void 0 : _a.map((exchange) => exchange.tool).map((exchangeTool) => exchangeTool.split('-')[0]);
9
- return Array.from(new Set(exchanges));
10
- }, [data === null || data === void 0 ? void 0 : data.exchanges]);
11
- return exchanges;
12
- };
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './useRouteExecution';
3
- export * from './useRouteStore';
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './useRouteExecution';
3
- export * from './useRouteStore';
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './useSettingsStore';
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './useSettingsStore';
@@ -1,5 +0,0 @@
1
- import { Appearance } from '../../types';
2
- export interface SettingsStore {
3
- appearance: Appearance;
4
- setAppearance(appearance: Appearance): void;
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { Appearance } from '../../types';
2
- import { SettingsStore } from './types';
3
- export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
4
- persist: {
5
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, Partial<SettingsStore>>>) => void;
6
- clearStorage: () => void;
7
- rehydrate: () => Promise<void>;
8
- hasHydrated: () => boolean;
9
- onHydrate: (fn: (state: SettingsStore) => void) => () => void;
10
- onFinishHydration: (fn: (state: SettingsStore) => void) => () => void;
11
- };
12
- }>;
13
- export declare const useAppearance: () => [Appearance, (appearance: Appearance) => void];
@@ -1,22 +0,0 @@
1
- import produce from 'immer';
2
- import create from 'zustand';
3
- import { persist } from 'zustand/middleware';
4
- import shallow from 'zustand/shallow';
5
- export const useSettingsStore = create()(persist((set) => ({
6
- appearance: 'auto',
7
- setAppearance: (appearance) => set(produce((state) => {
8
- state.appearance = appearance;
9
- })),
10
- }), {
11
- name: 'li.fi-widget-settings',
12
- version: 1,
13
- migrate: (persistedState, version) => {
14
- if (version === 0 && persistedState.appearance === 'system') {
15
- persistedState.appearance = 'auto';
16
- }
17
- return persistedState;
18
- },
19
- }));
20
- export const useAppearance = () => {
21
- return useSettingsStore((state) => [state.appearance, state.setAppearance], shallow);
22
- };
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const SendToRecipientForm: React.FC;
@@ -1,20 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { HelpOutline as HelpOutlineIcon } from '@mui/icons-material';
3
- import { Box, Checkbox, FormControl, FormControlLabel, Typography, } from '@mui/material';
4
- import { useFormContext, useWatch } from 'react-hook-form';
5
- import { useTranslation } from 'react-i18next';
6
- import { Input } from '../../components/Input';
7
- import { Switch } from '../../components/Switch';
8
- import { SwapFormKey } from '../../providers/SwapFormProvider';
9
- export const SendToRecipientForm = () => {
10
- const { t } = useTranslation();
11
- const { register } = useFormContext();
12
- const sendToRecipientChecked = useWatch({
13
- name: SwapFormKey.IsSendToRecipient,
14
- });
15
- return (_jsxs(_Fragment, { children: [_jsxs(Box, Object.assign({ mb: 2, sx: {
16
- display: 'flex',
17
- justifyContent: 'space-between',
18
- alignItems: 'center',
19
- } }, { children: [_jsxs(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: [_jsx(HelpOutlineIcon, { sx: { color: 'grey.500' } }), _jsx(Typography, Object.assign({ lineHeight: "normal", variant: "subtitle1", color: "text.primary", ml: 1 }, { children: t(`swap.sendToRecipient`) }))] })), _jsx(Switch, Object.assign({}, register(SwapFormKey.IsSendToRecipient)))] })), sendToRecipientChecked ? (_jsxs(_Fragment, { children: [_jsx(FormControl, Object.assign({ variant: "standard", fullWidth: true }, { children: _jsx(Input, { size: "small", placeholder: t(`swap.recipientsAddress`, { chain: 'ETH' }), required: true, inputProps: Object.assign({}, register(SwapFormKey.RecipientsAddress)) }) })), _jsx(Box, Object.assign({ mt: 0.5, mb: 1 }, { children: _jsx(FormControlLabel, { control: _jsx(Checkbox, Object.assign({ required: true }, register(SwapFormKey.IsAddressConfirmed))), label: t(`swap.addressConfirmation`), componentsProps: { typography: { variant: 'body2' } } }) }))] })) : null] }));
20
- };