@lifi/widget 2.9.3 → 2.9.4
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/cjs/AppProvider.js +1 -1
- package/cjs/components/Card/CardLabel.d.ts +1 -1
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useChains.js +5 -25
- package/cjs/pages/SelectTokenPage/SelectTokenPage.d.ts +1 -1
- package/cjs/providers/FormProvider/FormUpdater.js +5 -2
- package/cjs/providers/WidgetProvider/WidgetProvider.js +1 -0
- package/cjs/stores/chains/ChainOrderStore.js +24 -0
- package/components/Card/CardLabel.d.ts +1 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useChains.js +7 -27
- package/package.json +1 -1
- package/pages/SelectTokenPage/SelectTokenPage.d.ts +1 -1
- package/providers/FormProvider/FormUpdater.js +5 -2
- package/providers/WidgetProvider/WidgetProvider.js +1 -0
- package/stores/chains/ChainOrderStore.js +25 -1
- package/tsconfig.cjs.tsbuildinfo +1 -1
package/AppProvider.js
CHANGED
|
@@ -6,7 +6,7 @@ import { queryClient } from './config/queryClient';
|
|
|
6
6
|
import { FormProvider, I18nProvider, SDKProvider, ThemeProvider, URLSearchParamsBuilder, WalletProvider, WidgetProvider, useWidgetConfig, } from './providers';
|
|
7
7
|
import { StoreProvider } from './stores';
|
|
8
8
|
export const AppProvider = ({ children, config, }) => {
|
|
9
|
-
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(
|
|
9
|
+
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(WidgetProvider, { config: config, children: _jsx(SDKProvider, { children: _jsx(ThemeProvider, { children: _jsx(I18nProvider, { children: _jsx(WalletProvider, { children: _jsx(FormProvider, { children: _jsx(StoreProvider, { config: config, children: _jsx(AppRouter, { children: children }) }) }) }) }) }) }) }) }));
|
|
10
10
|
};
|
|
11
11
|
export const AppRouter = ({ children }) => {
|
|
12
12
|
const { buildUrl } = useWidgetConfig();
|
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 stores_1 = require("./stores");
|
|
11
11
|
const AppProvider = ({ children, config, }) => {
|
|
12
|
-
return ((0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient_1.queryClient, children: (0, jsx_runtime_1.jsx)(
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient_1.queryClient, children: (0, jsx_runtime_1.jsx)(providers_1.WidgetProvider, { config: config, children: (0, jsx_runtime_1.jsx)(providers_1.SDKProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.ThemeProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.I18nProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.WalletProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.FormProvider, { children: (0, jsx_runtime_1.jsx)(stores_1.StoreProvider, { config: config, children: (0, jsx_runtime_1.jsx)(exports.AppRouter, { children: children }) }) }) }) }) }) }) }) }));
|
|
13
13
|
};
|
|
14
14
|
exports.AppProvider = AppProvider;
|
|
15
15
|
const AppRouter = ({ children }) => {
|
|
@@ -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?: "insurance" | "active" | "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;
|
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.9.
|
|
2
|
+
export declare const version = "2.9.4";
|
package/cjs/config/version.js
CHANGED
package/cjs/hooks/useChains.js
CHANGED
|
@@ -3,38 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useChains = void 0;
|
|
4
4
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
7
6
|
const providers_1 = require("../providers");
|
|
8
|
-
const stores_1 = require("../stores");
|
|
9
7
|
const useChains = () => {
|
|
10
|
-
const { chains
|
|
8
|
+
const { chains } = (0, providers_1.useWidgetConfig)();
|
|
11
9
|
const lifi = (0, providers_1.useLiFi)();
|
|
12
|
-
const { getValues, setValue } = (0, react_hook_form_1.useFormContext)();
|
|
13
|
-
const initializeChains = (0, stores_1.useChainOrderStore)((state) => state.initializeChains);
|
|
14
10
|
const { data: availableChains, isLoading: isLoadingAvailableChains } = (0, react_query_1.useQuery)(['chains'], async () => lifi.getChains(), {
|
|
15
11
|
refetchInterval: 300000,
|
|
16
12
|
staleTime: 300000,
|
|
17
13
|
});
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const filteredChains = availableChains.filter((chain) => (0, providers_1.isItemAllowed)(chain.id, chains));
|
|
23
|
-
const chainOrder = initializeChains(filteredChains.map((chain) => chain.id));
|
|
24
|
-
const [fromChainValue, toChainValue] = getValues([
|
|
25
|
-
providers_1.FormKey.FromChain,
|
|
26
|
-
providers_1.FormKey.ToChain,
|
|
27
|
-
]);
|
|
28
|
-
if (!fromChainValue) {
|
|
29
|
-
setValue(providers_1.FormKey.FromChain, chainOrder[0]);
|
|
30
|
-
}
|
|
31
|
-
if (!toChainValue) {
|
|
32
|
-
setValue(providers_1.FormKey.ToChain, chainOrder[0]);
|
|
33
|
-
}
|
|
14
|
+
const filteredChains = (0, react_1.useMemo)(() => {
|
|
15
|
+
const filteredChains = availableChains?.filter((chain) => (0, providers_1.isItemAllowed)(chain.id, chains));
|
|
34
16
|
return filteredChains;
|
|
35
|
-
},
|
|
36
|
-
enabled: Boolean(availableChains),
|
|
37
|
-
});
|
|
17
|
+
}, [availableChains, chains]);
|
|
38
18
|
const getChainById = (0, react_1.useCallback)((chainId) => {
|
|
39
19
|
const chain = availableChains?.find((chain) => chain.id === chainId);
|
|
40
20
|
// if (!chain) {
|
|
@@ -45,7 +25,7 @@ const useChains = () => {
|
|
|
45
25
|
return {
|
|
46
26
|
chains: filteredChains,
|
|
47
27
|
getChainById,
|
|
48
|
-
isLoading: isLoadingAvailableChains
|
|
28
|
+
isLoading: isLoadingAvailableChains,
|
|
49
29
|
};
|
|
50
30
|
};
|
|
51
31
|
exports.useChains = useChains;
|
|
@@ -16,8 +16,11 @@ const FormUpdater = ({ defaultValues }) => {
|
|
|
16
16
|
const previousDefaultValues = (0, react_1.useRef)(defaultValues);
|
|
17
17
|
// Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
|
|
18
18
|
(0, react_1.useEffect)(() => {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
if (!account.isActive || !account.chainId) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const chainAllowed = (0, WidgetProvider_1.isItemAllowed)(account.chainId, chains);
|
|
23
|
+
if (!chainAllowed) {
|
|
21
24
|
return;
|
|
22
25
|
}
|
|
23
26
|
const { isTouched: isFromChainTouched } = getFieldState(_1.FormKey.FromChain);
|
|
@@ -3,13 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useChainOrderStoreContext = exports.useChainOrderStore = exports.ChainOrderStoreProvider = exports.ChainOrderStoreContext = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
7
|
+
const hooks_1 = require("../../hooks");
|
|
8
|
+
const providers_1 = require("../../providers");
|
|
6
9
|
const createChainOrderStore_1 = require("./createChainOrderStore");
|
|
7
10
|
exports.ChainOrderStoreContext = (0, react_1.createContext)(null);
|
|
8
11
|
function ChainOrderStoreProvider({ children, ...props }) {
|
|
9
12
|
const storeRef = (0, react_1.useRef)();
|
|
13
|
+
const { chains: filteredChains } = (0, hooks_1.useChains)();
|
|
14
|
+
const { setValue, getValues } = (0, react_hook_form_1.useFormContext)();
|
|
10
15
|
if (!storeRef.current) {
|
|
11
16
|
storeRef.current = (0, createChainOrderStore_1.createChainOrderStore)(props);
|
|
12
17
|
}
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
19
|
+
if (filteredChains) {
|
|
20
|
+
const chainOrder = storeRef.current
|
|
21
|
+
?.getState()
|
|
22
|
+
.initializeChains(filteredChains.map((chain) => chain.id));
|
|
23
|
+
if (chainOrder) {
|
|
24
|
+
const [fromChainValue, toChainValue] = getValues([
|
|
25
|
+
providers_1.FormKey.FromChain,
|
|
26
|
+
providers_1.FormKey.ToChain,
|
|
27
|
+
]);
|
|
28
|
+
if (!fromChainValue) {
|
|
29
|
+
setValue(providers_1.FormKey.FromChain, chainOrder[0]);
|
|
30
|
+
}
|
|
31
|
+
if (!toChainValue) {
|
|
32
|
+
setValue(providers_1.FormKey.ToChain, chainOrder[0]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, [filteredChains, getValues, setValue]);
|
|
13
37
|
return ((0, jsx_runtime_1.jsx)(exports.ChainOrderStoreContext.Provider, { value: storeRef.current, children: children }));
|
|
14
38
|
}
|
|
15
39
|
exports.ChainOrderStoreProvider = ChainOrderStoreProvider;
|
|
@@ -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?: "insurance" | "active" | "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;
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "2.9.
|
|
2
|
+
export declare const version = "2.9.4";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '2.9.
|
|
2
|
+
export const version = '2.9.4';
|
package/hooks/useChains.js
CHANGED
|
@@ -1,37 +1,17 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { FormKey, isItemAllowed, useLiFi, useWidgetConfig } from '../providers';
|
|
5
|
-
import { useChainOrderStore } from '../stores';
|
|
2
|
+
import { useCallback, useMemo } from 'react';
|
|
3
|
+
import { isItemAllowed, useLiFi, useWidgetConfig } from '../providers';
|
|
6
4
|
export const useChains = () => {
|
|
7
|
-
const { chains
|
|
5
|
+
const { chains } = useWidgetConfig();
|
|
8
6
|
const lifi = useLiFi();
|
|
9
|
-
const { getValues, setValue } = useFormContext();
|
|
10
|
-
const initializeChains = useChainOrderStore((state) => state.initializeChains);
|
|
11
7
|
const { data: availableChains, isLoading: isLoadingAvailableChains } = useQuery(['chains'], async () => lifi.getChains(), {
|
|
12
8
|
refetchInterval: 300000,
|
|
13
9
|
staleTime: 300000,
|
|
14
10
|
});
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const filteredChains = availableChains.filter((chain) => isItemAllowed(chain.id, chains));
|
|
20
|
-
const chainOrder = initializeChains(filteredChains.map((chain) => chain.id));
|
|
21
|
-
const [fromChainValue, toChainValue] = getValues([
|
|
22
|
-
FormKey.FromChain,
|
|
23
|
-
FormKey.ToChain,
|
|
24
|
-
]);
|
|
25
|
-
if (!fromChainValue) {
|
|
26
|
-
setValue(FormKey.FromChain, chainOrder[0]);
|
|
27
|
-
}
|
|
28
|
-
if (!toChainValue) {
|
|
29
|
-
setValue(FormKey.ToChain, chainOrder[0]);
|
|
30
|
-
}
|
|
11
|
+
const filteredChains = useMemo(() => {
|
|
12
|
+
const filteredChains = availableChains?.filter((chain) => isItemAllowed(chain.id, chains));
|
|
31
13
|
return filteredChains;
|
|
32
|
-
},
|
|
33
|
-
enabled: Boolean(availableChains),
|
|
34
|
-
});
|
|
14
|
+
}, [availableChains, chains]);
|
|
35
15
|
const getChainById = useCallback((chainId) => {
|
|
36
16
|
const chain = availableChains?.find((chain) => chain.id === chainId);
|
|
37
17
|
// if (!chain) {
|
|
@@ -42,6 +22,6 @@ export const useChains = () => {
|
|
|
42
22
|
return {
|
|
43
23
|
chains: filteredChains,
|
|
44
24
|
getChainById,
|
|
45
|
-
isLoading: isLoadingAvailableChains
|
|
25
|
+
isLoading: isLoadingAvailableChains,
|
|
46
26
|
};
|
|
47
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.4",
|
|
4
4
|
"description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -13,8 +13,11 @@ export const FormUpdater = ({ defaultValues }) => {
|
|
|
13
13
|
const previousDefaultValues = useRef(defaultValues);
|
|
14
14
|
// Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
|
|
15
15
|
useEffect(() => {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (!account.isActive || !account.chainId) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const chainAllowed = isItemAllowed(account.chainId, chains);
|
|
20
|
+
if (!chainAllowed) {
|
|
18
21
|
return;
|
|
19
22
|
}
|
|
20
23
|
const { isTouched: isFromChainTouched } = getFieldState(FormKey.FromChain);
|
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useRef } from 'react';
|
|
2
|
+
import { createContext, useContext, useEffect, useRef } from 'react';
|
|
3
|
+
import { useFormContext } from 'react-hook-form';
|
|
4
|
+
import { useChains } from '../../hooks';
|
|
5
|
+
import { FormKey } from '../../providers';
|
|
3
6
|
import { createChainOrderStore } from './createChainOrderStore';
|
|
4
7
|
export const ChainOrderStoreContext = createContext(null);
|
|
5
8
|
export function ChainOrderStoreProvider({ children, ...props }) {
|
|
6
9
|
const storeRef = useRef();
|
|
10
|
+
const { chains: filteredChains } = useChains();
|
|
11
|
+
const { setValue, getValues } = useFormContext();
|
|
7
12
|
if (!storeRef.current) {
|
|
8
13
|
storeRef.current = createChainOrderStore(props);
|
|
9
14
|
}
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (filteredChains) {
|
|
17
|
+
const chainOrder = storeRef.current
|
|
18
|
+
?.getState()
|
|
19
|
+
.initializeChains(filteredChains.map((chain) => chain.id));
|
|
20
|
+
if (chainOrder) {
|
|
21
|
+
const [fromChainValue, toChainValue] = getValues([
|
|
22
|
+
FormKey.FromChain,
|
|
23
|
+
FormKey.ToChain,
|
|
24
|
+
]);
|
|
25
|
+
if (!fromChainValue) {
|
|
26
|
+
setValue(FormKey.FromChain, chainOrder[0]);
|
|
27
|
+
}
|
|
28
|
+
if (!toChainValue) {
|
|
29
|
+
setValue(FormKey.ToChain, chainOrder[0]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, [filteredChains, getValues, setValue]);
|
|
10
34
|
return (_jsx(ChainOrderStoreContext.Provider, { value: storeRef.current, children: children }));
|
|
11
35
|
}
|
|
12
36
|
export function useChainOrderStore(selector, equalityFn) {
|