@lifi/widget 1.0.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.d.ts +4 -0
- package/App.js +18 -0
- package/AppDrawer.d.ts +14 -0
- package/AppDrawer.js +34 -0
- package/AppDrawer.style.d.ts +49 -0
- package/AppDrawer.style.js +52 -0
- package/AppProvider.d.ts +6 -0
- package/AppProvider.js +12 -0
- package/LICENSE.md +21 -0
- package/components/AppContainer.d.ts +5 -0
- package/components/AppContainer.js +53 -0
- package/components/BottomSheet/BottomSheet.d.ts +3 -0
- package/components/BottomSheet/BottomSheet.js +42 -0
- package/components/BottomSheet/index.d.ts +2 -0
- package/components/BottomSheet/index.js +2 -0
- package/components/BottomSheet/types.d.ts +10 -0
- package/components/BottomSheet/types.js +1 -0
- package/components/Card/Card.d.ts +8 -0
- package/components/Card/Card.js +8 -0
- package/components/Card/CardContainer.d.ts +11 -0
- package/components/Card/CardContainer.js +16 -0
- package/components/Card/CardHeader.d.ts +18 -0
- package/components/Card/CardHeader.js +20 -0
- package/components/Card/CardTitle.d.ts +14 -0
- package/components/Card/CardTitle.js +9 -0
- package/components/Card/index.d.ts +4 -0
- package/components/Card/index.js +4 -0
- package/components/Header/Header.d.ts +2 -0
- package/components/Header/Header.js +17 -0
- package/components/Header/Header.style.d.ts +22 -0
- package/components/Header/Header.style.js +21 -0
- package/components/Header/NavigationHeader.d.ts +2 -0
- package/components/Header/NavigationHeader.js +46 -0
- package/components/Header/WalletHeader.d.ts +2 -0
- package/components/Header/WalletHeader.js +28 -0
- package/components/Header/index.d.ts +1 -0
- package/components/Header/index.js +1 -0
- package/components/Input.d.ts +1 -0
- package/components/Input.js +14 -0
- package/components/LiFiLogo.d.ts +5 -0
- package/components/LiFiLogo.js +7 -0
- package/components/PoweredBy.d.ts +2 -0
- package/components/PoweredBy.js +14 -0
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.d.ts +7 -0
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +49 -0
- package/components/ProgressToNextUpdate/index.d.ts +1 -0
- package/components/ProgressToNextUpdate/index.js +1 -0
- package/components/ReverseTokensButton/ReverseTokensButton.d.ts +4 -0
- package/components/ReverseTokensButton/ReverseTokensButton.js +24 -0
- package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +29 -0
- package/components/ReverseTokensButton/ReverseTokensButton.style.js +14 -0
- package/components/ReverseTokensButton/index.d.ts +1 -0
- package/components/ReverseTokensButton/index.js +1 -0
- package/components/Select.d.ts +3 -0
- package/components/Select.js +27 -0
- package/components/SelectChainAndToken.d.ts +3 -0
- package/components/SelectChainAndToken.js +19 -0
- package/components/SelectTokenButton/SelectTokenButton.d.ts +5 -0
- package/components/SelectTokenButton/SelectTokenButton.js +29 -0
- package/components/SelectTokenButton/SelectTokenButton.style.d.ts +28 -0
- package/components/SelectTokenButton/SelectTokenButton.style.js +31 -0
- package/components/SelectTokenButton/index.d.ts +1 -0
- package/components/SelectTokenButton/index.js +1 -0
- package/components/StepActions/StepActions.d.ts +13 -0
- package/components/StepActions/StepActions.js +49 -0
- package/components/StepActions/StepActions.style.d.ts +20 -0
- package/components/StepActions/StepActions.style.js +56 -0
- package/components/StepActions/index.d.ts +1 -0
- package/components/StepActions/index.js +1 -0
- package/components/StepActions/types.d.ts +6 -0
- package/components/StepActions/types.js +1 -0
- package/components/StepToken.d.ts +6 -0
- package/components/StepToken.js +21 -0
- package/components/SwapButton/ButtonTooltip.d.ts +4 -0
- package/components/SwapButton/ButtonTooltip.js +3 -0
- package/components/SwapButton/SwapButton.d.ts +2 -0
- package/components/SwapButton/SwapButton.js +77 -0
- package/components/SwapButton/SwapButton.style.d.ts +65 -0
- package/components/SwapButton/SwapButton.style.js +20 -0
- package/components/SwapButton/index.d.ts +1 -0
- package/components/SwapButton/index.js +1 -0
- package/components/SwapInProgress/SwapInProgress.d.ts +3 -0
- package/components/SwapInProgress/SwapInProgress.js +22 -0
- package/components/SwapInProgress/SwapInProgress.style.d.ts +43 -0
- package/components/SwapInProgress/SwapInProgress.style.js +15 -0
- package/components/SwapInProgress/index.d.ts +1 -0
- package/components/SwapInProgress/index.js +1 -0
- package/components/SwapInput/FormPriceHelperText.d.ts +5 -0
- package/components/SwapInput/FormPriceHelperText.js +27 -0
- package/components/SwapInput/SwapInput.d.ts +3 -0
- package/components/SwapInput/SwapInput.js +43 -0
- package/components/SwapInput/SwapInput.style.d.ts +21 -0
- package/components/SwapInput/SwapInput.style.js +30 -0
- package/components/SwapInput/SwapInputAdornment.d.ts +2 -0
- package/components/SwapInput/SwapInputAdornment.js +23 -0
- package/components/SwapInput/SwapInputAdornment.style.d.ts +34 -0
- package/components/SwapInput/SwapInputAdornment.style.js +22 -0
- package/components/SwapInput/index.d.ts +1 -0
- package/components/SwapInput/index.js +1 -0
- package/components/SwapRouteCard/SwapRouteCard.d.ts +4 -0
- package/components/SwapRouteCard/SwapRouteCard.js +34 -0
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +36 -0
- package/components/SwapRouteCard/SwapRouteCard.style.js +71 -0
- package/components/SwapRouteCard/index.d.ts +1 -0
- package/components/SwapRouteCard/index.js +1 -0
- package/components/SwapRouteCard/types.d.ts +7 -0
- package/components/SwapRouteCard/types.js +1 -0
- package/components/SwapRoutes/SwapRoutes.d.ts +3 -0
- package/components/SwapRoutes/SwapRoutes.js +33 -0
- package/components/SwapRoutes/SwapRoutes.style.d.ts +11 -0
- package/components/SwapRoutes/SwapRoutes.style.js +9 -0
- package/components/SwapRoutes/SwapRoutesUpdateProgress.d.ts +3 -0
- package/components/SwapRoutes/SwapRoutesUpdateProgress.js +24 -0
- package/components/SwapRoutes/index.d.ts +1 -0
- package/components/SwapRoutes/index.js +1 -0
- package/components/Switch.d.ts +1 -0
- package/components/Switch.js +53 -0
- package/components/TextFitter/TextFitter.d.ts +3 -0
- package/components/TextFitter/TextFitter.js +44 -0
- package/components/TextFitter/index.d.ts +1 -0
- package/components/TextFitter/index.js +1 -0
- package/components/TextFitter/types.d.ts +12 -0
- package/components/TextFitter/types.js +1 -0
- package/components/TokenList/TokenList.d.ts +3 -0
- package/components/TokenList/TokenList.js +58 -0
- package/components/TokenList/TokenList.style.d.ts +32 -0
- package/components/TokenList/TokenList.style.js +22 -0
- package/components/TokenList/TokenListItem.d.ts +4 -0
- package/components/TokenList/TokenListItem.js +24 -0
- package/components/TokenList/index.d.ts +1 -0
- package/components/TokenList/index.js +1 -0
- package/components/TokenList/types.d.ts +16 -0
- package/components/TokenList/types.js +1 -0
- package/components/TokenList/utils.d.ts +15 -0
- package/components/TokenList/utils.js +10 -0
- package/config/env.d.ts +12 -0
- package/config/env.js +19 -0
- package/config/queryClient.d.ts +2 -0
- package/config/queryClient.js +25 -0
- package/config/rpcs.d.ts +1 -0
- package/config/rpcs.js +20 -0
- package/config/theme.d.ts +27 -0
- package/config/theme.js +126 -0
- package/hooks/index.d.ts +15 -0
- package/hooks/index.js +15 -0
- package/hooks/useBridges.d.ts +1 -0
- package/hooks/useBridges.js +12 -0
- package/hooks/useChain.d.ts +4 -0
- package/hooks/useChain.js +13 -0
- package/hooks/useChains.d.ts +101 -0
- package/hooks/useChains.js +39 -0
- package/hooks/useContentHeight.d.ts +1 -0
- package/hooks/useContentHeight.js +15 -0
- package/hooks/useDebouncedWatch.d.ts +1 -0
- package/hooks/useDebouncedWatch.js +27 -0
- package/hooks/useExchanges.d.ts +1 -0
- package/hooks/useExchanges.js +12 -0
- package/hooks/useHasSufficientBalance.d.ts +5 -0
- package/hooks/useHasSufficientBalance.js +59 -0
- package/hooks/useRouteExecution/index.d.ts +3 -0
- package/hooks/useRouteExecution/index.js +3 -0
- package/hooks/useRouteExecution/types.d.ts +15 -0
- package/hooks/useRouteExecution/types.js +1 -0
- package/hooks/useRouteExecution/useRouteExecution.d.ts +8 -0
- package/hooks/useRouteExecution/useRouteExecution.js +132 -0
- package/hooks/useRouteExecution/useRouteStore.d.ts +17 -0
- package/hooks/useRouteExecution/useRouteStore.js +71 -0
- package/hooks/useScrollableContainer.d.ts +2 -0
- package/hooks/useScrollableContainer.js +24 -0
- package/hooks/useSettings/index.d.ts +2 -0
- package/hooks/useSettings/index.js +2 -0
- package/hooks/useSettings/types.d.ts +5 -0
- package/hooks/useSettings/types.js +1 -0
- package/hooks/useSettings/useSettingsStore.d.ts +13 -0
- package/hooks/useSettings/useSettingsStore.js +22 -0
- package/hooks/useSwapRoutes.d.ts +8 -0
- package/hooks/useSwapRoutes.js +101 -0
- package/hooks/useToken.d.ts +4 -0
- package/hooks/useToken.js +13 -0
- package/hooks/useTokenBalance.d.ts +7 -0
- package/hooks/useTokenBalance.js +46 -0
- package/hooks/useTokenBalances.d.ts +7 -0
- package/hooks/useTokenBalances.js +54 -0
- package/hooks/useTokens.d.ts +5 -0
- package/hooks/useTokens.js +24 -0
- package/i18n/en/translation.json +138 -0
- package/i18n/index.d.ts +144 -0
- package/i18n/index.js +20 -0
- package/i18n/react-i18next.d.ts +9 -0
- package/index.d.ts +5 -0
- package/index.js +9 -0
- package/lifi.d.ts +2 -0
- package/lifi.js +10 -0
- package/package.json +55 -0
- package/pages/MainPage/MainPage.d.ts +2 -0
- package/pages/MainPage/MainPage.js +11 -0
- package/pages/MainPage/MainPage.style.d.ts +11 -0
- package/pages/MainPage/MainPage.style.js +8 -0
- package/pages/MainPage/SendToRecipientForm.d.ts +2 -0
- package/pages/MainPage/SendToRecipientForm.js +20 -0
- package/pages/MainPage/index.d.ts +1 -0
- package/pages/MainPage/index.js +1 -0
- package/pages/SelectTokenPage/ChainSelect.d.ts +2 -0
- package/pages/SelectTokenPage/ChainSelect.js +25 -0
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -0
- package/pages/SelectTokenPage/SearchTokenInput.js +17 -0
- package/pages/SelectTokenPage/SearchTokenInput.style.d.ts +1 -0
- package/pages/SelectTokenPage/SearchTokenInput.style.js +5 -0
- package/pages/SelectTokenPage/SelectTokenPage.d.ts +5 -0
- package/pages/SelectTokenPage/SelectTokenPage.js +16 -0
- package/pages/SelectTokenPage/index.d.ts +2 -0
- package/pages/SelectTokenPage/index.js +2 -0
- package/pages/SelectTokenPage/types.d.ts +4 -0
- package/pages/SelectTokenPage/types.js +5 -0
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -0
- package/pages/SelectWalletPage/SelectWalletPage.js +68 -0
- package/pages/SelectWalletPage/SelectWalletPage.style.d.ts +46 -0
- package/pages/SelectWalletPage/SelectWalletPage.style.js +27 -0
- package/pages/SelectWalletPage/index.d.ts +1 -0
- package/pages/SelectWalletPage/index.js +1 -0
- package/pages/SettingsPage/AdvancedPreferences.d.ts +1 -0
- package/pages/SettingsPage/AdvancedPreferences.js +19 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.d.ts +2 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.js +20 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +33 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.js +16 -0
- package/pages/SettingsPage/EnabledBridgesSelect.d.ts +2 -0
- package/pages/SettingsPage/EnabledBridgesSelect.js +15 -0
- package/pages/SettingsPage/EnabledExchangesSelect.d.ts +2 -0
- package/pages/SettingsPage/EnabledExchangesSelect.js +15 -0
- package/pages/SettingsPage/GasPriceSelect.d.ts +1 -0
- package/pages/SettingsPage/GasPriceSelect.js +13 -0
- package/pages/SettingsPage/RoutePrioritySelect.d.ts +2 -0
- package/pages/SettingsPage/RoutePrioritySelect.js +13 -0
- package/pages/SettingsPage/SettingsPage.d.ts +1 -0
- package/pages/SettingsPage/SettingsPage.js +10 -0
- package/pages/SettingsPage/SlippageInput.d.ts +1 -0
- package/pages/SettingsPage/SlippageInput.js +28 -0
- package/pages/SettingsPage/index.d.ts +1 -0
- package/pages/SettingsPage/index.js +1 -0
- package/pages/SwapPage/CircularProgress.d.ts +4 -0
- package/pages/SwapPage/CircularProgress.js +20 -0
- package/pages/SwapPage/CircularProgress.style.d.ts +6 -0
- package/pages/SwapPage/CircularProgress.style.js +51 -0
- package/pages/SwapPage/ExecutionItem.d.ts +6 -0
- package/pages/SwapPage/ExecutionItem.js +21 -0
- package/pages/SwapPage/ExecutionItem.style.d.ts +39 -0
- package/pages/SwapPage/ExecutionItem.style.js +5 -0
- package/pages/SwapPage/StatusBottomSheet.d.ts +3 -0
- package/pages/SwapPage/StatusBottomSheet.js +79 -0
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +25 -0
- package/pages/SwapPage/StatusBottomSheet.style.js +32 -0
- package/pages/SwapPage/StepDivider.d.ts +2 -0
- package/pages/SwapPage/StepDivider.js +6 -0
- package/pages/SwapPage/StepDivider.style.d.ts +11 -0
- package/pages/SwapPage/StepDivider.style.js +8 -0
- package/pages/SwapPage/StepItem.d.ts +7 -0
- package/pages/SwapPage/StepItem.js +29 -0
- package/pages/SwapPage/StepTimer.d.ts +5 -0
- package/pages/SwapPage/StepTimer.js +59 -0
- package/pages/SwapPage/SwapPage.d.ts +2 -0
- package/pages/SwapPage/SwapPage.js +22 -0
- package/pages/SwapPage/SwapPage.style.d.ts +44 -0
- package/pages/SwapPage/SwapPage.style.js +12 -0
- package/pages/SwapPage/index.d.ts +1 -0
- package/pages/SwapPage/index.js +1 -0
- package/pages/SwapPage/utils.d.ts +6 -0
- package/pages/SwapPage/utils.js +85 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.d.ts +3 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.js +24 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +11 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.style.js +6 -0
- package/pages/SwapRoutesPage/index.d.ts +1 -0
- package/pages/SwapRoutesPage/index.js +1 -0
- package/providers/SwapFormProvider/SwapFormProvider.d.ts +2 -0
- package/providers/SwapFormProvider/SwapFormProvider.js +20 -0
- package/providers/SwapFormProvider/index.d.ts +2 -0
- package/providers/SwapFormProvider/index.js +2 -0
- package/providers/SwapFormProvider/types.d.ts +44 -0
- package/providers/SwapFormProvider/types.js +24 -0
- package/providers/ThemeProvider/ThemeProvider.d.ts +2 -0
- package/providers/ThemeProvider/ThemeProvider.js +33 -0
- package/providers/ThemeProvider/index.d.ts +1 -0
- package/providers/ThemeProvider/index.js +1 -0
- package/providers/WalletProvider/WalletProvider.d.ts +4 -0
- package/providers/WalletProvider/WalletProvider.js +89 -0
- package/providers/WalletProvider/index.d.ts +2 -0
- package/providers/WalletProvider/index.js +2 -0
- package/providers/WalletProvider/types.d.ts +17 -0
- package/providers/WalletProvider/types.js +1 -0
- package/providers/WidgetProvider/WidgetProvider.d.ts +4 -0
- package/providers/WidgetProvider/WidgetProvider.js +44 -0
- package/providers/WidgetProvider/index.d.ts +2 -0
- package/providers/WidgetProvider/index.js +2 -0
- package/providers/WidgetProvider/types.d.ts +8 -0
- package/providers/WidgetProvider/types.js +1 -0
- package/react-app-env.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/widget.d.ts +41 -0
- package/types/widget.js +1 -0
- package/utils/colors.d.ts +2 -0
- package/utils/colors.js +3 -0
- package/utils/deepClone.d.ts +1 -0
- package/utils/deepClone.js +3 -0
- package/utils/elements.d.ts +4 -0
- package/utils/elements.js +5 -0
- package/utils/format.d.ts +9 -0
- package/utils/format.js +76 -0
- package/utils/input.d.ts +1 -0
- package/utils/input.js +24 -0
- package/utils/routes.d.ts +10 -0
- package/utils/routes.js +9 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Done as DoneIcon, Info as InfoIcon, Warning as WarningIcon, } from '@mui/icons-material';
|
|
3
|
+
import { Box, Typography } from '@mui/material';
|
|
4
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
5
|
+
import { useFormContext } from 'react-hook-form';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { useNavigate } from 'react-router-dom';
|
|
8
|
+
import { BottomSheet } from '../../components/BottomSheet';
|
|
9
|
+
import { StepToken } from '../../components/StepToken';
|
|
10
|
+
import { useChains, useTokenBalance } from '../../hooks';
|
|
11
|
+
import { SwapFormKey } from '../../providers/SwapFormProvider';
|
|
12
|
+
import { IconCircle, IconContainer, iconStyles, } from './StatusBottomSheet.style';
|
|
13
|
+
import { Button } from './SwapPage.style';
|
|
14
|
+
import { getProcessMessage } from './utils';
|
|
15
|
+
export const StatusBottomSheet = ({ status, route, }) => {
|
|
16
|
+
const { t } = useTranslation();
|
|
17
|
+
const navigate = useNavigate();
|
|
18
|
+
const ref = useRef(null);
|
|
19
|
+
const { getChainById } = useChains();
|
|
20
|
+
const { token, refetchBalance } = useTokenBalance(route.toChainId, route.toToken.address);
|
|
21
|
+
const { setValue } = useFormContext();
|
|
22
|
+
const clearFromAmount = () => {
|
|
23
|
+
refetchBalance(route.fromChainId, route.fromToken.address);
|
|
24
|
+
setValue(SwapFormKey.FromAmount, '');
|
|
25
|
+
};
|
|
26
|
+
const handleDone = () => {
|
|
27
|
+
clearFromAmount();
|
|
28
|
+
navigate(-1);
|
|
29
|
+
};
|
|
30
|
+
const handleClose = () => {
|
|
31
|
+
var _a;
|
|
32
|
+
clearFromAmount();
|
|
33
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.closeDrawer();
|
|
34
|
+
};
|
|
35
|
+
const { title, message } = useMemo(() => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
switch (status) {
|
|
38
|
+
case 'success':
|
|
39
|
+
return {
|
|
40
|
+
title: t('swap.success.title.fundsReceived'),
|
|
41
|
+
message: t('swap.success.message.fundsReceived', {
|
|
42
|
+
amount: token === null || token === void 0 ? void 0 : token.amount,
|
|
43
|
+
tokenSymbol: token === null || token === void 0 ? void 0 : token.symbol,
|
|
44
|
+
chainName: (_a = getChainById(route.toChainId)) === null || _a === void 0 ? void 0 : _a.name,
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
case 'error': {
|
|
48
|
+
const step = route.steps.find((step) => {
|
|
49
|
+
var _a;
|
|
50
|
+
return (_a = step.execution) === null || _a === void 0 ? void 0 : _a.process.some((process) => process.status === 'FAILED');
|
|
51
|
+
});
|
|
52
|
+
const process = (_b = step === null || step === void 0 ? void 0 : step.execution) === null || _b === void 0 ? void 0 : _b.process.find((process) => process.status === 'FAILED');
|
|
53
|
+
if (!step || !process) {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
return getProcessMessage(t, getChainById, step, process);
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
}, [
|
|
62
|
+
getChainById,
|
|
63
|
+
route.steps,
|
|
64
|
+
route.toChainId,
|
|
65
|
+
status,
|
|
66
|
+
t,
|
|
67
|
+
token === null || token === void 0 ? void 0 : token.amount,
|
|
68
|
+
token === null || token === void 0 ? void 0 : token.symbol,
|
|
69
|
+
]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
if ((status === 'success' || status === 'error') &&
|
|
73
|
+
!((_a = ref.current) === null || _a === void 0 ? void 0 : _a.isOpen())) {
|
|
74
|
+
refetchBalance();
|
|
75
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.openDrawer();
|
|
76
|
+
}
|
|
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(StepToken, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), py: 1 })) : null] }), _jsx(Typography, Object.assign({ pt: 2, pb: 1 }, { children: message })), _jsxs(Button, Object.assign({ variant: "contained", disableElevation: true, 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(Button, Object.assign({ variant: "outlined", disableElevation: true, fullWidth: true, onClick: handleClose }, { children: t('button.seeDetails') }))) : null] })) })));
|
|
79
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Theme } from '@mui/material';
|
|
3
|
+
import { RouteExecutionStatus } from '../../hooks';
|
|
4
|
+
export declare const IconContainer: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
|
|
5
|
+
children?: import("react").ReactNode;
|
|
6
|
+
component?: import("react").ElementType<any> | undefined;
|
|
7
|
+
ref?: import("react").Ref<unknown> | undefined;
|
|
8
|
+
sx?: import("@mui/material").SxProps<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" | "ref" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "component"> & import("@mui/system").MUIStyledCommonProps<Theme>, {}, {}>;
|
|
12
|
+
export declare const IconCircle: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
|
|
13
|
+
children?: import("react").ReactNode;
|
|
14
|
+
component?: import("react").ElementType<any> | undefined;
|
|
15
|
+
ref?: import("react").Ref<unknown> | undefined;
|
|
16
|
+
sx?: import("@mui/material").SxProps<Theme> | undefined;
|
|
17
|
+
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
18
|
+
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
19
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "ref" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "component"> & import("@mui/system").MUIStyledCommonProps<Theme> & {
|
|
20
|
+
status: RouteExecutionStatus;
|
|
21
|
+
}, {}, {}>;
|
|
22
|
+
export declare const iconStyles: {
|
|
23
|
+
position: string;
|
|
24
|
+
fontSize: string;
|
|
25
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Box } from '@mui/material';
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
|
+
const getStatusColor = (status, theme) => {
|
|
4
|
+
switch (status) {
|
|
5
|
+
case 'success':
|
|
6
|
+
return theme.palette.success.main;
|
|
7
|
+
case 'error':
|
|
8
|
+
return theme.palette.error.main;
|
|
9
|
+
default:
|
|
10
|
+
return theme.palette.primary.main;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export const IconContainer = styled(Box)(({ theme }) => ({
|
|
14
|
+
display: 'grid',
|
|
15
|
+
placeItems: 'center',
|
|
16
|
+
position: 'relative',
|
|
17
|
+
}));
|
|
18
|
+
export const IconCircle = styled(Box, {
|
|
19
|
+
shouldForwardProp: (prop) => prop !== 'status',
|
|
20
|
+
})(({ theme, status }) => ({
|
|
21
|
+
border: `3px solid ${getStatusColor(status, theme)}`,
|
|
22
|
+
borderRadius: '50%',
|
|
23
|
+
width: 64,
|
|
24
|
+
height: 64,
|
|
25
|
+
display: 'grid',
|
|
26
|
+
position: 'relative',
|
|
27
|
+
placeItems: 'center',
|
|
28
|
+
}));
|
|
29
|
+
export const iconStyles = {
|
|
30
|
+
position: 'absolute',
|
|
31
|
+
fontSize: '2.5rem',
|
|
32
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Divider } from '@mui/material';
|
|
3
|
+
import { Container } from './StepDivider.style';
|
|
4
|
+
export const StepDivider = () => {
|
|
5
|
+
return (_jsx(Container, { children: _jsx(Divider, { orientation: "vertical", flexItem: true }) }));
|
|
6
|
+
};
|
|
@@ -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,8 @@
|
|
|
1
|
+
import { Container as MuiContainer } from '@mui/material';
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
|
+
export const Container = styled(MuiContainer)(({ theme }) => ({
|
|
4
|
+
display: 'flex',
|
|
5
|
+
alignItems: 'center',
|
|
6
|
+
justifyContent: 'center',
|
|
7
|
+
height: theme.spacing(2),
|
|
8
|
+
}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from '@mui/material';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { CardContainer, CardTitle } from '../../components/Card';
|
|
5
|
+
import { StepActions } from '../../components/StepActions';
|
|
6
|
+
import { StepToken } from '../../components/StepToken';
|
|
7
|
+
import { ExecutionItem } from './ExecutionItem';
|
|
8
|
+
import { StepTimer } from './StepTimer';
|
|
9
|
+
export const StepItem = ({ step, fromToken, toToken }) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const { t } = useTranslation();
|
|
12
|
+
const stepHasError = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.process.some((process) => process.status === 'FAILED');
|
|
13
|
+
const getCardTitle = () => {
|
|
14
|
+
switch (step.type) {
|
|
15
|
+
case 'lifi':
|
|
16
|
+
return t('swap.stepSwapAndBridge');
|
|
17
|
+
case 'swap':
|
|
18
|
+
return t('swap.stepSwap');
|
|
19
|
+
case 'cross':
|
|
20
|
+
return t('swap.stepBridge');
|
|
21
|
+
default:
|
|
22
|
+
return t('swap.stepSwap');
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return (_jsxs(CardContainer, Object.assign({ isError: stepHasError }, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
26
|
+
display: 'flex',
|
|
27
|
+
flex: 1,
|
|
28
|
+
} }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: getCardTitle() })), _jsx(CardTitle, { children: _jsx(StepTimer, { step: step }) })] })), _jsxs(Box, Object.assign({ py: 1 }, { children: [fromToken ? _jsx(StepToken, { token: fromToken, px: 2, py: 1 }) : null, _jsx(StepActions, { step: step, px: 2, py: 1, dense: true }), (_b = step.execution) === null || _b === void 0 ? void 0 : _b.process.map((process, index) => (_jsx(ExecutionItem, { step: step, process: process }, index))), toToken ? _jsx(StepToken, { token: toToken, px: 2, py: 1 }) : null] }))] })));
|
|
29
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { useTimer } from 'react-timer-hook';
|
|
5
|
+
const getExpiryTimestamp = (step) => {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
return new Date(((_c = (_b = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.process[0]) === null || _b === void 0 ? void 0 : _b.startedAt) !== null && _c !== void 0 ? _c : Date.now()) +
|
|
8
|
+
step.estimate.executionDuration * 1000);
|
|
9
|
+
};
|
|
10
|
+
export const StepTimer = ({ step }) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const { t } = useTranslation();
|
|
13
|
+
const [isExpired, setExpired] = useState(false);
|
|
14
|
+
const [isExecutionStarted, setExecutionStarted] = useState(!!step.execution);
|
|
15
|
+
const [expiryTimestamp] = useState(() => getExpiryTimestamp(step));
|
|
16
|
+
const { seconds, minutes, isRunning, pause, resume, restart } = useTimer({
|
|
17
|
+
autoStart: false,
|
|
18
|
+
expiryTimestamp,
|
|
19
|
+
onExpire: () => setExpired(true),
|
|
20
|
+
});
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (isExpired || !step.execution) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!isExecutionStarted) {
|
|
26
|
+
setExecutionStarted(true);
|
|
27
|
+
restart(getExpiryTimestamp(step));
|
|
28
|
+
}
|
|
29
|
+
const shouldBePaused = step.execution.process.some((process) => process.status === 'ACTION_REQUIRED' ||
|
|
30
|
+
process.status === 'CHAIN_SWITCH_REQUIRED' ||
|
|
31
|
+
process.status === 'FAILED');
|
|
32
|
+
if (isRunning && shouldBePaused) {
|
|
33
|
+
pause();
|
|
34
|
+
}
|
|
35
|
+
else if (!isRunning && !shouldBePaused) {
|
|
36
|
+
resume();
|
|
37
|
+
}
|
|
38
|
+
}, [
|
|
39
|
+
expiryTimestamp,
|
|
40
|
+
isExecutionStarted,
|
|
41
|
+
isExpired,
|
|
42
|
+
isRunning,
|
|
43
|
+
pause,
|
|
44
|
+
restart,
|
|
45
|
+
resume,
|
|
46
|
+
step,
|
|
47
|
+
]);
|
|
48
|
+
if (!isExecutionStarted) {
|
|
49
|
+
return (_jsx(_Fragment, { children: t('swap.estimatedTime', {
|
|
50
|
+
value: (step.estimate.executionDuration / 60).toFixed(0),
|
|
51
|
+
}) }));
|
|
52
|
+
}
|
|
53
|
+
if (((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE') {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return isExpired ? (_jsx(_Fragment, { children: t('swap.networkIsBusy') })) : (
|
|
57
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
58
|
+
_jsx(_Fragment, { children: `${minutes}:${seconds < 10 ? `0${seconds}` : seconds}` }));
|
|
59
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
5
|
+
import { useRouteExecution } from '../../hooks';
|
|
6
|
+
import { StatusBottomSheet } from './StatusBottomSheet';
|
|
7
|
+
import { StepDivider } from './StepDivider';
|
|
8
|
+
import { StepItem } from './StepItem';
|
|
9
|
+
import { Button, Container } from './SwapPage.style';
|
|
10
|
+
export const SwapPage = () => {
|
|
11
|
+
const { t } = useTranslation();
|
|
12
|
+
const { state } = useLocation();
|
|
13
|
+
const navigate = useNavigate();
|
|
14
|
+
const { route, status, executeRoute, restartRoute, removeRoute } = useRouteExecution(state.routeId);
|
|
15
|
+
const handleRemoveRoute = () => {
|
|
16
|
+
removeRoute();
|
|
17
|
+
navigate(-1);
|
|
18
|
+
};
|
|
19
|
+
return (_jsxs(Container, { children: [route === null || route === void 0 ? void 0 : route.steps.map((step, index, steps) => (_jsxs(Fragment, { children: [_jsx(StepItem, { step: step, fromToken: index === 0
|
|
20
|
+
? Object.assign(Object.assign({}, route.fromToken), { amount: route.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
21
|
+
? Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id))), status === 'idle' ? (_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: executeRoute }, { children: t('button.startSwap') }))) : null, status === 'error' ? (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: restartRoute }, { children: t('button.restartSwap') })), _jsx(Button, Object.assign({ variant: "outlined", disableElevation: true, fullWidth: true, onClick: handleRemoveRoute }, { children: t('button.removeSwap') }))] })) : null, _jsx(StatusBottomSheet, { status: status, route: route })] }));
|
|
22
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
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>, {}, {}>;
|
|
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" | "error" | "primary" | "secondary" | "info" | "warning" | 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>, {}, {}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Button as MuiButton, Container as MuiContainer } from '@mui/material';
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
|
+
export const Container = styled(MuiContainer)(({ theme }) => ({
|
|
4
|
+
padding: theme.spacing(1, 3, 3, 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),
|
|
12
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SwapPage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SwapPage';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EVMChain, Process, Step } from '@lifinance/sdk';
|
|
2
|
+
import { TFunction } from 'react-i18next';
|
|
3
|
+
export declare function getProcessMessage(t: TFunction<'translation', undefined>, getChainById: (chainId: number) => EVMChain | undefined, step: Step, process: Process): {
|
|
4
|
+
title?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LifiErrorCode, MetaMaskProviderErrorCode, } from '@lifinance/sdk';
|
|
2
|
+
import { formatTokenAmount } from '../../utils/format';
|
|
3
|
+
const formatProcessMessage = (initialMessage, args = {}) => {
|
|
4
|
+
return Object.keys(args).reduce((message, key) => {
|
|
5
|
+
return message.replace(`{${key}}`, args[key]);
|
|
6
|
+
}, initialMessage);
|
|
7
|
+
};
|
|
8
|
+
const processMessages = {
|
|
9
|
+
TOKEN_ALLOWANCE: {
|
|
10
|
+
STARTED: (t) => t(`swap.process.tokenAllowance.started`),
|
|
11
|
+
PENDING: (t) => t(`swap.process.tokenAllowance.pending`),
|
|
12
|
+
DONE: (t) => t(`swap.process.tokenAllowance.done`),
|
|
13
|
+
},
|
|
14
|
+
SWITCH_CHAIN: {
|
|
15
|
+
PENDING: (t) => t(`swap.process.switchChain.pending`),
|
|
16
|
+
DONE: (t) => t(`swap.process.switchChain.done`),
|
|
17
|
+
},
|
|
18
|
+
SWAP: {
|
|
19
|
+
STARTED: (t) => t(`swap.process.swap.started`),
|
|
20
|
+
ACTION_REQUIRED: (t) => t(`swap.process.swap.actionRequired`),
|
|
21
|
+
PENDING: (t) => t(`swap.process.swap.pending`),
|
|
22
|
+
DONE: (t) => t(`swap.process.swap.done`),
|
|
23
|
+
},
|
|
24
|
+
CROSS_CHAIN: {
|
|
25
|
+
STARTED: (t) => t(`swap.process.crossChain.started`),
|
|
26
|
+
ACTION_REQUIRED: (t) => t(`swap.process.crossChain.actionRequired`),
|
|
27
|
+
PENDING: (t) => t(`swap.process.crossChain.pending`),
|
|
28
|
+
DONE: (t) => t(`swap.process.crossChain.done`),
|
|
29
|
+
},
|
|
30
|
+
RECEIVING_CHAIN: {
|
|
31
|
+
PENDING: (t) => t(`swap.process.receivingChain.pending`),
|
|
32
|
+
DONE: (t) => t(`swap.process.receivingChain.done`),
|
|
33
|
+
},
|
|
34
|
+
TRANSACTION: {},
|
|
35
|
+
};
|
|
36
|
+
export function getProcessMessage(t, getChainById, step, process) {
|
|
37
|
+
var _a, _b, _c, _d;
|
|
38
|
+
if (process.error && process.status === 'FAILED') {
|
|
39
|
+
const getTransactionNotSentMessage = () => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
return t(`swap.error.message.transactionNotSent`, {
|
|
42
|
+
amount: formatTokenAmount(step.action.fromAmount, step.action.fromToken.decimals),
|
|
43
|
+
tokenSymbol: step.action.fromToken.symbol,
|
|
44
|
+
chainName: (_b = (_a = getChainById(step.action.fromChainId)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '',
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
let title = '';
|
|
48
|
+
let message = '';
|
|
49
|
+
switch (process.error.code) {
|
|
50
|
+
case LifiErrorCode.ChainSwitchError:
|
|
51
|
+
title = t(`swap.error.title.chainSwitch`);
|
|
52
|
+
message = getTransactionNotSentMessage();
|
|
53
|
+
break;
|
|
54
|
+
case LifiErrorCode.TransactionFailed:
|
|
55
|
+
title = t(`swap.error.title.transactionFailed`);
|
|
56
|
+
message = t(`swap.error.message.transactionFailed`);
|
|
57
|
+
break;
|
|
58
|
+
case LifiErrorCode.TransactionUnderpriced:
|
|
59
|
+
title = t(`swap.error.title.transactionUnderpriced`);
|
|
60
|
+
message = getTransactionNotSentMessage();
|
|
61
|
+
break;
|
|
62
|
+
case LifiErrorCode.TransactionUnprepared:
|
|
63
|
+
title = t(`swap.error.title.transactionUnprepared`);
|
|
64
|
+
message = getTransactionNotSentMessage();
|
|
65
|
+
break;
|
|
66
|
+
case MetaMaskProviderErrorCode.userRejectedRequest:
|
|
67
|
+
title = t(`swap.error.title.userRejectedSignatureRequest`);
|
|
68
|
+
message = t(`swap.error.message.signatureRequired`, {
|
|
69
|
+
amount: formatTokenAmount(step.action.fromAmount, step.action.fromToken.decimals),
|
|
70
|
+
tokenSymbol: step.action.fromToken.symbol,
|
|
71
|
+
chainName: (_b = (_a = getChainById(step.action.fromChainId)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '',
|
|
72
|
+
});
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
title = t(`swap.error.title.unknown`);
|
|
76
|
+
if (process.txLink) {
|
|
77
|
+
message = t(`swap.error.message.transactionFailed`);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return { title, message };
|
|
82
|
+
}
|
|
83
|
+
const title = (_d = (_c = processMessages[process.type])[process.status]) === null || _d === void 0 ? void 0 : _d.call(_c, t);
|
|
84
|
+
return { title };
|
|
85
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Skeleton } from '@mui/material';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
import { SwapRouteCard } from '../../components/SwapRouteCard';
|
|
5
|
+
import { useCurrentRoute, useSetExecutableRoute, useSwapRoutes, } from '../../hooks';
|
|
6
|
+
import { routes } from '../../utils/routes';
|
|
7
|
+
import { Stack } from './SwapRoutesPage.style';
|
|
8
|
+
export const SwapRoutesPage = () => {
|
|
9
|
+
const navigate = useNavigate();
|
|
10
|
+
const { routes: swapRoutes, isLoading, isFetching } = useSwapRoutes();
|
|
11
|
+
const [currentRoute] = useCurrentRoute();
|
|
12
|
+
const setExecutableRoute = useSetExecutableRoute();
|
|
13
|
+
if (!(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching) {
|
|
14
|
+
// TODO: make no routes message
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const handleRouteClick = (route) => {
|
|
18
|
+
setExecutableRoute(route);
|
|
19
|
+
navigate(routes.swap, { state: { routeId: route.id }, replace: true });
|
|
20
|
+
};
|
|
21
|
+
return (_jsx(Stack, Object.assign({ direction: "column", spacing: 2 }, { children: isLoading || isFetching
|
|
22
|
+
? Array.from({ length: 3 }).map((_, index) => (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 196, sx: { borderRadius: 1 } }, index)))
|
|
23
|
+
: swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.map((route, index) => (_jsx(SwapRouteCard, { route: route, active: (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.id) === route.id, onClick: () => handleRouteClick(route) }, route.id))) })));
|
|
24
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Stack: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
3
|
+
ref?: import("react").Ref<unknown> | undefined;
|
|
4
|
+
children?: import("react").ReactNode;
|
|
5
|
+
direction?: import("@mui/system").ResponsiveStyleValue<"row" | "column" | "column-reverse" | "row-reverse"> | undefined;
|
|
6
|
+
spacing?: import("@mui/system").ResponsiveStyleValue<string | number> | undefined;
|
|
7
|
+
divider?: import("react").ReactNode;
|
|
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" | "ref" | "direction" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "spacing" | "divider"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SwapRoutesPage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SwapRoutesPage';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FormProvider, useForm } from 'react-hook-form';
|
|
3
|
+
import { useWidgetConfig } from '../WidgetProvider';
|
|
4
|
+
import { SwapFormKey } from './types';
|
|
5
|
+
const defaultValues = {
|
|
6
|
+
[SwapFormKey.FromAmount]: '',
|
|
7
|
+
[SwapFormKey.GasPrice]: 'normal',
|
|
8
|
+
[SwapFormKey.Slippage]: '3',
|
|
9
|
+
[SwapFormKey.SearchTokensFilter]: '',
|
|
10
|
+
};
|
|
11
|
+
export const SwapFormProvider = ({ children, }) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const { fromChain, fromToken, fromAmount, toChain, toToken } = useWidgetConfig();
|
|
14
|
+
const methods = useForm({
|
|
15
|
+
defaultValues: Object.assign(Object.assign({}, defaultValues), { fromChain,
|
|
16
|
+
fromToken, fromAmount: (_a = fromAmount === null || fromAmount === void 0 ? void 0 : fromAmount.toPrecision()) !== null && _a !== void 0 ? _a : defaultValues.fromAmount, toChain,
|
|
17
|
+
toToken }),
|
|
18
|
+
});
|
|
19
|
+
return _jsx(FormProvider, Object.assign({}, methods, { children: children }));
|
|
20
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare enum SwapFormKey {
|
|
2
|
+
BridgePrioritization = "bridgePrioritization",
|
|
3
|
+
EnabledBridges = "enabledBridges",
|
|
4
|
+
EnabledExchanges = "enabledExchanges",
|
|
5
|
+
FromAmount = "fromAmount",
|
|
6
|
+
FromChain = "fromChain",
|
|
7
|
+
FromToken = "fromToken",
|
|
8
|
+
GasPrice = "gasPrice",
|
|
9
|
+
IsAddressConfirmed = "isAddressConfirmed",
|
|
10
|
+
IsSendToRecipient = "isSendToRecipient",
|
|
11
|
+
RecipientsAddress = "recipientsAddress",
|
|
12
|
+
RoutePriority = "routePriority",
|
|
13
|
+
SearchTokensFilter = "searchTokensFilter",
|
|
14
|
+
Slippage = "slippage",
|
|
15
|
+
ToChain = "toChain",
|
|
16
|
+
ToToken = "toToken"
|
|
17
|
+
}
|
|
18
|
+
export declare type SwapFormValues = {
|
|
19
|
+
[SwapFormKey.BridgePrioritization]: string;
|
|
20
|
+
[SwapFormKey.EnabledBridges]: string[];
|
|
21
|
+
[SwapFormKey.EnabledExchanges]: string[];
|
|
22
|
+
[SwapFormKey.FromAmount]: string;
|
|
23
|
+
[SwapFormKey.FromChain]: number;
|
|
24
|
+
[SwapFormKey.FromToken]: string;
|
|
25
|
+
[SwapFormKey.GasPrice]: string;
|
|
26
|
+
[SwapFormKey.IsAddressConfirmed]: boolean;
|
|
27
|
+
[SwapFormKey.IsSendToRecipient]: boolean;
|
|
28
|
+
[SwapFormKey.RecipientsAddress]: string;
|
|
29
|
+
[SwapFormKey.RoutePriority]: string;
|
|
30
|
+
[SwapFormKey.SearchTokensFilter]: string;
|
|
31
|
+
[SwapFormKey.Slippage]: string;
|
|
32
|
+
[SwapFormKey.ToChain]: number;
|
|
33
|
+
[SwapFormKey.ToToken]: string;
|
|
34
|
+
};
|
|
35
|
+
export declare type SwapFormDirection = 'from' | 'to';
|
|
36
|
+
export declare const SwapFormKeyHelper: {
|
|
37
|
+
getChainKey: (formType: SwapFormDirection) => 'fromChain' | 'toChain';
|
|
38
|
+
getTokenKey: (formType: SwapFormDirection) => 'fromToken' | 'toToken';
|
|
39
|
+
getAmountKey: (formType: SwapFormDirection) => 'fromAmount' | 'toAmount';
|
|
40
|
+
getSearchTokensFilterKey: (formType: SwapFormDirection) => string;
|
|
41
|
+
};
|
|
42
|
+
export interface SwapFormTypeProps {
|
|
43
|
+
formType: SwapFormDirection;
|
|
44
|
+
}
|