@lifi/widget 1.12.0 → 1.12.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/AppDrawer.style.d.ts +1 -1
- package/AppDrawer.style.js +6 -2
- package/AppProvider.d.ts +4 -0
- package/AppProvider.js +5 -2
- package/components/Header/Header.js +1 -0
- package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
- package/components/Step/Step.js +4 -1
- package/components/Step/StepProcess.style.d.ts +1 -1
- package/components/StepActions/StepActions.js +4 -2
- package/components/SwapButton/SwapButton.js +7 -4
- package/components/SwapButton/SwapButton.style.d.ts +1 -1
- package/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
- package/components/SwapRouteCard/SwapRouteCard.style.js +4 -1
- package/components/TokenList/TokenList.js +2 -1
- package/components/TokenList/TokenList.style.d.ts +2 -2
- package/config/lifi.d.ts +1 -1
- package/config/lifi.js +2 -8
- package/config/theme.js +14 -11
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useGasSufficiency.js +11 -4
- package/hooks/useRouteExecution.js +31 -17
- package/hooks/useSwapRoutes.js +2 -2
- package/hooks/useTokenBalance.js +1 -1
- package/hooks/useTokenBalances.d.ts +4 -2
- package/hooks/useTokenBalances.js +23 -11
- package/package.json +12 -12
- package/pages/MainPage/SwapRoutes.style.d.ts +1 -1
- package/pages/SelectWalletPage/SelectWalletPage.style.d.ts +2 -2
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
- package/providers/WalletProvider/WalletProvider.d.ts +11 -1
- package/providers/WalletProvider/WalletProvider.js +24 -33
- package/providers/WidgetProvider/WidgetProvider.js +5 -2
- package/stores/route/useRouteStore.js +0 -12
- package/types/widget.d.ts +1 -1
- package/utils/colors.d.ts +1 -0
- package/utils/colors.js +5 -0
package/AppDrawer.style.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const DrawerButton: import("@emotion/styled").StyledComponent<{
|
|
3
3
|
children?: import("react").ReactNode;
|
|
4
4
|
classes?: Partial<import("@mui/material").ButtonClasses> | undefined;
|
|
5
|
-
color?: "inherit" | "
|
|
5
|
+
color?: "inherit" | "primary" | "secondary" | "error" | "warning" | "info" | "success" | undefined;
|
|
6
6
|
disabled?: boolean | undefined;
|
|
7
7
|
disableElevation?: boolean | undefined;
|
|
8
8
|
disableFocusRipple?: boolean | undefined;
|
package/AppDrawer.style.js
CHANGED
|
@@ -39,8 +39,12 @@ export const DrawerButton = styled(Button, {
|
|
|
39
39
|
? getButtonTransformWidth(drawerProps === null || drawerProps === void 0 ? void 0 : drawerProps.width, drawerProps === null || drawerProps === void 0 ? void 0 : drawerProps.maxWidth)
|
|
40
40
|
: '0px'} * -1), 0, 0)`,
|
|
41
41
|
transition: theme.transitions.create(['transform'], {
|
|
42
|
-
duration:
|
|
43
|
-
|
|
42
|
+
duration: open
|
|
43
|
+
? theme.transitions.duration.enteringScreen
|
|
44
|
+
: theme.transitions.duration.leavingScreen,
|
|
45
|
+
easing: open
|
|
46
|
+
? theme.transitions.easing.easeOut
|
|
47
|
+
: theme.transitions.easing.sharp,
|
|
44
48
|
}),
|
|
45
49
|
zIndex: 1500,
|
|
46
50
|
'&:hover': {
|
package/AppProvider.d.ts
CHANGED
|
@@ -5,3 +5,7 @@ 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
|
@@ -12,11 +12,14 @@ import { WalletProvider } from './providers/WalletProvider';
|
|
|
12
12
|
import { WidgetProvider } from './providers/WidgetProvider';
|
|
13
13
|
const QueryProvider = QueryClientProvider;
|
|
14
14
|
export const AppProvider = ({ children, config, }) => {
|
|
15
|
-
|
|
16
|
-
return (_jsx(WidgetProvider, Object.assign({ config: config }, { children: _jsx(ThemeProvider, { children: _jsx(QueryProvider, Object.assign({ client: queryClient }, { children: _jsx(WalletProvider, { children: _jsx(SwapFormProvider, { children: _jsx(AppRouter, { children: children }) }) }) })) }) })));
|
|
15
|
+
return (_jsx(QueryProvider, Object.assign({ client: queryClient }, { children: _jsx(TelemetryProvider, Object.assign({ disabled: config === null || config === void 0 ? void 0 : config.disableTelemetry }, { children: _jsx(WalletProvider, Object.assign({ walletManagement: config === null || config === void 0 ? void 0 : config.walletManagement }, { children: _jsx(WidgetProvider, Object.assign({ config: config }, { children: _jsx(ThemeProvider, { children: _jsx(SwapFormProvider, { children: _jsx(AppRouter, { children: children }) }) }) })) })) })) })));
|
|
17
16
|
};
|
|
18
17
|
export const AppRouter = ({ children }) => {
|
|
19
18
|
const inRouterContext = useInRouterContext();
|
|
20
19
|
const Router = inRouterContext ? Fragment : MemoryRouter;
|
|
21
20
|
return _jsx(Router, { children: children });
|
|
22
21
|
};
|
|
22
|
+
export const TelemetryProvider = ({ children, disabled }) => {
|
|
23
|
+
useTelemetry(disabled);
|
|
24
|
+
return children;
|
|
25
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const IconButton: import("@emotion/styled").StyledComponent<{
|
|
3
3
|
children?: import("react").ReactNode;
|
|
4
4
|
classes?: Partial<import("@mui/material").IconButtonClasses> | undefined;
|
|
5
|
-
color?: "inherit" | "default" | "
|
|
5
|
+
color?: "inherit" | "default" | "primary" | "secondary" | "error" | "warning" | "info" | "success" | undefined;
|
|
6
6
|
disabled?: boolean | undefined;
|
|
7
7
|
disableFocusRipple?: boolean | undefined;
|
|
8
8
|
edge?: false | "end" | "start" | undefined;
|
package/components/Step/Step.js
CHANGED
|
@@ -13,7 +13,10 @@ export const Step = ({ step, fromToken, toToken }) => {
|
|
|
13
13
|
const getCardTitle = () => {
|
|
14
14
|
switch (step.type) {
|
|
15
15
|
case 'lifi':
|
|
16
|
-
|
|
16
|
+
if (step.includedSteps.some((step) => step.type === 'cross')) {
|
|
17
|
+
return t('swap.stepSwapAndBridge');
|
|
18
|
+
}
|
|
19
|
+
return t('swap.stepSwap');
|
|
17
20
|
case 'swap':
|
|
18
21
|
return t('swap.stepSwap');
|
|
19
22
|
case 'cross':
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const LinkButton: import("@emotion/styled").StyledComponent<{
|
|
3
3
|
children?: import("react").ReactNode;
|
|
4
4
|
classes?: Partial<import("@mui/material").IconButtonClasses> | undefined;
|
|
5
|
-
color?: "inherit" | "default" | "
|
|
5
|
+
color?: "inherit" | "default" | "primary" | "secondary" | "error" | "warning" | "info" | "success" | undefined;
|
|
6
6
|
disabled?: boolean | undefined;
|
|
7
7
|
disableFocusRipple?: boolean | undefined;
|
|
8
8
|
edge?: false | "end" | "start" | undefined;
|
|
@@ -21,7 +21,9 @@ import { StepAvatar, StepConnector, StepContent, StepLabel, } from './StepAction
|
|
|
21
21
|
export const StepActions = (_a) => {
|
|
22
22
|
var _b;
|
|
23
23
|
var { step, dense } = _a, other = __rest(_a, ["step", "dense"]);
|
|
24
|
-
const StepDetailsLabel = step.type === 'cross' ||
|
|
24
|
+
const StepDetailsLabel = step.type === 'cross' ||
|
|
25
|
+
(step.type === 'lifi' &&
|
|
26
|
+
step.includedSteps.some((step) => step.type === 'cross'))
|
|
25
27
|
? CrossStepDetailsLabel
|
|
26
28
|
: SwapStepDetailsLabel;
|
|
27
29
|
const isFullView = !dense && ((_b = step.includedSteps) === null || _b === void 0 ? void 0 : _b.length) > 1;
|
|
@@ -33,7 +35,7 @@ export const StepActions = (_a) => {
|
|
|
33
35
|
boxSizing: 'content-box',
|
|
34
36
|
} }, { children: tool.toolDetails.name[0] }))) : null;
|
|
35
37
|
};
|
|
36
|
-
return (_jsxs(Box, Object.assign({}, other, { children: [_jsxs(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' }, mb: isFullView ? 1.5 : 0 }, { children: [_jsx(StepAvatar, Object.assign({ variant:
|
|
38
|
+
return (_jsxs(Box, Object.assign({}, other, { children: [_jsxs(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' }, mb: isFullView ? 1.5 : 0 }, { children: [_jsx(StepAvatar, Object.assign({ variant: "circular", src: step.type !== 'lifi' ? step.toolDetails.logoURI : undefined, alt: step.toolDetails.name }, { children: step.type === 'lifi' ? _jsx(LiFiToolLogo, {}) : step.toolDetails.name[0] })), _jsx(Typography, Object.assign({ ml: 2, fontSize: 18, fontWeight: "500", textTransform: "capitalize" }, { children: step.type === 'lifi'
|
|
37
39
|
? 'LI.FI Smart Contract'
|
|
38
40
|
: step.toolDetails.name }))] })), isFullView ? (_jsx(Stepper, Object.assign({ orientation: "vertical", connector: _jsx(StepConnector, {}), activeStep: -1 }, { children: step.includedSteps.map((step) => (_jsxs(MuiStep, Object.assign({ expanded: true }, { children: [_jsx(StepLabel, Object.assign({ StepIconComponent: StepIconComponent }, { children: step.type === 'cross' || step.type === 'lifi' ? (_jsx(CrossStepDetailsLabel, { step: step })) : (_jsx(SwapStepDetailsLabel, { step: step })) })), _jsx(StepContent, { children: _jsx(StepDetailsContent, { step: step }) })] }), step.id))) }))) : (_jsxs(Box, Object.assign({ ml: 6 }, { children: [_jsx(StepDetailsLabel, { step: step }), _jsx(StepDetailsContent, { step: step })] })))] })));
|
|
39
41
|
};
|
|
@@ -29,7 +29,10 @@ export const SwapButton = ({ onClick, currentRoute, text, loading, }) => {
|
|
|
29
29
|
const [chainId] = useWatch({
|
|
30
30
|
name: [SwapFormKeyHelper.getChainKey('from')],
|
|
31
31
|
});
|
|
32
|
-
|
|
32
|
+
// Allow switching chain only if execution is not started
|
|
33
|
+
const switchChainAllowed = ((_a = getChainById(chainId || ChainId.ETH)) === null || _a === void 0 ? void 0 : _a.id) !== account.chainId &&
|
|
34
|
+
currentRoute &&
|
|
35
|
+
!currentRoute.steps.some((step) => step.execution);
|
|
33
36
|
const handleSwapButtonClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
37
|
if (!account.isActive) {
|
|
35
38
|
if (config.walletManagement) {
|
|
@@ -39,7 +42,7 @@ export const SwapButton = ({ onClick, currentRoute, text, loading, }) => {
|
|
|
39
42
|
navigate(navigationRoutes.selectWallet);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
|
-
else if (
|
|
45
|
+
else if (switchChainAllowed) {
|
|
43
46
|
yield switchChain(chainId);
|
|
44
47
|
// check that the current route exists in the up to date route list
|
|
45
48
|
}
|
|
@@ -49,7 +52,7 @@ export const SwapButton = ({ onClick, currentRoute, text, loading, }) => {
|
|
|
49
52
|
});
|
|
50
53
|
const getButtonText = () => {
|
|
51
54
|
if (account.isActive) {
|
|
52
|
-
if (
|
|
55
|
+
if (switchChainAllowed) {
|
|
53
56
|
return t(`button.switchChain`);
|
|
54
57
|
}
|
|
55
58
|
if (!currentRoute) {
|
|
@@ -63,5 +66,5 @@ export const SwapButton = ({ onClick, currentRoute, text, loading, }) => {
|
|
|
63
66
|
// loading={isLoading || isFetching}
|
|
64
67
|
disabled: (insufficientFunds || !!insufficientGas.length || loading) &&
|
|
65
68
|
currentRoute &&
|
|
66
|
-
|
|
69
|
+
!switchChainAllowed, fullWidth: true }, { children: getButtonText() })));
|
|
67
70
|
};
|
|
@@ -17,7 +17,7 @@ export declare const Button: import("@emotion/styled").StyledComponent<{
|
|
|
17
17
|
} & Omit<{
|
|
18
18
|
children?: import("react").ReactNode;
|
|
19
19
|
classes?: Partial<import("@mui/material").ButtonClasses> | undefined;
|
|
20
|
-
color?: "inherit" | "
|
|
20
|
+
color?: "inherit" | "primary" | "secondary" | "error" | "warning" | "info" | "success" | undefined;
|
|
21
21
|
disabled?: boolean | undefined;
|
|
22
22
|
disableElevation?: boolean | undefined;
|
|
23
23
|
disableFocusRipple?: boolean | undefined;
|
|
@@ -4,7 +4,7 @@ export declare const minInputFontSize = 14;
|
|
|
4
4
|
export declare const FormControl: import("@emotion/styled").StyledComponent<{
|
|
5
5
|
children?: import("react").ReactNode;
|
|
6
6
|
classes?: Partial<import("@mui/material").FormControlClasses> | undefined;
|
|
7
|
-
color?: "
|
|
7
|
+
color?: "primary" | "secondary" | "error" | "warning" | "info" | "success" | undefined;
|
|
8
8
|
disabled?: boolean | undefined;
|
|
9
9
|
error?: boolean | undefined;
|
|
10
10
|
fullWidth?: boolean | undefined;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const Button: import("@emotion/styled").StyledComponent<{
|
|
3
3
|
children?: import("react").ReactNode;
|
|
4
4
|
classes?: Partial<import("@mui/material").ButtonClasses> | undefined;
|
|
5
|
-
color?: "inherit" | "
|
|
5
|
+
color?: "inherit" | "primary" | "secondary" | "error" | "warning" | "info" | "success" | undefined;
|
|
6
6
|
disabled?: boolean | undefined;
|
|
7
7
|
disableElevation?: boolean | undefined;
|
|
8
8
|
disableFocusRipple?: boolean | undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getContrastTextColor } from '@lifi/widget/utils';
|
|
1
2
|
import { Typography } from '@mui/material';
|
|
2
3
|
import { styled } from '@mui/material/styles';
|
|
3
4
|
export const Label = styled(Typography, {
|
|
@@ -11,7 +12,9 @@ export const Label = styled(Typography, {
|
|
|
11
12
|
? theme.palette.grey[500]
|
|
12
13
|
: theme.palette.grey[600],
|
|
13
14
|
borderRadius: theme.shape.borderRadiusSecondary,
|
|
14
|
-
color: active
|
|
15
|
+
color: active
|
|
16
|
+
? getContrastTextColor(theme, theme.palette.primary.main)
|
|
17
|
+
: theme.palette.text.secondary,
|
|
15
18
|
padding: theme.spacing(0.75),
|
|
16
19
|
fontSize: 12,
|
|
17
20
|
lineHeight: 1,
|
|
@@ -17,7 +17,8 @@ export const TokenList = ({ formType, height, onClick, }) => {
|
|
|
17
17
|
name: [SwapFormKeyHelper.getChainKey(formType)],
|
|
18
18
|
});
|
|
19
19
|
const [searchTokensFilter] = useDebouncedWatch([SwapFormKey.SearchTokensFilter], 250);
|
|
20
|
-
const { tokens, isLoading, isBalanceLoading } = useTokenBalances(selectedChainId);
|
|
20
|
+
const { tokens: tokensWithoutBalance, tokensWithBalance, isLoading, isBalanceLoading, } = useTokenBalances(selectedChainId);
|
|
21
|
+
const tokens = tokensWithBalance !== null && tokensWithBalance !== void 0 ? tokensWithBalance : tokensWithoutBalance;
|
|
21
22
|
const chainTokens = useMemo(() => {
|
|
22
23
|
var _a;
|
|
23
24
|
let chainTokens = tokens !== null && tokens !== void 0 ? tokens : [];
|
|
@@ -17,7 +17,7 @@ export declare const ListItemButton: import("@emotion/styled").StyledComponent<i
|
|
|
17
17
|
touchRippleRef?: import("react").Ref<import("@mui/material/ButtonBase/TouchRipple").TouchRippleActions> | undefined;
|
|
18
18
|
}, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
19
19
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
20
|
-
}, "className" | "style" | "classes" | "tabIndex" | "children" | "action" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "alignItems" | "autoFocus" | "dense" | "
|
|
20
|
+
}, "className" | "style" | "classes" | "tabIndex" | "children" | "action" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "alignItems" | "autoFocus" | "dense" | "divider" | "selected" | "disableGutters"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
21
21
|
export declare const ListItem: import("@emotion/styled").StyledComponent<{
|
|
22
22
|
button?: false | undefined;
|
|
23
23
|
} & import("@mui/material").ListItemBaseProps & {
|
|
@@ -29,4 +29,4 @@ export declare const ListItem: import("@emotion/styled").StyledComponent<{
|
|
|
29
29
|
} | undefined;
|
|
30
30
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "key" | keyof import("react").LiHTMLAttributes<HTMLLIElement>> & {
|
|
31
31
|
ref?: ((instance: HTMLLIElement | null) => void) | import("react").RefObject<HTMLLIElement> | null | undefined;
|
|
32
|
-
}, "button" | "className" | "style" | "classes" | "children" | "disabled" | "sx" | "alignItems" | "autoFocus" | "dense" | "
|
|
32
|
+
}, "button" | "className" | "style" | "classes" | "children" | "disabled" | "sx" | "alignItems" | "autoFocus" | "dense" | "divider" | "components" | "componentsProps" | "selected" | "disableGutters" | "ContainerComponent" | "ContainerProps" | "disablePadding" | "secondaryAction"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
package/config/lifi.d.ts
CHANGED
package/config/lifi.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import LIFI from '@lifi/sdk';
|
|
2
|
-
const
|
|
3
|
-
// apiUrl: env.LIFI_API_URL,
|
|
4
|
-
// defaultRouteOptions: {
|
|
5
|
-
// integrator: 'li.fi',
|
|
6
|
-
// },
|
|
7
|
-
};
|
|
8
|
-
export const LiFi = new LIFI(defaultConfig);
|
|
2
|
+
export const LiFi = new LIFI();
|
|
9
3
|
export const updateLiFiConfig = (configUpdate) => {
|
|
10
|
-
LiFi.setConfig(
|
|
4
|
+
LiFi.setConfig(configUpdate);
|
|
11
5
|
};
|
package/config/theme.js
CHANGED
|
@@ -31,12 +31,15 @@ const shape = {
|
|
|
31
31
|
};
|
|
32
32
|
export const createTheme = (mode, theme = {}) => {
|
|
33
33
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
34
|
+
const primaryMainColor = (_c = (_b = (_a = theme.palette) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b.main) !== null && _c !== void 0 ? _c : palette.primary.main;
|
|
35
|
+
const primaryLightColor = lighten((_f = (_e = (_d = theme.palette) === null || _d === void 0 ? void 0 : _d.primary) === null || _e === void 0 ? void 0 : _e.main) !== null && _f !== void 0 ? _f : palette.primary.main, 0.5);
|
|
36
|
+
const primaryDarkColor = darken((_j = (_h = (_g = theme.palette) === null || _g === void 0 ? void 0 : _g.primary) === null || _h === void 0 ? void 0 : _h.main) !== null && _j !== void 0 ? _j : palette.primary.main, 0.2);
|
|
34
37
|
return createMuiTheme({
|
|
35
38
|
typography: Object.assign({ fontFamily: 'Inter var, Inter, sans-serif' }, theme.typography),
|
|
36
39
|
palette: Object.assign(Object.assign(Object.assign({ mode }, palette), { primary: {
|
|
37
|
-
main:
|
|
38
|
-
light:
|
|
39
|
-
dark:
|
|
40
|
+
main: primaryMainColor,
|
|
41
|
+
light: primaryLightColor,
|
|
42
|
+
dark: primaryDarkColor,
|
|
40
43
|
}, secondary: {
|
|
41
44
|
main: (_m = (_l = (_k = theme.palette) === null || _k === void 0 ? void 0 : _k.secondary) === null || _l === void 0 ? void 0 : _l.main) !== null && _m !== void 0 ? _m : palette.secondary.main,
|
|
42
45
|
light: lighten((_q = (_p = (_o = theme.palette) === null || _o === void 0 ? void 0 : _o.secondary) === null || _p === void 0 ? void 0 : _p.main) !== null && _q !== void 0 ? _q : palette.secondary.main, 0.5),
|
|
@@ -85,18 +88,18 @@ export const createTheme = (mode, theme = {}) => {
|
|
|
85
88
|
styleOverrides: Object.assign(Object.assign({}, (mode === 'dark'
|
|
86
89
|
? {
|
|
87
90
|
outlined: {
|
|
88
|
-
color:
|
|
89
|
-
borderColor:
|
|
91
|
+
color: primaryLightColor,
|
|
92
|
+
borderColor: primaryLightColor,
|
|
90
93
|
'&:hover': {
|
|
91
|
-
backgroundColor: alpha(
|
|
92
|
-
borderColor:
|
|
94
|
+
backgroundColor: alpha(primaryLightColor, 0.08),
|
|
95
|
+
borderColor: primaryLightColor,
|
|
93
96
|
},
|
|
94
97
|
},
|
|
95
98
|
text: {
|
|
96
|
-
color:
|
|
99
|
+
color: primaryLightColor,
|
|
97
100
|
'&:hover': {
|
|
98
|
-
backgroundColor: alpha(
|
|
99
|
-
borderColor:
|
|
101
|
+
backgroundColor: alpha(primaryLightColor, 0.08),
|
|
102
|
+
borderColor: primaryLightColor,
|
|
100
103
|
},
|
|
101
104
|
},
|
|
102
105
|
}
|
|
@@ -117,7 +120,7 @@ export const createTheme = (mode, theme = {}) => {
|
|
|
117
120
|
},
|
|
118
121
|
}, contained: {
|
|
119
122
|
'&:hover': {
|
|
120
|
-
color: getContrastRatio(
|
|
123
|
+
color: getContrastRatio(dark.text.primary, primaryMainColor) >= 3
|
|
121
124
|
? dark.text.primary
|
|
122
125
|
: light.text.primary,
|
|
123
126
|
},
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "1.12.
|
|
2
|
+
export declare const version = "1.12.1";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '1.12.
|
|
2
|
+
export const version = '1.12.1';
|
|
@@ -15,12 +15,16 @@ export const useGasSufficiency = (route) => {
|
|
|
15
15
|
],
|
|
16
16
|
});
|
|
17
17
|
const fromAmount = useDebouncedWatch(SwapFormKey.FromAmount, 250);
|
|
18
|
-
const { tokens: fromChainTokenBalances } = useTokenBalances(fromChainId);
|
|
19
|
-
const { tokens: toChainTokenBalances } = useTokenBalances(toChainId);
|
|
20
18
|
const { getChainById } = useChains();
|
|
19
|
+
const { tokensWithBalance: fromChainTokenBalances } = useTokenBalances(fromChainId);
|
|
20
|
+
const { tokensWithBalance: toChainTokenBalances } = useTokenBalances(toChainId);
|
|
21
21
|
const insufficientGas = useMemo(() => {
|
|
22
22
|
var _a;
|
|
23
|
-
if (!account.isActive ||
|
|
23
|
+
if (!account.isActive ||
|
|
24
|
+
!route ||
|
|
25
|
+
!fromAmount ||
|
|
26
|
+
!fromChainTokenBalances ||
|
|
27
|
+
!toChainTokenBalances) {
|
|
24
28
|
return [];
|
|
25
29
|
}
|
|
26
30
|
const tokenBalancesByChain = {
|
|
@@ -78,7 +82,10 @@ export const useGasSufficiency = (route) => {
|
|
|
78
82
|
]);
|
|
79
83
|
const insufficientFunds = useMemo(() => {
|
|
80
84
|
var _a, _b;
|
|
81
|
-
if (!account.isActive ||
|
|
85
|
+
if (!account.isActive ||
|
|
86
|
+
!fromToken ||
|
|
87
|
+
!fromAmount ||
|
|
88
|
+
!fromChainTokenBalances) {
|
|
82
89
|
return false;
|
|
83
90
|
}
|
|
84
91
|
const balance = Big((_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);
|
|
@@ -20,21 +20,23 @@ export const useRouteExecution = (routeId) => {
|
|
|
20
20
|
const routeExecution = useRouteStore((state) => state.routes[routeId]);
|
|
21
21
|
const [updateRoute, restartRoute, deleteRoute] = useRouteStore((state) => [state.updateRoute, state.restartRoute, state.deleteRoute], shallow);
|
|
22
22
|
const updateCallback = (updatedRoute) => {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const clonedUpdatedRoute = deepClone(updatedRoute);
|
|
24
|
+
console.log('Route updated.', clonedUpdatedRoute);
|
|
25
|
+
updateRoute(clonedUpdatedRoute);
|
|
25
26
|
};
|
|
26
|
-
const switchChainHook =
|
|
27
|
+
const switchChainHook = (requiredChainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
28
|
if (!account.isActive || !account.signer) {
|
|
28
29
|
return account.signer;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
const currentChainId = yield account.signer.getChainId();
|
|
32
|
+
if (currentChainId !== requiredChainId) {
|
|
31
33
|
const switched = yield switchChain(requiredChainId);
|
|
32
34
|
if (!switched) {
|
|
33
35
|
throw new Error('Chain was not switched.');
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
return account.signer;
|
|
37
|
-
})
|
|
39
|
+
});
|
|
38
40
|
const executeRouteMutation = useMutation(() => {
|
|
39
41
|
if (!account.signer) {
|
|
40
42
|
throw Error('Account signer not found.');
|
|
@@ -112,26 +114,29 @@ export const useRouteExecution = (routeId) => {
|
|
|
112
114
|
deleteRoute(routeId);
|
|
113
115
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
114
116
|
}, [routeId]);
|
|
117
|
+
// Resume route execution after page reload
|
|
115
118
|
useEffect(() => {
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const alreadyStarted = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps.some((step) => step.execution);
|
|
120
|
-
if (!isDone &&
|
|
121
|
-
!isFailed &&
|
|
122
|
-
alreadyStarted &&
|
|
123
|
-
account.signer &&
|
|
119
|
+
// Check if route is eligible for automatic resuming
|
|
120
|
+
if (isActiveRoute(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route) &&
|
|
121
|
+
account.isActive &&
|
|
124
122
|
!resumedAfterMount.current) {
|
|
125
123
|
resumedAfterMount.current = true;
|
|
126
124
|
resumeRoute();
|
|
127
125
|
}
|
|
126
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
127
|
+
}, [account.isActive]);
|
|
128
|
+
useEffect(() => {
|
|
128
129
|
return () => {
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
var _a;
|
|
131
|
+
const route = (_a = useRouteStore.getState().routes[routeId]) === null || _a === void 0 ? void 0 : _a.route;
|
|
132
|
+
if (!route || !isActiveRoute(route)) {
|
|
133
|
+
return;
|
|
131
134
|
}
|
|
135
|
+
LiFi.moveExecutionToBackground(route);
|
|
136
|
+
console.log('Move route execution to background.', routeId);
|
|
137
|
+
resumedAfterMount.current = false;
|
|
132
138
|
};
|
|
133
|
-
|
|
134
|
-
}, [account.signer]);
|
|
139
|
+
}, [routeId]);
|
|
135
140
|
return {
|
|
136
141
|
executeRoute,
|
|
137
142
|
restartRoute: restartRouteMutation,
|
|
@@ -140,3 +145,12 @@ export const useRouteExecution = (routeId) => {
|
|
|
140
145
|
status: routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.status,
|
|
141
146
|
};
|
|
142
147
|
};
|
|
148
|
+
const isActiveRoute = (route) => {
|
|
149
|
+
if (!route) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const allDone = route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
|
|
153
|
+
const isFailed = route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
154
|
+
const alreadyStarted = route.steps.some((step) => step.execution);
|
|
155
|
+
return !allDone && !isFailed && alreadyStarted;
|
|
156
|
+
};
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -40,7 +40,7 @@ export const useSwapRoutes = () => {
|
|
|
40
40
|
// Boolean(account.address) &&
|
|
41
41
|
!isNaN(fromChainId) &&
|
|
42
42
|
!isNaN(toChainId) &&
|
|
43
|
-
Boolean(
|
|
43
|
+
Boolean(token === null || token === void 0 ? void 0 : token.address) &&
|
|
44
44
|
Boolean(toTokenAddress) &&
|
|
45
45
|
!isNaN(fromTokenAmount) &&
|
|
46
46
|
Number(fromTokenAmount) > 0 &&
|
|
@@ -49,7 +49,7 @@ export const useSwapRoutes = () => {
|
|
|
49
49
|
'routes',
|
|
50
50
|
account.address,
|
|
51
51
|
fromChainId,
|
|
52
|
-
|
|
52
|
+
token === null || token === void 0 ? void 0 : token.address,
|
|
53
53
|
fromTokenAmount,
|
|
54
54
|
toChainId,
|
|
55
55
|
toTokenAddress,
|
package/hooks/useTokenBalance.js
CHANGED
|
@@ -17,7 +17,7 @@ export const useTokenBalance = (chainId, tokenAddress) => {
|
|
|
17
17
|
const { account } = useWallet();
|
|
18
18
|
const queryClient = useQueryClient();
|
|
19
19
|
const { token } = useToken(chainId, tokenAddress);
|
|
20
|
-
const { data: tokenWithBalance, isLoading, isFetching, refetch, } = useQuery(['token', account.address, chainId, tokenAddress], ({ queryKey: [, address] }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const { data: tokenWithBalance, isLoading, isFetching, refetch, } = useQuery(['token-balance', account.address, chainId, tokenAddress], ({ queryKey: [, address] }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
if (!address || !token) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { TokenAmount } from '@lifi/sdk';
|
|
2
2
|
export declare const useTokenBalances: (selectedChainId: number) => {
|
|
3
|
-
tokens:
|
|
3
|
+
tokens: import("@lifi/sdk").Token[] | undefined;
|
|
4
|
+
tokensWithBalance: TokenAmount[] | undefined;
|
|
4
5
|
isLoading: boolean;
|
|
5
6
|
isBalanceLoading: boolean;
|
|
6
|
-
|
|
7
|
+
isBalanceFetched: boolean;
|
|
8
|
+
updateBalances: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<TokenAmount[] | undefined, unknown>>;
|
|
7
9
|
};
|
|
@@ -8,21 +8,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { useQuery } from '@tanstack/react-query';
|
|
11
|
+
import { useState } from 'react';
|
|
11
12
|
import { LiFi } from '../config/lifi';
|
|
12
13
|
import { useWallet } from '../providers/WalletProvider';
|
|
13
14
|
import { formatTokenAmount } from '../utils';
|
|
14
|
-
import { useChains } from './useChains';
|
|
15
15
|
import { useTokens } from './useTokens';
|
|
16
|
+
const defaultRefetchInterval = 60000;
|
|
17
|
+
const minRefetchInterval = 1000;
|
|
16
18
|
export const useTokenBalances = (selectedChainId) => {
|
|
17
19
|
const { account } = useWallet();
|
|
18
|
-
const { chains, isLoading: isChainsLoading } = useChains();
|
|
19
20
|
const { tokens, isLoading } = useTokens(selectedChainId);
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const [refetchInterval, setRefetchInterval] = useState(defaultRefetchInterval);
|
|
22
|
+
const isBalanceLoadingEnabled = Boolean(account.address) && Boolean(tokens);
|
|
23
|
+
const { data: tokensWithBalance, isLoading: isBalanceLoading, isFetched: isBalanceFetched, refetch, } = useQuery(['token-balances', selectedChainId, account.address], ({ queryKey: [, , accountAddress] }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
if (!accountAddress || !tokens) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const tokenBalances = yield LiFi.getTokenBalances(accountAddress, tokens);
|
|
28
|
+
if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
|
|
29
|
+
// Sometimes RPCs (e.g. Arbitrum) don't return balances on first call
|
|
30
|
+
// TODO: fix and remove backplane
|
|
31
|
+
setRefetchInterval((interval) => interval === defaultRefetchInterval
|
|
32
|
+
? minRefetchInterval
|
|
33
|
+
: interval * 2);
|
|
34
|
+
return;
|
|
24
35
|
}
|
|
25
|
-
const tokenBalances = yield LiFi.getTokenBalances(account, tokens);
|
|
26
36
|
const formatedTokens = (tokenBalances.length === 0 ? tokens : tokenBalances).map((token) => {
|
|
27
37
|
token.amount = formatTokenAmount(token.amount);
|
|
28
38
|
return token;
|
|
@@ -40,13 +50,15 @@ export const useTokenBalances = (selectedChainId) => {
|
|
|
40
50
|
}), {
|
|
41
51
|
enabled: isBalanceLoadingEnabled,
|
|
42
52
|
refetchIntervalInBackground: true,
|
|
43
|
-
refetchInterval
|
|
44
|
-
staleTime:
|
|
53
|
+
refetchInterval,
|
|
54
|
+
staleTime: refetchInterval,
|
|
45
55
|
});
|
|
46
56
|
return {
|
|
47
|
-
tokens
|
|
48
|
-
|
|
57
|
+
tokens,
|
|
58
|
+
tokensWithBalance,
|
|
59
|
+
isLoading,
|
|
49
60
|
isBalanceLoading: isBalanceLoading && isBalanceLoadingEnabled,
|
|
61
|
+
isBalanceFetched,
|
|
50
62
|
updateBalances: refetch,
|
|
51
63
|
};
|
|
52
64
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.1",
|
|
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
|
"sideEffects": false,
|
|
6
6
|
"main": "./index.js",
|
|
@@ -37,25 +37,25 @@
|
|
|
37
37
|
"lifi"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@emotion/react": "^11.
|
|
41
|
-
"@emotion/styled": "^11.
|
|
40
|
+
"@emotion/react": "^11.10.0",
|
|
41
|
+
"@emotion/styled": "^11.10.0",
|
|
42
42
|
"@ethersproject/experimental": "^5.6.3",
|
|
43
43
|
"@ethersproject/providers": "^5.6.8",
|
|
44
|
-
"@lifi/sdk": "^1.
|
|
45
|
-
"@lifi/wallet-management": "^1.1.
|
|
44
|
+
"@lifi/sdk": "^1.1.3",
|
|
45
|
+
"@lifi/wallet-management": "^1.1.3",
|
|
46
46
|
"@mui/icons-material": "^5.8.4",
|
|
47
|
-
"@mui/lab": "^5.0.0-alpha.
|
|
48
|
-
"@mui/material": "^5.9.
|
|
49
|
-
"@sentry/integrations": "^7.
|
|
50
|
-
"@sentry/react": "^7.
|
|
51
|
-
"@sentry/tracing": "^7.
|
|
47
|
+
"@mui/lab": "^5.0.0-alpha.93",
|
|
48
|
+
"@mui/material": "^5.9.3",
|
|
49
|
+
"@sentry/integrations": "^7.9.0",
|
|
50
|
+
"@sentry/react": "^7.9.0",
|
|
51
|
+
"@sentry/tracing": "^7.9.0",
|
|
52
52
|
"@tanstack/react-query": "^4.0.10",
|
|
53
53
|
"big.js": "^6.2.1",
|
|
54
|
-
"i18next": "^21.8.
|
|
54
|
+
"i18next": "^21.8.16",
|
|
55
55
|
"immer": "^9.0.15",
|
|
56
56
|
"react": "^18.2.0",
|
|
57
57
|
"react-dom": "^18.2.0",
|
|
58
|
-
"react-hook-form": "^7.
|
|
58
|
+
"react-hook-form": "^7.34.0",
|
|
59
59
|
"react-i18next": "^11.18.3",
|
|
60
60
|
"react-resize-detector": "^7.1.2",
|
|
61
61
|
"react-router-dom": "^6.3.0",
|
|
@@ -8,4 +8,4 @@ export declare const Stack: import("@emotion/styled").StyledComponent<import("@m
|
|
|
8
8
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
9
9
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
10
10
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
11
|
-
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "ref" | "direction" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "
|
|
11
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "ref" | "direction" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "divider" | "spacing"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
@@ -17,7 +17,7 @@ export declare const WalletListItemButton: import("@emotion/styled").StyledCompo
|
|
|
17
17
|
touchRippleRef?: import("react").Ref<import("@mui/material/ButtonBase/TouchRipple").TouchRippleActions> | undefined;
|
|
18
18
|
}, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
19
19
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
20
|
-
}, "className" | "style" | "classes" | "tabIndex" | "children" | "action" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "alignItems" | "autoFocus" | "dense" | "
|
|
20
|
+
}, "className" | "style" | "classes" | "tabIndex" | "children" | "action" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "alignItems" | "autoFocus" | "dense" | "divider" | "selected" | "disableGutters"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
21
21
|
export declare const WalletListItem: import("@emotion/styled").StyledComponent<{
|
|
22
22
|
button?: false | undefined;
|
|
23
23
|
} & import("@mui/material").ListItemBaseProps & {
|
|
@@ -29,7 +29,7 @@ export declare const WalletListItem: import("@emotion/styled").StyledComponent<{
|
|
|
29
29
|
} | undefined;
|
|
30
30
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "key" | keyof import("react").LiHTMLAttributes<HTMLLIElement>> & {
|
|
31
31
|
ref?: ((instance: HTMLLIElement | null) => void) | import("react").RefObject<HTMLLIElement> | null | undefined;
|
|
32
|
-
}, "button" | "className" | "style" | "classes" | "children" | "disabled" | "sx" | "alignItems" | "autoFocus" | "dense" | "
|
|
32
|
+
}, "button" | "className" | "style" | "classes" | "children" | "disabled" | "sx" | "alignItems" | "autoFocus" | "dense" | "divider" | "components" | "componentsProps" | "selected" | "disableGutters" | "ContainerComponent" | "ContainerProps" | "disablePadding" | "secondaryAction"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
33
33
|
export declare const WalletListItemText: import("@emotion/styled").StyledComponent<import("@mui/material").ListItemTextProps<import("react").ElementType<any>, import("react").ElementType<any>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
34
34
|
export declare const WalletIdentityPopoverContent: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
35
35
|
align?: "inherit" | "left" | "right" | "center" | "justify" | undefined;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const ToggleButton: import("@emotion/styled").StyledComponent<{
|
|
3
3
|
children?: import("react").ReactNode;
|
|
4
4
|
classes?: Partial<import("@mui/material").ToggleButtonClasses> | undefined;
|
|
5
|
-
color?: "
|
|
5
|
+
color?: "primary" | "secondary" | "error" | "warning" | "info" | "success" | "standard" | undefined;
|
|
6
6
|
disabled?: boolean | undefined;
|
|
7
7
|
disableFocusRipple?: boolean | undefined;
|
|
8
8
|
fullWidth?: boolean | undefined;
|
|
@@ -8,4 +8,4 @@ export declare const Stack: import("@emotion/styled").StyledComponent<import("@m
|
|
|
8
8
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
9
9
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
10
10
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
11
|
-
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "ref" | "direction" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "
|
|
11
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "ref" | "direction" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "divider" | "spacing"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
import { Signer } from 'ethers';
|
|
1
2
|
import { FC, PropsWithChildren } from 'react';
|
|
3
|
+
import { WidgetWalletManagement } from '../../types';
|
|
2
4
|
import type { WalletContextProps } from './types';
|
|
3
5
|
export declare const useWallet: () => WalletContextProps;
|
|
4
|
-
export declare const WalletProvider: FC<PropsWithChildren<{
|
|
6
|
+
export declare const WalletProvider: FC<PropsWithChildren<{
|
|
7
|
+
walletManagement?: WidgetWalletManagement;
|
|
8
|
+
}>>;
|
|
9
|
+
export declare const extractAccountFromSigner: (signer?: Signer) => Promise<{
|
|
10
|
+
address: string | undefined;
|
|
11
|
+
isActive: boolean;
|
|
12
|
+
signer: Signer | undefined;
|
|
13
|
+
chainId: number | undefined;
|
|
14
|
+
}>;
|
|
@@ -8,9 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
import { addChain as walletAddChain, switchChain as walletSwitchChain, switchChainAndAddToken,
|
|
11
|
+
import { addChain as walletAddChain, switchChain as walletSwitchChain, switchChainAndAddToken, useLiFiWalletManagement, } from '@lifi/wallet-management';
|
|
12
12
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
|
|
13
|
-
import { useWidgetConfig } from '../WidgetProvider';
|
|
14
13
|
const stub = () => {
|
|
15
14
|
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
16
15
|
};
|
|
@@ -24,65 +23,57 @@ const initialContext = {
|
|
|
24
23
|
};
|
|
25
24
|
const WalletContext = createContext(initialContext);
|
|
26
25
|
export const useWallet = () => useContext(WalletContext);
|
|
27
|
-
export const WalletProvider = ({ children }) => {
|
|
28
|
-
const
|
|
29
|
-
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, } = useLifiWalletManagement();
|
|
26
|
+
export const WalletProvider = ({ children, walletManagement }) => {
|
|
27
|
+
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, } = useLiFiWalletManagement();
|
|
30
28
|
const [account, setAccount] = useState({});
|
|
31
29
|
const connect = useCallback((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
if (
|
|
33
|
-
const signer = yield
|
|
30
|
+
if (walletManagement) {
|
|
31
|
+
const signer = yield walletManagement.connect();
|
|
34
32
|
const account = yield extractAccountFromSigner(signer);
|
|
35
33
|
setAccount(account);
|
|
36
34
|
return;
|
|
37
35
|
}
|
|
38
36
|
yield walletManagementConnect(wallet);
|
|
39
|
-
}), [
|
|
37
|
+
}), [walletManagement, walletManagementConnect]);
|
|
40
38
|
const disconnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
if (
|
|
42
|
-
yield
|
|
39
|
+
if (walletManagement) {
|
|
40
|
+
yield walletManagement.disconnect();
|
|
43
41
|
setAccount({});
|
|
44
42
|
return;
|
|
45
43
|
}
|
|
46
44
|
yield walletManagementDisconnect();
|
|
47
|
-
}), [
|
|
45
|
+
}), [walletManagement, walletManagementDisconnect]);
|
|
48
46
|
// only for injected wallets
|
|
49
47
|
const switchChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const signer = yield config.walletManagement.switchChain(chainId);
|
|
48
|
+
if (walletManagement === null || walletManagement === void 0 ? void 0 : walletManagement.switchChain) {
|
|
49
|
+
const signer = yield walletManagement.switchChain(chainId);
|
|
53
50
|
const account = yield extractAccountFromSigner(signer);
|
|
54
51
|
setAccount(account);
|
|
52
|
+
return true;
|
|
55
53
|
}
|
|
56
54
|
return walletSwitchChain(chainId);
|
|
57
|
-
}), [
|
|
55
|
+
}), [walletManagement]);
|
|
58
56
|
const addChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return config.walletManagement.addChain(chainId);
|
|
57
|
+
if (walletManagement === null || walletManagement === void 0 ? void 0 : walletManagement.addChain) {
|
|
58
|
+
return walletManagement.addChain(chainId);
|
|
62
59
|
}
|
|
63
60
|
return walletAddChain(chainId);
|
|
64
|
-
}), [
|
|
61
|
+
}), [walletManagement]);
|
|
65
62
|
const addToken = useCallback((chainId, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return config.walletManagement.addToken(token, chainId);
|
|
63
|
+
if (walletManagement === null || walletManagement === void 0 ? void 0 : walletManagement.addToken) {
|
|
64
|
+
return walletManagement.addToken(token, chainId);
|
|
69
65
|
}
|
|
70
66
|
return switchChainAndAddToken(chainId, token);
|
|
71
|
-
}), [
|
|
67
|
+
}), [walletManagement]);
|
|
72
68
|
// keep account information up to date
|
|
73
69
|
useEffect(() => {
|
|
74
70
|
const updateAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
const account = yield extractAccountFromSigner(signer);
|
|
81
|
-
setAccount(account);
|
|
82
|
-
}
|
|
71
|
+
var _a;
|
|
72
|
+
const account = yield extractAccountFromSigner((_a = walletManagement === null || walletManagement === void 0 ? void 0 : walletManagement.signer) !== null && _a !== void 0 ? _a : signer);
|
|
73
|
+
setAccount(account);
|
|
83
74
|
});
|
|
84
75
|
updateAccount();
|
|
85
|
-
}, [signer,
|
|
76
|
+
}, [signer, walletManagement]);
|
|
86
77
|
const value = useMemo(() => ({
|
|
87
78
|
connect,
|
|
88
79
|
disconnect,
|
|
@@ -93,7 +84,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
93
84
|
}), [account, addChain, addToken, connect, disconnect, switchChain]);
|
|
94
85
|
return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
95
86
|
};
|
|
96
|
-
const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
export const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
88
|
return ({
|
|
98
89
|
address: (yield (signer === null || signer === void 0 ? void 0 : signer.getAddress())) || undefined,
|
|
99
90
|
isActive: (signer && !!(yield signer.getAddress()) === null) || !!signer,
|
|
@@ -13,6 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
import { ChainId, getChainByKey } from '@lifi/sdk';
|
|
14
14
|
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
15
15
|
import { updateLiFiConfig } from '../../config/lifi';
|
|
16
|
+
import { useWallet } from '../WalletProvider';
|
|
16
17
|
const stub = () => {
|
|
17
18
|
throw new Error('You forgot to wrap your component in <WidgetProvider>.');
|
|
18
19
|
};
|
|
@@ -23,13 +24,15 @@ const WidgetContext = createContext(initialContext);
|
|
|
23
24
|
export const useWidgetConfig = () => useContext(WidgetContext);
|
|
24
25
|
export const WidgetProvider = (_a) => {
|
|
25
26
|
var { children } = _a, _b = _a.config, _c = _b === void 0 ? {} : _b, { fromChain, fromToken, toChain, toToken, integrator } = _c, config = __rest(_c, ["fromChain", "fromToken", "toChain", "toToken", "integrator"]);
|
|
27
|
+
const { account } = useWallet();
|
|
26
28
|
const value = useMemo(() => {
|
|
29
|
+
var _a;
|
|
27
30
|
try {
|
|
28
31
|
return Object.assign(Object.assign({}, config), { fromChain: typeof fromChain === 'number'
|
|
29
32
|
? fromChain
|
|
30
33
|
: typeof fromChain === 'string'
|
|
31
34
|
? getChainByKey(fromChain.toLowerCase()).id
|
|
32
|
-
: ChainId.ETH, toChain: typeof toChain === 'number'
|
|
35
|
+
: (_a = account.chainId) !== null && _a !== void 0 ? _a : ChainId.ETH, toChain: typeof toChain === 'number'
|
|
33
36
|
? toChain
|
|
34
37
|
: typeof toChain === 'string'
|
|
35
38
|
? getChainByKey(toChain.toLowerCase()).id
|
|
@@ -39,7 +42,7 @@ export const WidgetProvider = (_a) => {
|
|
|
39
42
|
console.warn(e);
|
|
40
43
|
return config;
|
|
41
44
|
}
|
|
42
|
-
}, [config, fromChain, fromToken, toChain, toToken]);
|
|
45
|
+
}, [account.chainId, config, fromChain, fromToken, toChain, toToken]);
|
|
43
46
|
useEffect(() => {
|
|
44
47
|
updateLiFiConfig({
|
|
45
48
|
defaultRouteOptions: {
|
|
@@ -35,18 +35,6 @@ export const useRouteStore = create()(persist(immer((set) => ({
|
|
|
35
35
|
}
|
|
36
36
|
}),
|
|
37
37
|
restartRoute: (routeId) => set((state) => {
|
|
38
|
-
var _a;
|
|
39
|
-
(_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.route.steps.forEach((step) => {
|
|
40
|
-
var _a, _b;
|
|
41
|
-
const stepHasFailed = ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED';
|
|
42
|
-
// check if the step has been cancelled which is a "failed" state
|
|
43
|
-
const stepHasBeenCancelled = (_b = step.execution) === null || _b === void 0 ? void 0 : _b.process.some((process) => process.status === 'CANCELLED');
|
|
44
|
-
if (step.execution && (stepHasFailed || stepHasBeenCancelled)) {
|
|
45
|
-
step.execution.status = 'RESUME';
|
|
46
|
-
// remove last (failed) process
|
|
47
|
-
step.execution.process.pop();
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
38
|
state.routes[routeId].status = 'loading';
|
|
51
39
|
}),
|
|
52
40
|
deleteRoute: (routeId) => set((state) => {
|
package/types/widget.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Signer } from 'ethers';
|
|
|
5
5
|
import { CSSProperties } from 'react';
|
|
6
6
|
export declare type Appearance = PaletteMode | 'auto';
|
|
7
7
|
export declare type ThemeConfig = {
|
|
8
|
-
palette?: PaletteOptions
|
|
8
|
+
palette?: Pick<PaletteOptions, 'primary' | 'secondary'>;
|
|
9
9
|
shape?: Shape;
|
|
10
10
|
typography?: TypographyOptions;
|
|
11
11
|
};
|
package/utils/colors.d.ts
CHANGED
package/utils/colors.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { getContrastRatio } from '@mui/material/styles';
|
|
2
|
+
import { dark, light } from '@mui/material/styles/createPalette';
|
|
1
3
|
export const getContrastAlphaColor = (theme, alpha) => theme.palette.mode === 'light'
|
|
2
4
|
? `rgb(0 0 0 / ${alpha})`
|
|
3
5
|
: `rgb(255 255 255 / ${alpha})`;
|
|
6
|
+
export const getContrastTextColor = (theme, background) => getContrastRatio(dark.text.primary, background !== null && background !== void 0 ? background : theme.palette.primary.main) >= 3
|
|
7
|
+
? dark.text.primary
|
|
8
|
+
: light.text.primary;
|