@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.
- package/cjs/components/Card/CardLabel.d.ts +1 -1
- package/cjs/components/GasMessage/GasMessage.js +2 -2
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +1 -1
- package/cjs/hooks/index.js +1 -1
- package/cjs/hooks/useFromTokenSufficiency.d.ts +5 -0
- package/cjs/hooks/{useFundsSufficiency.js → useFromTokenSufficiency.js} +6 -6
- package/cjs/hooks/useGasSufficiency.js +14 -8
- package/cjs/i18n/en.json +2 -1
- package/cjs/i18n/pt.json +2 -1
- package/cjs/i18n/tr.json +2 -1
- package/cjs/i18n/uk.json +2 -1
- package/cjs/pages/SettingsPage/ResetSettingsButton.js +29 -1
- package/cjs/pages/SettingsPage/ResetSettingsButton.style.d.ts +4 -0
- package/cjs/pages/SettingsPage/ResetSettingsButton.style.js +13 -0
- package/cjs/pages/TransactionPage/StartTransactionButton.js +3 -3
- package/cjs/providers/SDKProvider/SDKProvider.js +5 -4
- package/cjs/stores/StoreProvider.js +3 -1
- package/cjs/stores/routes/createRouteExecutionStore.js +1 -1
- package/cjs/stores/settings/types.d.ts +4 -3
- package/cjs/stores/settings/useSettingsStore.d.ts +1 -1
- package/cjs/stores/settings/useSettingsStore.js +7 -3
- package/cjs/stores/settings/useSplitSubvariantStore.js +1 -1
- package/cjs/types/widget.d.ts +4 -1
- package/components/Card/CardLabel.d.ts +1 -1
- package/components/GasMessage/GasMessage.js +3 -3
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +1 -1
- package/hooks/index.js +1 -1
- package/hooks/useFromTokenSufficiency.d.ts +5 -0
- package/hooks/{useFundsSufficiency.js → useFromTokenSufficiency.js} +4 -4
- package/hooks/useGasSufficiency.js +14 -8
- package/i18n/en.json +2 -1
- package/i18n/pt.json +2 -1
- package/i18n/tr.json +2 -1
- package/i18n/uk.json +2 -1
- package/package.json +10 -10
- package/pages/SettingsPage/ResetSettingsButton.js +30 -2
- package/pages/SettingsPage/ResetSettingsButton.style.d.ts +4 -0
- package/pages/SettingsPage/ResetSettingsButton.style.js +10 -0
- package/pages/TransactionPage/StartTransactionButton.js +4 -4
- package/providers/SDKProvider/SDKProvider.js +5 -4
- package/stores/StoreProvider.js +3 -1
- package/stores/routes/createRouteExecutionStore.js +1 -1
- package/stores/settings/types.d.ts +4 -3
- package/stores/settings/useSettingsStore.d.ts +1 -1
- package/stores/settings/useSettingsStore.js +7 -3
- package/stores/settings/useSplitSubvariantStore.js +1 -1
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +4 -1
- package/cjs/hooks/useFundsSufficiency.d.ts +0 -5
- package/hooks/useFundsSufficiency.d.ts +0 -5
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const CardLabel: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
3
3
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
4
4
|
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
|
|
5
|
-
type?: "
|
|
5
|
+
type?: "active" | "insurance" | "insurance-icon" | undefined;
|
|
6
6
|
}, {}, {}>;
|
|
7
7
|
export declare const CardLabelTypography: import("@emotion/styled").StyledComponent<import("@mui/material").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
8
8
|
ref?: ((instance: HTMLSpanElement | null) => void) | import("react").RefObject<HTMLSpanElement> | null | undefined;
|
|
@@ -9,10 +9,10 @@ const FundsSufficiencyMessage_1 = require("./FundsSufficiencyMessage");
|
|
|
9
9
|
const GasSufficiencyMessage_1 = require("./GasSufficiencyMessage");
|
|
10
10
|
const GasMessage = ({ route, ...props }) => {
|
|
11
11
|
const { insufficientGas } = (0, hooks_1.useGasSufficiency)(route);
|
|
12
|
-
const {
|
|
12
|
+
const { insufficientFromToken } = (0, hooks_1.useFromTokenSufficiency)(route);
|
|
13
13
|
const { sdkConfig } = (0, providers_1.useWidgetConfig)();
|
|
14
14
|
const isMultisigSigner = sdkConfig?.multisigConfig?.isMultisigSigner;
|
|
15
15
|
const validInsufficientGas = insufficientGas?.length && !isMultisigSigner;
|
|
16
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Collapse, { timeout: 225, in: Boolean(
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Collapse, { timeout: 225, in: Boolean(insufficientFromToken || validInsufficientGas), unmountOnExit: true, mountOnEnter: true, children: (0, jsx_runtime_1.jsx)(material_1.Box, { ...props, children: insufficientFromToken ? ((0, jsx_runtime_1.jsx)(FundsSufficiencyMessage_1.FundsSufficiencyMessage, {})) : validInsufficientGas ? ((0, jsx_runtime_1.jsx)(GasSufficiencyMessage_1.GasSufficiencyMessage, { insufficientGas: insufficientGas })) : null }) }));
|
|
17
17
|
};
|
|
18
18
|
exports.GasMessage = GasMessage;
|
package/cjs/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "2.
|
|
2
|
+
export declare const version = "2.5.0";
|
package/cjs/config/version.js
CHANGED
package/cjs/hooks/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './useDebouncedWatch';
|
|
|
5
5
|
export * from './useDefaultElementId';
|
|
6
6
|
export * from './useExpandableVariant';
|
|
7
7
|
export * from './useFeaturedTokens';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './useFromTokenSufficiency';
|
|
9
9
|
export * from './useGasRecommendation';
|
|
10
10
|
export * from './useGasRefuel';
|
|
11
11
|
export * from './useGasSufficiency';
|
package/cjs/hooks/index.js
CHANGED
|
@@ -21,7 +21,7 @@ __exportStar(require("./useDebouncedWatch"), exports);
|
|
|
21
21
|
__exportStar(require("./useDefaultElementId"), exports);
|
|
22
22
|
__exportStar(require("./useExpandableVariant"), exports);
|
|
23
23
|
__exportStar(require("./useFeaturedTokens"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
24
|
+
__exportStar(require("./useFromTokenSufficiency"), exports);
|
|
25
25
|
__exportStar(require("./useGasRecommendation"), exports);
|
|
26
26
|
__exportStar(require("./useGasRefuel"), exports);
|
|
27
27
|
__exportStar(require("./useGasSufficiency"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.useFromTokenSufficiency = void 0;
|
|
4
4
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
5
|
const big_js_1 = require("big.js");
|
|
6
6
|
const react_hook_form_1 = require("react-hook-form");
|
|
@@ -9,7 +9,7 @@ const stores_1 = require("../stores");
|
|
|
9
9
|
const useGetTokenBalancesWithRetry_1 = require("./useGetTokenBalancesWithRetry");
|
|
10
10
|
const useTokenAddressBalance_1 = require("./useTokenAddressBalance");
|
|
11
11
|
const refetchInterval = 30000;
|
|
12
|
-
const
|
|
12
|
+
const useFromTokenSufficiency = (route) => {
|
|
13
13
|
const { account } = (0, providers_1.useWallet)();
|
|
14
14
|
const getTokenBalancesWithRetry = (0, useGetTokenBalancesWithRetry_1.useGetTokenBalancesWithRetry)(account.signer?.provider);
|
|
15
15
|
const [fromChainId, fromTokenAddress, fromAmount] = (0, react_hook_form_1.useWatch)({
|
|
@@ -22,8 +22,8 @@ const useFundsSufficiency = (route) => {
|
|
|
22
22
|
tokenAddress = route.fromToken.address;
|
|
23
23
|
}
|
|
24
24
|
const { token, isLoading } = (0, useTokenAddressBalance_1.useTokenAddressBalance)(chainId, tokenAddress);
|
|
25
|
-
const { data:
|
|
26
|
-
'
|
|
25
|
+
const { data: insufficientFromToken, isInitialLoading } = (0, react_query_1.useQuery)([
|
|
26
|
+
'from-token-sufficiency-check',
|
|
27
27
|
account.address,
|
|
28
28
|
chainId,
|
|
29
29
|
tokenAddress,
|
|
@@ -62,8 +62,8 @@ const useFundsSufficiency = (route) => {
|
|
|
62
62
|
keepPreviousData: true,
|
|
63
63
|
});
|
|
64
64
|
return {
|
|
65
|
-
|
|
65
|
+
insufficientFromToken,
|
|
66
66
|
isInitialLoading,
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
|
-
exports.
|
|
69
|
+
exports.useFromTokenSufficiency = useFromTokenSufficiency;
|
|
@@ -30,21 +30,27 @@ const useGasSufficiency = (route) => {
|
|
|
30
30
|
const gasCostAmount = step.estimate.gasCosts
|
|
31
31
|
.reduce((amount, gasCost) => amount.plus((0, big_js_1.default)(gasCost.amount || 0)), (0, big_js_1.default)(0))
|
|
32
32
|
.div(10 ** token.decimals);
|
|
33
|
-
const groupedGasCost = groupedGasCosts[token.chainId];
|
|
34
|
-
const gasAmount = groupedGasCost
|
|
35
|
-
? groupedGasCost.gasAmount.plus(gasCostAmount)
|
|
36
|
-
: gasCostAmount;
|
|
37
33
|
groupedGasCosts[token.chainId] = {
|
|
38
|
-
gasAmount,
|
|
39
|
-
|
|
34
|
+
gasAmount: groupedGasCosts[token.chainId]?.gasAmount.plus(gasCostAmount) ?? gasCostAmount,
|
|
35
|
+
token,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Add fees paid in native tokens to gas sufficiency check (included: false)
|
|
39
|
+
const nonIncludedFeeCosts = step.estimate.feeCosts?.filter((feeCost) => !feeCost.included);
|
|
40
|
+
if (nonIncludedFeeCosts?.length) {
|
|
41
|
+
const { token } = nonIncludedFeeCosts[0];
|
|
42
|
+
const feeCostAmount = nonIncludedFeeCosts
|
|
43
|
+
.reduce((amount, feeCost) => amount.plus((0, big_js_1.default)(feeCost.amount || 0)), (0, big_js_1.default)(0))
|
|
44
|
+
.div(10 ** token.decimals);
|
|
45
|
+
groupedGasCosts[token.chainId] = {
|
|
46
|
+
gasAmount: groupedGasCosts[token.chainId]?.gasAmount.plus(feeCostAmount) ?? feeCostAmount,
|
|
40
47
|
token,
|
|
41
48
|
};
|
|
42
|
-
return groupedGasCosts;
|
|
43
49
|
}
|
|
44
50
|
return groupedGasCosts;
|
|
45
51
|
}, {});
|
|
46
52
|
if (route.fromToken.address === gasCosts[route.fromChainId]?.token.address) {
|
|
47
|
-
gasCosts[route.fromChainId].tokenAmount = gasCosts[route.fromChainId]
|
|
53
|
+
gasCosts[route.fromChainId].tokenAmount = gasCosts[route.fromChainId].gasAmount.plus((0, big_js_1.default)(route.fromAmount).div(10 ** route.fromToken.decimals));
|
|
48
54
|
}
|
|
49
55
|
const tokenBalances = await getTokenBalancesWithRetry(account.address, Object.values(gasCosts).map((item) => item.token));
|
|
50
56
|
if (!tokenBalances?.length) {
|
package/cjs/i18n/en.json
CHANGED
|
@@ -255,7 +255,8 @@
|
|
|
255
255
|
},
|
|
256
256
|
"routePriority": "Route priority",
|
|
257
257
|
"showDestinationWallet": "Show destination wallet",
|
|
258
|
-
"slippage": "Slippage"
|
|
258
|
+
"slippage": "Slippage",
|
|
259
|
+
"resetSettings": "You're using custom setting limiting the number of available routes."
|
|
259
260
|
},
|
|
260
261
|
"wallet": {
|
|
261
262
|
"extensionNotFound": "Please make sure that only the {{name}} browser extension is active before choosing this wallet."
|
package/cjs/i18n/pt.json
CHANGED
|
@@ -255,7 +255,8 @@
|
|
|
255
255
|
},
|
|
256
256
|
"routePriority": "Prioridade de rota / caminho",
|
|
257
257
|
"showDestinationWallet": "Mostrar carteira de destino",
|
|
258
|
-
"slippage": "Derrapagem"
|
|
258
|
+
"slippage": "Derrapagem",
|
|
259
|
+
"resetSettings": "Você está usando a configuração personalizada que limita a quantidade de rotas disponíveis."
|
|
259
260
|
},
|
|
260
261
|
"wallet": {
|
|
261
262
|
"extensionNotFound": "Por favor, certifique-se de que apenas a extensão do navegador da {{name}} está ativa antes de escolher esta carteira."
|
package/cjs/i18n/tr.json
CHANGED
|
@@ -255,7 +255,8 @@
|
|
|
255
255
|
},
|
|
256
256
|
"routePriority": "Rota önceliği",
|
|
257
257
|
"showDestinationWallet": "Hedef Adresi Göster",
|
|
258
|
-
"slippage": "Sapma toleransı"
|
|
258
|
+
"slippage": "Sapma toleransı",
|
|
259
|
+
"resetSettings": "Kullanılabilir rotaların sayısını sınırlayan özel bir ayar kullanıyorsunuz."
|
|
259
260
|
},
|
|
260
261
|
"wallet": {
|
|
261
262
|
"extensionNotFound": "Lütfen bu cüzdanı seçmeden önce yalnızca {{name}} tarayıcı uzantısının etkin olduğundan emin olun."
|
package/cjs/i18n/uk.json
CHANGED
|
@@ -255,7 +255,8 @@
|
|
|
255
255
|
},
|
|
256
256
|
"routePriority": "Пріоритет маршруту",
|
|
257
257
|
"showDestinationWallet": "Показати цільовий гаманець",
|
|
258
|
-
"slippage": "Прослизання"
|
|
258
|
+
"slippage": "Прослизання",
|
|
259
|
+
"resetSettings": "Ви використовуєте налаштування які можуть обмежувати кількість доступних маршрутів."
|
|
259
260
|
},
|
|
260
261
|
"wallet": {
|
|
261
262
|
"extensionNotFound": "Перш ніж вибрати цей гаманець, переконайтеся, що в браузері активне лише розширення {{name}}."
|
|
@@ -9,7 +9,17 @@ const Dialog_1 = require("../../components/Dialog");
|
|
|
9
9
|
const hooks_1 = require("../../hooks");
|
|
10
10
|
const providers_1 = require("../../providers");
|
|
11
11
|
const stores_1 = require("../../stores");
|
|
12
|
+
const ResetSettingsButton_style_1 = require("./ResetSettingsButton.style");
|
|
13
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
14
|
+
const shallow_1 = require("zustand/shallow");
|
|
12
15
|
const ResetSettingsButton = () => {
|
|
16
|
+
const [enabledBridges, enabledExchanges, routePriority, slippage, gasPrice] = (0, stores_1.useSettingsStore)((state) => [
|
|
17
|
+
state.enabledBridges,
|
|
18
|
+
state.enabledExchanges,
|
|
19
|
+
state.routePriority,
|
|
20
|
+
state.slippage,
|
|
21
|
+
state.gasPrice,
|
|
22
|
+
], shallow_1.shallow);
|
|
13
23
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
14
24
|
const { tools } = (0, hooks_1.useTools)();
|
|
15
25
|
const config = (0, providers_1.useWidgetConfig)();
|
|
@@ -21,9 +31,27 @@ const ResetSettingsButton = () => {
|
|
|
21
31
|
const handleReset = () => {
|
|
22
32
|
if (tools) {
|
|
23
33
|
resetSettings(config, tools.bridges.map((tool) => tool.key), tools.exchanges.map((tool) => tool.key));
|
|
34
|
+
(0, stores_1.setDefaultSettings)(config);
|
|
24
35
|
}
|
|
25
36
|
toggleDialog();
|
|
26
37
|
};
|
|
27
|
-
|
|
38
|
+
const isSlippageChanged = config.slippage
|
|
39
|
+
? Number(slippage) !== config.slippage * 100
|
|
40
|
+
: slippage !== stores_1.defaultConfigurableSettings.slippage;
|
|
41
|
+
const isRoutePriorityChanged = config.routePriority
|
|
42
|
+
? routePriority !== config.routePriority
|
|
43
|
+
: routePriority !== stores_1.defaultConfigurableSettings.routePriority;
|
|
44
|
+
const isGasPriceChanged = gasPrice !== stores_1.defaultConfigurableSettings.gasPrice;
|
|
45
|
+
const isCustomRouteSettings = tools?.bridges?.length !== enabledBridges?.length ||
|
|
46
|
+
tools?.exchanges?.length !== enabledExchanges?.length ||
|
|
47
|
+
isSlippageChanged ||
|
|
48
|
+
isRoutePriorityChanged ||
|
|
49
|
+
isGasPriceChanged;
|
|
50
|
+
if (!isCustomRouteSettings) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { px: 3, mt: 1.5, mb: 1, children: (0, jsx_runtime_1.jsxs)(ResetSettingsButton_style_1.ResetButtonContainer, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", marginBottom: "12px", children: [(0, jsx_runtime_1.jsx)(icons_material_1.InfoRounded, { sx: {
|
|
54
|
+
marginRight: '8px',
|
|
55
|
+
} }), (0, jsx_runtime_1.jsx)(material_1.Box, { fontSize: 14, children: t(`settings.resetSettings`) })] }), (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: toggleDialog, fullWidth: true, children: t('button.resetSettings') }), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, { open: open, onClose: toggleDialog, children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: t('warning.title.resetSettings') }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('warning.message.resetSettings') }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { onClick: toggleDialog, children: t('button.cancel') }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", onClick: handleReset, autoFocus: true, children: t('button.reset') })] })] })] }) }));
|
|
28
56
|
};
|
|
29
57
|
exports.ResetSettingsButton = ResetSettingsButton;
|
|
@@ -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,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResetButtonContainer = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
exports.ResetButtonContainer = (0, material_1.styled)(material_1.Box)(({ theme }) => ({
|
|
7
|
+
background: (0, utils_1.getContrastAlphaColor)(theme.palette.mode, '4%'),
|
|
8
|
+
borderRadius: '16px',
|
|
9
|
+
padding: '16px',
|
|
10
|
+
[`svg`]: {
|
|
11
|
+
fill: (0, utils_1.getContrastAlphaColor)(theme.palette.mode, '40%'),
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
@@ -10,9 +10,9 @@ const StartTransactionButton = ({ onClick, route, text, loading, }) => {
|
|
|
10
10
|
const { sdkConfig } = (0, providers_1.useWidgetConfig)();
|
|
11
11
|
const isMultisigSigner = sdkConfig?.multisigConfig?.isMultisigSigner;
|
|
12
12
|
const { insufficientGas, isInitialLoading: isGasSufficiencyLoading } = (0, hooks_1.useGasSufficiency)(route);
|
|
13
|
-
const {
|
|
14
|
-
const shouldDisableButton = !isMultisigSigner && (
|
|
15
|
-
return ((0, jsx_runtime_1.jsx)(DefaultTransactionButton_1.DefaultTransactionButton, { onClick: onClick, text: text, disabled: shouldDisableButton, loading:
|
|
13
|
+
const { insufficientFromToken, isInitialLoading: isFromTokenSufficiencyLoading, } = (0, hooks_1.useFromTokenSufficiency)(route);
|
|
14
|
+
const shouldDisableButton = !isMultisigSigner && (insufficientFromToken || !!insufficientGas?.length);
|
|
15
|
+
return ((0, jsx_runtime_1.jsx)(DefaultTransactionButton_1.DefaultTransactionButton, { onClick: onClick, text: text, disabled: shouldDisableButton, loading: isFromTokenSufficiencyLoading || isGasSufficiencyLoading || loading }));
|
|
16
16
|
};
|
|
17
17
|
exports.StartTransactionButton = StartTransactionButton;
|
|
18
18
|
const StartInsurableTransactionButton = ({ onClick, text, route, loading, disabled, insurableRouteId }) => {
|
|
@@ -11,16 +11,17 @@ const SDKContext = (0, react_1.createContext)(null);
|
|
|
11
11
|
const useLiFi = () => (0, react_1.useContext)(SDKContext);
|
|
12
12
|
exports.useLiFi = useLiFi;
|
|
13
13
|
const SDKProvider = ({ children, }) => {
|
|
14
|
-
const { sdkConfig,
|
|
14
|
+
const { sdkConfig, integrator, apiKey, fee, referrer, routePriority, slippage, } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
15
15
|
const value = (0, react_1.useMemo)(() => {
|
|
16
16
|
const config = {
|
|
17
17
|
...sdkConfig,
|
|
18
|
+
apiKey,
|
|
18
19
|
integrator: integrator ?? window.location.hostname,
|
|
19
20
|
defaultRouteOptions: {
|
|
20
|
-
fee,
|
|
21
21
|
integrator: integrator ?? window.location.hostname,
|
|
22
|
+
fee,
|
|
22
23
|
referrer,
|
|
23
|
-
routePriority,
|
|
24
|
+
order: routePriority,
|
|
24
25
|
slippage,
|
|
25
26
|
...sdkConfig?.defaultRouteOptions,
|
|
26
27
|
},
|
|
@@ -34,7 +35,7 @@ const SDKProvider = ({ children, }) => {
|
|
|
34
35
|
}
|
|
35
36
|
lifi.setConfig(config);
|
|
36
37
|
return lifi;
|
|
37
|
-
}, [fee, integrator, referrer, routePriority, sdkConfig, slippage]);
|
|
38
|
+
}, [apiKey, fee, integrator, referrer, routePriority, sdkConfig, slippage]);
|
|
38
39
|
return (0, jsx_runtime_1.jsx)(SDKContext.Provider, { value: value, children: children });
|
|
39
40
|
};
|
|
40
41
|
exports.SDKProvider = SDKProvider;
|
|
@@ -7,6 +7,8 @@ const header_1 = require("./header");
|
|
|
7
7
|
const routes_1 = require("./routes");
|
|
8
8
|
const settings_1 = require("./settings");
|
|
9
9
|
const StoreProvider = ({ children, config, }) => {
|
|
10
|
-
return ((0, jsx_runtime_1.jsx)(settings_1.SplitSubvariantStoreProvider, { state: config.subvariant === 'split'
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)(settings_1.SplitSubvariantStoreProvider, { state: config.subvariant === 'split'
|
|
11
|
+
? config.subvariantOptions || 'swap'
|
|
12
|
+
: undefined, children: (0, jsx_runtime_1.jsx)(header_1.HeaderStoreProvider, { namePrefix: config?.keyPrefix, children: (0, jsx_runtime_1.jsx)(chains_1.ChainOrderStoreProvider, { namePrefix: config?.keyPrefix, children: (0, jsx_runtime_1.jsx)(routes_1.RouteExecutionStoreProvider, { namePrefix: config?.keyPrefix, children: children }) }) }) }));
|
|
11
13
|
};
|
|
12
14
|
exports.StoreProvider = StoreProvider;
|
|
@@ -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?:
|
|
40
|
-
setState(state:
|
|
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?:
|
|
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;
|
|
@@ -7,6 +7,7 @@ const types_1 = require("./types");
|
|
|
7
7
|
exports.defaultConfigurableSettings = {
|
|
8
8
|
routePriority: 'RECOMMENDED',
|
|
9
9
|
slippage: '0.5',
|
|
10
|
+
gasPrice: 'normal',
|
|
10
11
|
};
|
|
11
12
|
exports.defaultSettings = {
|
|
12
13
|
appearance: 'auto',
|
|
@@ -67,10 +68,10 @@ exports.useSettingsStore = (0, traditional_1.createWithEqualityFn)((0, middlewar
|
|
|
67
68
|
}, {}),
|
|
68
69
|
})),
|
|
69
70
|
reset: (config, bridges, exchanges) => {
|
|
71
|
+
const { appearance, ...restDefaultSettings } = exports.defaultSettings;
|
|
70
72
|
set(() => ({
|
|
71
|
-
...
|
|
73
|
+
...restDefaultSettings,
|
|
72
74
|
...exports.defaultConfigurableSettings,
|
|
73
|
-
appearance: config.appearance ?? exports.defaultSettings.appearance,
|
|
74
75
|
}));
|
|
75
76
|
get().initializeTools('Bridges', bridges, true);
|
|
76
77
|
get().initializeTools('Exchanges', exchanges, true);
|
|
@@ -102,7 +103,7 @@ exports.useSettingsStore = (0, traditional_1.createWithEqualityFn)((0, middlewar
|
|
|
102
103
|
},
|
|
103
104
|
}), Object.is);
|
|
104
105
|
const setDefaultSettings = (config) => {
|
|
105
|
-
const { slippage, routePriority, setValue } = exports.useSettingsStore.getState();
|
|
106
|
+
const { slippage, routePriority, setValue, gasPrice } = exports.useSettingsStore.getState();
|
|
106
107
|
const defaultSlippage = (config?.slippage ||
|
|
107
108
|
config?.sdkConfig?.defaultRouteOptions?.slippage ||
|
|
108
109
|
0) * 100;
|
|
@@ -116,5 +117,8 @@ const setDefaultSettings = (config) => {
|
|
|
116
117
|
if (!routePriority) {
|
|
117
118
|
setValue('routePriority', exports.defaultConfigurableSettings.routePriority);
|
|
118
119
|
}
|
|
120
|
+
if (!gasPrice) {
|
|
121
|
+
setValue('gasPrice', exports.defaultConfigurableSettings.gasPrice);
|
|
122
|
+
}
|
|
119
123
|
};
|
|
120
124
|
exports.setDefaultSettings = setDefaultSettings;
|
|
@@ -7,7 +7,7 @@ const traditional_1 = require("zustand/traditional");
|
|
|
7
7
|
exports.SplitSubvariantStoreContext = (0, react_1.createContext)(null);
|
|
8
8
|
const shouldRecreateStore = (store, props) => {
|
|
9
9
|
const { state } = store.getState();
|
|
10
|
-
return
|
|
10
|
+
return state !== props.state;
|
|
11
11
|
};
|
|
12
12
|
function SplitSubvariantStoreProvider({ children, ...props }) {
|
|
13
13
|
const storeRef = (0, react_1.useRef)();
|
package/cjs/types/widget.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { Components, PaletteMode, PaletteOptions, Shape, Theme } from '@mui
|
|
|
4
4
|
import type { TypographyOptions } from '@mui/material/styles/createTypography';
|
|
5
5
|
import type { CSSProperties, ReactNode, RefObject } from 'react';
|
|
6
6
|
import type { LanguageKey, LanguageResources } from '../providers';
|
|
7
|
+
import type { SplitSubvariantOptions } from '../stores';
|
|
7
8
|
export type WidgetVariant = 'default' | 'expandable' | 'drawer';
|
|
8
9
|
export type WidgetSubvariant = 'default' | 'split' | 'nft' | 'refuel';
|
|
9
10
|
export declare enum DisabledUI {
|
|
@@ -71,14 +72,16 @@ export interface WidgetConfig {
|
|
|
71
72
|
contractSecondaryComponent?: ReactNode;
|
|
72
73
|
contractCompactComponent?: ReactNode;
|
|
73
74
|
contractTool?: WidgetContractTool;
|
|
74
|
-
fee?: number;
|
|
75
75
|
integrator: string;
|
|
76
|
+
apiKey?: string;
|
|
77
|
+
fee?: number;
|
|
76
78
|
referrer?: string;
|
|
77
79
|
routePriority?: Order;
|
|
78
80
|
slippage?: number;
|
|
79
81
|
insurance?: boolean;
|
|
80
82
|
variant?: WidgetVariant;
|
|
81
83
|
subvariant?: WidgetSubvariant;
|
|
84
|
+
subvariantOptions?: SplitSubvariantOptions;
|
|
82
85
|
appearance?: Appearance;
|
|
83
86
|
theme?: ThemeConfig;
|
|
84
87
|
containerStyle?: CSSProperties;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const CardLabel: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
3
3
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
4
4
|
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
|
|
5
|
-
type?: "
|
|
5
|
+
type?: "active" | "insurance" | "insurance-icon" | undefined;
|
|
6
6
|
}, {}, {}>;
|
|
7
7
|
export declare const CardLabelTypography: import("@emotion/styled").StyledComponent<import("@mui/material").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
8
8
|
ref?: ((instance: HTMLSpanElement | null) => void) | import("react").RefObject<HTMLSpanElement> | null | undefined;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Collapse } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { useFromTokenSufficiency, useGasSufficiency } from '../../hooks';
|
|
4
4
|
import { useWidgetConfig } from '../../providers';
|
|
5
5
|
import { FundsSufficiencyMessage } from './FundsSufficiencyMessage';
|
|
6
6
|
import { GasSufficiencyMessage } from './GasSufficiencyMessage';
|
|
7
7
|
export const GasMessage = ({ route, ...props }) => {
|
|
8
8
|
const { insufficientGas } = useGasSufficiency(route);
|
|
9
|
-
const {
|
|
9
|
+
const { insufficientFromToken } = useFromTokenSufficiency(route);
|
|
10
10
|
const { sdkConfig } = useWidgetConfig();
|
|
11
11
|
const isMultisigSigner = sdkConfig?.multisigConfig?.isMultisigSigner;
|
|
12
12
|
const validInsufficientGas = insufficientGas?.length && !isMultisigSigner;
|
|
13
|
-
return (_jsx(Collapse, { timeout: 225, in: Boolean(
|
|
13
|
+
return (_jsx(Collapse, { timeout: 225, in: Boolean(insufficientFromToken || validInsufficientGas), unmountOnExit: true, mountOnEnter: true, children: _jsx(Box, { ...props, children: insufficientFromToken ? (_jsx(FundsSufficiencyMessage, {})) : validInsufficientGas ? (_jsx(GasSufficiencyMessage, { insufficientGas: insufficientGas })) : null }) }));
|
|
14
14
|
};
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "2.
|
|
2
|
+
export declare const version = "2.5.0";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '2.
|
|
2
|
+
export const version = '2.5.0';
|
package/hooks/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './useDebouncedWatch';
|
|
|
5
5
|
export * from './useDefaultElementId';
|
|
6
6
|
export * from './useExpandableVariant';
|
|
7
7
|
export * from './useFeaturedTokens';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './useFromTokenSufficiency';
|
|
9
9
|
export * from './useGasRecommendation';
|
|
10
10
|
export * from './useGasRefuel';
|
|
11
11
|
export * from './useGasSufficiency';
|
package/hooks/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export * from './useDebouncedWatch';
|
|
|
5
5
|
export * from './useDefaultElementId';
|
|
6
6
|
export * from './useExpandableVariant';
|
|
7
7
|
export * from './useFeaturedTokens';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './useFromTokenSufficiency';
|
|
9
9
|
export * from './useGasRecommendation';
|
|
10
10
|
export * from './useGasRefuel';
|
|
11
11
|
export * from './useGasSufficiency';
|
|
@@ -6,7 +6,7 @@ import { isRouteDone } from '../stores';
|
|
|
6
6
|
import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry';
|
|
7
7
|
import { useTokenAddressBalance } from './useTokenAddressBalance';
|
|
8
8
|
const refetchInterval = 30000;
|
|
9
|
-
export const
|
|
9
|
+
export const useFromTokenSufficiency = (route) => {
|
|
10
10
|
const { account } = useWallet();
|
|
11
11
|
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(account.signer?.provider);
|
|
12
12
|
const [fromChainId, fromTokenAddress, fromAmount] = useWatch({
|
|
@@ -19,8 +19,8 @@ export const useFundsSufficiency = (route) => {
|
|
|
19
19
|
tokenAddress = route.fromToken.address;
|
|
20
20
|
}
|
|
21
21
|
const { token, isLoading } = useTokenAddressBalance(chainId, tokenAddress);
|
|
22
|
-
const { data:
|
|
23
|
-
'
|
|
22
|
+
const { data: insufficientFromToken, isInitialLoading } = useQuery([
|
|
23
|
+
'from-token-sufficiency-check',
|
|
24
24
|
account.address,
|
|
25
25
|
chainId,
|
|
26
26
|
tokenAddress,
|
|
@@ -59,7 +59,7 @@ export const useFundsSufficiency = (route) => {
|
|
|
59
59
|
keepPreviousData: true,
|
|
60
60
|
});
|
|
61
61
|
return {
|
|
62
|
-
|
|
62
|
+
insufficientFromToken,
|
|
63
63
|
isInitialLoading,
|
|
64
64
|
};
|
|
65
65
|
};
|
|
@@ -27,21 +27,27 @@ export const useGasSufficiency = (route) => {
|
|
|
27
27
|
const gasCostAmount = step.estimate.gasCosts
|
|
28
28
|
.reduce((amount, gasCost) => amount.plus(Big(gasCost.amount || 0)), Big(0))
|
|
29
29
|
.div(10 ** token.decimals);
|
|
30
|
-
const groupedGasCost = groupedGasCosts[token.chainId];
|
|
31
|
-
const gasAmount = groupedGasCost
|
|
32
|
-
? groupedGasCost.gasAmount.plus(gasCostAmount)
|
|
33
|
-
: gasCostAmount;
|
|
34
30
|
groupedGasCosts[token.chainId] = {
|
|
35
|
-
gasAmount,
|
|
36
|
-
|
|
31
|
+
gasAmount: groupedGasCosts[token.chainId]?.gasAmount.plus(gasCostAmount) ?? gasCostAmount,
|
|
32
|
+
token,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Add fees paid in native tokens to gas sufficiency check (included: false)
|
|
36
|
+
const nonIncludedFeeCosts = step.estimate.feeCosts?.filter((feeCost) => !feeCost.included);
|
|
37
|
+
if (nonIncludedFeeCosts?.length) {
|
|
38
|
+
const { token } = nonIncludedFeeCosts[0];
|
|
39
|
+
const feeCostAmount = nonIncludedFeeCosts
|
|
40
|
+
.reduce((amount, feeCost) => amount.plus(Big(feeCost.amount || 0)), Big(0))
|
|
41
|
+
.div(10 ** token.decimals);
|
|
42
|
+
groupedGasCosts[token.chainId] = {
|
|
43
|
+
gasAmount: groupedGasCosts[token.chainId]?.gasAmount.plus(feeCostAmount) ?? feeCostAmount,
|
|
37
44
|
token,
|
|
38
45
|
};
|
|
39
|
-
return groupedGasCosts;
|
|
40
46
|
}
|
|
41
47
|
return groupedGasCosts;
|
|
42
48
|
}, {});
|
|
43
49
|
if (route.fromToken.address === gasCosts[route.fromChainId]?.token.address) {
|
|
44
|
-
gasCosts[route.fromChainId].tokenAmount = gasCosts[route.fromChainId]
|
|
50
|
+
gasCosts[route.fromChainId].tokenAmount = gasCosts[route.fromChainId].gasAmount.plus(Big(route.fromAmount).div(10 ** route.fromToken.decimals));
|
|
45
51
|
}
|
|
46
52
|
const tokenBalances = await getTokenBalancesWithRetry(account.address, Object.values(gasCosts).map((item) => item.token));
|
|
47
53
|
if (!tokenBalances?.length) {
|
package/i18n/en.json
CHANGED
|
@@ -255,7 +255,8 @@
|
|
|
255
255
|
},
|
|
256
256
|
"routePriority": "Route priority",
|
|
257
257
|
"showDestinationWallet": "Show destination wallet",
|
|
258
|
-
"slippage": "Slippage"
|
|
258
|
+
"slippage": "Slippage",
|
|
259
|
+
"resetSettings": "You're using custom setting limiting the number of available routes."
|
|
259
260
|
},
|
|
260
261
|
"wallet": {
|
|
261
262
|
"extensionNotFound": "Please make sure that only the {{name}} browser extension is active before choosing this wallet."
|
package/i18n/pt.json
CHANGED
|
@@ -255,7 +255,8 @@
|
|
|
255
255
|
},
|
|
256
256
|
"routePriority": "Prioridade de rota / caminho",
|
|
257
257
|
"showDestinationWallet": "Mostrar carteira de destino",
|
|
258
|
-
"slippage": "Derrapagem"
|
|
258
|
+
"slippage": "Derrapagem",
|
|
259
|
+
"resetSettings": "Você está usando a configuração personalizada que limita a quantidade de rotas disponíveis."
|
|
259
260
|
},
|
|
260
261
|
"wallet": {
|
|
261
262
|
"extensionNotFound": "Por favor, certifique-se de que apenas a extensão do navegador da {{name}} está ativa antes de escolher esta carteira."
|
package/i18n/tr.json
CHANGED
|
@@ -255,7 +255,8 @@
|
|
|
255
255
|
},
|
|
256
256
|
"routePriority": "Rota önceliği",
|
|
257
257
|
"showDestinationWallet": "Hedef Adresi Göster",
|
|
258
|
-
"slippage": "Sapma toleransı"
|
|
258
|
+
"slippage": "Sapma toleransı",
|
|
259
|
+
"resetSettings": "Kullanılabilir rotaların sayısını sınırlayan özel bir ayar kullanıyorsunuz."
|
|
259
260
|
},
|
|
260
261
|
"wallet": {
|
|
261
262
|
"extensionNotFound": "Lütfen bu cüzdanı seçmeden önce yalnızca {{name}} tarayıcı uzantısının etkin olduğundan emin olun."
|
package/i18n/uk.json
CHANGED
|
@@ -255,7 +255,8 @@
|
|
|
255
255
|
},
|
|
256
256
|
"routePriority": "Пріоритет маршруту",
|
|
257
257
|
"showDestinationWallet": "Показати цільовий гаманець",
|
|
258
|
-
"slippage": "Прослизання"
|
|
258
|
+
"slippage": "Прослизання",
|
|
259
|
+
"resetSettings": "Ви використовуєте налаштування які можуть обмежувати кількість доступних маршрутів."
|
|
259
260
|
},
|
|
260
261
|
"wallet": {
|
|
261
262
|
"extensionNotFound": "Перш ніж вибрати цей гаманець, переконайтеся, що в браузері активне лише розширення {{name}}."
|