@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.
- package/App.js +9 -1
- package/AppProvider.js +7 -2
- package/components/Header/Header.js +1 -1
- package/components/Header/NavigationHeader.js +5 -3
- package/components/Header/WalletHeader.js +19 -3
- package/components/Initializer.d.ts +2 -0
- package/components/Initializer.js +5 -0
- package/components/StepToken.js +1 -1
- package/components/SwapButton/SwapButton.js +5 -2
- package/components/SwapInProgress/SwapInProgress.js +1 -1
- package/components/SwapRoutes/SwapRoutes.js +2 -1
- package/components/TextFitter/TextFitter.js +9 -5
- package/hooks/index.d.ts +1 -3
- package/hooks/index.js +1 -3
- package/hooks/useContentHeight.js +18 -10
- package/hooks/useHasSufficientBalance.js +1 -1
- package/hooks/useInitializer.d.ts +1 -0
- package/hooks/useInitializer.js +5 -0
- package/hooks/{useRouteExecution/useRouteExecution.d.ts → useRouteExecution.d.ts} +1 -1
- package/hooks/{useRouteExecution/useRouteExecution.js → useRouteExecution.js} +5 -5
- package/hooks/useSwapRoutes.js +9 -7
- package/hooks/useTools.d.ts +1 -0
- package/hooks/useTools.js +14 -0
- package/i18n/en/translation.json +0 -2
- package/i18n/index.d.ts +0 -2
- package/package.json +6 -6
- package/pages/SelectTokenPage/ChainSelect.js +1 -1
- package/pages/SettingsPage/AdvancedPreferences.js +5 -4
- package/pages/SettingsPage/ColorSchemeButtonGroup.js +1 -1
- package/pages/SettingsPage/EnabledBridgesSelect.js +11 -6
- package/pages/SettingsPage/EnabledExchangesSelect.js +10 -6
- package/pages/SettingsPage/GasPriceSelect.js +4 -4
- package/pages/SettingsPage/RoutePrioritySelect.js +4 -4
- package/pages/SettingsPage/SlippageInput.js +7 -10
- package/pages/SwapPage/ExecutionItem.js +1 -1
- package/pages/SwapPage/StatusBottomSheet.d.ts +1 -1
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
- package/pages/SwapPage/StepItem.js +1 -1
- package/pages/SwapPage/StepTimer.js +3 -2
- package/pages/SwapRoutesPage/SwapRoutesPage.js +2 -1
- package/providers/SwapFormProvider/SwapFormProvider.d.ts +0 -3
- package/providers/SwapFormProvider/SwapFormProvider.js +0 -3
- package/providers/SwapFormProvider/types.d.ts +0 -19
- package/providers/SwapFormProvider/types.js +0 -9
- package/providers/ThemeProvider/ThemeProvider.js +1 -1
- package/providers/WalletProvider/WalletProvider.js +46 -13
- package/providers/WalletProvider/types.d.ts +2 -1
- package/providers/WidgetProvider/types.d.ts +2 -2
- package/stores/index.d.ts +2 -0
- package/stores/index.js +2 -0
- package/stores/route/index.d.ts +5 -0
- package/stores/route/index.js +5 -0
- package/{hooks/useRouteExecution → stores/route}/types.d.ts +0 -0
- package/{hooks/useRouteExecution → stores/route}/types.js +0 -0
- package/stores/route/useCurrentRoute.d.ts +2 -0
- package/stores/route/useCurrentRoute.js +5 -0
- package/stores/route/useExecutingRoutes.d.ts +1 -0
- package/stores/route/useExecutingRoutes.js +4 -0
- package/{hooks/useRouteExecution → stores/route}/useRouteStore.d.ts +3 -5
- package/{hooks/useRouteExecution → stores/route}/useRouteStore.js +16 -26
- package/stores/route/useSetExecutableRoute.d.ts +1 -0
- package/stores/route/useSetExecutableRoute.js +4 -0
- package/stores/settings/index.d.ts +5 -0
- package/stores/settings/index.js +5 -0
- package/stores/settings/types.d.ts +23 -0
- package/stores/settings/types.js +1 -0
- package/stores/settings/useAppearance.d.ts +2 -0
- package/stores/settings/useAppearance.js +7 -0
- package/stores/settings/useSetSettings.d.ts +5 -0
- package/stores/settings/useSetSettings.js +5 -0
- package/stores/settings/useSettings.d.ts +2 -0
- package/stores/settings/useSettings.js +8 -0
- package/stores/settings/useSettingsStore.d.ts +25 -0
- package/stores/settings/useSettingsStore.js +84 -0
- package/types/widget.d.ts +33 -24
- package/utils/format.d.ts +1 -1
- package/utils/format.js +1 -1
- package/utils/routes.d.ts +1 -0
- package/utils/routes.js +7 -6
- package/hooks/useBridges.d.ts +0 -1
- package/hooks/useBridges.js +0 -12
- package/hooks/useExchanges.d.ts +0 -1
- package/hooks/useExchanges.js +0 -12
- package/hooks/useRouteExecution/index.d.ts +0 -3
- package/hooks/useRouteExecution/index.js +0 -3
- package/hooks/useSettings/index.d.ts +0 -2
- package/hooks/useSettings/index.js +0 -2
- package/hooks/useSettings/types.d.ts +0 -5
- package/hooks/useSettings/types.js +0 -1
- package/hooks/useSettings/useSettingsStore.d.ts +0 -13
- package/hooks/useSettings/useSettingsStore.js +0 -22
- package/pages/MainPage/SendToRecipientForm.d.ts +0 -2
- package/pages/MainPage/SendToRecipientForm.js +0 -20
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
/* eslint-disable no-underscore-dangle */
|
|
13
|
+
import create from 'zustand';
|
|
14
|
+
import { persist } from 'zustand/middleware';
|
|
15
|
+
import { immer } from 'zustand/middleware/immer';
|
|
16
|
+
import { SettingsToolTypes } from './types';
|
|
17
|
+
export const useSettingsStore = create()(persist(immer((set) => ({
|
|
18
|
+
advancedPreferences: false,
|
|
19
|
+
appearance: 'auto',
|
|
20
|
+
gasPrice: 'normal',
|
|
21
|
+
routePriority: 'RECOMMENDED',
|
|
22
|
+
slippage: '3',
|
|
23
|
+
setValue: (key, value) => set((state) => {
|
|
24
|
+
state[key] = value;
|
|
25
|
+
}),
|
|
26
|
+
setValues: (values) => set((state) => {
|
|
27
|
+
for (const key in values) {
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(state, key)) {
|
|
29
|
+
state[key] = values[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}),
|
|
33
|
+
initializeTools: (toolType, tools) => set((state) => {
|
|
34
|
+
if (!tools.length) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (state[`_enabled${toolType}`]) {
|
|
38
|
+
state[`_enabled${toolType}`] = tools
|
|
39
|
+
.filter((tool) => !Object.prototype.hasOwnProperty.call(state._enabledBridges, tool))
|
|
40
|
+
.reduce((values, tool) => {
|
|
41
|
+
values[tool] = true;
|
|
42
|
+
return values;
|
|
43
|
+
}, state[`_enabled${toolType}`]);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
state[`_enabled${toolType}`] = tools.reduce((values, tool) => {
|
|
47
|
+
values[tool] = true;
|
|
48
|
+
return values;
|
|
49
|
+
}, {});
|
|
50
|
+
}
|
|
51
|
+
state[`enabled${toolType}`] = Object.entries(state[`_enabled${toolType}`])
|
|
52
|
+
.filter(([_, value]) => value)
|
|
53
|
+
.map(([key]) => key);
|
|
54
|
+
}),
|
|
55
|
+
setTools: (toolType, tools, availableTools) => set((state) => {
|
|
56
|
+
state[`enabled${toolType}`] = tools;
|
|
57
|
+
state[`_enabled${toolType}`] = availableTools.reduce((values, tool) => {
|
|
58
|
+
values[tool.key] = tools.includes(tool.key);
|
|
59
|
+
return values;
|
|
60
|
+
}, {});
|
|
61
|
+
}),
|
|
62
|
+
})), {
|
|
63
|
+
name: 'li.fi-widget-settings',
|
|
64
|
+
version: 1,
|
|
65
|
+
partialize: (state) => {
|
|
66
|
+
const { enabledBridges, enabledExchanges } = state, partializedState = __rest(state, ["enabledBridges", "enabledExchanges"]);
|
|
67
|
+
return partializedState;
|
|
68
|
+
},
|
|
69
|
+
merge: (persistedState, currentState) => {
|
|
70
|
+
const state = Object.assign(Object.assign({}, currentState), persistedState);
|
|
71
|
+
SettingsToolTypes.forEach((toolType) => {
|
|
72
|
+
state[`enabled${toolType}`] = Object.entries(persistedState[`_enabled${toolType}`])
|
|
73
|
+
.filter(([_, value]) => value)
|
|
74
|
+
.map(([key]) => key);
|
|
75
|
+
});
|
|
76
|
+
return state;
|
|
77
|
+
},
|
|
78
|
+
migrate: (persistedState, version) => {
|
|
79
|
+
if (version === 0 && persistedState.appearance === 'system') {
|
|
80
|
+
persistedState.appearance = 'auto';
|
|
81
|
+
}
|
|
82
|
+
return persistedState;
|
|
83
|
+
},
|
|
84
|
+
}));
|
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,42 @@ export declare type ThemeConfig = {
|
|
|
9
9
|
shape?: Shape;
|
|
10
10
|
typography?: TypographyOptions;
|
|
11
11
|
};
|
|
12
|
-
export interface
|
|
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
|
+
}
|
|
20
|
+
interface WidgetConfigBase {
|
|
13
21
|
fromAmount?: number;
|
|
14
|
-
fromChain?: `${ChainKey}` | number;
|
|
15
|
-
fromToken?: string;
|
|
16
|
-
toChain?: `${ChainKey}` | number;
|
|
17
|
-
toToken?: string;
|
|
18
22
|
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
23
|
containerStyle?: CSSProperties;
|
|
38
24
|
theme?: ThemeConfig;
|
|
39
25
|
appearance?: Appearance;
|
|
40
26
|
disableAppearance?: boolean;
|
|
41
27
|
}
|
|
28
|
+
declare type WidgetFromTokenConfig = {
|
|
29
|
+
fromChain: `${ChainKey}` | number;
|
|
30
|
+
fromToken?: string;
|
|
31
|
+
} | {
|
|
32
|
+
fromChain?: never;
|
|
33
|
+
fromToken?: never;
|
|
34
|
+
};
|
|
35
|
+
declare type WidgetToTokenConfig = {
|
|
36
|
+
toChain: `${ChainKey}` | number;
|
|
37
|
+
toToken?: string;
|
|
38
|
+
} | {
|
|
39
|
+
toChain?: never;
|
|
40
|
+
toToken?: never;
|
|
41
|
+
};
|
|
42
|
+
declare type WidgetWalletManagementConfig = {
|
|
43
|
+
disableInternalWalletManagement: true;
|
|
44
|
+
walletCallbacks: WidgetWalletCallbacks;
|
|
45
|
+
} | {
|
|
46
|
+
disableInternalWalletManagement?: false;
|
|
47
|
+
walletCallbacks?: never;
|
|
48
|
+
};
|
|
49
|
+
export declare type WidgetConfig = WidgetConfigBase & WidgetFromTokenConfig & WidgetToTokenConfig & WidgetWalletManagementConfig;
|
|
50
|
+
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
|
|
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;
|
package/utils/routes.d.ts
CHANGED
package/utils/routes.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export const routes = {
|
|
2
2
|
home: '/',
|
|
3
|
-
selectWallet: '
|
|
4
|
-
settings: '
|
|
5
|
-
fromToken: '
|
|
6
|
-
toToken: '
|
|
7
|
-
swapRoutes: '
|
|
8
|
-
swap: '
|
|
3
|
+
selectWallet: 'select-wallet',
|
|
4
|
+
settings: 'settings',
|
|
5
|
+
fromToken: 'select-from-token',
|
|
6
|
+
toToken: 'select-to-token',
|
|
7
|
+
swapRoutes: 'swap-routes',
|
|
8
|
+
swap: 'swap',
|
|
9
9
|
};
|
|
10
|
+
export const routesValues = Object.values(routes);
|
package/hooks/useBridges.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useBridges: () => string[];
|
package/hooks/useBridges.js
DELETED
|
@@ -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
|
-
};
|
package/hooks/useExchanges.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useExchanges: () => string[];
|
package/hooks/useExchanges.js
DELETED
|
@@ -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 +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,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
|
-
};
|