@lifi/widget 1.16.1 → 1.17.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/AppProvider.js +1 -1
- package/README.md +1 -1
- package/cjs/AppProvider.js +1 -1
- package/cjs/components/ChainSelect/ChainSelect.style.js +4 -4
- package/cjs/components/ChainSelect/useChainSelect.d.ts +2 -2
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +3 -3
- package/cjs/components/Header/useHeaderActionStore.d.ts +0 -2
- package/cjs/components/Header/useHeaderActionStore.js +1 -5
- package/cjs/components/SwapButton/SwapButton.js +3 -23
- package/cjs/components/TokenList/TokenList.js +1 -1
- package/cjs/components/TokenList/TokenList.style.js +4 -3
- package/cjs/components/TokenList/TokenListItem.js +1 -1
- package/cjs/components/TokenList/TokenNotFound.d.ts +2 -1
- package/cjs/components/TokenList/TokenNotFound.js +12 -2
- package/cjs/components/TokenList/types.d.ts +2 -2
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useChains.js +21 -8
- package/cjs/hooks/useFeaturedTokens.d.ts +1 -1
- package/cjs/hooks/useFeaturedTokens.js +5 -2
- package/cjs/hooks/useGasSufficiency.d.ts +1 -1
- package/cjs/hooks/useGasSufficiency.js +30 -21
- package/cjs/hooks/useToken.d.ts +0 -1
- package/cjs/hooks/useToken.js +1 -2
- package/cjs/hooks/useTokenBalances.d.ts +1 -2
- package/cjs/hooks/useTokenBalances.js +1 -2
- package/cjs/hooks/useTokens.d.ts +1 -2
- package/cjs/hooks/useTokens.js +30 -8
- package/cjs/hooks/useTools.js +8 -3
- package/cjs/i18n/en/translation.json +2 -3
- package/cjs/i18n/index.d.ts +1 -2
- package/cjs/pages/MainPage/MainSwapButton.js +1 -1
- package/cjs/pages/SettingsPage/AdvancedPreferences.js +1 -1
- package/cjs/pages/SettingsPage/GasPriceSelect.js +1 -1
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +1 -1
- package/cjs/pages/SettingsPage/ShowDestinationWallet.js +1 -1
- package/cjs/pages/SettingsPage/SlippageInput.js +1 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -3
- package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -3
- package/cjs/pages/SwapPage/SwapPage.js +11 -2
- package/cjs/pages/SwapRoutesPage/SwapRoutesPage.js +4 -3
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +4 -58
- package/cjs/providers/SwapFormProvider/types.d.ts +5 -5
- package/cjs/providers/WalletProvider/WalletProvider.js +57 -1
- package/cjs/providers/WidgetProvider/index.d.ts +1 -0
- package/cjs/providers/WidgetProvider/index.js +1 -0
- package/cjs/providers/WidgetProvider/utils.d.ts +4 -0
- package/cjs/providers/WidgetProvider/utils.js +13 -0
- package/cjs/stores/chains/index.d.ts +0 -1
- package/cjs/stores/chains/index.js +0 -1
- package/cjs/stores/chains/types.d.ts +1 -1
- package/cjs/stores/chains/useChainOrderStore.js +17 -14
- package/cjs/stores/settings/index.d.ts +0 -1
- package/cjs/stores/settings/index.js +0 -1
- package/cjs/stores/settings/useAppearance.js +3 -1
- package/cjs/types/widget.d.ts +29 -22
- package/components/ChainSelect/ChainSelect.style.js +4 -4
- package/components/ChainSelect/useChainSelect.d.ts +2 -2
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +3 -3
- package/components/Header/useHeaderActionStore.d.ts +0 -2
- package/components/Header/useHeaderActionStore.js +0 -3
- package/components/SwapButton/SwapButton.js +5 -25
- package/components/TokenList/TokenList.js +1 -1
- package/components/TokenList/TokenList.style.js +4 -3
- package/components/TokenList/TokenListItem.js +1 -1
- package/components/TokenList/TokenNotFound.d.ts +2 -1
- package/components/TokenList/TokenNotFound.js +12 -2
- package/components/TokenList/types.d.ts +2 -2
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useChains.js +23 -10
- package/hooks/useFeaturedTokens.d.ts +1 -1
- package/hooks/useFeaturedTokens.js +5 -2
- package/hooks/useGasSufficiency.d.ts +1 -1
- package/hooks/useGasSufficiency.js +32 -23
- package/hooks/useToken.d.ts +0 -1
- package/hooks/useToken.js +1 -2
- package/hooks/useTokenBalances.d.ts +1 -2
- package/hooks/useTokenBalances.js +1 -2
- package/hooks/useTokens.d.ts +1 -2
- package/hooks/useTokens.js +31 -9
- package/hooks/useTools.js +9 -4
- package/i18n/en/translation.json +2 -3
- package/i18n/index.d.ts +1 -2
- package/package.json +4 -4
- package/pages/MainPage/MainSwapButton.js +1 -1
- package/pages/SettingsPage/AdvancedPreferences.js +2 -2
- package/pages/SettingsPage/GasPriceSelect.js +2 -2
- package/pages/SettingsPage/RoutePrioritySelect.js +2 -2
- package/pages/SettingsPage/ShowDestinationWallet.js +2 -2
- package/pages/SettingsPage/SlippageInput.js +2 -2
- package/pages/SwapDetailsPage/SwapDetailsPage.js +3 -4
- package/pages/SwapHistoryPage/SwapHistoryPage.js +3 -4
- package/pages/SwapPage/SwapPage.js +11 -2
- package/pages/SwapRoutesPage/SwapRoutesPage.js +5 -4
- package/providers/SwapFormProvider/SwapFormProvider.js +4 -58
- package/providers/SwapFormProvider/types.d.ts +5 -5
- package/providers/WalletProvider/WalletProvider.js +58 -2
- package/providers/WidgetProvider/index.d.ts +1 -0
- package/providers/WidgetProvider/index.js +1 -0
- package/providers/WidgetProvider/utils.d.ts +4 -0
- package/providers/WidgetProvider/utils.js +9 -0
- package/stores/chains/index.d.ts +0 -1
- package/stores/chains/index.js +0 -1
- package/stores/chains/types.d.ts +1 -1
- package/stores/chains/useChainOrderStore.js +17 -14
- package/stores/settings/index.d.ts +0 -1
- package/stores/settings/index.js +0 -1
- package/stores/settings/useAppearance.js +3 -1
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +29 -22
- package/cjs/stores/chains/useInitializeChainOrder.d.ts +0 -1
- package/cjs/stores/chains/useInitializeChainOrder.js +0 -12
- package/cjs/stores/settings/useSetSettings.d.ts +0 -5
- package/cjs/stores/settings/useSetSettings.js +0 -12
- package/stores/chains/useInitializeChainOrder.d.ts +0 -1
- package/stores/chains/useInitializeChainOrder.js +0 -5
- package/stores/settings/useSetSettings.d.ts +0 -5
- package/stores/settings/useSetSettings.js +0 -5
package/AppProvider.js
CHANGED
|
@@ -6,7 +6,7 @@ import { queryClient } from './config/queryClient';
|
|
|
6
6
|
import { SDKProvider, SwapFormProvider, TelemetryProvider, ThemeProvider, WalletProvider, WidgetProvider, } from './providers';
|
|
7
7
|
const QueryProvider = QueryClientProvider;
|
|
8
8
|
export const AppProvider = ({ children, config, }) => {
|
|
9
|
-
return (_jsx(
|
|
9
|
+
return (_jsx(QueryProvider, Object.assign({ client: queryClient }, { children: _jsx(WidgetProvider, Object.assign({ config: config }, { children: _jsx(SDKProvider, { children: _jsx(TelemetryProvider, { children: _jsx(SwapFormProvider, { children: _jsx(ThemeProvider, { children: _jsx(WalletProvider, { children: _jsx(AppRouter, { children: children }) }) }) }) }) }) })) })));
|
|
10
10
|
};
|
|
11
11
|
export const AppRouter = ({ children }) => {
|
|
12
12
|
const inRouterContext = useInRouterContext();
|
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ Visit our [playground](https://testing.li.finance) to see how you can customize
|
|
|
83
83
|
|
|
84
84
|
## Documentation
|
|
85
85
|
|
|
86
|
-
[LI.FI Documentation](https://docs.li.fi)
|
|
86
|
+
[LI.FI Widget Documentation](https://docs.li.fi/integrate-li.fi-widget/li.fi-widget-overview)
|
|
87
87
|
|
|
88
88
|
## Changelog
|
|
89
89
|
|
package/cjs/AppProvider.js
CHANGED
|
@@ -9,7 +9,7 @@ const queryClient_1 = require("./config/queryClient");
|
|
|
9
9
|
const providers_1 = require("./providers");
|
|
10
10
|
const QueryProvider = react_query_1.QueryClientProvider;
|
|
11
11
|
const AppProvider = ({ children, config, }) => {
|
|
12
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)(QueryProvider, Object.assign({ client: queryClient_1.queryClient }, { children: (0, jsx_runtime_1.jsx)(providers_1.WidgetProvider, Object.assign({ config: config }, { children: (0, jsx_runtime_1.jsx)(providers_1.SDKProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.TelemetryProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.SwapFormProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.ThemeProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.WalletProvider, { children: (0, jsx_runtime_1.jsx)(exports.AppRouter, { children: children }) }) }) }) }) }) })) })));
|
|
13
13
|
};
|
|
14
14
|
exports.AppProvider = AppProvider;
|
|
15
15
|
const AppRouter = ({ children }) => {
|
|
@@ -4,15 +4,15 @@ exports.ChainContainer = exports.ChainCard = void 0;
|
|
|
4
4
|
const material_1 = require("@mui/material");
|
|
5
5
|
const styles_1 = require("@mui/material/styles");
|
|
6
6
|
const Card_1 = require("../../components/Card");
|
|
7
|
-
exports.ChainCard = (0, styles_1.styled)(Card_1.Card)(
|
|
7
|
+
exports.ChainCard = (0, styles_1.styled)(Card_1.Card)({
|
|
8
8
|
display: 'grid',
|
|
9
9
|
placeItems: 'center',
|
|
10
|
-
|
|
10
|
+
minWidth: 56,
|
|
11
11
|
height: 56,
|
|
12
|
-
})
|
|
12
|
+
});
|
|
13
13
|
exports.ChainContainer = (0, styles_1.styled)(material_1.Box)(({ theme }) => ({
|
|
14
14
|
display: 'grid',
|
|
15
|
-
gridTemplateColumns: 'repeat(auto-fit, 56px)',
|
|
15
|
+
gridTemplateColumns: 'repeat(auto-fit, minmax(56px, 1fr))',
|
|
16
16
|
gridAutoRows: '56px',
|
|
17
17
|
justifyContent: 'space-between',
|
|
18
18
|
gap: theme.spacing(1.5),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EVMChain } from '@lifi/sdk';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const useChainSelect: (formType:
|
|
2
|
+
import type { SwapFormType } from '../../providers';
|
|
3
|
+
export declare const useChainSelect: (formType: SwapFormType) => {
|
|
4
4
|
chains: EVMChain[] | undefined;
|
|
5
5
|
getChains: () => EVMChain[];
|
|
6
6
|
setCurrentChain: (chainId: number) => void;
|
|
@@ -23,15 +23,15 @@ const GasSufficiencyMessage = (_a) => {
|
|
|
23
23
|
var { route } = _a, props = __rest(_a, ["route"]);
|
|
24
24
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
25
25
|
const { insufficientFunds, insufficientGas } = (0, hooks_1.useGasSufficiency)(route);
|
|
26
|
-
if (!insufficientFunds && !insufficientGas.length) {
|
|
26
|
+
if (!insufficientFunds && !(insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length)) {
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
return ((0, jsx_runtime_1.jsxs)(GasSufficiencyMessage_style_1.MessageCard, Object.assign({}, props, { children: [(0, jsx_runtime_1.jsx)(icons_material_1.WarningAmber, { sx: {
|
|
30
30
|
marginTop: 2,
|
|
31
31
|
marginLeft: 2,
|
|
32
|
-
} }), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [insufficientGas.length ? ((0, jsx_runtime_1.jsx)(Card_1.CardTitle, { children: t(`swap.warning.title.insufficientGas`) })) : null, insufficientFunds ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", px: 2, pb: insufficientGas.length ? 0 : 2, pt: insufficientGas.length ? 1 : 2 }, { children: insufficientFunds
|
|
32
|
+
} }), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) ? ((0, jsx_runtime_1.jsx)(Card_1.CardTitle, { children: t(`swap.warning.title.insufficientGas`) })) : null, insufficientFunds ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", px: 2, pb: (insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) ? 0 : 2, pt: (insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) ? 1 : 2 }, { children: insufficientFunds
|
|
33
33
|
? t(`swap.warning.message.insufficientFunds`)
|
|
34
|
-
: null }))) : null, insufficientGas.length ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", px: 2, pt: 1 }, { children: t(`swap.warning.message.insufficientGas`) }))) : null, insufficientGas.length
|
|
34
|
+
: null }))) : null, (insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", px: 2, pt: 1 }, { children: t(`swap.warning.message.insufficientGas`) }))) : null, (insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length)
|
|
35
35
|
? insufficientGas.map((item, index) => {
|
|
36
36
|
var _a, _b;
|
|
37
37
|
return ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", px: 2, pb: insufficientGas.length - 1 === index ? 2 : 0, pt: 0.5 }, { children: t(`swap.tokenOnChainAmount`, {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { HeaderActionStore } from './types';
|
|
3
2
|
export declare const useHeaderActionStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<HeaderActionStore>, "setState"> & {
|
|
4
3
|
setState(nextStateOrUpdater: HeaderActionStore | Partial<HeaderActionStore> | ((state: import("immer/dist/internal").WritableDraft<HeaderActionStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
5
4
|
}>;
|
|
6
|
-
export declare const useSetHeaderAction: () => (element?: import("react").ReactNode) => () => void;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.useHeaderActionStore = void 0;
|
|
7
7
|
/* eslint-disable no-underscore-dangle */
|
|
8
8
|
const zustand_1 = __importDefault(require("zustand"));
|
|
9
9
|
const immer_1 = require("zustand/middleware/immer");
|
|
@@ -20,7 +20,3 @@ exports.useHeaderActionStore = (0, zustand_1.default)()((0, immer_1.immer)((set,
|
|
|
20
20
|
});
|
|
21
21
|
},
|
|
22
22
|
})));
|
|
23
|
-
const useSetHeaderAction = () => {
|
|
24
|
-
return (0, exports.useHeaderActionStore)((state) => state.setAction);
|
|
25
|
-
};
|
|
26
|
-
exports.useSetHeaderAction = useSetHeaderAction;
|
|
@@ -11,51 +11,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SwapButton = void 0;
|
|
13
13
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
14
|
-
const sdk_1 = require("@lifi/sdk");
|
|
15
14
|
const material_1 = require("@mui/material");
|
|
16
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
17
15
|
const react_i18next_1 = require("react-i18next");
|
|
18
16
|
const react_router_dom_1 = require("react-router-dom");
|
|
19
17
|
const hooks_1 = require("../../hooks");
|
|
20
18
|
const providers_1 = require("../../providers");
|
|
21
19
|
const utils_1 = require("../../utils");
|
|
22
20
|
const SwapButton = ({ onClick, currentRoute, text, disable, }) => {
|
|
23
|
-
var _a;
|
|
24
21
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
25
22
|
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
26
|
-
const { getChainById } = (0, hooks_1.useChains)();
|
|
27
23
|
const config = (0, providers_1.useWidgetConfig)();
|
|
28
|
-
const { account,
|
|
24
|
+
const { account, connect } = (0, providers_1.useWallet)();
|
|
29
25
|
const { insufficientFunds, insufficientGas } = (0, hooks_1.useGasSufficiency)(currentRoute);
|
|
30
|
-
const [chainId] = (0, react_hook_form_1.useWatch)({
|
|
31
|
-
name: [providers_1.SwapFormKeyHelper.getChainKey('from')],
|
|
32
|
-
});
|
|
33
|
-
// Allow switching chain only if execution is not started
|
|
34
|
-
const switchChainAllowed = ((_a = getChainById(chainId || sdk_1.ChainId.ETH)) === null || _a === void 0 ? void 0 : _a.id) !== account.chainId &&
|
|
35
|
-
currentRoute &&
|
|
36
|
-
!currentRoute.steps.some((step) => step.execution);
|
|
37
26
|
const handleSwapButtonClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
27
|
if (!account.isActive) {
|
|
39
28
|
if (config.walletManagement) {
|
|
40
|
-
yield
|
|
29
|
+
yield connect();
|
|
41
30
|
}
|
|
42
31
|
else {
|
|
43
32
|
navigate(utils_1.navigationRoutes.selectWallet);
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
|
-
else if (switchChainAllowed) {
|
|
47
|
-
yield switchChain(chainId);
|
|
48
|
-
// check that the current route exists in the up to date route list
|
|
49
|
-
}
|
|
50
35
|
else {
|
|
51
36
|
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
52
37
|
}
|
|
53
38
|
});
|
|
54
39
|
const getButtonText = () => {
|
|
55
40
|
if (account.isActive) {
|
|
56
|
-
if (switchChainAllowed) {
|
|
57
|
-
return t(`button.switchChain`);
|
|
58
|
-
}
|
|
59
41
|
if (!currentRoute) {
|
|
60
42
|
return t(`button.swap`);
|
|
61
43
|
}
|
|
@@ -63,8 +45,6 @@ const SwapButton = ({ onClick, currentRoute, text, disable, }) => {
|
|
|
63
45
|
}
|
|
64
46
|
return t(`button.connectWallet`);
|
|
65
47
|
};
|
|
66
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", color: account.isActive ? 'primary' : 'success', onClick: handleSwapButtonClick, disabled:
|
|
67
|
-
!switchChainAllowed &&
|
|
68
|
-
(insufficientFunds || !!insufficientGas.length || disable), fullWidth: true }, { children: getButtonText() })));
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", color: account.isActive ? 'primary' : 'success', onClick: handleSwapButtonClick, disabled: insufficientFunds || !!(insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) || disable, fullWidth: true }, { children: getButtonText() })));
|
|
69
49
|
};
|
|
70
50
|
exports.SwapButton = SwapButton;
|
|
@@ -53,6 +53,6 @@ const TokenList = ({ formType, height, onClick, }) => {
|
|
|
53
53
|
}
|
|
54
54
|
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
55
55
|
}, [formType, getValues, onClick, setValue]);
|
|
56
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!tokens.length && !isLoading ? (0, jsx_runtime_1.jsx)(TokenNotFound_1.TokenNotFound, {}) : null, (0, jsx_runtime_1.jsx)(VirtualizedTokenList_1.VirtualizedTokenList, { tokens: tokens, featuredTokensLength: featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length, scrollElementRef: parentRef, chainId: selectedChainId, isLoading: isLoading, isBalanceLoading: isBalanceLoading, showBalance: account.isActive, showFeatured: !tokenSearchFilter, onClick: handleTokenClick })] })));
|
|
56
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!tokens.length && !isLoading ? ((0, jsx_runtime_1.jsx)(TokenNotFound_1.TokenNotFound, { formType: formType })) : null, (0, jsx_runtime_1.jsx)(VirtualizedTokenList_1.VirtualizedTokenList, { tokens: tokens, featuredTokensLength: featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length, scrollElementRef: parentRef, chainId: selectedChainId, isLoading: isLoading, isBalanceLoading: isBalanceLoading, showBalance: account.isActive, showFeatured: !tokenSearchFilter, onClick: handleTokenClick })] })));
|
|
57
57
|
};
|
|
58
58
|
exports.TokenList = TokenList;
|
|
@@ -7,7 +7,8 @@ const styles_1 = require("@mui/material/styles");
|
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
exports.ListItemButton = (0, styles_1.styled)(material_1.ListItemButton)(({ theme }) => ({
|
|
9
9
|
borderRadius: theme.shape.borderRadiusSecondary,
|
|
10
|
-
paddingLeft: theme.spacing(
|
|
10
|
+
paddingLeft: theme.spacing(1.5),
|
|
11
|
+
paddingRight: theme.spacing(1.5),
|
|
11
12
|
height: 64,
|
|
12
13
|
width: '100%',
|
|
13
14
|
'&:hover': {
|
|
@@ -21,8 +22,8 @@ exports.ListItem = (0, styles_1.styled)(material_1.ListItem)(({ theme }) => ({
|
|
|
21
22
|
height: 64,
|
|
22
23
|
flexDirection: 'column',
|
|
23
24
|
alignItems: 'flex-start',
|
|
24
|
-
padding: theme.spacing(0,
|
|
25
|
+
padding: theme.spacing(0, 1.5),
|
|
25
26
|
[`.${ListItemSecondaryAction_1.listItemSecondaryActionClasses.root}`]: {
|
|
26
|
-
right: theme.spacing(
|
|
27
|
+
right: theme.spacing(3),
|
|
27
28
|
},
|
|
28
29
|
}));
|
|
@@ -19,7 +19,7 @@ exports.TokenListItem = (0, react_1.memo)(({ onClick, size, start, token, showBa
|
|
|
19
19
|
}) }))) : null] })))) : null] })), endAdornment] })));
|
|
20
20
|
});
|
|
21
21
|
const TokenListItemSkeleton = () => {
|
|
22
|
-
return ((0, jsx_runtime_1.jsxs)(TokenList_style_1.ListItem, Object.assign({ secondaryAction: (0, jsx_runtime_1.jsx)(exports.TokenAmountSkeleton, {}), disablePadding: true, sx: { position: 'relative', flexDirection: 'row', alignItems: 'center' } }, { children: [(0, jsx_runtime_1.jsx)(material_1.ListItemAvatar, { children: (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "circular", width: 32, height: 32, sx: { marginLeft:
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(TokenList_style_1.ListItem, Object.assign({ secondaryAction: (0, jsx_runtime_1.jsx)(exports.TokenAmountSkeleton, {}), disablePadding: true, sx: { position: 'relative', flexDirection: 'row', alignItems: 'center' } }, { children: [(0, jsx_runtime_1.jsx)(material_1.ListItemAvatar, { children: (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "circular", width: 32, height: 32, sx: { marginLeft: 1.5, marginRight: 2 } }) }), (0, jsx_runtime_1.jsx)(material_1.ListItemText, { primary: (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 48, height: 20 }), secondary: (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 96, height: 20 }) })] })));
|
|
23
23
|
};
|
|
24
24
|
exports.TokenListItemSkeleton = TokenListItemSkeleton;
|
|
25
25
|
const TokenAmountSkeleton = () => {
|
|
@@ -4,9 +4,17 @@ exports.TokenNotFound = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const icons_material_1 = require("@mui/icons-material");
|
|
6
6
|
const material_1 = require("@mui/material");
|
|
7
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
7
8
|
const react_i18next_1 = require("react-i18next");
|
|
8
|
-
const
|
|
9
|
+
const hooks_1 = require("../../hooks");
|
|
10
|
+
const providers_1 = require("../../providers");
|
|
11
|
+
const TokenNotFound = ({ formType }) => {
|
|
12
|
+
var _a;
|
|
9
13
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
14
|
+
const [selectedChainId] = (0, react_hook_form_1.useWatch)({
|
|
15
|
+
name: [providers_1.SwapFormKeyHelper.getChainKey(formType)],
|
|
16
|
+
});
|
|
17
|
+
const { getChainById } = (0, hooks_1.useChains)();
|
|
10
18
|
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
|
|
11
19
|
display: 'flex',
|
|
12
20
|
justifyContent: 'center',
|
|
@@ -14,6 +22,8 @@ const TokenNotFound = () => {
|
|
|
14
22
|
flexDirection: 'column',
|
|
15
23
|
flex: 1,
|
|
16
24
|
padding: 3,
|
|
17
|
-
} }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 48, lineHeight: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.SearchOff, { fontSize: "inherit" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2, px: 2 }, { children: t('swap.
|
|
25
|
+
} }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 48, lineHeight: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.SearchOff, { fontSize: "inherit" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2, px: 2 }, { children: t('swap.info.message.emptyTokenList', {
|
|
26
|
+
chainName: (_a = getChainById(selectedChainId)) === null || _a === void 0 ? void 0 : _a.name,
|
|
27
|
+
}) }))] })));
|
|
18
28
|
};
|
|
19
29
|
exports.TokenNotFound = TokenNotFound;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TokenAmount } from '@lifi/sdk';
|
|
2
2
|
import type { MutableRefObject } from 'react';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SwapFormType } from '../../providers';
|
|
4
4
|
import type { Token } from '../../types';
|
|
5
5
|
export interface TokenListProps {
|
|
6
|
-
formType:
|
|
6
|
+
formType: SwapFormType;
|
|
7
7
|
height: number;
|
|
8
8
|
onClick?(): void;
|
|
9
9
|
}
|
package/cjs/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "1.
|
|
2
|
+
export declare const version = "1.17.0";
|
package/cjs/config/version.js
CHANGED
package/cjs/hooks/useChains.js
CHANGED
|
@@ -12,25 +12,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.useChains = void 0;
|
|
13
13
|
const react_query_1 = require("@tanstack/react-query");
|
|
14
14
|
const react_1 = require("react");
|
|
15
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
15
16
|
const providers_1 = require("../providers");
|
|
16
17
|
const chains_1 = require("../stores/chains");
|
|
17
18
|
const useChains = () => {
|
|
18
|
-
const { disabledChains } = (0, providers_1.useWidgetConfig)();
|
|
19
|
+
const { disabledChains, chains } = (0, providers_1.useWidgetConfig)();
|
|
19
20
|
const lifi = (0, providers_1.useLiFi)();
|
|
20
|
-
const
|
|
21
|
+
const { getValues, setValue } = (0, react_hook_form_1.useFormContext)();
|
|
21
22
|
const { data, isLoading } = (0, react_query_1.useQuery)(['chains'], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
const
|
|
23
|
-
const filteredChains =
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const availableChains = yield lifi.getChains();
|
|
24
|
+
const filteredChains = availableChains.filter((chain) => (0, providers_1.isItemAllowed)(chain.id, chains, disabledChains));
|
|
25
|
+
const chainOrder = chains_1.useChainOrderStore
|
|
26
|
+
.getState()
|
|
27
|
+
.initializeChains(filteredChains.map((chain) => chain.id));
|
|
28
|
+
const [fromChainValue, toChainValue] = getValues([
|
|
29
|
+
providers_1.SwapFormKey.FromChain,
|
|
30
|
+
providers_1.SwapFormKey.ToChain,
|
|
31
|
+
]);
|
|
32
|
+
if (!fromChainValue) {
|
|
33
|
+
setValue(providers_1.SwapFormKey.FromChain, chainOrder[0]);
|
|
34
|
+
}
|
|
35
|
+
if (!toChainValue) {
|
|
36
|
+
setValue(providers_1.SwapFormKey.ToChain, chainOrder[0]);
|
|
37
|
+
}
|
|
38
|
+
return { availableChains, filteredChains };
|
|
26
39
|
}));
|
|
27
40
|
const getChainById = (0, react_1.useCallback)((chainId) => {
|
|
28
|
-
const chain = data === null || data === void 0 ? void 0 : data.find((chain) => chain.id === chainId);
|
|
41
|
+
const chain = data === null || data === void 0 ? void 0 : data.availableChains.find((chain) => chain.id === chainId);
|
|
29
42
|
// if (!chain) {
|
|
30
43
|
// throw new Error('Chain not found or chainId is invalid.');
|
|
31
44
|
// }
|
|
32
45
|
return chain;
|
|
33
46
|
}, [data]);
|
|
34
|
-
return { chains: data, getChainById, isLoading };
|
|
47
|
+
return { chains: data === null || data === void 0 ? void 0 : data.filteredChains, getChainById, isLoading };
|
|
35
48
|
};
|
|
36
49
|
exports.useChains = useChains;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useFeaturedTokens: (selectedChainId
|
|
1
|
+
export declare const useFeaturedTokens: (selectedChainId?: number) => import("@lifi/types").Token[];
|
|
@@ -4,7 +4,10 @@ exports.useFeaturedTokens = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const providers_1 = require("../providers");
|
|
6
6
|
const useFeaturedTokens = (selectedChainId) => {
|
|
7
|
-
const { featuredTokens } = (0, providers_1.useWidgetConfig)();
|
|
8
|
-
return (0, react_1.useMemo)(() =>
|
|
7
|
+
const { featuredTokens, tokens } = (0, providers_1.useWidgetConfig)();
|
|
8
|
+
return (0, react_1.useMemo)(() => {
|
|
9
|
+
var _a;
|
|
10
|
+
return [...((_a = tokens === null || tokens === void 0 ? void 0 : tokens.featured) !== null && _a !== void 0 ? _a : []), ...(featuredTokens !== null && featuredTokens !== void 0 ? featuredTokens : [])].filter((token) => token.chainId === selectedChainId);
|
|
11
|
+
}, [featuredTokens, selectedChainId, tokens === null || tokens === void 0 ? void 0 : tokens.featured]);
|
|
9
12
|
};
|
|
10
13
|
exports.useFeaturedTokens = useFeaturedTokens;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -11,6 +20,7 @@ const _1 = require(".");
|
|
|
11
20
|
const providers_1 = require("../providers");
|
|
12
21
|
const useTokenBalances_1 = require("./useTokenBalances");
|
|
13
22
|
const useGasSufficiency = (route) => {
|
|
23
|
+
const lifi = (0, providers_1.useLiFi)();
|
|
14
24
|
const { account } = (0, providers_1.useWallet)();
|
|
15
25
|
const [fromChainId, toChainId, fromToken] = (0, react_hook_form_1.useWatch)({
|
|
16
26
|
name: [
|
|
@@ -22,20 +32,12 @@ const useGasSufficiency = (route) => {
|
|
|
22
32
|
const fromAmount = (0, _1.useDebouncedWatch)(providers_1.SwapFormKey.FromAmount, 250);
|
|
23
33
|
const { getChainById } = (0, _1.useChains)();
|
|
24
34
|
const { tokensWithBalance: fromChainTokenBalances } = (0, useTokenBalances_1.useTokenBalances)(fromChainId);
|
|
25
|
-
const
|
|
26
|
-
const
|
|
35
|
+
const [insufficientGas, setInsufficientGas] = (0, react_1.useState)();
|
|
36
|
+
const checkInsufficientGas = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
37
|
var _a;
|
|
28
|
-
if (!account.isActive ||
|
|
29
|
-
|
|
30
|
-
!fromAmount ||
|
|
31
|
-
!fromChainTokenBalances ||
|
|
32
|
-
!toChainTokenBalances) {
|
|
33
|
-
return [];
|
|
38
|
+
if (!account.isActive || !route || !fromAmount) {
|
|
39
|
+
return;
|
|
34
40
|
}
|
|
35
|
-
const tokenBalancesByChain = {
|
|
36
|
-
[fromChainId]: fromChainTokenBalances,
|
|
37
|
-
[toChainId]: toChainTokenBalances,
|
|
38
|
-
};
|
|
39
41
|
const gasCosts = route.steps.reduce((groupedGasCosts, step) => {
|
|
40
42
|
if (step.estimate.gasCosts) {
|
|
41
43
|
const { token } = step.estimate.gasCosts[0];
|
|
@@ -60,30 +62,34 @@ const useGasSufficiency = (route) => {
|
|
|
60
62
|
route.fromToken.address === gasCosts[fromChainId].token.address) {
|
|
61
63
|
gasCosts[fromChainId].tokenAmount = (_a = gasCosts[fromChainId]) === null || _a === void 0 ? void 0 : _a.gasAmount.plus((0, big_js_1.default)(fromAmount));
|
|
62
64
|
}
|
|
65
|
+
const tokenBalances = yield lifi.getTokenBalances(account.address, Object.values(gasCosts).map((item) => item.token));
|
|
66
|
+
if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
63
69
|
[fromChainId, toChainId].forEach((chainId) => {
|
|
64
|
-
var _a, _b, _c, _d, _e, _f
|
|
70
|
+
var _a, _b, _c, _d, _e, _f;
|
|
65
71
|
if (gasCosts[chainId]) {
|
|
66
|
-
const gasTokenBalance = (0, big_js_1.default)((
|
|
72
|
+
const gasTokenBalance = (0, big_js_1.default)((_b = (_a = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.find((t) => t.address === gasCosts[chainId].token.address)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
|
|
67
73
|
const insufficientFromChainGas = gasTokenBalance.lte(0) ||
|
|
68
|
-
gasTokenBalance.lt((
|
|
69
|
-
gasTokenBalance.lt((
|
|
74
|
+
gasTokenBalance.lt((_c = gasCosts[chainId].gasAmount) !== null && _c !== void 0 ? _c : (0, big_js_1.default)(0)) ||
|
|
75
|
+
gasTokenBalance.lt((_d = gasCosts[chainId].tokenAmount) !== null && _d !== void 0 ? _d : (0, big_js_1.default)(0));
|
|
70
76
|
const insufficientFromChainGasAmount = insufficientFromChainGas
|
|
71
|
-
? (
|
|
77
|
+
? (_f = (_e = gasCosts[chainId].tokenAmount) === null || _e === void 0 ? void 0 : _e.minus(gasTokenBalance)) !== null && _f !== void 0 ? _f : gasCosts[chainId].gasAmount.minus(gasTokenBalance)
|
|
72
78
|
: undefined;
|
|
73
79
|
gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient: insufficientFromChainGas, insufficientAmount: insufficientFromChainGasAmount });
|
|
74
80
|
}
|
|
75
81
|
});
|
|
76
82
|
const gasCostResult = Object.values(gasCosts).filter((gasCost) => gasCost.insufficient);
|
|
77
|
-
|
|
78
|
-
}, [
|
|
83
|
+
setInsufficientGas(gasCostResult);
|
|
84
|
+
}), [
|
|
85
|
+
account.address,
|
|
79
86
|
account.isActive,
|
|
80
87
|
fromAmount,
|
|
81
88
|
fromChainId,
|
|
82
|
-
fromChainTokenBalances,
|
|
83
89
|
getChainById,
|
|
90
|
+
lifi,
|
|
84
91
|
route,
|
|
85
92
|
toChainId,
|
|
86
|
-
toChainTokenBalances,
|
|
87
93
|
]);
|
|
88
94
|
const insufficientFunds = (0, react_1.useMemo)(() => {
|
|
89
95
|
var _a, _b;
|
|
@@ -96,6 +102,9 @@ const useGasSufficiency = (route) => {
|
|
|
96
102
|
const balance = (0, big_js_1.default)((_b = (_a = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === fromToken)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
|
|
97
103
|
return (0, big_js_1.default)(fromAmount).gt(balance);
|
|
98
104
|
}, [account.isActive, fromAmount, fromChainTokenBalances, fromToken]);
|
|
105
|
+
(0, react_1.useEffect)(() => {
|
|
106
|
+
checkInsufficientGas();
|
|
107
|
+
}, [checkInsufficientGas]);
|
|
99
108
|
return {
|
|
100
109
|
insufficientGas,
|
|
101
110
|
insufficientFunds,
|
package/cjs/hooks/useToken.d.ts
CHANGED
package/cjs/hooks/useToken.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.useToken = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useTokens_1 = require("./useTokens");
|
|
6
6
|
const useToken = (chainId, tokenAddress) => {
|
|
7
|
-
const { tokens, isLoading
|
|
7
|
+
const { tokens, isLoading } = (0, useTokens_1.useTokens)(chainId);
|
|
8
8
|
const token = (0, react_1.useMemo)(() => {
|
|
9
9
|
const token = tokens === null || tokens === void 0 ? void 0 : tokens.find((token) => token.address === tokenAddress && token.chainId === chainId);
|
|
10
10
|
return token;
|
|
@@ -12,7 +12,6 @@ const useToken = (chainId, tokenAddress) => {
|
|
|
12
12
|
return {
|
|
13
13
|
token,
|
|
14
14
|
isLoading,
|
|
15
|
-
isFetching,
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
17
|
exports.useToken = useToken;
|
|
@@ -2,9 +2,8 @@ import type { Token } from '../types';
|
|
|
2
2
|
export declare const useTokenBalances: (selectedChainId: number) => {
|
|
3
3
|
tokens: Token[] | undefined;
|
|
4
4
|
tokensWithBalance: Token[] | undefined;
|
|
5
|
-
featuredTokens: import("@lifi/types").Token[]
|
|
5
|
+
featuredTokens: import("@lifi/types").Token[];
|
|
6
6
|
isLoading: boolean;
|
|
7
7
|
isBalanceLoading: boolean;
|
|
8
|
-
isBalanceFetched: boolean;
|
|
9
8
|
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<Token[] | undefined, unknown>>;
|
|
10
9
|
};
|
|
@@ -26,7 +26,7 @@ const useTokenBalances = (selectedChainId) => {
|
|
|
26
26
|
const { tokens, isLoading } = (0, useTokens_1.useTokens)(selectedChainId);
|
|
27
27
|
const [refetchInterval, setRefetchInterval] = (0, react_1.useState)(defaultRefetchInterval);
|
|
28
28
|
const isBalanceLoadingEnabled = Boolean(account.address) && Boolean(tokens === null || tokens === void 0 ? void 0 : tokens.length);
|
|
29
|
-
const { data: tokensWithBalance, isLoading: isBalanceLoading,
|
|
29
|
+
const { data: tokensWithBalance, isLoading: isBalanceLoading, refetch, } = (0, react_query_1.useQuery)(['token-balances', account.address, selectedChainId, tokens === null || tokens === void 0 ? void 0 : tokens.length], ({ queryKey: [, accountAddress] }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
30
|
if (!accountAddress || !tokens) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
@@ -73,7 +73,6 @@ const useTokenBalances = (selectedChainId) => {
|
|
|
73
73
|
featuredTokens,
|
|
74
74
|
isLoading,
|
|
75
75
|
isBalanceLoading: isBalanceLoading && isBalanceLoadingEnabled,
|
|
76
|
-
isBalanceFetched,
|
|
77
76
|
refetch,
|
|
78
77
|
};
|
|
79
78
|
};
|
package/cjs/hooks/useTokens.d.ts
CHANGED
package/cjs/hooks/useTokens.js
CHANGED
|
@@ -14,24 +14,46 @@ const react_query_1 = require("@tanstack/react-query");
|
|
|
14
14
|
const providers_1 = require("../providers");
|
|
15
15
|
const useFeaturedTokens_1 = require("./useFeaturedTokens");
|
|
16
16
|
const useTokens = (selectedChainId) => {
|
|
17
|
+
var _a, _b, _c, _d;
|
|
17
18
|
const lifi = (0, providers_1.useLiFi)();
|
|
18
19
|
const featuredTokens = (0, useFeaturedTokens_1.useFeaturedTokens)(selectedChainId);
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const { tokens, chains, disabledChains } = (0, providers_1.useWidgetConfig)();
|
|
21
|
+
const { data, isLoading } = (0, react_query_1.useQuery)([
|
|
22
|
+
'tokens',
|
|
23
|
+
selectedChainId,
|
|
24
|
+
featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length,
|
|
25
|
+
(_a = tokens === null || tokens === void 0 ? void 0 : tokens.allow) === null || _a === void 0 ? void 0 : _a.length,
|
|
26
|
+
(_b = tokens === null || tokens === void 0 ? void 0 : tokens.deny) === null || _b === void 0 ? void 0 : _b.length,
|
|
27
|
+
(_c = chains === null || chains === void 0 ? void 0 : chains.allow) === null || _c === void 0 ? void 0 : _c.length,
|
|
28
|
+
(_d = chains === null || chains === void 0 ? void 0 : chains.deny) === null || _d === void 0 ? void 0 : _d.length,
|
|
29
|
+
], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
var _e, _f, _g, _h, _j;
|
|
31
|
+
const chainAllowed = selectedChainId &&
|
|
32
|
+
(0, providers_1.isItemAllowed)(selectedChainId, chains, disabledChains);
|
|
33
|
+
if (!chainAllowed) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
let filteredTokens = (_e = tokens === null || tokens === void 0 ? void 0 : tokens.allow) === null || _e === void 0 ? void 0 : _e.filter((token) => token.chainId === selectedChainId);
|
|
37
|
+
if (!(filteredTokens === null || filteredTokens === void 0 ? void 0 : filteredTokens.length)) {
|
|
38
|
+
const data = yield lifi.getTokens({ chains: [selectedChainId] });
|
|
39
|
+
filteredTokens = (_f = data.tokens) === null || _f === void 0 ? void 0 : _f[selectedChainId];
|
|
40
|
+
}
|
|
41
|
+
const deniedTokenAddresses = (_g = tokens === null || tokens === void 0 ? void 0 : tokens.deny) === null || _g === void 0 ? void 0 : _g.filter((token) => token.chainId === selectedChainId).map((token) => token.address);
|
|
42
|
+
if (deniedTokenAddresses === null || deniedTokenAddresses === void 0 ? void 0 : deniedTokenAddresses.length) {
|
|
43
|
+
filteredTokens = filteredTokens === null || filteredTokens === void 0 ? void 0 : filteredTokens.filter((token) => !deniedTokenAddresses.includes(token.address));
|
|
44
|
+
}
|
|
22
45
|
const featuredTokenAddresses = new Set(featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => token.address));
|
|
23
46
|
return [
|
|
24
|
-
...((
|
|
47
|
+
...((_h = featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => {
|
|
25
48
|
token.featured = true;
|
|
26
49
|
return token;
|
|
27
|
-
})) !== null &&
|
|
28
|
-
...((
|
|
50
|
+
})) !== null && _h !== void 0 ? _h : []),
|
|
51
|
+
...((_j = filteredTokens === null || filteredTokens === void 0 ? void 0 : filteredTokens.filter((token) => !featuredTokenAddresses.has(token.address))) !== null && _j !== void 0 ? _j : []),
|
|
29
52
|
];
|
|
30
53
|
}));
|
|
31
54
|
return {
|
|
32
|
-
tokens,
|
|
55
|
+
tokens: data,
|
|
33
56
|
isLoading,
|
|
34
|
-
isFetching,
|
|
35
57
|
};
|
|
36
58
|
};
|
|
37
59
|
exports.useTokens = useTokens;
|
package/cjs/hooks/useTools.js
CHANGED
|
@@ -7,11 +7,16 @@ const providers_1 = require("../providers");
|
|
|
7
7
|
const stores_1 = require("../stores");
|
|
8
8
|
const useTools = () => {
|
|
9
9
|
const lifi = (0, providers_1.useLiFi)();
|
|
10
|
-
const
|
|
10
|
+
const { bridges, exchanges } = (0, providers_1.useWidgetConfig)();
|
|
11
11
|
const { data } = (0, react_query_1.useQuery)(['tools'], ({ signal }) => lifi.getTools(undefined, { signal }), {
|
|
12
12
|
onSuccess(data) {
|
|
13
|
-
initializeTools
|
|
14
|
-
initializeTools('
|
|
13
|
+
const { initializeTools } = stores_1.useSettingsStore.getState();
|
|
14
|
+
initializeTools('Bridges', data.bridges
|
|
15
|
+
.filter((bridge) => (0, providers_1.isItemAllowed)(bridge.key, bridges))
|
|
16
|
+
.map((bridge) => bridge.key));
|
|
17
|
+
initializeTools('Exchanges', data.exchanges
|
|
18
|
+
.filter((exchange) => (0, providers_1.isItemAllowed)(exchange.key, exchanges))
|
|
19
|
+
.map((exchange) => exchange.key));
|
|
15
20
|
},
|
|
16
21
|
});
|
|
17
22
|
const formattedTools = (0, react_1.useMemo)(() => ({
|