@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.
Files changed (88) hide show
  1. package/App.js +2 -1
  2. package/AppDrawer.style.d.ts +1 -1
  3. package/LICENSE.md +201 -21
  4. package/components/Header/Header.js +1 -1
  5. package/components/Header/NavigationHeader.js +1 -1
  6. package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.d.ts +3 -0
  7. package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.js +31 -0
  8. package/{pages/MainPage → components/InsufficientGasOrFundsMessage}/InsufficientGasOrFundsMessage.style.d.ts +0 -0
  9. package/{pages/MainPage → components/InsufficientGasOrFundsMessage}/InsufficientGasOrFundsMessage.style.js +3 -2
  10. package/components/InsufficientGasOrFundsMessage/index.d.ts +1 -0
  11. package/components/InsufficientGasOrFundsMessage/index.js +1 -0
  12. package/components/NotFound.d.ts +2 -0
  13. package/components/NotFound.js +14 -0
  14. package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
  15. package/components/StepActions/StepActions.d.ts +1 -1
  16. package/components/StepActions/types.d.ts +1 -1
  17. package/components/StepToken.d.ts +1 -1
  18. package/components/SwapButton/ButtonTooltip.d.ts +1 -0
  19. package/components/SwapButton/SwapButton.js +3 -3
  20. package/components/SwapButton/SwapButton.style.d.ts +3 -3
  21. package/components/SwapButton/SwapButton.style.js +0 -4
  22. package/components/SwapInput/SwapInput.style.d.ts +1 -1
  23. package/components/SwapInput/SwapInputAdornment.d.ts +1 -0
  24. package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
  25. package/components/SwapRouteCard/SwapRouteCardSkeleton.d.ts +4 -0
  26. package/components/SwapRouteCard/SwapRouteCardSkeleton.js +32 -0
  27. package/components/SwapRouteCard/SwapRouteNotFoundCard.d.ts +4 -0
  28. package/components/SwapRouteCard/SwapRouteNotFoundCard.js +27 -0
  29. package/components/SwapRouteCard/index.d.ts +2 -0
  30. package/components/SwapRouteCard/index.js +2 -0
  31. package/components/SwapRouteCard/types.d.ts +6 -1
  32. package/components/SwapRoutes/SwapRoutes.js +7 -9
  33. package/components/TokenList/types.d.ts +1 -1
  34. package/components/TokenList/utils.d.ts +2 -2
  35. package/config/theme.js +17 -2
  36. package/config/version.d.ts +1 -1
  37. package/config/version.js +1 -1
  38. package/hooks/useChain.d.ts +1 -1
  39. package/hooks/useChains.d.ts +12 -12
  40. package/hooks/useHasSufficientBalance.d.ts +1 -1
  41. package/hooks/useHasSufficientBalance.js +27 -22
  42. package/hooks/useRouteExecution.d.ts +1 -1
  43. package/hooks/useSwapRoutes.d.ts +3 -2
  44. package/hooks/useSwapRoutes.js +6 -6
  45. package/hooks/useToken.d.ts +1 -1
  46. package/hooks/useTokenBalance.d.ts +1 -1
  47. package/hooks/useTokenBalances.d.ts +1 -1
  48. package/hooks/useTokens.d.ts +1 -1
  49. package/hooks/useTools.d.ts +1 -1
  50. package/i18n/en/translation.json +17 -7
  51. package/i18n/index.d.ts +13 -3
  52. package/lifi.d.ts +1 -1
  53. package/lifi.js +1 -1
  54. package/package.json +12 -12
  55. package/pages/MainPage/MainPage.js +2 -2
  56. package/pages/MainPage/MainPage.style.d.ts +1 -1
  57. package/pages/MainPage/MainPage.style.js +1 -1
  58. package/pages/SelectTokenPage/ChainSelect.d.ts +1 -0
  59. package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -0
  60. package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -0
  61. package/pages/SettingsPage/AdvancedPreferences.d.ts +1 -0
  62. package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
  63. package/pages/SettingsPage/GasPriceSelect.d.ts +1 -0
  64. package/pages/SettingsPage/RoutePrioritySelect.js +1 -1
  65. package/pages/SettingsPage/SettingsPage.d.ts +1 -0
  66. package/pages/SettingsPage/SlippageInput.d.ts +1 -0
  67. package/pages/SwapPage/CircularProgress.d.ts +2 -1
  68. package/pages/SwapPage/CircularProgress.style.d.ts +1 -1
  69. package/pages/SwapPage/ExecutionItem.d.ts +1 -1
  70. package/pages/SwapPage/ExecutionItem.style.d.ts +1 -1
  71. package/pages/SwapPage/StepItem.d.ts +1 -1
  72. package/pages/SwapPage/StepTimer.d.ts +1 -1
  73. package/pages/SwapPage/SwapPage.js +5 -2
  74. package/pages/SwapPage/SwapPage.style.d.ts +1 -1
  75. package/pages/SwapPage/utils.d.ts +1 -1
  76. package/pages/SwapPage/utils.js +1 -1
  77. package/pages/SwapRoutesPage/SwapRoutesPage.js +12 -13
  78. package/providers/WalletProvider/types.d.ts +1 -1
  79. package/providers/WidgetProvider/WidgetProvider.js +1 -1
  80. package/stores/route/types.d.ts +1 -1
  81. package/stores/route/useCurrentRoute.d.ts +1 -1
  82. package/stores/route/useSetExecutableRoute.d.ts +1 -1
  83. package/stores/settings/types.d.ts +1 -1
  84. package/stores/settings/useSettingsStore.d.ts +1 -1
  85. package/types/widget.d.ts +1 -1
  86. package/utils/format.js +3 -3
  87. package/pages/MainPage/InsufficientGasOrFundsMessage.d.ts +0 -2
  88. package/pages/MainPage/InsufficientGasOrFundsMessage.js +0 -28
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Process, Step } from '@lifinance/sdk';
2
+ import { Process, Step } from '@lifi/sdk';
3
3
  export declare const ExecutionItem: React.FC<{
4
4
  step: Step;
5
5
  process: Process;
@@ -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" | "warning" | "error" | "info" | "primary" | "secondary" | undefined;
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;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Step, TokenAmount } from '@lifinance/sdk';
2
+ import { Step, TokenAmount } from '@lifi/sdk';
3
3
  export declare const StepItem: React.FC<{
4
4
  step: Step;
5
5
  fromToken?: TokenAmount;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Step } from '@lifinance/sdk';
2
+ import { Step } from '@lifi/sdk';
3
3
  export declare const StepTimer: React.FC<{
4
4
  step: Step;
5
5
  }>;
@@ -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 { useRouteExecution } from '../../hooks';
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" | "warning" | "error" | "info" | "primary" | "secondary" | undefined;
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 '@lifinance/sdk';
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;
@@ -1,4 +1,4 @@
1
- import { LifiErrorCode, MetaMaskProviderErrorCode, } from '@lifinance/sdk';
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 { Skeleton } from '@mui/material';
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
- // A route for this transaction does not exist yet possibly due to liquidity issues or because the amount of tokens you are sending is below the bridge minimum amount.
23
- // Please try again later or change the tokens you intend to swap.
24
- // If the problem persists, come to our Discord and leave a message in the support channel.
25
- return (_jsx(Stack, Object.assign({ direction: "column", spacing: 2 }, { children: isLoading || isFetching
26
- ? Array.from({ length: 3 }).map((_, index) => (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 196, sx: { borderRadius: 1 } }, index)))
27
- : 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))) })));
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
  };
@@ -1,5 +1,5 @@
1
+ import { Token } from '@lifi/sdk';
1
2
  import { Wallet } from '@lifi/wallet-management';
2
- import { Token } from '@lifinance/sdk';
3
3
  import { Signer } from 'ethers';
4
4
  export interface WalletContextProps {
5
5
  account: WalletAccount;
@@ -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 '@lifinance/sdk';
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>.');
@@ -1,4 +1,4 @@
1
- import { Route } from '@lifinance/sdk';
1
+ import { Route } from '@lifi/sdk';
2
2
  export interface RouteExecutionStore {
3
3
  currentRoute?: Route;
4
4
  routes: Record<string, RouteExecution>;
@@ -1,2 +1,2 @@
1
- import { Route } from '@lifinance/sdk';
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("@lifinance/types").Route) => void;
1
+ export declare const useSetExecutableRoute: () => (route: import("@lifi/types").Route) => void;
@@ -1,4 +1,4 @@
1
- import { Bridge, Exchange, Order } from '@lifinance/sdk';
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("@lifinance/types").Bridge, "key"> | Pick<import("@lifinance/types").Exchange, "key">)[]): void;
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 '@lifinance/sdk';
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 = 21;
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 = -21;
5
+ Big.NE = -42;
6
6
  /**
7
7
  * Format token amount to at least 4 decimals.
8
8
  * @param amount amount to format.
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const InsufficientGasOrFundsMessage: React.FC;
@@ -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
- };