@lifi/widget 1.18.8 → 1.19.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 +3 -3
- package/cjs/App.js +3 -3
- package/cjs/components/ActiveSwaps/ActiveSwaps.js +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
- package/cjs/components/AppContainer.d.ts +11 -1
- package/cjs/components/AppContainer.js +3 -6
- package/cjs/components/BottomSheet/BottomSheet.js +9 -32
- package/cjs/components/BottomSheet/types.d.ts +2 -2
- package/cjs/components/Card/Card.js +1 -1
- package/cjs/components/Card/CardHeader.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.js +1 -1
- package/cjs/components/ChainSelect/useChainSelect.js +2 -4
- package/cjs/components/Dialog.d.ts +22 -1
- package/cjs/components/Dialog.js +23 -20
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +19 -22
- package/cjs/components/Header/NavigationHeader.js +1 -1
- package/cjs/components/Header/WalletHeader.js +2 -2
- package/cjs/components/PoweredBy/PoweredBy.js +1 -1
- package/cjs/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
- package/cjs/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
- package/cjs/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/cjs/components/SendToWallet/SendToWallet.d.ts +1 -0
- package/cjs/components/SendToWallet/SendToWallet.js +10 -5
- package/cjs/components/SendToWallet/SendToWalletButton.js +2 -2
- package/cjs/components/Step/StepProcess.js +1 -1
- package/cjs/components/SwapButton/SwapButton.js +4 -4
- package/cjs/components/SwapButton/types.d.ts +2 -0
- package/cjs/components/SwapInput/SwapInput.js +6 -2
- package/cjs/components/SwapInput/SwapInputAdornment.js +4 -2
- package/cjs/components/SwapInput/SwapInputAdornment.style.js +1 -13
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +8 -4
- package/cjs/components/SwapRoutes/SwapRoutes.js +4 -4
- package/cjs/components/SwapRoutes/SwapRoutes.style.d.ts +14 -14
- package/cjs/components/SwapRoutes/SwapRoutes.style.js +13 -13
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +17 -12
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.js +13 -0
- package/cjs/components/Token/Token.js +5 -5
- package/cjs/components/Token/Token.style.d.ts +10 -0
- package/cjs/components/Token/Token.style.js +13 -7
- package/cjs/components/TokenList/TokenList.js +10 -7
- package/cjs/config/theme.js +22 -8
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +1 -0
- package/cjs/hooks/index.js +1 -0
- package/cjs/hooks/useExpandableVariant.d.ts +1 -0
- package/cjs/hooks/useExpandableVariant.js +14 -0
- package/cjs/hooks/useGasSufficiency.d.ts +3 -2
- package/cjs/hooks/useGasSufficiency.js +50 -26
- package/cjs/hooks/useSwapRoutes.js +4 -2
- package/cjs/hooks/useToken.js +5 -2
- package/cjs/hooks/useTokenBalance.js +15 -10
- package/cjs/hooks/useTokenSearch.d.ts +1 -3
- package/cjs/hooks/useTokenSearch.js +3 -5
- package/cjs/i18n/en/translation.json +9 -8
- package/cjs/i18n/index.d.ts +6 -5
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.js +21 -4
- package/cjs/pages/MainPage/MainPage.js +3 -3
- package/cjs/pages/SelectWalletPage/SelectWalletPage.js +1 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
- package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/cjs/pages/SwapPage/SwapPage.js +4 -4
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +3 -2
- package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
- package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.js +46 -0
- package/cjs/providers/SwapFormProvider/types.d.ts +4 -4
- package/cjs/providers/SwapFormProvider/types.js +2 -2
- package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
- package/cjs/providers/WalletProvider/WalletFormUpdate.js +64 -0
- package/cjs/providers/WalletProvider/WalletProvider.js +3 -58
- package/cjs/providers/WidgetProvider/WidgetProvider.js +12 -5
- package/cjs/stores/routes/index.d.ts +1 -1
- package/cjs/stores/routes/index.js +1 -1
- package/cjs/stores/routes/types.d.ts +4 -4
- package/cjs/stores/routes/useRecommendedRouteStore.d.ts +4 -0
- package/cjs/stores/routes/{useSelectedRouteStore.js → useRecommendedRouteStore.js} +4 -4
- package/cjs/stores/routes/useRouteExecutionStore.js +10 -2
- package/cjs/stores/settings/useSettingsStore.js +5 -2
- package/cjs/types/widget.d.ts +1 -0
- package/components/ActiveSwaps/ActiveSwaps.js +3 -3
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
- package/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
- package/components/AppContainer.d.ts +11 -1
- package/components/AppContainer.js +2 -4
- package/components/BottomSheet/BottomSheet.js +9 -32
- package/components/BottomSheet/types.d.ts +2 -2
- package/components/Card/Card.js +1 -1
- package/components/Card/CardHeader.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.js +1 -1
- package/components/ChainSelect/useChainSelect.js +2 -4
- package/components/Dialog.d.ts +22 -1
- package/components/Dialog.js +22 -19
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +21 -24
- package/components/Header/NavigationHeader.js +2 -2
- package/components/Header/WalletHeader.js +2 -2
- package/components/PoweredBy/PoweredBy.js +1 -1
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
- package/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
- package/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/components/SendToWallet/SendToWallet.d.ts +1 -0
- package/components/SendToWallet/SendToWallet.js +9 -5
- package/components/SendToWallet/SendToWalletButton.js +2 -2
- package/components/Step/StepProcess.js +1 -1
- package/components/SwapButton/SwapButton.js +4 -4
- package/components/SwapButton/types.d.ts +2 -0
- package/components/SwapInput/SwapInput.js +6 -2
- package/components/SwapInput/SwapInputAdornment.js +4 -2
- package/components/SwapInput/SwapInputAdornment.style.js +2 -14
- package/components/SwapRouteCard/SwapRouteCard.js +9 -5
- package/components/SwapRoutes/SwapRoutes.js +4 -4
- package/components/SwapRoutes/SwapRoutes.style.d.ts +14 -14
- package/components/SwapRoutes/SwapRoutes.style.js +13 -13
- package/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
- package/components/SwapRoutes/SwapRoutesExpanded.js +16 -12
- package/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
- package/components/SwapRoutes/useSetRecommendedRoute.js +9 -0
- package/components/Token/Token.js +7 -7
- package/components/Token/Token.style.d.ts +10 -0
- package/components/Token/Token.style.js +12 -6
- package/components/TokenList/TokenList.js +10 -7
- package/config/theme.js +22 -8
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useExpandableVariant.d.ts +1 -0
- package/hooks/useExpandableVariant.js +10 -0
- package/hooks/useGasSufficiency.d.ts +3 -2
- package/hooks/useGasSufficiency.js +50 -26
- package/hooks/useSwapRoutes.js +4 -2
- package/hooks/useToken.js +5 -2
- package/hooks/useTokenBalance.js +15 -10
- package/hooks/useTokenSearch.d.ts +1 -3
- package/hooks/useTokenSearch.js +3 -5
- package/i18n/en/translation.json +9 -8
- package/i18n/index.d.ts +6 -5
- package/package.json +11 -11
- package/pages/ActiveSwapsPage/ActiveSwapsPage.js +24 -7
- package/pages/MainPage/MainPage.js +3 -3
- package/pages/SelectWalletPage/SelectWalletPage.js +1 -1
- package/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
- package/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/pages/SwapPage/SwapPage.js +5 -5
- package/providers/SwapFormProvider/SwapFormProvider.js +4 -3
- package/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
- package/providers/SwapFormProvider/URLSearchParamsBuilder.js +42 -0
- package/providers/SwapFormProvider/types.d.ts +4 -4
- package/providers/SwapFormProvider/types.js +2 -2
- package/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
- package/providers/WalletProvider/WalletFormUpdate.js +60 -0
- package/providers/WalletProvider/WalletProvider.js +5 -60
- package/providers/WidgetProvider/WidgetProvider.js +12 -5
- package/stores/routes/index.d.ts +1 -1
- package/stores/routes/index.js +1 -1
- package/stores/routes/types.d.ts +4 -4
- package/stores/routes/useRecommendedRouteStore.d.ts +4 -0
- package/stores/routes/useRecommendedRouteStore.js +9 -0
- package/stores/routes/useRouteExecutionStore.js +10 -2
- package/stores/settings/useSettingsStore.js +5 -2
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +1 -0
- package/cjs/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
- package/cjs/components/SwapRoutes/useSetSelectedRoute.js +0 -13
- package/cjs/stores/routes/useSelectedRouteStore.d.ts +0 -4
- package/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
- package/components/SwapRoutes/useSetSelectedRoute.js +0 -9
- package/stores/routes/useSelectedRouteStore.d.ts +0 -4
- package/stores/routes/useSelectedRouteStore.js +0 -9
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable consistent-return */
|
|
3
|
+
import { DeleteOutline as DeleteIcon } from '@mui/icons-material';
|
|
4
|
+
import { Button, Container, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton, List, } from '@mui/material';
|
|
5
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
3
7
|
import { ActiveSwapItem } from '../../components/ActiveSwaps';
|
|
8
|
+
import { Dialog } from '../../components/Dialog';
|
|
9
|
+
import { useHeaderActionStore } from '../../components/Header';
|
|
4
10
|
import { useWallet } from '../../providers';
|
|
5
|
-
import { useExecutingRoutesIds } from '../../stores';
|
|
11
|
+
import { useExecutingRoutesIds, useRouteExecutionStore } from '../../stores';
|
|
6
12
|
import { ActiveSwapsEmpty } from './ActiveSwapsEmpty';
|
|
7
13
|
export const ActiveSwapsPage = () => {
|
|
14
|
+
const { t } = useTranslation();
|
|
8
15
|
const { account } = useWallet();
|
|
9
16
|
const executingRoutes = useExecutingRoutesIds(account.address);
|
|
17
|
+
const deleteRoutes = useRouteExecutionStore((store) => store.deleteRoutes);
|
|
18
|
+
const [open, setOpen] = useState(false);
|
|
19
|
+
const toggleDialog = useCallback(() => {
|
|
20
|
+
setOpen((open) => !open);
|
|
21
|
+
}, []);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (executingRoutes.length) {
|
|
24
|
+
return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
|
|
25
|
+
}
|
|
26
|
+
}, [executingRoutes.length, toggleDialog]);
|
|
10
27
|
if (!executingRoutes.length) {
|
|
11
28
|
return _jsx(ActiveSwapsEmpty, {});
|
|
12
29
|
}
|
|
13
|
-
return (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
return (_jsxs(Container, Object.assign({ disableGutters: true }, { children: [_jsx(List, Object.assign({ sx: {
|
|
31
|
+
paddingLeft: 1.5,
|
|
32
|
+
paddingRight: 1.5,
|
|
33
|
+
} }, { children: executingRoutes.map((routeId) => (_jsx(ActiveSwapItem, { routeId: routeId }, routeId))) })), _jsxs(Dialog, Object.assign({ open: open, onClose: toggleDialog }, { children: [_jsx(DialogTitle, { children: t('swap.warning.title.deleteActiveSwaps') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('swap.warning.message.deleteActiveSwaps') }) }), _jsxs(DialogActions, { children: [_jsx(Button, Object.assign({ onClick: toggleDialog }, { children: t('button.cancel') })), _jsx(Button, Object.assign({ variant: "contained", onClick: () => deleteRoutes('active'), autoFocus: true }, { children: t('button.delete') }))] })] }))] })));
|
|
17
34
|
};
|
|
@@ -6,10 +6,10 @@ import { SelectChainAndToken } from '../../components/SelectChainAndToken';
|
|
|
6
6
|
import { SendToWallet, SendToWalletButton, } from '../../components/SendToWallet';
|
|
7
7
|
import { SwapInput } from '../../components/SwapInput';
|
|
8
8
|
import { SwapRoutes } from '../../components/SwapRoutes';
|
|
9
|
-
import {
|
|
9
|
+
import { useExpandableVariant } from '../../hooks';
|
|
10
10
|
import { FormContainer } from './MainPage.style';
|
|
11
11
|
import { MainSwapButton } from './MainSwapButton';
|
|
12
12
|
export const MainPage = () => {
|
|
13
|
-
const
|
|
14
|
-
return (_jsxs(FormContainer, Object.assign({ disableGutters: true }, { children: [_jsx(ActiveSwaps, { mx: 3, mt: 1, mb: 2 }), _jsx(SelectChainAndToken, { mt: 1, mx: 3, mb: 3 }), _jsx(Box, Object.assign({ mx: 3, mb: 3 }, { children: _jsx(SwapInput, { formType: "from" }) })),
|
|
13
|
+
const expandable = useExpandableVariant();
|
|
14
|
+
return (_jsxs(FormContainer, Object.assign({ disableGutters: true }, { children: [_jsx(ActiveSwaps, { mx: 3, mt: 1, mb: 2 }), _jsx(SelectChainAndToken, { mt: 1, mx: 3, mb: 3 }), _jsx(Box, Object.assign({ mx: 3, mb: 3 }, { children: _jsx(SwapInput, { formType: "from" }) })), !expandable ? _jsx(SwapRoutes, { mx: 3, mb: 3 }) : null, _jsx(GasSufficiencyMessage, { mx: 3, mb: 3 }), _jsxs(Box, Object.assign({ mx: 3, mb: 1 }, { children: [_jsx(SendToWallet, { mb: 3 }), _jsxs(Box, Object.assign({ sx: { display: 'flex' } }, { children: [_jsx(MainSwapButton, {}), _jsx(SendToWalletButton, {})] }))] }))] })));
|
|
15
15
|
};
|
|
@@ -45,5 +45,5 @@ export const SelectWalletPage = () => {
|
|
|
45
45
|
paddingRight: 1.5,
|
|
46
46
|
} }, { children: supportedWallets.map((wallet) => (_jsxs(ListItemButton, Object.assign({ onClick: () => handleConnect(wallet), disableRipple: true }, { children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, Object.assign({ src: wallet.icon.src || wallet.icon, alt: wallet.name }, { children: wallet.name[0] })) }), _jsx(ListItemText, { primary: wallet.name })] }), wallet.name))) })), _jsxs(Dialog, Object.assign({ open: walletIdentity.show, onClose: closeDialog }, { children: [_jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('wallet.extensionNotFound', {
|
|
47
47
|
name: (_a = walletIdentity.wallet) === null || _a === void 0 ? void 0 : _a.name,
|
|
48
|
-
}) }) }), _jsx(DialogActions, { children: _jsx(Button, Object.assign({ onClick: closeDialog, autoFocus: true }, { children: t('button.ok') })) })] }))] })));
|
|
48
|
+
}) }) }), _jsx(DialogActions, { children: _jsx(Button, Object.assign({ variant: "contained", onClick: closeDialog, autoFocus: true }, { children: t('button.ok') })) })] }))] })));
|
|
49
49
|
};
|
|
@@ -43,7 +43,7 @@ export const SwapDetailsPage = () => {
|
|
|
43
43
|
yield navigator.clipboard.writeText((_c = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id) !== null && _c !== void 0 ? _c : '');
|
|
44
44
|
});
|
|
45
45
|
useEffect(() => {
|
|
46
|
-
return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium",
|
|
46
|
+
return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
|
|
47
47
|
}, [toggleDialog]);
|
|
48
48
|
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);
|
|
49
49
|
return (_jsxs(Container, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
@@ -58,5 +58,5 @@ export const SwapDetailsPage = () => {
|
|
|
58
58
|
}), _jsxs(Card, Object.assign({ mt: 2 }, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
59
59
|
display: 'flex',
|
|
60
60
|
flex: 1,
|
|
61
|
-
} }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: t('swap.supportId') })), _jsx(Box, Object.assign({ mr: 1, mt: 1 }, { children: _jsx(IconButton, Object.assign({ size: "medium",
|
|
61
|
+
} }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: t('swap.supportId') })), _jsx(Box, Object.assign({ mr: 1, mt: 1 }, { children: _jsx(IconButton, Object.assign({ size: "medium", 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.deleteSwapHistory') }) }), _jsxs(DialogActions, { children: [_jsx(Button, Object.assign({ onClick: toggleDialog }, { children: t('button.cancel') })), _jsx(Button, Object.assign({ variant: "contained", onClick: handleDeleteRoute, autoFocus: true }, { children: t('button.delete') }))] })] }))] }));
|
|
62
62
|
};
|
|
@@ -22,11 +22,11 @@ export const SwapHistoryPage = () => {
|
|
|
22
22
|
}, []);
|
|
23
23
|
useEffect(() => {
|
|
24
24
|
if (swaps.length) {
|
|
25
|
-
return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium",
|
|
25
|
+
return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
|
|
26
26
|
}
|
|
27
27
|
}, [swaps.length, toggleDialog]);
|
|
28
28
|
if (!swaps.length) {
|
|
29
29
|
return _jsx(SwapHistoryEmpty, {});
|
|
30
30
|
}
|
|
31
|
-
return (_jsxs(Container, { children: [_jsx(Stack, Object.assign({ spacing: 2, mt: 1 }, { children: swaps.length ? (swaps.map(({ route }) => (_jsx(SwapHistoryItem, { route: route }, route.id)))) : (_jsx(SwapHistoryEmpty, {})) })), _jsxs(Dialog, Object.assign({ open: open, onClose: toggleDialog }, { children: [_jsx(DialogTitle, { children: t('swap.warning.title.deleteSwapHistory') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('swap.warning.message.
|
|
31
|
+
return (_jsxs(Container, { children: [_jsx(Stack, Object.assign({ spacing: 2, mt: 1 }, { children: swaps.length ? (swaps.map(({ route }) => (_jsx(SwapHistoryItem, { route: route }, route.id)))) : (_jsx(SwapHistoryEmpty, {})) })), _jsxs(Dialog, Object.assign({ open: open, onClose: toggleDialog }, { children: [_jsx(DialogTitle, { children: t('swap.warning.title.deleteSwapHistory') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), _jsxs(DialogActions, { children: [_jsx(Button, Object.assign({ onClick: toggleDialog }, { children: t('button.cancel') })), _jsx(Button, Object.assign({ variant: "contained", onClick: () => deleteRoutes('completed'), autoFocus: true }, { children: t('button.delete') }))] })] }))] }));
|
|
32
32
|
};
|
|
@@ -17,8 +17,8 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
17
17
|
const { navigateBack, navigate } = useNavigateBack();
|
|
18
18
|
const ref = useRef(null);
|
|
19
19
|
const { getChainById } = useChains();
|
|
20
|
-
const { token, refetch, refetchNewBalance, refetchAllBalances } = useTokenBalance(route.toToken, route.toAddress);
|
|
21
20
|
const { setValue } = useFormContext();
|
|
21
|
+
const { token, refetch, refetchNewBalance, refetchAllBalances } = useTokenBalance(route.toToken, route.toAddress);
|
|
22
22
|
const clearFromAmount = () => {
|
|
23
23
|
refetchAllBalances();
|
|
24
24
|
setValue(SwapFormKey.FromAmount, '');
|
|
@@ -30,7 +30,7 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
30
30
|
const handleClose = () => {
|
|
31
31
|
var _a;
|
|
32
32
|
clearFromAmount();
|
|
33
|
-
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.
|
|
33
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
34
34
|
};
|
|
35
35
|
const handleSeeDetails = () => {
|
|
36
36
|
handleClose();
|
|
@@ -73,8 +73,8 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
73
73
|
refetchNewBalance();
|
|
74
74
|
refetch();
|
|
75
75
|
}
|
|
76
|
-
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.
|
|
76
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.open();
|
|
77
77
|
}
|
|
78
78
|
}, [refetch, refetchNewBalance, status]);
|
|
79
|
-
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: (_g = (_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 : (_f = route.steps.at(-1)) === null || _f === void 0 ? void 0 : _f.estimate.toAmount) !== null && _g !== void 0 ? _g : 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: "
|
|
79
|
+
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: (_g = (_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 : (_f = route.steps.at(-1)) === null || _f === void 0 ? void 0 : _f.estimate.toAmount) !== null && _g !== void 0 ? _g : 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: "text", fullWidth: true, onClick: handleSeeDetails }, { children: t('button.seeDetails') })) }))) : null] })) })));
|
|
80
80
|
};
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
11
|
import { Delete as DeleteIcon } from '@mui/icons-material';
|
|
12
12
|
import { Box, Button } from '@mui/material';
|
|
13
13
|
import { Fragment } from 'react';
|
|
@@ -55,8 +55,8 @@ export const SwapPage = () => {
|
|
|
55
55
|
return (_jsxs(Fragment, { children: [_jsx(Step, { step: step, fromToken: index === 0
|
|
56
56
|
? Object.assign(Object.assign({}, step.action.fromToken), { amount: step.action.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
57
57
|
? 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));
|
|
58
|
-
}), status === 'idle' ? (_jsx(GasSufficiencyMessage, { route: route, mt: 2 })
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
}), status === 'idle' || status === 'error' ? (_jsxs(_Fragment, { children: [_jsx(GasSufficiencyMessage, { route: route, mt: 2 }), _jsxs(Box, Object.assign({ mt: 2, display: "flex" }, { children: [_jsx(SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, currentRoute: route, disable: status === 'idle' && (isValidating || !isValid), enableLoading: true }), status === 'error' ? (_jsx(Button, Object.assign({ onClick: handleRemoveRoute, sx: {
|
|
59
|
+
minWidth: 48,
|
|
60
|
+
marginLeft: 1,
|
|
61
|
+
} }, { children: _jsx(DeleteIcon, {}) }))) : null] }))] })) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null] }));
|
|
62
62
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
3
3
|
import { useWidgetConfig } from '../WidgetProvider';
|
|
4
4
|
import { SwapFormKey } from './types';
|
|
5
|
+
import { URLSearchParamsBuilder } from './URLSearchParamsBuilder';
|
|
5
6
|
export const formDefaultValues = {
|
|
6
7
|
[SwapFormKey.FromAmount]: '',
|
|
7
8
|
[SwapFormKey.ToAddress]: '',
|
|
8
9
|
[SwapFormKey.TokenSearchFilter]: '',
|
|
9
10
|
};
|
|
10
11
|
export const SwapFormProvider = ({ children, }) => {
|
|
11
|
-
const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress } = useWidgetConfig();
|
|
12
|
+
const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress, buildSwapUrl, } = useWidgetConfig();
|
|
12
13
|
const methods = useForm({
|
|
13
14
|
defaultValues: Object.assign(Object.assign({}, formDefaultValues), { fromChain,
|
|
14
15
|
fromToken, fromAmount: (typeof fromAmount === 'number'
|
|
@@ -17,5 +18,5 @@ export const SwapFormProvider = ({ children, }) => {
|
|
|
17
18
|
toToken,
|
|
18
19
|
toAddress }),
|
|
19
20
|
});
|
|
20
|
-
return
|
|
21
|
+
return (_jsxs(FormProvider, Object.assign({}, methods, { children: [buildSwapUrl ? _jsx(URLSearchParamsBuilder, {}) : null, children] })));
|
|
21
22
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const URLSearchParamsBuilder: () => null;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { useEffect } from 'react';
|
|
13
|
+
import { useFormState, useWatch } from 'react-hook-form';
|
|
14
|
+
import { useLocation } from 'react-router-dom';
|
|
15
|
+
import { SwapFormKey } from './types';
|
|
16
|
+
const formValueKeys = [
|
|
17
|
+
SwapFormKey.FromAmount,
|
|
18
|
+
SwapFormKey.FromChain,
|
|
19
|
+
SwapFormKey.FromToken,
|
|
20
|
+
SwapFormKey.ToAddress,
|
|
21
|
+
SwapFormKey.ToChain,
|
|
22
|
+
SwapFormKey.ToToken,
|
|
23
|
+
];
|
|
24
|
+
export const URLSearchParamsBuilder = () => {
|
|
25
|
+
const { pathname } = useLocation();
|
|
26
|
+
const touchedFields = __rest(useFormState().touchedFields, []);
|
|
27
|
+
const values = useWatch({ name: formValueKeys });
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const url = new URL(window.location);
|
|
30
|
+
formValueKeys.forEach((key, index) => {
|
|
31
|
+
if (touchedFields[key] && values[index]) {
|
|
32
|
+
url.searchParams.set(key, values[index]);
|
|
33
|
+
}
|
|
34
|
+
else if (url.searchParams.has(key) && !values[index]) {
|
|
35
|
+
url.searchParams.delete(key);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
url.searchParams.sort();
|
|
39
|
+
window.history.replaceState(window.history.state, '', url);
|
|
40
|
+
}, [pathname, touchedFields, values]);
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
@@ -2,19 +2,19 @@ export declare enum SwapFormKey {
|
|
|
2
2
|
FromAmount = "fromAmount",
|
|
3
3
|
FromChain = "fromChain",
|
|
4
4
|
FromToken = "fromToken",
|
|
5
|
-
|
|
5
|
+
ToAddress = "toAddress",
|
|
6
6
|
ToChain = "toChain",
|
|
7
7
|
ToToken = "toToken",
|
|
8
|
-
|
|
8
|
+
TokenSearchFilter = "tokenSearchFilter"
|
|
9
9
|
}
|
|
10
10
|
export declare type SwapFormValues = {
|
|
11
11
|
[SwapFormKey.FromAmount]: string;
|
|
12
12
|
[SwapFormKey.FromChain]: number;
|
|
13
13
|
[SwapFormKey.FromToken]: string;
|
|
14
|
-
[SwapFormKey.
|
|
14
|
+
[SwapFormKey.ToAddress]: string;
|
|
15
15
|
[SwapFormKey.ToChain]: number;
|
|
16
16
|
[SwapFormKey.ToToken]: string;
|
|
17
|
-
[SwapFormKey.
|
|
17
|
+
[SwapFormKey.TokenSearchFilter]: string;
|
|
18
18
|
};
|
|
19
19
|
export declare type SwapFormType = 'from' | 'to';
|
|
20
20
|
export declare const SwapFormKeyHelper: {
|
|
@@ -3,10 +3,10 @@ export var SwapFormKey;
|
|
|
3
3
|
SwapFormKey["FromAmount"] = "fromAmount";
|
|
4
4
|
SwapFormKey["FromChain"] = "fromChain";
|
|
5
5
|
SwapFormKey["FromToken"] = "fromToken";
|
|
6
|
-
SwapFormKey["
|
|
6
|
+
SwapFormKey["ToAddress"] = "toAddress";
|
|
7
7
|
SwapFormKey["ToChain"] = "toChain";
|
|
8
8
|
SwapFormKey["ToToken"] = "toToken";
|
|
9
|
-
SwapFormKey["
|
|
9
|
+
SwapFormKey["TokenSearchFilter"] = "tokenSearchFilter";
|
|
10
10
|
})(SwapFormKey || (SwapFormKey = {}));
|
|
11
11
|
export const SwapFormKeyHelper = {
|
|
12
12
|
getChainKey: (formType) => `${formType}Chain`,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useFormContext } from 'react-hook-form';
|
|
4
|
+
import { useChainOrderStore } from '../../stores';
|
|
5
|
+
import { SwapFormKey } from '../SwapFormProvider';
|
|
6
|
+
import { isItemAllowed, useWidgetConfig } from '../WidgetProvider';
|
|
7
|
+
export const WalletFormUpdate = ({ account, }) => {
|
|
8
|
+
const { fromChain, toChain, chains, disabledChains } = useWidgetConfig();
|
|
9
|
+
const { setValue, getValues, getFieldState,
|
|
10
|
+
// Subscription to touchedFields is required by getFieldState to work
|
|
11
|
+
formState: { touchedFields }, } = useFormContext();
|
|
12
|
+
// Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const chainAllowed = account.chainId && isItemAllowed(account.chainId, chains, disabledChains);
|
|
15
|
+
if (!account.isActive || !account.chainId || !chainAllowed) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const [fromChainValue, toChainValue] = getValues([
|
|
19
|
+
SwapFormKey.FromChain,
|
|
20
|
+
SwapFormKey.ToChain,
|
|
21
|
+
]);
|
|
22
|
+
const { isTouched: isFromChainTouched } = getFieldState(SwapFormKey.FromChain);
|
|
23
|
+
const { isTouched: isToChainTouched } = getFieldState(SwapFormKey.ToChain);
|
|
24
|
+
const { isTouched: isFromTokenTouched } = getFieldState(SwapFormKey.FromToken);
|
|
25
|
+
const { isTouched: isToTokenTouched } = getFieldState(SwapFormKey.ToToken);
|
|
26
|
+
const { isTouched: isFromAmountTouched } = getFieldState(SwapFormKey.FromAmount);
|
|
27
|
+
const { chainOrder, setChain } = useChainOrderStore.getState();
|
|
28
|
+
// Users can switch chains in the wallet.
|
|
29
|
+
// If we don't have a chain in the ordered chain list we should add it.
|
|
30
|
+
setChain(account.chainId);
|
|
31
|
+
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
32
|
+
// we should make a recently switched chain as current.
|
|
33
|
+
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
34
|
+
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
35
|
+
if ((!fromChain && !isFromChainTouched && !isFromTokenTouched) ||
|
|
36
|
+
!hasFromChainInOrderedList) {
|
|
37
|
+
setValue(SwapFormKey.FromChain, account.chainId);
|
|
38
|
+
setValue(SwapFormKey.FromToken, '');
|
|
39
|
+
if (isFromAmountTouched) {
|
|
40
|
+
setValue(SwapFormKey.FromAmount, '');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if ((!toChain && !isToChainTouched && !isToTokenTouched) ||
|
|
44
|
+
!hasToChainInOrderedList) {
|
|
45
|
+
setValue(SwapFormKey.ToChain, account.chainId);
|
|
46
|
+
setValue(SwapFormKey.ToToken, '');
|
|
47
|
+
}
|
|
48
|
+
}, [
|
|
49
|
+
account.chainId,
|
|
50
|
+
account.isActive,
|
|
51
|
+
chains,
|
|
52
|
+
disabledChains,
|
|
53
|
+
fromChain,
|
|
54
|
+
getFieldState,
|
|
55
|
+
getValues,
|
|
56
|
+
setValue,
|
|
57
|
+
toChain,
|
|
58
|
+
]);
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
@@ -7,13 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
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 {
|
|
14
|
-
import {
|
|
15
|
-
import { SwapFormKey } from '../SwapFormProvider';
|
|
16
|
-
import { isItemAllowed, useWidgetConfig } from '../WidgetProvider';
|
|
13
|
+
import { useWidgetConfig } from '../WidgetProvider';
|
|
14
|
+
import { WalletFormUpdate } from './WalletFormUpdate';
|
|
17
15
|
const stub = () => {
|
|
18
16
|
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
19
17
|
};
|
|
@@ -28,8 +26,7 @@ const initialContext = {
|
|
|
28
26
|
const WalletContext = createContext(initialContext);
|
|
29
27
|
export const useWallet = () => useContext(WalletContext);
|
|
30
28
|
export const WalletProvider = ({ children }) => {
|
|
31
|
-
const { walletManagement
|
|
32
|
-
const methods = useFormContext();
|
|
29
|
+
const { walletManagement } = useWidgetConfig();
|
|
33
30
|
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, provider, } = useLiFiWalletManagement();
|
|
34
31
|
const [account, setAccount] = useState({});
|
|
35
32
|
const connect = useCallback((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -94,59 +91,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
94
91
|
account,
|
|
95
92
|
provider,
|
|
96
93
|
}), [account, addChain, addToken, connect, disconnect, provider, switchChain]);
|
|
97
|
-
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
const chainAllowed = account.chainId && isItemAllowed(account.chainId, chains, disabledChains);
|
|
100
|
-
if (!account.isActive || !account.chainId || !chainAllowed) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const [fromChainValue, toChainValue] = methods.getValues([
|
|
104
|
-
SwapFormKey.FromChain,
|
|
105
|
-
SwapFormKey.ToChain,
|
|
106
|
-
]);
|
|
107
|
-
const { isDirty: isFromChainDirty } = methods.getFieldState(SwapFormKey.FromChain, methods.formState);
|
|
108
|
-
const { isDirty: isToChainDirty } = methods.getFieldState(SwapFormKey.ToChain, methods.formState);
|
|
109
|
-
const { isDirty: isFromTokenDirty } = methods.getFieldState(SwapFormKey.FromToken, methods.formState);
|
|
110
|
-
const { isDirty: isToTokenDirty } = methods.getFieldState(SwapFormKey.ToToken, methods.formState);
|
|
111
|
-
const { chainOrder, setChain } = useChainOrderStore.getState();
|
|
112
|
-
// Users can switch chains in the wallet.
|
|
113
|
-
// If we don't have a chain in the ordered chain list we should add it.
|
|
114
|
-
setChain(account.chainId);
|
|
115
|
-
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
116
|
-
// we should make a recently switched chain as current.
|
|
117
|
-
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
118
|
-
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
119
|
-
if ((!fromChain && !isFromChainDirty && !isFromTokenDirty) ||
|
|
120
|
-
!hasFromChainInOrderedList) {
|
|
121
|
-
methods.setValue(SwapFormKey.FromChain, account.chainId, {
|
|
122
|
-
shouldDirty: false,
|
|
123
|
-
});
|
|
124
|
-
methods.setValue(SwapFormKey.FromToken, '', {
|
|
125
|
-
shouldDirty: false,
|
|
126
|
-
});
|
|
127
|
-
methods.setValue(SwapFormKey.FromAmount, '', {
|
|
128
|
-
shouldDirty: false,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
if ((!toChain && !isToChainDirty && !isToTokenDirty) ||
|
|
132
|
-
!hasToChainInOrderedList) {
|
|
133
|
-
methods.setValue(SwapFormKey.ToChain, account.chainId, {
|
|
134
|
-
shouldDirty: false,
|
|
135
|
-
});
|
|
136
|
-
methods.setValue(SwapFormKey.ToToken, '', {
|
|
137
|
-
shouldDirty: false,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}, [
|
|
141
|
-
account.chainId,
|
|
142
|
-
account.isActive,
|
|
143
|
-
chains,
|
|
144
|
-
disabledChains,
|
|
145
|
-
fromChain,
|
|
146
|
-
methods,
|
|
147
|
-
toChain,
|
|
148
|
-
]);
|
|
149
|
-
return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
94
|
+
return (_jsxs(WalletContext.Provider, Object.assign({ value: value }, { children: [_jsx(WalletFormUpdate, { account: account }), children] })));
|
|
150
95
|
};
|
|
151
96
|
export const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
97
|
try {
|
|
@@ -12,6 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { getChainByKey } from '@lifi/sdk';
|
|
14
14
|
import { createContext, useContext, useMemo } from 'react';
|
|
15
|
+
import { formatAmount } from '../../utils';
|
|
15
16
|
const initialContext = {
|
|
16
17
|
disabledChains: [],
|
|
17
18
|
};
|
|
@@ -20,27 +21,33 @@ export const useWidgetConfig = () => useContext(WidgetContext);
|
|
|
20
21
|
export const WidgetProvider = (_a) => {
|
|
21
22
|
var { children } = _a, _b = _a.config, _c = _b === void 0 ? {} : _b, { fromChain, fromToken, toChain, toToken, fromAmount } = _c, config = __rest(_c, ["fromChain", "fromToken", "toChain", "toToken", "fromAmount"]);
|
|
22
23
|
const value = useMemo(() => {
|
|
23
|
-
var _a, _b, _c, _d;
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
24
25
|
try {
|
|
25
26
|
const searchParams = Object.fromEntries(new URLSearchParams(window === null || window === void 0 ? void 0 : window.location.search));
|
|
27
|
+
// Prevent using fromToken/toToken params if chain is not selected
|
|
28
|
+
['from', 'to'].forEach((key) => {
|
|
29
|
+
if (searchParams[`${key}Token`] && !searchParams[`${key}Chain`]) {
|
|
30
|
+
delete searchParams[`${key}Token`];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
26
33
|
return Object.assign(Object.assign({}, config), { fromChain: (searchParams.fromChain &&
|
|
27
34
|
isNaN(parseInt(searchParams.fromChain, 10))) ||
|
|
28
35
|
typeof fromChain === 'string'
|
|
29
|
-
? getChainByKey((_a = (searchParams.fromChain || fromChain)) === null || _a === void 0 ? void 0 : _a.toLowerCase()).id
|
|
36
|
+
? (_b = getChainByKey((_a = (searchParams.fromChain || fromChain)) === null || _a === void 0 ? void 0 : _a.toLowerCase())) === null || _b === void 0 ? void 0 : _b.id
|
|
30
37
|
: (searchParams.fromChain &&
|
|
31
38
|
!isNaN(parseInt(searchParams.fromChain, 10))) ||
|
|
32
39
|
typeof fromChain === 'number'
|
|
33
40
|
? parseInt(searchParams.fromChain, 10) || fromChain
|
|
34
41
|
: undefined, toChain: (searchParams.toChain && isNaN(parseInt(searchParams.toChain, 10))) ||
|
|
35
42
|
typeof toChain === 'string'
|
|
36
|
-
? getChainByKey((
|
|
43
|
+
? (_d = getChainByKey((_c = (searchParams.toChain || toChain)) === null || _c === void 0 ? void 0 : _c.toLowerCase())) === null || _d === void 0 ? void 0 : _d.id
|
|
37
44
|
: (searchParams.toChain &&
|
|
38
45
|
!isNaN(parseInt(searchParams.toChain, 10))) ||
|
|
39
46
|
typeof toChain === 'number'
|
|
40
47
|
? parseInt(searchParams.toChain, 10) || toChain
|
|
41
|
-
: undefined, fromToken: ((
|
|
48
|
+
: undefined, fromToken: ((_e = searchParams.fromToken) === null || _e === void 0 ? void 0 : _e.toLowerCase()) || (fromToken === null || fromToken === void 0 ? void 0 : fromToken.toLowerCase()), toToken: ((_f = searchParams.toToken) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || (toToken === null || toToken === void 0 ? void 0 : toToken.toLowerCase()), fromAmount: typeof searchParams.fromAmount === 'string' &&
|
|
42
49
|
!isNaN(parseFloat(searchParams.fromAmount))
|
|
43
|
-
? searchParams.fromAmount
|
|
50
|
+
? formatAmount(searchParams.fromAmount)
|
|
44
51
|
: fromAmount });
|
|
45
52
|
}
|
|
46
53
|
catch (e) {
|
package/stores/routes/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export * from './useExecutingRoutesIds';
|
|
3
|
+
export * from './useRecommendedRouteStore';
|
|
3
4
|
export * from './useRouteExecutionStore';
|
|
4
|
-
export * from './useSelectedRouteStore';
|
|
5
5
|
export * from './useSetExecutableRoute';
|
|
6
6
|
export * from './useSwapHistory';
|
|
7
7
|
export * from './utils';
|
package/stores/routes/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export * from './useExecutingRoutesIds';
|
|
3
|
+
export * from './useRecommendedRouteStore';
|
|
3
4
|
export * from './useRouteExecutionStore';
|
|
4
|
-
export * from './useSelectedRouteStore';
|
|
5
5
|
export * from './useSetExecutableRoute';
|
|
6
6
|
export * from './useSwapHistory';
|
|
7
7
|
export * from './utils';
|
package/stores/routes/types.d.ts
CHANGED
|
@@ -5,14 +5,14 @@ export interface RouteExecutionStore {
|
|
|
5
5
|
updateRoute: (route: Route) => void;
|
|
6
6
|
restartRoute: (routeId: string) => void;
|
|
7
7
|
deleteRoute: (routeId: string) => void;
|
|
8
|
-
deleteRoutes: () => void;
|
|
8
|
+
deleteRoutes: (type: 'completed' | 'active') => void;
|
|
9
9
|
}
|
|
10
10
|
export declare type RouteExecutionStatus = 'error' | 'idle' | 'loading' | 'success';
|
|
11
11
|
export interface RouteExecution {
|
|
12
12
|
route: Route;
|
|
13
13
|
status: RouteExecutionStatus;
|
|
14
14
|
}
|
|
15
|
-
export interface
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export interface RecommendedRouteStore {
|
|
16
|
+
recommendedRoute?: Route;
|
|
17
|
+
setRecommendedRoute: (route?: Route) => void;
|
|
18
18
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RecommendedRouteStore } from './types';
|
|
2
|
+
export declare const useRecommendedRouteStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<RecommendedRouteStore>, "setState"> & {
|
|
3
|
+
setState(nextStateOrUpdater: RecommendedRouteStore | Partial<RecommendedRouteStore> | ((state: import("immer/dist/internal").WritableDraft<RecommendedRouteStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
4
|
+
}>;
|
|
@@ -43,8 +43,15 @@ export const useRouteExecutionStore = create()(persist(immer((set) => ({
|
|
|
43
43
|
delete state.routes[routeId];
|
|
44
44
|
}
|
|
45
45
|
}),
|
|
46
|
-
deleteRoutes: () => set((state) => {
|
|
47
|
-
state.routes
|
|
46
|
+
deleteRoutes: (type) => set((state) => {
|
|
47
|
+
Object.keys(state.routes)
|
|
48
|
+
.filter((routeId) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return type === 'completed'
|
|
51
|
+
? ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === 'success'
|
|
52
|
+
: ((_b = state.routes[routeId]) === null || _b === void 0 ? void 0 : _b.status) !== 'success';
|
|
53
|
+
})
|
|
54
|
+
.forEach((routeId) => delete state.routes[routeId]);
|
|
48
55
|
}),
|
|
49
56
|
})), {
|
|
50
57
|
name: 'li.fi-widget-routes',
|
|
@@ -79,6 +86,7 @@ export const useRouteExecutionStore = create()(persist(immer((set) => ({
|
|
|
79
86
|
}
|
|
80
87
|
});
|
|
81
88
|
}
|
|
89
|
+
localStorage.removeItem('routes');
|
|
82
90
|
}
|
|
83
91
|
catch (error) {
|
|
84
92
|
console.log(error);
|
|
@@ -20,7 +20,7 @@ export const useSettingsStore = create()(persist(immer((set) => ({
|
|
|
20
20
|
appearance: 'auto',
|
|
21
21
|
gasPrice: 'normal',
|
|
22
22
|
routePriority: 'RECOMMENDED',
|
|
23
|
-
slippage: '
|
|
23
|
+
slippage: '0.5',
|
|
24
24
|
setValue: (key, value) => set((state) => {
|
|
25
25
|
state[key] = value;
|
|
26
26
|
}),
|
|
@@ -65,7 +65,7 @@ export const useSettingsStore = create()(persist(immer((set) => ({
|
|
|
65
65
|
}),
|
|
66
66
|
})), {
|
|
67
67
|
name: 'li.fi-widget-settings',
|
|
68
|
-
version:
|
|
68
|
+
version: 2,
|
|
69
69
|
partialize: (state) => {
|
|
70
70
|
const { enabledBridges, enabledExchanges } = state, partializedState = __rest(state, ["enabledBridges", "enabledExchanges"]);
|
|
71
71
|
return partializedState;
|
|
@@ -83,6 +83,9 @@ export const useSettingsStore = create()(persist(immer((set) => ({
|
|
|
83
83
|
if (version === 0 && persistedState.appearance === 'system') {
|
|
84
84
|
persistedState.appearance = 'auto';
|
|
85
85
|
}
|
|
86
|
+
if (version === 1) {
|
|
87
|
+
persistedState.slippage = '0.5';
|
|
88
|
+
}
|
|
86
89
|
return persistedState;
|
|
87
90
|
},
|
|
88
91
|
}));
|