@lifi/widget 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +2 -1
- package/AppDrawer.style.d.ts +1 -1
- package/LICENSE.md +201 -21
- package/components/Header/Header.js +1 -1
- package/components/Header/NavigationHeader.js +1 -1
- package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.d.ts +3 -0
- package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.js +31 -0
- package/{pages/MainPage → components/InsufficientGasOrFundsMessage}/InsufficientGasOrFundsMessage.style.d.ts +0 -0
- package/{pages/MainPage → components/InsufficientGasOrFundsMessage}/InsufficientGasOrFundsMessage.style.js +3 -2
- package/components/InsufficientGasOrFundsMessage/index.d.ts +1 -0
- package/components/InsufficientGasOrFundsMessage/index.js +1 -0
- package/components/NotFound.d.ts +2 -0
- package/components/NotFound.js +14 -0
- package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
- package/components/StepActions/StepActions.d.ts +1 -1
- package/components/StepActions/types.d.ts +1 -1
- package/components/StepToken.d.ts +1 -1
- package/components/SwapButton/ButtonTooltip.d.ts +1 -0
- package/components/SwapButton/SwapButton.js +3 -3
- package/components/SwapButton/SwapButton.style.d.ts +3 -3
- package/components/SwapButton/SwapButton.style.js +0 -4
- package/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/components/SwapInput/SwapInputAdornment.d.ts +1 -0
- package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
- package/components/SwapRouteCard/SwapRouteCardSkeleton.d.ts +4 -0
- package/components/SwapRouteCard/SwapRouteCardSkeleton.js +32 -0
- package/components/SwapRouteCard/SwapRouteNotFoundCard.d.ts +4 -0
- package/components/SwapRouteCard/SwapRouteNotFoundCard.js +27 -0
- package/components/SwapRouteCard/index.d.ts +2 -0
- package/components/SwapRouteCard/index.js +2 -0
- package/components/SwapRouteCard/types.d.ts +6 -1
- package/components/SwapRoutes/SwapRoutes.js +7 -9
- package/components/TokenList/types.d.ts +1 -1
- package/components/TokenList/utils.d.ts +2 -2
- package/config/theme.js +17 -2
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useChain.d.ts +1 -1
- package/hooks/useChains.d.ts +12 -12
- package/hooks/useHasSufficientBalance.d.ts +1 -1
- package/hooks/useHasSufficientBalance.js +27 -22
- package/hooks/useRouteExecution.d.ts +1 -1
- package/hooks/useSwapRoutes.d.ts +3 -2
- package/hooks/useSwapRoutes.js +6 -6
- package/hooks/useToken.d.ts +1 -1
- package/hooks/useTokenBalance.d.ts +1 -1
- package/hooks/useTokenBalances.d.ts +1 -1
- package/hooks/useTokens.d.ts +1 -1
- package/hooks/useTools.d.ts +1 -1
- package/i18n/en/translation.json +17 -7
- package/i18n/index.d.ts +13 -3
- package/lifi.d.ts +1 -1
- package/lifi.js +1 -1
- package/package.json +12 -12
- package/pages/MainPage/MainPage.js +2 -2
- package/pages/MainPage/MainPage.style.d.ts +1 -1
- package/pages/MainPage/MainPage.style.js +1 -1
- package/pages/SelectTokenPage/ChainSelect.d.ts +1 -0
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -0
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -0
- package/pages/SettingsPage/AdvancedPreferences.d.ts +1 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/pages/SettingsPage/GasPriceSelect.d.ts +1 -0
- package/pages/SettingsPage/RoutePrioritySelect.js +1 -1
- package/pages/SettingsPage/SettingsPage.d.ts +1 -0
- package/pages/SettingsPage/SlippageInput.d.ts +1 -0
- package/pages/SwapPage/CircularProgress.d.ts +2 -1
- package/pages/SwapPage/CircularProgress.style.d.ts +1 -1
- package/pages/SwapPage/ExecutionItem.d.ts +1 -1
- package/pages/SwapPage/ExecutionItem.style.d.ts +1 -1
- package/pages/SwapPage/StepItem.d.ts +1 -1
- package/pages/SwapPage/StepTimer.d.ts +1 -1
- package/pages/SwapPage/SwapPage.js +5 -2
- package/pages/SwapPage/SwapPage.style.d.ts +1 -1
- package/pages/SwapPage/utils.d.ts +1 -1
- package/pages/SwapPage/utils.js +1 -1
- package/pages/SwapRoutesPage/SwapRoutesPage.js +12 -13
- package/providers/WalletProvider/types.d.ts +1 -1
- package/providers/WidgetProvider/WidgetProvider.js +1 -1
- package/stores/route/types.d.ts +1 -1
- package/stores/route/useCurrentRoute.d.ts +1 -1
- package/stores/route/useSetExecutableRoute.d.ts +1 -1
- package/stores/settings/types.d.ts +1 -1
- package/stores/settings/useSettingsStore.d.ts +1 -1
- package/types/widget.d.ts +1 -1
- package/utils/format.js +3 -3
- package/pages/MainPage/InsufficientGasOrFundsMessage.d.ts +0 -2
- package/pages/MainPage/InsufficientGasOrFundsMessage.js +0 -28
|
@@ -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" | "success" | "
|
|
5
|
+
color?: "inherit" | "default" | "success" | "info" | "warning" | "error" | "primary" | "secondary" | undefined;
|
|
6
6
|
disabled?: boolean | undefined;
|
|
7
7
|
disableFocusRipple?: boolean | undefined;
|
|
8
8
|
edge?: false | "end" | "start" | undefined;
|
|
@@ -2,7 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { Fragment } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
5
|
-
import {
|
|
5
|
+
import { InsufficientGasOrFundsMessage } from '../../components/InsufficientGasOrFundsMessage';
|
|
6
|
+
import { useHasSufficientBalance, useRouteExecution } from '../../hooks';
|
|
6
7
|
import { StatusBottomSheet } from './StatusBottomSheet';
|
|
7
8
|
import { StepDivider } from './StepDivider';
|
|
8
9
|
import { StepItem } from './StepItem';
|
|
@@ -11,12 +12,14 @@ export const SwapPage = () => {
|
|
|
11
12
|
const { t } = useTranslation();
|
|
12
13
|
const { state } = useLocation();
|
|
13
14
|
const navigate = useNavigate();
|
|
15
|
+
const { hasGasOnStartChain, hasGasOnCrossChain, hasSufficientBalance } = useHasSufficientBalance();
|
|
14
16
|
const { route, status, executeRoute, restartRoute, removeRoute } = useRouteExecution(state.routeId);
|
|
15
17
|
const handleRemoveRoute = () => {
|
|
16
18
|
removeRoute();
|
|
17
19
|
navigate(-1);
|
|
18
20
|
};
|
|
21
|
+
const isDisabled = !hasSufficientBalance || !hasGasOnStartChain || !hasGasOnCrossChain;
|
|
19
22
|
return (_jsxs(Container, { children: [route === null || route === void 0 ? void 0 : route.steps.map((step, index, steps) => (_jsxs(Fragment, { children: [_jsx(StepItem, { step: step, fromToken: index === 0
|
|
20
23
|
? Object.assign(Object.assign({}, route.fromToken), { amount: route.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
21
|
-
? Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id))), status === 'idle' ? (_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: executeRoute }, { children: t('button.startSwap') }))) : null, status === 'error' ? (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: restartRoute }, { children: t('button.restartSwap') })), _jsx(Button, Object.assign({ variant: "outlined", disableElevation: true, fullWidth: true, onClick: handleRemoveRoute }, { children: t('button.removeSwap') }))] })) : null, _jsx(StatusBottomSheet, { status: status, route: route })] }));
|
|
24
|
+
? Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id))), _jsx(InsufficientGasOrFundsMessage, { mt: 2 }), status === 'idle' ? (_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: executeRoute, disabled: isDisabled }, { children: t('button.startSwap') }))) : null, status === 'error' ? (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: restartRoute, disabled: isDisabled }, { children: t('button.restartSwap') })), _jsx(Button, Object.assign({ variant: "outlined", disableElevation: true, fullWidth: true, onClick: handleRemoveRoute, disabled: isDisabled }, { children: t('button.removeSwap') }))] })) : null, _jsx(StatusBottomSheet, { status: status, route: route })] }));
|
|
22
25
|
};
|
|
@@ -12,7 +12,7 @@ export declare const Container: import("@emotion/styled").StyledComponent<{
|
|
|
12
12
|
export declare const Button: import("@emotion/styled").StyledComponent<{
|
|
13
13
|
children?: import("react").ReactNode;
|
|
14
14
|
classes?: Partial<import("@mui/material").ButtonClasses> | undefined;
|
|
15
|
-
color?: "inherit" | "success" | "
|
|
15
|
+
color?: "inherit" | "success" | "info" | "warning" | "error" | "primary" | "secondary" | undefined;
|
|
16
16
|
disabled?: boolean | undefined;
|
|
17
17
|
disableElevation?: boolean | undefined;
|
|
18
18
|
disableFocusRipple?: boolean | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EVMChain, Process, Step } from '@
|
|
1
|
+
import { EVMChain, Process, Step } from '@lifi/sdk';
|
|
2
2
|
import { TFunction } from 'react-i18next';
|
|
3
3
|
export declare function getProcessMessage(t: TFunction<'translation', undefined>, getChainById: (chainId: number) => EVMChain | undefined, step: Step, process: Process): {
|
|
4
4
|
title?: string;
|
package/pages/SwapPage/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LifiErrorCode, MetaMaskProviderErrorCode, } from '@
|
|
1
|
+
import { LifiErrorCode, MetaMaskProviderErrorCode, } from '@lifi/sdk';
|
|
2
2
|
import { formatTokenAmount } from '../../utils/format';
|
|
3
3
|
const formatProcessMessage = (initialMessage, args = {}) => {
|
|
4
4
|
return Object.keys(args).reduce((message, key) => {
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
3
|
import { useNavigate } from 'react-router-dom';
|
|
4
|
-
import { SwapRouteCard } from '../../components/SwapRouteCard';
|
|
4
|
+
import { SwapRouteCard, SwapRouteCardSkeleton, SwapRouteNotFoundCard, } from '../../components/SwapRouteCard';
|
|
5
5
|
import { useSwapRoutes } from '../../hooks';
|
|
6
6
|
import { useCurrentRoute, useSetExecutableRoute } from '../../stores';
|
|
7
7
|
import { routes } from '../../utils/routes';
|
|
8
8
|
import { Stack } from './SwapRoutesPage.style';
|
|
9
9
|
export const SwapRoutesPage = () => {
|
|
10
10
|
const navigate = useNavigate();
|
|
11
|
-
const { routes: swapRoutes, isLoading, isFetching } = useSwapRoutes();
|
|
11
|
+
const { routes: swapRoutes, isLoading, isFetching, isFetched, } = useSwapRoutes();
|
|
12
12
|
const [currentRoute] = useCurrentRoute();
|
|
13
13
|
const setExecutableRoute = useSetExecutableRoute();
|
|
14
|
-
if (!(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching) {
|
|
15
|
-
// TODO: make no routes message
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
14
|
const handleRouteClick = (route) => {
|
|
19
15
|
setExecutableRoute(route);
|
|
20
16
|
navigate(routes.swap, { state: { routeId: route.id }, replace: true });
|
|
21
17
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching) {
|
|
20
|
+
navigate(routes.home);
|
|
21
|
+
}
|
|
22
|
+
// redirect to the home page if no routes are found on page reload
|
|
23
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
+
}, []);
|
|
25
|
+
const routeNotFound = !(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && isFetched;
|
|
26
|
+
return (_jsx(Stack, Object.assign({ direction: "column", spacing: 2 }, { children: routeNotFound ? (_jsx(SwapRouteNotFoundCard, { minWidth: "100%", dense: true })) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => (_jsx(SwapRouteCardSkeleton, { minWidth: "100%", dense: true }, index)))) : (swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.map((route, index) => (_jsx(SwapRouteCard, { route: route, active: (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.id) === route.id, onClick: () => handleRouteClick(route) }, route.id)))) })));
|
|
28
27
|
};
|
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { ChainId, getChainByKey } from '@
|
|
13
|
+
import { ChainId, getChainByKey } from '@lifi/sdk';
|
|
14
14
|
import { createContext, useContext, useMemo } from 'react';
|
|
15
15
|
const stub = () => {
|
|
16
16
|
throw new Error('You forgot to wrap your component in <WidgetProvider>.');
|
package/stores/route/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Route } from '@
|
|
1
|
+
import { Route } from '@lifi/sdk';
|
|
2
2
|
export declare const useCurrentRoute: () => [Route | undefined, (route?: Route) => void];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useSetExecutableRoute: () => (route: import("@
|
|
1
|
+
export declare const useSetExecutableRoute: () => (route: import("@lifi/types").Route) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bridge, Exchange, Order } from '@
|
|
1
|
+
import { Bridge, Exchange, Order } from '@lifi/sdk';
|
|
2
2
|
import { Appearance } from '../../types';
|
|
3
3
|
export declare type ValueSetter<S> = <K extends keyof S>(key: K, value: S[Extract<K, string>]) => void;
|
|
4
4
|
export declare type ValuesSetter<S> = <K extends keyof S>(values: Record<K, S[Extract<K, string>]>) => void;
|
|
@@ -5,7 +5,7 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
|
|
|
5
5
|
setValue: import("./types").ValueSetter<SettingsState>;
|
|
6
6
|
setValues: import("./types").ValuesSetter<SettingsState>;
|
|
7
7
|
initializeTools(toolType: import("./types").SettingsToolType, tools: string[]): void;
|
|
8
|
-
setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@
|
|
8
|
+
setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifi/types").Bridge, "key"> | Pick<import("@lifi/types").Exchange, "key">)[]): void;
|
|
9
9
|
advancedPreferences: boolean;
|
|
10
10
|
appearance: import("../..").Appearance;
|
|
11
11
|
routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
|
package/types/widget.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainKey, Token } from '@
|
|
1
|
+
import { ChainKey, Token } from '@lifi/sdk';
|
|
2
2
|
import { PaletteMode, PaletteOptions, Shape } from '@mui/material';
|
|
3
3
|
import { TypographyOptions } from '@mui/material/styles/createTypography';
|
|
4
4
|
import { Signer } from 'ethers';
|
package/utils/format.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Big from 'big.js';
|
|
2
|
-
// JavaScript numbers use exponential notation for positive exponents of 21 and above.
|
|
3
|
-
Big.PE =
|
|
2
|
+
// JavaScript numbers use exponential notation for positive exponents of 21 and above. We need more.
|
|
3
|
+
Big.PE = 42;
|
|
4
4
|
// JavaScript numbers use exponential notation for negative exponents of -7 and below. We need more.
|
|
5
|
-
Big.NE = -
|
|
5
|
+
Big.NE = -42;
|
|
6
6
|
/**
|
|
7
7
|
* Format token amount to at least 4 decimals.
|
|
8
8
|
* @param amount amount to format.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Typography } from '@mui/material';
|
|
3
|
-
import { useTranslation } from 'react-i18next';
|
|
4
|
-
import { CardTitle } from '../../components/Card';
|
|
5
|
-
import { useHasSufficientBalance } from '../../hooks';
|
|
6
|
-
import { MessageCard } from './InsufficientGasOrFundsMessage.style';
|
|
7
|
-
export const InsufficientGasOrFundsMessage = () => {
|
|
8
|
-
const { t } = useTranslation();
|
|
9
|
-
const { hasGasBalanceOnStartChain, hasGasOnCrossChain, hasSufficientBalance, } = useHasSufficientBalance();
|
|
10
|
-
if (hasSufficientBalance && hasGasBalanceOnStartChain && hasGasOnCrossChain) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
let title;
|
|
14
|
-
let message;
|
|
15
|
-
if (!hasSufficientBalance) {
|
|
16
|
-
title = t(`swap.warning.title.insufficientFunds`);
|
|
17
|
-
message = t(`swap.warning.message.insufficientFunds`);
|
|
18
|
-
}
|
|
19
|
-
if (!hasGasBalanceOnStartChain) {
|
|
20
|
-
title = t(`swap.warning.title.insufficientGasOnStartChain`);
|
|
21
|
-
message = t(`swap.warning.message.insufficientGasOnStartChain`);
|
|
22
|
-
}
|
|
23
|
-
if (!hasGasOnCrossChain) {
|
|
24
|
-
title = t(`swap.warning.title.insufficientGasOnDestinationChain`);
|
|
25
|
-
message = t(`swap.warning.message.insufficientGasOnDestinationChain`);
|
|
26
|
-
}
|
|
27
|
-
return (_jsxs(MessageCard, Object.assign({ mx: 3, mb: 3 }, { children: [_jsx(CardTitle, { children: title }), _jsx(Typography, Object.assign({ variant: "body2", px: 2, pb: 2, pt: 1 }, { children: message }))] })));
|
|
28
|
-
};
|