@lifi/widget 1.16.0 → 1.16.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/AppProvider.d.ts +0 -4
- package/AppProvider.js +2 -10
- package/cjs/AppProvider.d.ts +0 -4
- package/cjs/AppProvider.js +3 -12
- package/cjs/components/AppContainer.js +2 -2
- package/cjs/components/SelectChainAndToken.js +5 -5
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useChains.js +4 -4
- package/cjs/hooks/useFeaturedTokens.js +2 -2
- package/cjs/hooks/useGasSufficiency.js +6 -7
- package/cjs/hooks/useInitializer.js +6 -0
- package/cjs/hooks/useRouteExecution.js +7 -7
- package/cjs/hooks/useSwapRoutes.js +10 -11
- package/cjs/hooks/useTokenBalances.js +4 -4
- package/cjs/hooks/useTokenSearch.js +3 -2
- package/cjs/hooks/useTokens.js +3 -2
- package/cjs/hooks/useTools.js +3 -2
- package/cjs/providers/SDKProvider/SDKProvider.d.ts +4 -0
- package/cjs/providers/SDKProvider/SDKProvider.js +27 -0
- package/cjs/providers/SDKProvider/index.d.ts +1 -0
- package/cjs/providers/SDKProvider/index.js +17 -0
- package/cjs/providers/TelemetryProvider/TelemetryProvider.d.ts +4 -0
- package/cjs/providers/TelemetryProvider/TelemetryProvider.js +11 -0
- package/cjs/providers/TelemetryProvider/index.d.ts +1 -0
- package/cjs/providers/TelemetryProvider/index.js +17 -0
- package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -4
- package/cjs/providers/WalletProvider/WalletProvider.js +3 -1
- package/cjs/providers/WidgetProvider/WidgetProvider.js +1 -12
- package/cjs/providers/index.d.ts +2 -0
- package/cjs/providers/index.js +2 -0
- package/cjs/utils/colors.d.ts +1 -1
- package/components/AppContainer.js +1 -1
- package/components/SelectChainAndToken.js +1 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useChains.js +3 -3
- package/hooks/useFeaturedTokens.js +1 -1
- package/hooks/useGasSufficiency.js +1 -2
- package/hooks/useInitializer.js +6 -0
- package/hooks/useRouteExecution.js +6 -6
- package/hooks/useSwapRoutes.js +3 -4
- package/hooks/useTokenBalances.js +3 -3
- package/hooks/useTokenSearch.js +3 -2
- package/hooks/useTokens.js +3 -2
- package/hooks/useTools.js +3 -2
- package/package.json +1 -1
- package/providers/SDKProvider/SDKProvider.d.ts +4 -0
- package/providers/SDKProvider/SDKProvider.js +19 -0
- package/providers/SDKProvider/index.d.ts +1 -0
- package/providers/SDKProvider/index.js +1 -0
- package/providers/TelemetryProvider/TelemetryProvider.d.ts +4 -0
- package/providers/TelemetryProvider/TelemetryProvider.js +7 -0
- package/providers/TelemetryProvider/index.d.ts +1 -0
- package/providers/TelemetryProvider/index.js +1 -0
- package/providers/WalletProvider/WalletProvider.d.ts +1 -4
- package/providers/WalletProvider/WalletProvider.js +3 -1
- package/providers/WidgetProvider/WidgetProvider.js +3 -14
- package/providers/index.d.ts +2 -0
- package/providers/index.js +2 -0
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/utils/colors.d.ts +1 -1
- package/cjs/config/lifi.d.ts +0 -4
- package/cjs/config/lifi.js +0 -14
- package/config/lifi.d.ts +0 -4
- package/config/lifi.js +0 -7
package/AppProvider.d.ts
CHANGED
|
@@ -5,7 +5,3 @@ export interface AppProps {
|
|
|
5
5
|
}
|
|
6
6
|
export declare const AppProvider: React.FC<PropsWithChildren<AppProps>>;
|
|
7
7
|
export declare const AppRouter: React.FC<PropsWithChildren<{}>>;
|
|
8
|
-
export declare const TelemetryProvider: React.FC<{
|
|
9
|
-
children: React.ReactElement<any, any> | null;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
}>;
|
package/AppProvider.js
CHANGED
|
@@ -3,21 +3,13 @@ import { QueryClientProvider } from '@tanstack/react-query';
|
|
|
3
3
|
import { Fragment } from 'react';
|
|
4
4
|
import { MemoryRouter, useInRouterContext } from 'react-router-dom';
|
|
5
5
|
import { queryClient } from './config/queryClient';
|
|
6
|
-
import {
|
|
7
|
-
import { SwapFormProvider } from './providers/SwapFormProvider';
|
|
8
|
-
import { ThemeProvider } from './providers/ThemeProvider';
|
|
9
|
-
import { WalletProvider } from './providers/WalletProvider';
|
|
10
|
-
import { WidgetProvider } from './providers/WidgetProvider';
|
|
6
|
+
import { SDKProvider, SwapFormProvider, TelemetryProvider, ThemeProvider, WalletProvider, WidgetProvider, } from './providers';
|
|
11
7
|
const QueryProvider = QueryClientProvider;
|
|
12
8
|
export const AppProvider = ({ children, config, }) => {
|
|
13
|
-
return (_jsx(
|
|
9
|
+
return (_jsx(WidgetProvider, Object.assign({ config: config }, { children: _jsx(SDKProvider, { children: _jsx(QueryProvider, Object.assign({ client: queryClient }, { children: _jsx(TelemetryProvider, { children: _jsx(WalletProvider, { children: _jsx(ThemeProvider, { children: _jsx(SwapFormProvider, { children: _jsx(AppRouter, { children: children }) }) }) }) }) })) }) })));
|
|
14
10
|
};
|
|
15
11
|
export const AppRouter = ({ children }) => {
|
|
16
12
|
const inRouterContext = useInRouterContext();
|
|
17
13
|
const Router = inRouterContext ? Fragment : MemoryRouter;
|
|
18
14
|
return _jsx(Router, { children: children });
|
|
19
15
|
};
|
|
20
|
-
export const TelemetryProvider = ({ children, disabled }) => {
|
|
21
|
-
useTelemetry(disabled);
|
|
22
|
-
return children;
|
|
23
|
-
};
|
package/cjs/AppProvider.d.ts
CHANGED
|
@@ -5,7 +5,3 @@ export interface AppProps {
|
|
|
5
5
|
}
|
|
6
6
|
export declare const AppProvider: React.FC<PropsWithChildren<AppProps>>;
|
|
7
7
|
export declare const AppRouter: React.FC<PropsWithChildren<{}>>;
|
|
8
|
-
export declare const TelemetryProvider: React.FC<{
|
|
9
|
-
children: React.ReactElement<any, any> | null;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
}>;
|
package/cjs/AppProvider.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AppRouter = exports.AppProvider = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_query_1 = require("@tanstack/react-query");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const react_router_dom_1 = require("react-router-dom");
|
|
8
8
|
const queryClient_1 = require("./config/queryClient");
|
|
9
|
-
const
|
|
10
|
-
const SwapFormProvider_1 = require("./providers/SwapFormProvider");
|
|
11
|
-
const ThemeProvider_1 = require("./providers/ThemeProvider");
|
|
12
|
-
const WalletProvider_1 = require("./providers/WalletProvider");
|
|
13
|
-
const WidgetProvider_1 = require("./providers/WidgetProvider");
|
|
9
|
+
const providers_1 = require("./providers");
|
|
14
10
|
const QueryProvider = react_query_1.QueryClientProvider;
|
|
15
11
|
const AppProvider = ({ children, config, }) => {
|
|
16
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
12
|
+
return ((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)(QueryProvider, Object.assign({ client: queryClient_1.queryClient }, { children: (0, jsx_runtime_1.jsx)(providers_1.TelemetryProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.WalletProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.ThemeProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.SwapFormProvider, { children: (0, jsx_runtime_1.jsx)(exports.AppRouter, { children: children }) }) }) }) }) })) }) })));
|
|
17
13
|
};
|
|
18
14
|
exports.AppProvider = AppProvider;
|
|
19
15
|
const AppRouter = ({ children }) => {
|
|
@@ -22,8 +18,3 @@ const AppRouter = ({ children }) => {
|
|
|
22
18
|
return (0, jsx_runtime_1.jsx)(Router, { children: children });
|
|
23
19
|
};
|
|
24
20
|
exports.AppRouter = AppRouter;
|
|
25
|
-
const TelemetryProvider = ({ children, disabled }) => {
|
|
26
|
-
(0, hooks_1.useTelemetry)(disabled);
|
|
27
|
-
return children;
|
|
28
|
-
};
|
|
29
|
-
exports.TelemetryProvider = TelemetryProvider;
|
|
@@ -6,7 +6,7 @@ const material_1 = require("@mui/material");
|
|
|
6
6
|
const styles_1 = require("@mui/material/styles");
|
|
7
7
|
const react_1 = require("react");
|
|
8
8
|
const react_router_dom_1 = require("react-router-dom");
|
|
9
|
-
const
|
|
9
|
+
const providers_1 = require("../providers");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
11
|
const CssBaselineContainer = (0, styles_1.styled)(material_1.ScopedCssBaseline)(({ theme }) => ({
|
|
12
12
|
// height: '100%',
|
|
@@ -44,7 +44,7 @@ exports.FlexContainer = (0, styles_1.styled)(material_1.Container)({
|
|
|
44
44
|
});
|
|
45
45
|
const AppContainer = ({ children }) => {
|
|
46
46
|
const ref = (0, react_1.useRef)(null);
|
|
47
|
-
const { containerStyle } = (0,
|
|
47
|
+
const { containerStyle } = (0, providers_1.useWidgetConfig)();
|
|
48
48
|
return ((0, jsx_runtime_1.jsxs)(RelativeContainer, Object.assign({ sx: containerStyle }, { children: [(0, jsx_runtime_1.jsx)(ScrollableContainer, Object.assign({ id: utils_1.ElementId.ScrollableContainer, ref: ref }, { children: (0, jsx_runtime_1.jsx)(CssBaselineContainer, Object.assign({ enableColorScheme: true }, { children: (0, jsx_runtime_1.jsx)(exports.FlexContainer, Object.assign({ disableGutters: true }, { children: children })) })) })), (0, jsx_runtime_1.jsx)(exports.ScrollToLocation, { elementRef: ref })] })));
|
|
49
49
|
};
|
|
50
50
|
exports.AppContainer = AppContainer;
|
|
@@ -6,15 +6,15 @@ const material_1 = require("@mui/material");
|
|
|
6
6
|
const react_hook_form_1 = require("react-hook-form");
|
|
7
7
|
const ReverseTokensButton_1 = require("../components/ReverseTokensButton");
|
|
8
8
|
const SelectTokenButton_1 = require("../components/SelectTokenButton");
|
|
9
|
-
const
|
|
9
|
+
const providers_1 = require("../providers");
|
|
10
10
|
const SelectChainAndToken = (props) => {
|
|
11
11
|
const prefersNarrowView = (0, material_1.useMediaQuery)((theme) => theme.breakpoints.down('sm'));
|
|
12
12
|
const [fromChain, toChain, fromToken, toToken] = (0, react_hook_form_1.useWatch)({
|
|
13
13
|
name: [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
providers_1.SwapFormKey.FromChain,
|
|
15
|
+
providers_1.SwapFormKey.ToChain,
|
|
16
|
+
providers_1.SwapFormKey.FromToken,
|
|
17
|
+
providers_1.SwapFormKey.ToToken,
|
|
18
18
|
],
|
|
19
19
|
});
|
|
20
20
|
const isCompact = fromChain && toChain && fromToken && toToken && !prefersNarrowView;
|
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.16.
|
|
2
|
+
export declare const version = "1.16.1";
|
package/cjs/config/version.js
CHANGED
package/cjs/hooks/useChains.js
CHANGED
|
@@ -12,14 +12,14 @@ 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
|
|
16
|
-
const WidgetProvider_1 = require("../providers/WidgetProvider");
|
|
15
|
+
const providers_1 = require("../providers");
|
|
17
16
|
const chains_1 = require("../stores/chains");
|
|
18
17
|
const useChains = () => {
|
|
19
|
-
const { disabledChains } = (0,
|
|
18
|
+
const { disabledChains } = (0, providers_1.useWidgetConfig)();
|
|
19
|
+
const lifi = (0, providers_1.useLiFi)();
|
|
20
20
|
const [, initializeChains] = (0, chains_1.useSetChainOrder)();
|
|
21
21
|
const { data, isLoading } = (0, react_query_1.useQuery)(['chains'], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
const chains = yield
|
|
22
|
+
const chains = yield lifi.getChains();
|
|
23
23
|
const filteredChains = chains.filter((chain) => !(disabledChains === null || disabledChains === void 0 ? void 0 : disabledChains.includes(chain.id)));
|
|
24
24
|
initializeChains(filteredChains.map((chain) => chain.id));
|
|
25
25
|
return filteredChains;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useFeaturedTokens = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const providers_1 = require("../providers");
|
|
6
6
|
const useFeaturedTokens = (selectedChainId) => {
|
|
7
|
-
const { featuredTokens } = (0,
|
|
7
|
+
const { featuredTokens } = (0, providers_1.useWidgetConfig)();
|
|
8
8
|
return (0, react_1.useMemo)(() => featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.filter((token) => token.chainId === selectedChainId), [featuredTokens, selectedChainId]);
|
|
9
9
|
};
|
|
10
10
|
exports.useFeaturedTokens = useFeaturedTokens;
|
|
@@ -8,19 +8,18 @@ const big_js_1 = __importDefault(require("big.js"));
|
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const react_hook_form_1 = require("react-hook-form");
|
|
10
10
|
const _1 = require(".");
|
|
11
|
-
const
|
|
12
|
-
const WalletProvider_1 = require("../providers/WalletProvider");
|
|
11
|
+
const providers_1 = require("../providers");
|
|
13
12
|
const useTokenBalances_1 = require("./useTokenBalances");
|
|
14
13
|
const useGasSufficiency = (route) => {
|
|
15
|
-
const { account } = (0,
|
|
14
|
+
const { account } = (0, providers_1.useWallet)();
|
|
16
15
|
const [fromChainId, toChainId, fromToken] = (0, react_hook_form_1.useWatch)({
|
|
17
16
|
name: [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
providers_1.SwapFormKeyHelper.getChainKey('from'),
|
|
18
|
+
providers_1.SwapFormKeyHelper.getChainKey('to'),
|
|
19
|
+
providers_1.SwapFormKey.FromToken,
|
|
21
20
|
],
|
|
22
21
|
});
|
|
23
|
-
const fromAmount = (0, _1.useDebouncedWatch)(
|
|
22
|
+
const fromAmount = (0, _1.useDebouncedWatch)(providers_1.SwapFormKey.FromAmount, 250);
|
|
24
23
|
const { getChainById } = (0, _1.useChains)();
|
|
25
24
|
const { tokensWithBalance: fromChainTokenBalances } = (0, useTokenBalances_1.useTokenBalances)(fromChainId);
|
|
26
25
|
const { tokensWithBalance: toChainTokenBalances } = (0, useTokenBalances_1.useTokenBalances)(toChainId);
|
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useInitializer = void 0;
|
|
4
4
|
/* eslint-disable no-underscore-dangle */
|
|
5
|
+
const sdk_1 = require("@lifi/sdk");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const version_1 = require("../config/version");
|
|
5
8
|
const useTools_1 = require("./useTools");
|
|
6
9
|
const useInitializer = () => {
|
|
7
10
|
(0, useTools_1.useTools)();
|
|
11
|
+
(0, react_1.useEffect)(() => {
|
|
12
|
+
(0, sdk_1.checkPackageUpdates)(version_1.name, version_1.version);
|
|
13
|
+
}, []);
|
|
8
14
|
};
|
|
9
15
|
exports.useInitializer = useInitializer;
|
|
@@ -16,14 +16,14 @@ exports.useRouteExecution = void 0;
|
|
|
16
16
|
const react_query_1 = require("@tanstack/react-query");
|
|
17
17
|
const react_1 = require("react");
|
|
18
18
|
const shallow_1 = __importDefault(require("zustand/shallow"));
|
|
19
|
-
const
|
|
20
|
-
const WalletProvider_1 = require("../providers/WalletProvider");
|
|
19
|
+
const providers_1 = require("../providers");
|
|
21
20
|
const stores_1 = require("../stores");
|
|
22
21
|
const events_1 = require("../types/events");
|
|
23
22
|
const utils_1 = require("../utils");
|
|
24
23
|
const useWidgetEvents_1 = require("./useWidgetEvents");
|
|
25
24
|
const useRouteExecution = (routeId, executeInBackground) => {
|
|
26
|
-
const
|
|
25
|
+
const lifi = (0, providers_1.useLiFi)();
|
|
26
|
+
const { account, switchChain } = (0, providers_1.useWallet)();
|
|
27
27
|
const resumedAfterMount = (0, react_1.useRef)(false);
|
|
28
28
|
const emitter = (0, useWidgetEvents_1.useWidgetEvents)();
|
|
29
29
|
const routeExecution = (0, stores_1.useRouteStore)((state) => state.routes[routeId]);
|
|
@@ -59,7 +59,7 @@ const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
59
59
|
if (!(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route)) {
|
|
60
60
|
throw Error('Execution route not found.');
|
|
61
61
|
}
|
|
62
|
-
return
|
|
62
|
+
return lifi.executeRoute(account.signer, routeExecution.route, {
|
|
63
63
|
updateCallback,
|
|
64
64
|
switchChainHook,
|
|
65
65
|
infiniteApproval: false,
|
|
@@ -78,7 +78,7 @@ const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
78
78
|
if (!(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route)) {
|
|
79
79
|
throw Error('Execution route not found.');
|
|
80
80
|
}
|
|
81
|
-
return
|
|
81
|
+
return lifi.resumeRoute(account.signer, resumedRoute !== null && resumedRoute !== void 0 ? resumedRoute : routeExecution.route, {
|
|
82
82
|
updateCallback,
|
|
83
83
|
switchChainHook,
|
|
84
84
|
infiniteApproval: false,
|
|
@@ -138,11 +138,11 @@ const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
138
138
|
if (!route || !(0, stores_1.isRouteActive)(route)) {
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
|
-
|
|
141
|
+
lifi.updateRouteExecution(route, { executeInBackground: true });
|
|
142
142
|
console.log('Move route execution to background.', routeId);
|
|
143
143
|
resumedAfterMount.current = false;
|
|
144
144
|
};
|
|
145
|
-
}, [routeId]);
|
|
145
|
+
}, [lifi, routeId]);
|
|
146
146
|
return {
|
|
147
147
|
executeRoute,
|
|
148
148
|
restartRoute: restartRouteMutation,
|
|
@@ -18,14 +18,13 @@ const react_query_1 = require("@tanstack/react-query");
|
|
|
18
18
|
const big_js_1 = __importDefault(require("big.js"));
|
|
19
19
|
const react_hook_form_1 = require("react-hook-form");
|
|
20
20
|
const _1 = require(".");
|
|
21
|
-
const
|
|
22
|
-
const SwapFormProvider_1 = require("../providers/SwapFormProvider");
|
|
23
|
-
const WalletProvider_1 = require("../providers/WalletProvider");
|
|
21
|
+
const providers_1 = require("../providers");
|
|
24
22
|
const stores_1 = require("../stores");
|
|
25
23
|
const refetchTime = 60000;
|
|
26
24
|
const useSwapRoutes = () => {
|
|
27
25
|
var _a;
|
|
28
|
-
const
|
|
26
|
+
const lifi = (0, providers_1.useLiFi)();
|
|
27
|
+
const { account, provider } = (0, providers_1.useWallet)();
|
|
29
28
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
30
29
|
const { slippage, enabledBridges, enabledExchanges, routePriority } = (0, stores_1.useSettings)([
|
|
31
30
|
'slippage',
|
|
@@ -35,14 +34,14 @@ const useSwapRoutes = () => {
|
|
|
35
34
|
]);
|
|
36
35
|
const [fromChainId, fromTokenAddress, toChainId, toTokenAddress, toAddress] = (0, react_hook_form_1.useWatch)({
|
|
37
36
|
name: [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
providers_1.SwapFormKey.FromChain,
|
|
38
|
+
providers_1.SwapFormKey.FromToken,
|
|
39
|
+
providers_1.SwapFormKey.ToChain,
|
|
40
|
+
providers_1.SwapFormKey.ToToken,
|
|
41
|
+
providers_1.SwapFormKey.ToAddress,
|
|
43
42
|
],
|
|
44
43
|
});
|
|
45
|
-
const [fromTokenAmount] = (0, _1.useDebouncedWatch)([
|
|
44
|
+
const [fromTokenAmount] = (0, _1.useDebouncedWatch)([providers_1.SwapFormKey.FromAmount], 250);
|
|
46
45
|
const { token } = (0, _1.useToken)(fromChainId, fromTokenAddress);
|
|
47
46
|
const isEnabled =
|
|
48
47
|
// Boolean(account.address) &&
|
|
@@ -81,7 +80,7 @@ const useSwapRoutes = () => {
|
|
|
81
80
|
catch (_d) {
|
|
82
81
|
toWalletAddress = (0, address_1.isAddress)(toAddress) ? toAddress : fromAddress;
|
|
83
82
|
}
|
|
84
|
-
return
|
|
83
|
+
return lifi.getRoutes({
|
|
85
84
|
fromChainId,
|
|
86
85
|
fromAmount: (0, big_js_1.default)(Number(fromTokenAmount) * Math.pow(10, ((_c = token === null || token === void 0 ? void 0 : token.decimals) !== null && _c !== void 0 ? _c : 0))).toString(),
|
|
87
86
|
fromTokenAddress,
|
|
@@ -13,15 +13,15 @@ exports.useTokenBalances = void 0;
|
|
|
13
13
|
/* eslint-disable consistent-return */
|
|
14
14
|
const react_query_1 = require("@tanstack/react-query");
|
|
15
15
|
const react_1 = require("react");
|
|
16
|
-
const
|
|
17
|
-
const WalletProvider_1 = require("../providers/WalletProvider");
|
|
16
|
+
const providers_1 = require("../providers");
|
|
18
17
|
const utils_1 = require("../utils");
|
|
19
18
|
const useFeaturedTokens_1 = require("./useFeaturedTokens");
|
|
20
19
|
const useTokens_1 = require("./useTokens");
|
|
21
20
|
const defaultRefetchInterval = 60000;
|
|
22
21
|
const minRefetchInterval = 1000;
|
|
23
22
|
const useTokenBalances = (selectedChainId) => {
|
|
24
|
-
const
|
|
23
|
+
const lifi = (0, providers_1.useLiFi)();
|
|
24
|
+
const { account } = (0, providers_1.useWallet)();
|
|
25
25
|
const featuredTokens = (0, useFeaturedTokens_1.useFeaturedTokens)(selectedChainId);
|
|
26
26
|
const { tokens, isLoading } = (0, useTokens_1.useTokens)(selectedChainId);
|
|
27
27
|
const [refetchInterval, setRefetchInterval] = (0, react_1.useState)(defaultRefetchInterval);
|
|
@@ -30,7 +30,7 @@ const useTokenBalances = (selectedChainId) => {
|
|
|
30
30
|
if (!accountAddress || !tokens) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
const tokenBalances = yield
|
|
33
|
+
const tokenBalances = yield lifi.getTokenBalances(accountAddress, tokens);
|
|
34
34
|
if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
|
|
35
35
|
// Sometimes RPCs (e.g. Arbitrum) don't return balances on first call
|
|
36
36
|
// TODO: fix and remove backplane
|
|
@@ -11,11 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.useTokenSearch = void 0;
|
|
13
13
|
const react_query_1 = require("@tanstack/react-query");
|
|
14
|
-
const
|
|
14
|
+
const providers_1 = require("../providers");
|
|
15
15
|
const useTokenSearch = (token, chainId, enabled) => {
|
|
16
|
+
const lifi = (0, providers_1.useLiFi)();
|
|
16
17
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
17
18
|
const { data, isLoading, isFetching, isFetched } = (0, react_query_1.useQuery)(['token-search', chainId, token], ({ queryKey: [, chainId, token], signal }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const data = yield
|
|
19
|
+
const data = yield lifi.getToken(chainId, token, {
|
|
19
20
|
signal,
|
|
20
21
|
});
|
|
21
22
|
if (data) {
|
package/cjs/hooks/useTokens.js
CHANGED
|
@@ -11,13 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.useTokens = void 0;
|
|
13
13
|
const react_query_1 = require("@tanstack/react-query");
|
|
14
|
-
const
|
|
14
|
+
const providers_1 = require("../providers");
|
|
15
15
|
const useFeaturedTokens_1 = require("./useFeaturedTokens");
|
|
16
16
|
const useTokens = (selectedChainId) => {
|
|
17
|
+
const lifi = (0, providers_1.useLiFi)();
|
|
17
18
|
const featuredTokens = (0, useFeaturedTokens_1.useFeaturedTokens)(selectedChainId);
|
|
18
19
|
const { data: tokens, isLoading, isFetching, } = (0, react_query_1.useQuery)(['tokens', selectedChainId, featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
20
|
var _a, _b, _c;
|
|
20
|
-
const data = yield
|
|
21
|
+
const data = yield lifi.getTokens({ chains: [selectedChainId] });
|
|
21
22
|
const featuredTokenAddresses = new Set(featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => token.address));
|
|
22
23
|
return [
|
|
23
24
|
...((_a = featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => {
|
package/cjs/hooks/useTools.js
CHANGED
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useTools = void 0;
|
|
4
4
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
const
|
|
6
|
+
const providers_1 = require("../providers");
|
|
7
7
|
const stores_1 = require("../stores");
|
|
8
8
|
const useTools = () => {
|
|
9
|
+
const lifi = (0, providers_1.useLiFi)();
|
|
9
10
|
const initializeTools = (0, stores_1.useSettingsStore)((state) => state.initializeTools);
|
|
10
|
-
const { data } = (0, react_query_1.useQuery)(['tools'], ({ signal }) =>
|
|
11
|
+
const { data } = (0, react_query_1.useQuery)(['tools'], ({ signal }) => lifi.getTools(undefined, { signal }), {
|
|
11
12
|
onSuccess(data) {
|
|
12
13
|
initializeTools('Bridges', data.bridges.map((bridge) => bridge.key));
|
|
13
14
|
initializeTools('Exchanges', data.exchanges.map((exchange) => exchange.key));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SDKProvider = exports.useLiFi = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const sdk_1 = __importDefault(require("@lifi/sdk"));
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const WidgetProvider_1 = require("../WidgetProvider");
|
|
11
|
+
let lifi;
|
|
12
|
+
const SDKContext = (0, react_1.createContext)(null);
|
|
13
|
+
const useLiFi = () => (0, react_1.useContext)(SDKContext);
|
|
14
|
+
exports.useLiFi = useLiFi;
|
|
15
|
+
const SDKProvider = ({ children, }) => {
|
|
16
|
+
const { sdkConfig, integrator } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
17
|
+
const value = (0, react_1.useMemo)(() => {
|
|
18
|
+
const config = Object.assign(Object.assign({}, sdkConfig), { defaultRouteOptions: Object.assign(Object.assign({}, sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.defaultRouteOptions), { integrator: integrator !== null && integrator !== void 0 ? integrator : window.location.hostname }) });
|
|
19
|
+
if (!lifi) {
|
|
20
|
+
lifi = new sdk_1.default(Object.assign({ disableVersionCheck: true }, config));
|
|
21
|
+
}
|
|
22
|
+
lifi.setConfig(config);
|
|
23
|
+
return lifi;
|
|
24
|
+
}, [integrator, sdkConfig]);
|
|
25
|
+
return (0, jsx_runtime_1.jsx)(SDKContext.Provider, Object.assign({ value: value }, { children: children }));
|
|
26
|
+
};
|
|
27
|
+
exports.SDKProvider = SDKProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SDKProvider';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./SDKProvider"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelemetryProvider = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const hooks_1 = require("../../hooks");
|
|
6
|
+
const TelemetryProvider = ({ children }) => {
|
|
7
|
+
const config = (0, __1.useWidgetConfig)();
|
|
8
|
+
(0, hooks_1.useTelemetry)(config === null || config === void 0 ? void 0 : config.disableTelemetry);
|
|
9
|
+
return children;
|
|
10
|
+
};
|
|
11
|
+
exports.TelemetryProvider = TelemetryProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TelemetryProvider';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TelemetryProvider"), exports);
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { Signer } from 'ethers';
|
|
2
2
|
import type { FC, PropsWithChildren } from 'react';
|
|
3
|
-
import type { WidgetWalletManagement } from '../../types';
|
|
4
3
|
import type { WalletContextProps } from './types';
|
|
5
4
|
export declare const useWallet: () => WalletContextProps;
|
|
6
|
-
export declare const WalletProvider: FC<PropsWithChildren
|
|
7
|
-
walletManagement?: WidgetWalletManagement;
|
|
8
|
-
}>>;
|
|
5
|
+
export declare const WalletProvider: FC<PropsWithChildren>;
|
|
9
6
|
export declare const extractAccountFromSigner: (signer?: Signer) => Promise<{
|
|
10
7
|
address: string | undefined;
|
|
11
8
|
isActive: boolean;
|
|
@@ -13,6 +13,7 @@ exports.extractAccountFromSigner = exports.WalletProvider = exports.useWallet =
|
|
|
13
13
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
14
14
|
const wallet_management_1 = require("@lifi/wallet-management");
|
|
15
15
|
const react_1 = require("react");
|
|
16
|
+
const WidgetProvider_1 = require("../WidgetProvider");
|
|
16
17
|
const stub = () => {
|
|
17
18
|
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
18
19
|
};
|
|
@@ -27,7 +28,8 @@ const initialContext = {
|
|
|
27
28
|
const WalletContext = (0, react_1.createContext)(initialContext);
|
|
28
29
|
const useWallet = () => (0, react_1.useContext)(WalletContext);
|
|
29
30
|
exports.useWallet = useWallet;
|
|
30
|
-
const WalletProvider = ({ children
|
|
31
|
+
const WalletProvider = ({ children }) => {
|
|
32
|
+
const { walletManagement } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
31
33
|
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, provider, } = (0, wallet_management_1.useLiFiWalletManagement)();
|
|
32
34
|
const [account, setAccount] = (0, react_1.useState)({});
|
|
33
35
|
const connect = (0, react_1.useCallback)((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -15,11 +15,6 @@ exports.WidgetProvider = exports.useWidgetConfig = void 0;
|
|
|
15
15
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
16
|
const sdk_1 = require("@lifi/sdk");
|
|
17
17
|
const react_1 = require("react");
|
|
18
|
-
const lifi_1 = require("../../config/lifi");
|
|
19
|
-
const version_1 = require("../../config/version");
|
|
20
|
-
const stub = () => {
|
|
21
|
-
throw new Error('You forgot to wrap your component in <WidgetProvider>.');
|
|
22
|
-
};
|
|
23
18
|
const initialContext = {
|
|
24
19
|
disabledChains: [],
|
|
25
20
|
};
|
|
@@ -27,7 +22,7 @@ const WidgetContext = (0, react_1.createContext)(initialContext);
|
|
|
27
22
|
const useWidgetConfig = () => (0, react_1.useContext)(WidgetContext);
|
|
28
23
|
exports.useWidgetConfig = useWidgetConfig;
|
|
29
24
|
const WidgetProvider = (_a) => {
|
|
30
|
-
var { children } = _a, _b = _a.config, _c = _b === void 0 ? {} : _b, { fromChain, fromToken, toChain, toToken, fromAmount
|
|
25
|
+
var { children } = _a, _b = _a.config, _c = _b === void 0 ? {} : _b, { fromChain, fromToken, toChain, toToken, fromAmount } = _c, config = __rest(_c, ["fromChain", "fromToken", "toChain", "toToken", "fromAmount"]);
|
|
31
26
|
const value = (0, react_1.useMemo)(() => {
|
|
32
27
|
var _a, _b, _c, _d;
|
|
33
28
|
try {
|
|
@@ -57,12 +52,6 @@ const WidgetProvider = (_a) => {
|
|
|
57
52
|
return config;
|
|
58
53
|
}
|
|
59
54
|
}, [config, fromAmount, fromChain, fromToken, toChain, toToken]);
|
|
60
|
-
(0, react_1.useEffect)(() => {
|
|
61
|
-
(0, lifi_1.updateLiFiConfig)(Object.assign(Object.assign({}, sdkConfig), { defaultRouteOptions: Object.assign(Object.assign({}, sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.defaultRouteOptions), { integrator: integrator !== null && integrator !== void 0 ? integrator : window.location.hostname }) }));
|
|
62
|
-
}, [integrator, sdkConfig]);
|
|
63
|
-
(0, react_1.useEffect)(() => {
|
|
64
|
-
(0, sdk_1.checkPackageUpdates)(version_1.name, version_1.version);
|
|
65
|
-
}, []);
|
|
66
55
|
return ((0, jsx_runtime_1.jsx)(WidgetContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
67
56
|
};
|
|
68
57
|
exports.WidgetProvider = WidgetProvider;
|
package/cjs/providers/index.d.ts
CHANGED
package/cjs/providers/index.js
CHANGED
|
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./SDKProvider"), exports);
|
|
17
18
|
__exportStar(require("./SwapFormProvider"), exports);
|
|
19
|
+
__exportStar(require("./TelemetryProvider"), exports);
|
|
18
20
|
__exportStar(require("./ThemeProvider"), exports);
|
|
19
21
|
__exportStar(require("./WalletProvider"), exports);
|
|
20
22
|
__exportStar(require("./WidgetProvider"), exports);
|
package/cjs/utils/colors.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Theme } from '@mui/material';
|
|
2
2
|
export declare const getContrastAlphaColor: (theme: Theme, alpha: string | number) => string;
|
|
3
|
-
export declare const getContrastTextColor: (theme: Theme, background?: string) => "#
|
|
3
|
+
export declare const getContrastTextColor: (theme: Theme, background?: string) => "#000" | "#fff";
|
|
@@ -3,7 +3,7 @@ import { Box, Container, ScopedCssBaseline } from '@mui/material';
|
|
|
3
3
|
import { styled } from '@mui/material/styles';
|
|
4
4
|
import { useLayoutEffect, useRef } from 'react';
|
|
5
5
|
import { useLocation } from 'react-router-dom';
|
|
6
|
-
import { useWidgetConfig } from '../providers
|
|
6
|
+
import { useWidgetConfig } from '../providers';
|
|
7
7
|
import { ElementId } from '../utils';
|
|
8
8
|
const CssBaselineContainer = styled(ScopedCssBaseline)(({ theme }) => ({
|
|
9
9
|
// height: '100%',
|
|
@@ -3,7 +3,7 @@ import { Box, useMediaQuery } from '@mui/material';
|
|
|
3
3
|
import { useWatch } from 'react-hook-form';
|
|
4
4
|
import { ReverseTokensButton } from '../components/ReverseTokensButton';
|
|
5
5
|
import { SelectTokenButton } from '../components/SelectTokenButton';
|
|
6
|
-
import { SwapFormKey } from '../providers
|
|
6
|
+
import { SwapFormKey } from '../providers';
|
|
7
7
|
export const SelectChainAndToken = (props) => {
|
|
8
8
|
const prefersNarrowView = useMediaQuery((theme) => theme.breakpoints.down('sm'));
|
|
9
9
|
const [fromChain, toChain, fromToken, toToken] = useWatch({
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "1.16.
|
|
2
|
+
export declare const version = "1.16.1";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '1.16.
|
|
2
|
+
export const version = '1.16.1';
|