@lifi/widget 1.10.2 → 1.11.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 +6 -10
- package/AppDrawer.js +1 -1
- package/AppDrawer.style.d.ts +1 -1
- package/AppDrawer.style.js +0 -1
- package/AppProvider.d.ts +1 -0
- package/AppProvider.js +5 -2
- package/components/AppContainer.d.ts +10 -0
- package/components/AppContainer.js +4 -7
- package/components/Card/Card.d.ts +11 -5
- package/components/Card/Card.js +29 -5
- package/components/Card/index.d.ts +0 -1
- package/components/Card/index.js +0 -1
- package/components/Dialog.d.ts +3 -0
- package/components/Dialog.js +23 -0
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.d.ts +6 -0
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +48 -0
- package/components/{InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.style.d.ts → GasSufficiencyMessage/GasSufficiencyMessage.style.d.ts} +0 -0
- package/components/{InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.style.js → GasSufficiencyMessage/GasSufficiencyMessage.style.js} +1 -0
- package/components/GasSufficiencyMessage/index.d.ts +1 -0
- package/components/GasSufficiencyMessage/index.js +1 -0
- package/components/Header/Header.js +5 -6
- package/components/Header/Header.style.js +2 -1
- package/components/Header/NavigationHeader.js +27 -23
- package/components/Header/WalletHeader.js +4 -4
- package/components/Header/index.d.ts +1 -0
- package/components/Header/index.js +1 -0
- package/components/Header/types.d.ts +9 -0
- package/components/Header/types.js +1 -0
- package/components/Header/useHeaderActionStore.d.ts +6 -0
- package/components/Header/useHeaderActionStore.js +21 -0
- package/components/PoweredBy/PoweredBy.js +0 -1
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +14 -2
- package/components/ReverseTokensButton/ReverseTokensButton.js +5 -7
- package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
- package/components/ReverseTokensButton/ReverseTokensButton.style.js +4 -2
- package/components/SelectTokenButton/SelectTokenButton.js +9 -7
- package/components/SelectTokenButton/SelectTokenButton.style.d.ts +3 -10
- package/components/SelectTokenButton/SelectTokenButton.style.js +0 -7
- package/components/SmallAvatar.d.ts +16 -0
- package/components/SmallAvatar.js +8 -0
- package/{pages/SwapPage → components/Step}/CircularProgress.d.ts +0 -0
- package/{pages/SwapPage → components/Step}/CircularProgress.js +0 -0
- package/{pages/SwapPage → components/Step}/CircularProgress.style.d.ts +0 -0
- package/{pages/SwapPage → components/Step}/CircularProgress.style.js +0 -0
- package/components/Step/Step.d.ts +7 -0
- package/{pages/SwapPage/StepItem.js → components/Step/Step.js} +6 -6
- package/{pages/SwapPage/ExecutionItem.d.ts → components/Step/StepProcess.d.ts} +1 -1
- package/{pages/SwapPage/ExecutionItem.js → components/Step/StepProcess.js} +2 -2
- package/{pages/SwapPage/ExecutionItem.style.d.ts → components/Step/StepProcess.style.d.ts} +1 -1
- package/{pages/SwapPage/ExecutionItem.style.js → components/Step/StepProcess.style.js} +0 -0
- package/{pages/SwapPage → components/Step}/StepTimer.d.ts +0 -0
- package/{pages/SwapPage → components/Step}/StepTimer.js +0 -0
- package/components/Step/index.d.ts +1 -0
- package/components/Step/index.js +1 -0
- package/components/Step/utils.d.ts +6 -0
- package/components/Step/utils.js +89 -0
- package/components/StepActions/StepActions.js +17 -7
- package/components/StepActions/StepActions.style.js +2 -2
- package/{pages/SwapPage → components/StepDivider}/StepDivider.d.ts +0 -0
- package/{pages/SwapPage → components/StepDivider}/StepDivider.js +0 -0
- package/{pages/SwapPage → components/StepDivider}/StepDivider.style.d.ts +0 -0
- package/{pages/SwapPage → components/StepDivider}/StepDivider.style.js +0 -0
- package/components/StepDivider/index.d.ts +1 -0
- package/components/StepDivider/index.js +1 -0
- package/components/SwapButton/SwapButton.js +9 -12
- package/components/SwapButton/SwapButton.style.d.ts +1 -1
- package/components/SwapButton/SwapButton.style.js +1 -5
- package/components/SwapButton/types.d.ts +2 -0
- package/components/SwapInProgress/SwapInProgress.js +9 -6
- package/components/SwapInProgress/SwapInProgress.style.d.ts +9 -21
- package/components/SwapInProgress/SwapInProgress.style.js +5 -6
- package/components/SwapInput/FormPriceHelperText.js +1 -1
- package/components/SwapInput/SwapInput.js +4 -5
- package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
- package/components/SwapInput/SwapInputAdornment.style.js +0 -2
- package/components/SwapRouteCard/SwapRouteCard.js +15 -15
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +0 -20
- package/components/SwapRouteCard/SwapRouteCard.style.js +7 -54
- package/components/SwapRouteCard/SwapRouteCardSkeleton.js +6 -10
- package/components/SwapRouteCard/SwapRouteNotFoundCard.js +3 -3
- package/components/SwapRouteCard/types.d.ts +0 -3
- package/components/{StepToken.d.ts → Token/Token.d.ts} +2 -1
- package/components/Token/Token.js +31 -0
- package/components/Token/Token.style.d.ts +24 -0
- package/components/Token/Token.style.js +31 -0
- package/components/Token/index.d.ts +2 -0
- package/components/Token/index.js +2 -0
- package/components/TokenAvatar/TokenAvatar.d.ts +7 -0
- package/components/TokenAvatar/TokenAvatar.js +8 -0
- package/components/TokenAvatar/TokenAvatar.style.d.ts +1 -0
- package/components/TokenAvatar/TokenAvatar.style.js +16 -0
- package/components/TokenAvatar/index.d.ts +2 -0
- package/components/TokenAvatar/index.js +2 -0
- package/components/TokenList/TokenList.js +2 -2
- package/components/TokenList/TokenList.style.js +1 -1
- package/components/TokenList/TokenListItem.d.ts +1 -0
- package/components/TokenList/TokenListItem.js +13 -7
- package/components/TokenList/types.d.ts +1 -0
- package/config/queryClient.d.ts +1 -1
- package/config/queryClient.js +1 -1
- package/config/sentry.js +1 -1
- package/config/theme.js +14 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +1 -1
- package/hooks/index.js +1 -1
- package/hooks/useChains.d.ts +8 -8
- package/hooks/useChains.js +1 -1
- package/hooks/useContentHeight.js +1 -1
- package/hooks/useGasSufficiency.d.ts +15 -0
- package/hooks/useGasSufficiency.js +91 -0
- package/hooks/useRouteExecution.d.ts +3 -3
- package/hooks/useRouteExecution.js +23 -19
- package/hooks/useScrollableContainer.js +1 -1
- package/hooks/useSwapRoutes.d.ts +1 -1
- package/hooks/useSwapRoutes.js +2 -14
- package/hooks/useTelemetry.js +11 -3
- package/hooks/useTokenBalance.js +5 -5
- package/hooks/useTokenBalances.d.ts +2 -2
- package/hooks/useTokenBalances.js +8 -10
- package/hooks/useTokens.js +1 -1
- package/hooks/useTools.d.ts +10 -1
- package/hooks/useTools.js +13 -3
- package/i18n/en/translation.json +18 -9
- package/i18n/index.d.ts +12 -3
- package/icons/LiFiToolLogo.svg +6 -0
- package/index.js +0 -2
- package/package.json +9 -9
- package/pages/MainPage/MainPage.js +2 -3
- package/pages/MainPage/MainSwapButton.js +6 -7
- package/{components/SwapRoutes → pages/MainPage}/SwapRoutes.d.ts +0 -0
- package/pages/MainPage/SwapRoutes.js +36 -0
- package/{components/SwapRoutes → pages/MainPage}/SwapRoutes.style.d.ts +0 -0
- package/{components/SwapRoutes → pages/MainPage}/SwapRoutes.style.js +4 -0
- package/pages/SelectTokenPage/ChainSelect.js +2 -2
- package/pages/SelectTokenPage/SearchTokenInput.js +2 -2
- package/pages/SelectWalletPage/SelectWalletPage.js +4 -23
- package/pages/SelectWalletPage/SelectWalletPage.style.js +1 -1
- package/pages/SettingsPage/AdvancedPreferences.js +1 -1
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/pages/SettingsPage/EnabledBridgesSelect.js +7 -4
- package/pages/SettingsPage/EnabledExchangesSelect.js +7 -4
- package/pages/SettingsPage/GasPriceSelect.js +2 -2
- package/pages/SettingsPage/RoutePrioritySelect.js +2 -2
- package/pages/SettingsPage/SlippageInput.js +3 -3
- package/pages/SwapDetailsPage/SwapDetailsPage.d.ts +2 -0
- package/pages/SwapDetailsPage/SwapDetailsPage.js +63 -0
- package/pages/SwapDetailsPage/SwapDetailsPage.style.d.ts +11 -0
- package/pages/SwapDetailsPage/SwapDetailsPage.style.js +5 -0
- package/pages/SwapDetailsPage/index.d.ts +1 -0
- package/pages/SwapDetailsPage/index.js +1 -0
- package/pages/SwapHistoryPage/SwapHistoryEmpty.d.ts +2 -0
- package/pages/SwapHistoryPage/SwapHistoryEmpty.js +14 -0
- package/pages/SwapHistoryPage/SwapHistoryItem.d.ts +5 -0
- package/pages/SwapHistoryPage/SwapHistoryItem.js +23 -0
- package/pages/SwapHistoryPage/SwapHistoryPage.d.ts +2 -0
- package/pages/SwapHistoryPage/SwapHistoryPage.js +14 -0
- package/pages/SwapHistoryPage/index.d.ts +1 -0
- package/pages/SwapHistoryPage/index.js +1 -0
- package/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/pages/SwapPage/SwapPage.js +13 -10
- package/pages/SwapPage/SwapPage.style.d.ts +0 -33
- package/pages/SwapPage/SwapPage.style.js +2 -9
- package/pages/SwapPage/utils.js +1 -1
- package/pages/SwapRoutesPage/SwapRoutesPage.js +14 -7
- package/pages/SwapRoutesPage/SwapRoutesPage.style.js +1 -1
- package/providers/WalletProvider/WalletProvider.js +7 -26
- package/providers/WalletProvider/types.d.ts +0 -1
- package/providers/WidgetProvider/WidgetProvider.js +1 -1
- package/stores/route/index.d.ts +1 -1
- package/stores/route/index.js +1 -1
- package/stores/route/types.d.ts +2 -4
- package/stores/route/useExecutingRoutes.d.ts +2 -1
- package/stores/route/useExecutingRoutes.js +4 -2
- package/stores/route/useRouteStore.d.ts +4 -1
- package/stores/route/useRouteStore.js +23 -24
- package/stores/route/useSwapHistory.d.ts +2 -0
- package/stores/route/useSwapHistory.js +11 -0
- package/stores/settings/useSettingsStore.d.ts +13 -0
- package/types/widget.d.ts +3 -4
- package/utils/index.d.ts +6 -0
- package/utils/index.js +6 -0
- package/utils/navigationRoutes.d.ts +13 -0
- package/utils/navigationRoutes.js +12 -0
- package/components/Card/CardContainer.d.ts +0 -11
- package/components/Card/CardContainer.js +0 -16
- package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.d.ts +0 -3
- package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.js +0 -31
- package/components/InsufficientGasOrFundsMessage/index.d.ts +0 -1
- package/components/InsufficientGasOrFundsMessage/index.js +0 -1
- package/components/StepToken.js +0 -21
- package/components/SwapRoutes/SwapRoutes.js +0 -32
- package/components/SwapRoutes/SwapRoutesUpdateProgress.d.ts +0 -3
- package/components/SwapRoutes/SwapRoutesUpdateProgress.js +0 -24
- package/components/SwapRoutes/index.d.ts +0 -1
- package/components/SwapRoutes/index.js +0 -1
- package/hooks/useHasSufficientBalance.d.ts +0 -5
- package/hooks/useHasSufficientBalance.js +0 -72
- package/pages/SwapPage/StepItem.d.ts +0 -7
- package/stores/route/useCurrentRoute.d.ts +0 -2
- package/stores/route/useCurrentRoute.js +0 -5
- package/utils/routes.d.ts +0 -11
- package/utils/routes.js +0 -10
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { ContentCopy as ContentCopyIcon, DeleteOutline as DeleteIcon, } from '@mui/icons-material';
|
|
12
|
+
import { Box, Button, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton, Typography, } from '@mui/material';
|
|
13
|
+
import { Fragment, useCallback, useEffect, useState } from 'react';
|
|
14
|
+
import { useTranslation } from 'react-i18next';
|
|
15
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
16
|
+
import shallow from 'zustand/shallow';
|
|
17
|
+
import { Card, CardTitle } from '../../components/Card';
|
|
18
|
+
import { Dialog } from '../../components/Dialog';
|
|
19
|
+
import { useSetHeaderAction } from '../../components/Header';
|
|
20
|
+
import { Step } from '../../components/Step';
|
|
21
|
+
import { StepDivider } from '../../components/StepDivider';
|
|
22
|
+
import { useRouteStore } from '../../stores';
|
|
23
|
+
import { navigationRoutes } from '../../utils';
|
|
24
|
+
import { Container } from './SwapDetailsPage.style';
|
|
25
|
+
export const SwapDetailsPage = () => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
const navigate = useNavigate();
|
|
29
|
+
const setHeaderAction = useSetHeaderAction();
|
|
30
|
+
const { state } = useLocation();
|
|
31
|
+
const [routeExecution, deleteRoute] = useRouteStore((store) => [store.routes[state === null || state === void 0 ? void 0 : state.routeId], store.deleteRoute], shallow);
|
|
32
|
+
const [open, setOpen] = useState(false);
|
|
33
|
+
const toggleDialog = useCallback(() => {
|
|
34
|
+
setOpen((open) => !open);
|
|
35
|
+
}, []);
|
|
36
|
+
const handleDeleteRoute = () => {
|
|
37
|
+
navigate(-1);
|
|
38
|
+
if (routeExecution) {
|
|
39
|
+
deleteRoute(routeExecution.route.id);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const copyRouteId = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
var _c;
|
|
44
|
+
yield navigator.clipboard.writeText((_c = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id) !== null && _c !== void 0 ? _c : '');
|
|
45
|
+
});
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
return setHeaderAction(navigationRoutes.swapDetails, _jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
|
|
48
|
+
}, [setHeaderAction, toggleDialog]);
|
|
49
|
+
const startedAt = new Date((_b = (_a = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0);
|
|
50
|
+
return (_jsxs(Container, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
51
|
+
display: 'flex',
|
|
52
|
+
flex: 1,
|
|
53
|
+
justifyContent: 'space-between',
|
|
54
|
+
}, pb: 1 }, { children: [_jsx(Typography, Object.assign({ fontSize: 12 }, { children: new Intl.DateTimeFormat(undefined, { dateStyle: 'long' }).format(startedAt) })), _jsx(Typography, Object.assign({ fontSize: 12 }, { children: new Intl.DateTimeFormat(undefined, { timeStyle: 'short' }).format(startedAt) }))] })), routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps.map((step, index, steps) => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
return (_jsxs(Fragment, { children: [_jsx(Step, { step: step, fromToken: index === 0
|
|
57
|
+
? Object.assign(Object.assign({}, step.action.fromToken), { amount: step.action.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
58
|
+
? Object.assign(Object.assign({}, step.action.toToken), { amount: (_b = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.toAmount) !== null && _b !== void 0 ? _b : step.estimate.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id));
|
|
59
|
+
}), _jsxs(Card, Object.assign({ mt: 2 }, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
60
|
+
display: 'flex',
|
|
61
|
+
flex: 1,
|
|
62
|
+
} }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: t('swap.routeId') })), _jsx(Box, Object.assign({ mr: 1, mt: 1 }, { children: _jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", onClick: copyRouteId }, { children: _jsx(ContentCopyIcon, { fontSize: "small" }) })) }))] })), _jsx(Typography, Object.assign({ variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' } }, { children: routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id }))] })), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "contained", href: "https://discord.com/channels/849912621360218112/863689862514343946", target: "_blank", rel: "nofollow noreferrer", fullWidth: true }, { children: t('button.contactSupport') })) })), _jsxs(Dialog, Object.assign({ open: open, onClose: toggleDialog }, { children: [_jsx(DialogTitle, { children: t('swap.warning.title.deleteSwap') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('swap.warning.message.deleteSwap') }) }), _jsxs(DialogActions, { children: [_jsx(Button, Object.assign({ onClick: toggleDialog }, { children: t('button.cancel') })), _jsx(Button, Object.assign({ onClick: handleDeleteRoute, autoFocus: true }, { children: t('button.delete') }))] })] }))] }));
|
|
63
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Container: import("@emotion/styled").StyledComponent<{
|
|
3
|
+
children?: import("react").ReactNode;
|
|
4
|
+
classes?: Partial<import("@mui/material").ContainerClasses> | undefined;
|
|
5
|
+
disableGutters?: boolean | undefined;
|
|
6
|
+
fixed?: boolean | undefined;
|
|
7
|
+
maxWidth?: false | import("@mui/material").Breakpoint | undefined;
|
|
8
|
+
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
9
|
+
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
10
|
+
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
11
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "maxWidth" | "fixed" | "disableGutters"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SwapDetailsPage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SwapDetailsPage';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { History as HistoryIcon } from '@mui/icons-material';
|
|
3
|
+
import { Container, Typography } from '@mui/material';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
export const SwapHistoryEmpty = () => {
|
|
6
|
+
const { t } = useTranslation();
|
|
7
|
+
return (_jsxs(Container, Object.assign({ sx: {
|
|
8
|
+
display: 'flex',
|
|
9
|
+
flex: 1,
|
|
10
|
+
flexDirection: 'column',
|
|
11
|
+
alignItems: 'center',
|
|
12
|
+
justifyContent: 'center',
|
|
13
|
+
} }, { children: [_jsx(Typography, Object.assign({ fontSize: 48 }, { children: _jsx(HistoryIcon, { fontSize: "inherit" }) })), _jsx(Typography, Object.assign({ fontSize: 18, fontWeight: 700 }, { children: "No recent swaps" })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2 }, { children: "Swap history is only stored locally and will be deleted if you clear your browser data." }))] })));
|
|
14
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Typography } from '@mui/material';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { useNavigate } from 'react-router-dom';
|
|
5
|
+
import { Card } from '../../components/Card';
|
|
6
|
+
import { Token, TokenDivider } from '../../components/Token';
|
|
7
|
+
import { navigationRoutes } from '../../utils';
|
|
8
|
+
export const SwapHistoryItem = ({ route }) => {
|
|
9
|
+
var _a, _b, _c, _d, _e;
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
const navigate = useNavigate();
|
|
12
|
+
const handleClick = () => {
|
|
13
|
+
navigate(navigationRoutes.swapDetails, {
|
|
14
|
+
state: { routeId: route.id },
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const startedAt = new Date((_b = (_a = route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0);
|
|
18
|
+
return (_jsxs(Card, Object.assign({ onClick: handleClick }, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
19
|
+
display: 'flex',
|
|
20
|
+
flex: 1,
|
|
21
|
+
justifyContent: 'space-between',
|
|
22
|
+
}, pt: 1.75, px: 2 }, { children: [_jsx(Typography, Object.assign({ fontSize: 12 }, { children: new Intl.DateTimeFormat(undefined, { dateStyle: 'long' }).format(startedAt) })), _jsx(Typography, Object.assign({ fontSize: 12 }, { children: new Intl.DateTimeFormat(undefined, { timeStyle: 'short' }).format(startedAt) }))] })), _jsxs(Box, Object.assign({ py: 1 }, { children: [_jsx(Token, { token: Object.assign(Object.assign({}, route.fromToken), { amount: route.fromAmount }), px: 2, pt: 1, connected: true }), _jsx(TokenDivider, {}), _jsx(Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: (_e = (_d = (_c = route.steps.at(-1)) === null || _c === void 0 ? void 0 : _c.execution) === null || _d === void 0 ? void 0 : _d.toAmount) !== null && _e !== void 0 ? _e : route.toAmount }), px: 2, pt: 0.5, pb: 1 })] }))] })));
|
|
23
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Container, Stack } from '@mui/material';
|
|
3
|
+
import { useWallet } from '../../providers/WalletProvider';
|
|
4
|
+
import { useSwapHistory } from '../../stores/route';
|
|
5
|
+
import { SwapHistoryEmpty } from './SwapHistoryEmpty';
|
|
6
|
+
import { SwapHistoryItem } from './SwapHistoryItem';
|
|
7
|
+
export const SwapHistoryPage = () => {
|
|
8
|
+
const { account } = useWallet();
|
|
9
|
+
const swaps = useSwapHistory(account.address);
|
|
10
|
+
if (!swaps.length) {
|
|
11
|
+
return _jsx(SwapHistoryEmpty, {});
|
|
12
|
+
}
|
|
13
|
+
return (_jsx(Container, { children: _jsx(Stack, Object.assign({ spacing: 2, mt: 1 }, { children: swaps.length ? (swaps.map(({ route }) => (_jsx(SwapHistoryItem, { route: route }, route.id)))) : (_jsx(SwapHistoryEmpty, {})) })) }));
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SwapHistoryPage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SwapHistoryPage';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Done as DoneIcon, Info as InfoIcon, Warning as WarningIcon, } from '@mui/icons-material';
|
|
3
|
-
import { Box, Typography } from '@mui/material';
|
|
3
|
+
import { Box, Button, Typography } from '@mui/material';
|
|
4
4
|
import { useEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import { useFormContext } from 'react-hook-form';
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
import { useNavigate } from 'react-router-dom';
|
|
8
8
|
import { BottomSheet } from '../../components/BottomSheet';
|
|
9
|
-
import {
|
|
9
|
+
import { Token } from '../../components/Token';
|
|
10
10
|
import { useChains, useTokenBalance } from '../../hooks';
|
|
11
11
|
import { SwapFormKey } from '../../providers/SwapFormProvider';
|
|
12
12
|
import { IconCircle, IconContainer, iconStyles, } from './StatusBottomSheet.style';
|
|
13
|
-
import { Button } from './SwapPage.style';
|
|
14
13
|
import { getProcessMessage } from './utils';
|
|
15
14
|
export const StatusBottomSheet = ({ status, route, }) => {
|
|
15
|
+
var _a, _b, _c, _d, _e;
|
|
16
16
|
const { t } = useTranslation();
|
|
17
17
|
const navigate = useNavigate();
|
|
18
18
|
const ref = useRef(null);
|
|
@@ -75,5 +75,5 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
75
75
|
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.openDrawer();
|
|
76
76
|
}
|
|
77
77
|
}, [refetchBalance, status]);
|
|
78
|
-
return (_jsx(BottomSheet, Object.assign({ ref: ref }, { children: _jsxs(Box, Object.assign({ p: 3 }, { children: [_jsxs(IconContainer, { children: [_jsxs(IconCircle, Object.assign({ status: status, mb: 1 }, { children: [status === 'idle' ? (_jsx(InfoIcon, { color: "primary", sx: iconStyles })) : null, status === 'success' ? (_jsx(DoneIcon, { color: "success", sx: iconStyles })) : null, status === 'error' ? (_jsx(WarningIcon, { color: "error", sx: iconStyles })) : null] })), _jsx(Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: title })), status === 'success' ? (_jsx(
|
|
78
|
+
return (_jsx(BottomSheet, Object.assign({ ref: ref }, { children: _jsxs(Box, Object.assign({ p: 3 }, { children: [_jsxs(IconContainer, { children: [_jsxs(IconCircle, Object.assign({ status: status, mb: 1 }, { children: [status === 'idle' ? (_jsx(InfoIcon, { color: "primary", sx: iconStyles })) : null, status === 'success' ? (_jsx(DoneIcon, { color: "success", sx: iconStyles })) : null, status === 'error' ? (_jsx(WarningIcon, { color: "error", sx: iconStyles })) : null] })), _jsx(Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: title })), status === 'success' ? (_jsx(Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: (_e = (_c = (_b = (_a = route.steps.at(-1)) === null || _a === void 0 ? void 0 : _a.execution) === null || _b === void 0 ? void 0 : _b.toAmount) !== null && _c !== void 0 ? _c : (_d = route.steps.at(-1)) === null || _d === void 0 ? void 0 : _d.estimate.toAmount) !== null && _e !== void 0 ? _e : route.toAmount }), py: 1 })) : null] }), _jsx(Typography, Object.assign({ pt: 2, pb: 1 }, { children: message })), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsxs(Button, Object.assign({ variant: "contained", fullWidth: true, onClick: status === 'success' ? handleDone : handleClose }, { children: [status === 'idle' ? t('button.okay') : null, status === 'success' ? t('button.done') : null, status === 'error' ? t('button.tryAgain') : null] })) })), status === 'success' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "outlined", fullWidth: true, onClick: handleClose }, { children: t('button.seeDetails') })) }))) : null] })) })));
|
|
79
79
|
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Box } from '@mui/material';
|
|
2
|
+
import { Box, Button } from '@mui/material';
|
|
3
3
|
import { Fragment } from 'react';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
6
|
-
import {
|
|
6
|
+
import { GasSufficiencyMessage } from '../../components/GasSufficiencyMessage';
|
|
7
|
+
import { Step } from '../../components/Step';
|
|
8
|
+
import { StepDivider } from '../../components/StepDivider';
|
|
7
9
|
import { SwapButton } from '../../components/SwapButton';
|
|
8
10
|
import { useRouteExecution } from '../../hooks';
|
|
9
11
|
import { StatusBottomSheet } from './StatusBottomSheet';
|
|
10
|
-
import {
|
|
11
|
-
import { StepItem } from './StepItem';
|
|
12
|
-
import { Button, Container } from './SwapPage.style';
|
|
12
|
+
import { Container } from './SwapPage.style';
|
|
13
13
|
export const SwapPage = () => {
|
|
14
14
|
const { t } = useTranslation();
|
|
15
15
|
const { state } = useLocation();
|
|
16
16
|
const navigate = useNavigate();
|
|
17
|
-
const { route, status, executeRoute, restartRoute,
|
|
17
|
+
const { route, status, executeRoute, restartRoute, deleteRoute } = useRouteExecution(state === null || state === void 0 ? void 0 : state.routeId);
|
|
18
18
|
const handleRemoveRoute = () => {
|
|
19
|
-
removeRoute();
|
|
20
19
|
navigate(-1);
|
|
20
|
+
deleteRoute();
|
|
21
21
|
};
|
|
22
22
|
const handleSwapClick = () => {
|
|
23
23
|
if (status === 'idle') {
|
|
@@ -36,7 +36,10 @@ export const SwapPage = () => {
|
|
|
36
36
|
return t('button.restartSwap');
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
return (_jsxs(Container, { children: [route === null || route === void 0 ? void 0 : route.steps.map((step, index, steps) =>
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
return (_jsxs(Container, { children: [route === null || route === void 0 ? void 0 : route.steps.map((step, index, steps) => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
return (_jsxs(Fragment, { children: [_jsx(Step, { step: step, fromToken: index === 0
|
|
42
|
+
? Object.assign(Object.assign({}, step.action.fromToken), { amount: step.action.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
43
|
+
? Object.assign(Object.assign({}, step.action.toToken), { amount: (_b = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.toAmount) !== null && _b !== void 0 ? _b : step.estimate.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id));
|
|
44
|
+
}), status === 'idle' ? (_jsx(GasSufficiencyMessage, { route: route, mt: 2 })) : null, status === 'idle' || status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SwapButton, { onClick: handleSwapClick, text: getSwapButtonText() }) }))) : null, status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "outlined", onClick: handleRemoveRoute, fullWidth: true }, { children: t('button.removeSwap') })) }))) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null] }));
|
|
42
45
|
};
|
|
@@ -9,36 +9,3 @@ export declare const Container: import("@emotion/styled").StyledComponent<{
|
|
|
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
11
|
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "maxWidth" | "fixed" | "disableGutters"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
12
|
-
export declare const Button: import("@emotion/styled").StyledComponent<{
|
|
13
|
-
children?: import("react").ReactNode;
|
|
14
|
-
classes?: Partial<import("@mui/material").ButtonClasses> | undefined;
|
|
15
|
-
color?: "inherit" | "success" | "info" | "warning" | "error" | "primary" | "secondary" | undefined;
|
|
16
|
-
disabled?: boolean | undefined;
|
|
17
|
-
disableElevation?: boolean | undefined;
|
|
18
|
-
disableFocusRipple?: boolean | undefined;
|
|
19
|
-
endIcon?: import("react").ReactNode;
|
|
20
|
-
fullWidth?: boolean | undefined;
|
|
21
|
-
href?: string | undefined;
|
|
22
|
-
size?: "small" | "large" | "medium" | undefined;
|
|
23
|
-
startIcon?: import("react").ReactNode;
|
|
24
|
-
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
25
|
-
variant?: "text" | "outlined" | "contained" | undefined;
|
|
26
|
-
} & Omit<{
|
|
27
|
-
action?: import("react").Ref<import("@mui/material").ButtonBaseActions> | undefined;
|
|
28
|
-
centerRipple?: boolean | undefined;
|
|
29
|
-
children?: import("react").ReactNode;
|
|
30
|
-
classes?: Partial<import("@mui/material").ButtonBaseClasses> | undefined;
|
|
31
|
-
disabled?: boolean | undefined;
|
|
32
|
-
disableRipple?: boolean | undefined;
|
|
33
|
-
disableTouchRipple?: boolean | undefined;
|
|
34
|
-
focusRipple?: boolean | undefined;
|
|
35
|
-
focusVisibleClassName?: string | undefined;
|
|
36
|
-
LinkComponent?: import("react").ElementType<any> | undefined;
|
|
37
|
-
onFocusVisible?: import("react").FocusEventHandler<any> | undefined;
|
|
38
|
-
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
39
|
-
tabIndex?: number | undefined;
|
|
40
|
-
TouchRippleProps?: Partial<import("@mui/material/ButtonBase/TouchRipple").TouchRippleProps> | undefined;
|
|
41
|
-
touchRippleRef?: import("react").Ref<import("@mui/material/ButtonBase/TouchRipple").TouchRippleActions> | undefined;
|
|
42
|
-
}, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "key" | keyof import("react").ButtonHTMLAttributes<HTMLButtonElement>> & {
|
|
43
|
-
ref?: ((instance: HTMLButtonElement | null) => void) | import("react").RefObject<HTMLButtonElement> | null | undefined;
|
|
44
|
-
}, keyof import("@mui/material/OverridableComponent").CommonProps | "tabIndex" | "color" | "children" | "action" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "href" | "disableElevation" | "disableFocusRipple" | "endIcon" | "fullWidth" | "size" | "startIcon" | "variant"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Container as MuiContainer } from '@mui/material';
|
|
2
2
|
import { styled } from '@mui/material/styles';
|
|
3
3
|
export const Container = styled(MuiContainer)(({ theme }) => ({
|
|
4
|
-
padding: theme.spacing(1, 3
|
|
5
|
-
}));
|
|
6
|
-
export const Button = styled(MuiButton)(({ theme }) => ({
|
|
7
|
-
textTransform: 'none',
|
|
8
|
-
borderRadius: theme.shape.borderRadiusSecondary,
|
|
9
|
-
padding: theme.spacing(1.25, 2),
|
|
10
|
-
fontSize: '1rem',
|
|
11
|
-
marginTop: theme.spacing(2),
|
|
4
|
+
padding: theme.spacing(1, 3),
|
|
12
5
|
}));
|
package/pages/SwapPage/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LifiErrorCode, MetaMaskProviderErrorCode, } from '@lifi/sdk';
|
|
2
|
-
import { formatTokenAmount } from '../../utils
|
|
2
|
+
import { formatTokenAmount } from '../../utils';
|
|
3
3
|
const formatProcessMessage = (initialMessage, args = {}) => {
|
|
4
4
|
return Object.keys(args).reduce((message, key) => {
|
|
5
5
|
return message.replace(`{${key}}`, args[key]);
|
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
import { useSetHeaderAction } from '../../components/Header';
|
|
5
|
+
import { ProgressToNextUpdate } from '../../components/ProgressToNextUpdate';
|
|
4
6
|
import { SwapRouteCard, SwapRouteCardSkeleton, SwapRouteNotFoundCard, } from '../../components/SwapRouteCard';
|
|
5
7
|
import { useSwapRoutes } from '../../hooks';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
+
import { useSetExecutableRoute } from '../../stores';
|
|
9
|
+
import { navigationRoutes } from '../../utils';
|
|
8
10
|
import { Stack } from './SwapRoutesPage.style';
|
|
9
11
|
export const SwapRoutesPage = () => {
|
|
10
12
|
const navigate = useNavigate();
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
+
const setHeaderAction = useSetHeaderAction();
|
|
14
|
+
const { routes: swapRoutes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = useSwapRoutes();
|
|
13
15
|
const setExecutableRoute = useSetExecutableRoute();
|
|
14
16
|
const handleRouteClick = (route) => {
|
|
15
17
|
setExecutableRoute(route);
|
|
16
|
-
navigate(
|
|
18
|
+
navigate(navigationRoutes.swap, {
|
|
19
|
+
state: { routeId: route.id },
|
|
20
|
+
});
|
|
17
21
|
};
|
|
18
22
|
useEffect(() => {
|
|
19
23
|
if (!(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching) {
|
|
20
|
-
navigate(
|
|
24
|
+
navigate(navigationRoutes.home);
|
|
21
25
|
}
|
|
22
26
|
// redirect to the home page if no routes are found on page reload
|
|
23
27
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
28
|
}, []);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
return setHeaderAction(navigationRoutes.swapRoutes, _jsx(ProgressToNextUpdate, { updatedAt: dataUpdatedAt, timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: { marginRight: -1 }, size: "medium", edge: "end" }));
|
|
31
|
+
}, [dataUpdatedAt, isFetching, refetch, refetchTime, setHeaderAction]);
|
|
25
32
|
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, {
|
|
33
|
+
return (_jsx(Stack, Object.assign({ direction: "column", spacing: 2 }, { children: routeNotFound ? (_jsx(SwapRouteNotFoundCard, { dense: true })) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => (_jsx(SwapRouteCardSkeleton, { dense: true }, index)))) : (swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.map((route, index) => (_jsx(SwapRouteCard, { route: route, onClick: () => handleRouteClick(route) }, route.id)))) })));
|
|
27
34
|
};
|
|
@@ -20,7 +20,6 @@ const initialContext = {
|
|
|
20
20
|
switchChain: stub,
|
|
21
21
|
addChain: stub,
|
|
22
22
|
addToken: stub,
|
|
23
|
-
attemptEagerConnect: stub,
|
|
24
23
|
account: {},
|
|
25
24
|
};
|
|
26
25
|
const WalletContext = createContext(initialContext);
|
|
@@ -48,7 +47,8 @@ export const WalletProvider = ({ children }) => {
|
|
|
48
47
|
}), [config.walletManagement, walletManagementDisconnect]);
|
|
49
48
|
// only for injected wallets
|
|
50
49
|
const switchChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
-
|
|
50
|
+
var _a;
|
|
51
|
+
if ((_a = config.walletManagement) === null || _a === void 0 ? void 0 : _a.switchChain) {
|
|
52
52
|
const signer = yield config.walletManagement.switchChain(chainId);
|
|
53
53
|
const account = yield extractAccountFromSigner(signer);
|
|
54
54
|
setAccount(account);
|
|
@@ -56,29 +56,19 @@ export const WalletProvider = ({ children }) => {
|
|
|
56
56
|
return walletSwitchChain(chainId);
|
|
57
57
|
}), [config.walletManagement]);
|
|
58
58
|
const addChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
-
|
|
59
|
+
var _b;
|
|
60
|
+
if ((_b = config.walletManagement) === null || _b === void 0 ? void 0 : _b.addChain) {
|
|
60
61
|
return config.walletManagement.addChain(chainId);
|
|
61
62
|
}
|
|
62
63
|
return walletAddChain(chainId);
|
|
63
64
|
}), [config.walletManagement]);
|
|
64
65
|
const addToken = useCallback((chainId, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
|
|
66
|
+
var _c;
|
|
67
|
+
if ((_c = config.walletManagement) === null || _c === void 0 ? void 0 : _c.addToken) {
|
|
66
68
|
return config.walletManagement.addToken(token, chainId);
|
|
67
69
|
}
|
|
68
70
|
return switchChainAndAddToken(chainId, token);
|
|
69
71
|
}), [config.walletManagement]);
|
|
70
|
-
const attemptEagerConnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
-
if (config.walletManagement) {
|
|
72
|
-
try {
|
|
73
|
-
const signer = yield config.walletManagement.getSigner();
|
|
74
|
-
const account = yield extractAccountFromSigner(signer);
|
|
75
|
-
setAccount(() => (Object.assign({}, account)));
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
console.warn('WalletProvider: attempted eager connect.', e);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}), [config.walletManagement]);
|
|
82
72
|
// keep account information up to date
|
|
83
73
|
useEffect(() => {
|
|
84
74
|
const updateAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -99,17 +89,8 @@ export const WalletProvider = ({ children }) => {
|
|
|
99
89
|
switchChain,
|
|
100
90
|
addChain,
|
|
101
91
|
addToken,
|
|
102
|
-
attemptEagerConnect,
|
|
103
|
-
account,
|
|
104
|
-
}), [
|
|
105
92
|
account,
|
|
106
|
-
|
|
107
|
-
addToken,
|
|
108
|
-
connect,
|
|
109
|
-
disconnect,
|
|
110
|
-
switchChain,
|
|
111
|
-
attemptEagerConnect,
|
|
112
|
-
]);
|
|
93
|
+
}), [account, addChain, addToken, connect, disconnect, switchChain]);
|
|
113
94
|
return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
114
95
|
};
|
|
115
96
|
const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -8,7 +8,6 @@ export interface WalletContextProps {
|
|
|
8
8
|
disconnect(): void;
|
|
9
9
|
switchChain(chainId: number): Promise<boolean>;
|
|
10
10
|
connect(wallet?: Wallet | undefined): Promise<void>;
|
|
11
|
-
attemptEagerConnect(): Promise<void>;
|
|
12
11
|
}
|
|
13
12
|
export interface WalletAccount {
|
|
14
13
|
address?: string;
|
|
@@ -11,8 +11,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { ChainId, getChainByKey } from '@lifi/sdk';
|
|
14
|
-
import { updateLiFiConfig } from '@lifi/widget/config/lifi';
|
|
15
14
|
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
15
|
+
import { updateLiFiConfig } from '../../config/lifi';
|
|
16
16
|
const stub = () => {
|
|
17
17
|
throw new Error('You forgot to wrap your component in <WidgetProvider>.');
|
|
18
18
|
};
|
package/stores/route/index.d.ts
CHANGED
package/stores/route/index.js
CHANGED
package/stores/route/types.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Route } from '@lifi/sdk';
|
|
2
2
|
export interface RouteExecutionStore {
|
|
3
|
-
|
|
4
|
-
routes: Record<string, RouteExecution>;
|
|
5
|
-
setCurrentRoute: (route?: Route) => void;
|
|
3
|
+
routes: Partial<Record<string, RouteExecution>>;
|
|
6
4
|
setExecutableRoute: (route: Route) => void;
|
|
7
5
|
updateRoute: (route: Route) => void;
|
|
8
6
|
restartRoute: (routeId: string) => void;
|
|
9
|
-
|
|
7
|
+
deleteRoute: (routeId: string) => void;
|
|
10
8
|
}
|
|
11
9
|
export declare type RouteExecutionStatus = 'error' | 'idle' | 'loading' | 'success';
|
|
12
10
|
export interface RouteExecution {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RouteExecution } from './types';
|
|
2
|
+
export declare const useExecutingRoutes: (address?: string) => RouteExecution[];
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import shallow from 'zustand/shallow';
|
|
1
2
|
import { useRouteStore } from './useRouteStore';
|
|
2
|
-
export const useExecutingRoutes = () => {
|
|
3
|
-
return useRouteStore((state) => Object.values(state.routes).filter((
|
|
3
|
+
export const useExecutingRoutes = (address) => {
|
|
4
|
+
return useRouteStore((state) => Object.values(state.routes).filter((item) => (item === null || item === void 0 ? void 0 : item.route.fromAddress) === address &&
|
|
5
|
+
((item === null || item === void 0 ? void 0 : item.status) === 'loading' || (item === null || item === void 0 ? void 0 : item.status) === 'error')), shallow);
|
|
4
6
|
};
|
|
@@ -2,13 +2,16 @@ import type { RouteExecutionStore } from './types';
|
|
|
2
2
|
export declare const useRouteStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<RouteExecutionStore>, "persist"> & {
|
|
3
3
|
persist: {
|
|
4
4
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<RouteExecutionStore, {
|
|
5
|
-
routes: Record<string, import("./types").RouteExecution
|
|
5
|
+
routes: Partial<Record<string, import("./types").RouteExecution>>;
|
|
6
6
|
}>>) => void;
|
|
7
7
|
clearStorage: () => void;
|
|
8
8
|
rehydrate: () => Promise<void>;
|
|
9
9
|
hasHydrated: () => boolean;
|
|
10
10
|
onHydrate: (fn: (state: RouteExecutionStore) => void) => () => void;
|
|
11
11
|
onFinishHydration: (fn: (state: RouteExecutionStore) => void) => () => void;
|
|
12
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<RouteExecutionStore, {
|
|
13
|
+
routes: Partial<Record<string, import("./types").RouteExecution>>;
|
|
14
|
+
}>>;
|
|
12
15
|
};
|
|
13
16
|
}, "setState"> & {
|
|
14
17
|
setState(nextStateOrUpdater: RouteExecutionStore | Partial<RouteExecutionStore> | ((state: import("immer/dist/internal").WritableDraft<RouteExecutionStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
@@ -3,41 +3,40 @@ import { persist } from 'zustand/middleware';
|
|
|
3
3
|
import { immer } from 'zustand/middleware/immer';
|
|
4
4
|
export const useRouteStore = create()(persist(immer((set) => ({
|
|
5
5
|
routes: {},
|
|
6
|
-
setCurrentRoute: (route) => set((state) => {
|
|
7
|
-
state.currentRoute = route;
|
|
8
|
-
}),
|
|
9
6
|
setExecutableRoute: (route) => set((state) => {
|
|
10
7
|
if (!state.routes[route.id]) {
|
|
11
8
|
// clean previous idle routes that were not executed
|
|
12
9
|
Object.keys(state.routes)
|
|
13
|
-
.filter((routeId) => state.routes[routeId].status === 'idle')
|
|
10
|
+
.filter((routeId) => { var _a; return ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === 'idle'; })
|
|
14
11
|
.forEach((routeId) => delete state.routes[routeId]);
|
|
15
12
|
state.routes[route.id] = {
|
|
16
13
|
route,
|
|
17
14
|
status: 'idle',
|
|
18
15
|
};
|
|
19
|
-
state.currentRoute = route;
|
|
20
16
|
}
|
|
21
17
|
}),
|
|
22
18
|
updateRoute: (route) => set((state) => {
|
|
23
|
-
state.routes[route.id]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
if (state.routes[route.id]) {
|
|
20
|
+
state.routes[route.id].route = route;
|
|
21
|
+
const isFailed = route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
22
|
+
if (isFailed) {
|
|
23
|
+
state.routes[route.id].status = 'error';
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const isDone = route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
|
|
27
|
+
if (isDone) {
|
|
28
|
+
state.routes[route.id].status = 'success';
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const isLoading = route.steps.some((step) => step.execution);
|
|
32
|
+
if (isLoading) {
|
|
33
|
+
state.routes[route.id].status = 'loading';
|
|
34
|
+
}
|
|
37
35
|
}
|
|
38
36
|
}),
|
|
39
37
|
restartRoute: (routeId) => set((state) => {
|
|
40
|
-
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.route.steps.forEach((step) => {
|
|
41
40
|
var _a, _b;
|
|
42
41
|
const stepHasFailed = ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED';
|
|
43
42
|
// check if the step has been cancelled which is a "failed" state
|
|
@@ -50,10 +49,10 @@ export const useRouteStore = create()(persist(immer((set) => ({
|
|
|
50
49
|
});
|
|
51
50
|
state.routes[routeId].status = 'loading';
|
|
52
51
|
}),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
deleteRoute: (routeId) => set((state) => {
|
|
53
|
+
if (state.routes[routeId]) {
|
|
54
|
+
delete state.routes[routeId];
|
|
55
|
+
}
|
|
57
56
|
}),
|
|
58
57
|
})), {
|
|
59
58
|
name: 'li.fi-widget-routes',
|