@lifi/widget 1.15.0 → 1.16.1
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 +21 -0
- package/AppProvider.d.ts +0 -4
- package/AppProvider.js +2 -10
- package/cjs/App.js +21 -0
- package/cjs/AppProvider.d.ts +0 -4
- package/cjs/AppProvider.js +3 -12
- package/cjs/components/ActiveSwaps/ActiveSwapItem.d.ts +5 -0
- package/cjs/components/ActiveSwaps/ActiveSwapItem.js +45 -0
- package/cjs/components/{SwapsInProgress/SwapsInProgress.d.ts → ActiveSwaps/ActiveSwaps.d.ts} +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwaps.js +30 -0
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +78 -0
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.js +40 -0
- package/cjs/components/ActiveSwaps/index.d.ts +2 -0
- package/cjs/components/ActiveSwaps/index.js +18 -0
- package/cjs/components/AppContainer.js +2 -2
- package/cjs/components/Card/Card.d.ts +7 -4
- package/cjs/components/Card/Card.js +38 -28
- package/cjs/{pages/SelectTokenPage → components/ChainSelect}/ChainSelect.d.ts +0 -0
- package/cjs/components/ChainSelect/ChainSelect.js +35 -0
- package/cjs/components/{SwapsInProgress/SwapsInProgress.style.d.ts → ChainSelect/ChainSelect.style.d.ts} +10 -19
- package/cjs/components/ChainSelect/ChainSelect.style.js +19 -0
- package/cjs/components/ChainSelect/index.d.ts +2 -0
- package/cjs/components/ChainSelect/index.js +18 -0
- package/cjs/components/ChainSelect/useChainSelect.d.ts +8 -0
- package/cjs/components/ChainSelect/useChainSelect.js +33 -0
- package/cjs/components/Header/Header.js +1 -9
- package/cjs/components/Header/NavigationHeader.js +6 -11
- package/cjs/components/PoweredBy/PoweredBy.style.d.ts +1 -1
- package/cjs/components/PoweredBy/PoweredBy.style.js +1 -0
- package/cjs/components/SelectChainAndToken.js +5 -5
- package/cjs/components/SendToWallet/SendToWallet.js +6 -6
- package/cjs/components/Step/CircularProgress.js +1 -1
- package/cjs/components/Step/CircularProgress.style.js +1 -1
- package/cjs/components/Step/StepProcess.js +1 -5
- package/cjs/components/Step/StepProcess.style.d.ts +1 -1
- package/cjs/components/Step/StepTimer.d.ts +1 -0
- package/cjs/components/Step/StepTimer.js +6 -6
- package/cjs/components/SwapButton/SwapButton.js +5 -12
- package/cjs/components/SwapButton/types.d.ts +2 -2
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +1 -1
- package/cjs/components/TokenAvatar/TokenAvatar.style.js +0 -3
- package/cjs/components/TokenList/TokenList.js +6 -2
- package/cjs/config/theme.js +24 -23
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +2 -0
- package/cjs/hooks/index.js +2 -0
- package/cjs/hooks/useChains.d.ts +1 -97
- package/cjs/hooks/useChains.js +12 -19
- package/cjs/hooks/useFeaturedTokens.js +2 -2
- package/cjs/hooks/useGasSufficiency.js +6 -7
- package/cjs/hooks/useInitializer.js +6 -0
- package/cjs/{components/Step/utils.d.ts → hooks/useProcessMessage.d.ts} +4 -0
- package/cjs/{components/Step/utils.js → hooks/useProcessMessage.js} +16 -10
- package/cjs/hooks/useRouteExecution.d.ts +1 -1
- package/cjs/hooks/useRouteExecution.js +26 -35
- package/cjs/hooks/useSwapRoutes.js +10 -11
- package/cjs/hooks/useTokenBalances.js +4 -4
- package/cjs/hooks/useTokenSearch.js +3 -2
- package/cjs/hooks/useTokens.js +3 -2
- package/cjs/hooks/useTools.js +3 -2
- package/cjs/hooks/useWidgetEvents.d.ts +3 -0
- package/cjs/hooks/useWidgetEvents.js +13 -0
- package/cjs/i18n/en/translation.json +13 -8
- package/cjs/i18n/index.d.ts +10 -5
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +3 -1
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsEmpty.d.ts +2 -0
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsEmpty.js +18 -0
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +2 -0
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.js +21 -0
- package/cjs/pages/ActiveSwapsPage/index.d.ts +1 -0
- package/cjs/{components/SwapsInProgress → pages/ActiveSwapsPage}/index.js +1 -1
- package/cjs/pages/MainPage/MainPage.js +2 -3
- package/cjs/pages/MainPage/MainSwapButton.js +3 -1
- package/cjs/pages/MainPage/SwapRoutes.js +4 -1
- package/cjs/pages/SelectChainPage/SelectChainPage.d.ts +3 -0
- package/cjs/pages/SelectChainPage/SelectChainPage.js +33 -0
- package/cjs/pages/SelectChainPage/SelectChainPage.style.d.ts +21 -0
- package/cjs/pages/SelectChainPage/SelectChainPage.style.js +20 -0
- package/cjs/pages/SelectChainPage/index.d.ts +1 -0
- package/cjs/pages/SelectChainPage/index.js +17 -0
- package/cjs/pages/SelectTokenPage/SelectTokenPage.d.ts +2 -4
- package/cjs/pages/SelectTokenPage/SelectTokenPage.js +2 -2
- package/cjs/pages/SelectWalletPage/SelectWalletPage.js +4 -4
- package/cjs/pages/SelectWalletPage/SelectWalletPage.style.d.ts +2 -27
- package/cjs/pages/SelectWalletPage/SelectWalletPage.style.js +4 -14
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/cjs/pages/SettingsPage/EnabledBridgesSelect.js +3 -6
- package/cjs/pages/SettingsPage/EnabledExchangesSelect.js +3 -5
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +5 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +1 -1
- package/cjs/pages/SwapPage/StatusBottomSheet.js +25 -36
- package/cjs/pages/SwapPage/SwapPage.js +5 -1
- package/cjs/providers/SDKProvider/SDKProvider.d.ts +4 -0
- package/cjs/providers/SDKProvider/SDKProvider.js +27 -0
- package/cjs/providers/SDKProvider/index.d.ts +1 -0
- package/cjs/providers/SDKProvider/index.js +17 -0
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +39 -11
- package/cjs/providers/TelemetryProvider/TelemetryProvider.d.ts +4 -0
- package/cjs/providers/TelemetryProvider/TelemetryProvider.js +11 -0
- package/cjs/providers/TelemetryProvider/index.d.ts +1 -0
- package/cjs/providers/TelemetryProvider/index.js +17 -0
- package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -4
- package/cjs/providers/WalletProvider/WalletProvider.js +10 -3
- package/cjs/providers/WidgetProvider/WidgetProvider.js +1 -16
- package/cjs/providers/index.d.ts +2 -0
- package/cjs/providers/index.js +2 -0
- package/cjs/stores/chains/index.d.ts +4 -0
- package/cjs/stores/chains/index.js +20 -0
- package/cjs/stores/chains/types.d.ts +8 -0
- package/cjs/stores/chains/types.js +2 -0
- package/cjs/stores/chains/useChainOrder.d.ts +1 -0
- package/cjs/stores/chains/useChainOrder.js +12 -0
- package/cjs/stores/chains/useChainOrderStore.d.ts +19 -0
- package/cjs/stores/chains/useChainOrderStore.js +42 -0
- package/cjs/stores/chains/useInitializeChainOrder.d.ts +1 -0
- package/cjs/stores/chains/useInitializeChainOrder.js +12 -0
- package/cjs/stores/route/index.d.ts +2 -1
- package/cjs/stores/route/index.js +2 -1
- package/cjs/stores/route/useExecutingRoutesIds.d.ts +1 -0
- package/cjs/stores/route/useExecutingRoutesIds.js +20 -0
- package/cjs/stores/route/useRouteStore.js +5 -4
- package/cjs/stores/route/utils.d.ts +4 -0
- package/cjs/stores/route/utils.js +21 -0
- package/cjs/stores/settings/useSettingsStore.js +5 -2
- package/cjs/types/events.d.ts +5 -0
- package/cjs/types/events.js +9 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/widget.d.ts +2 -1
- package/cjs/utils/colors.d.ts +1 -1
- package/cjs/utils/navigationRoutes.d.ts +5 -0
- package/cjs/utils/navigationRoutes.js +31 -4
- package/components/ActiveSwaps/ActiveSwapItem.d.ts +5 -0
- package/components/ActiveSwaps/ActiveSwapItem.js +41 -0
- package/components/{SwapsInProgress/SwapsInProgress.d.ts → ActiveSwaps/ActiveSwaps.d.ts} +1 -1
- package/components/ActiveSwaps/ActiveSwaps.js +26 -0
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +78 -0
- package/components/ActiveSwaps/ActiveSwaps.style.js +37 -0
- package/components/ActiveSwaps/index.d.ts +2 -0
- package/components/ActiveSwaps/index.js +2 -0
- package/components/AppContainer.js +1 -1
- package/components/Card/Card.d.ts +7 -4
- package/components/Card/Card.js +39 -29
- package/{pages/SelectTokenPage → components/ChainSelect}/ChainSelect.d.ts +0 -0
- package/components/ChainSelect/ChainSelect.js +31 -0
- package/components/{SwapsInProgress/SwapsInProgress.style.d.ts → ChainSelect/ChainSelect.style.d.ts} +10 -19
- package/components/ChainSelect/ChainSelect.style.js +16 -0
- package/components/ChainSelect/index.d.ts +2 -0
- package/components/ChainSelect/index.js +2 -0
- package/components/ChainSelect/useChainSelect.d.ts +8 -0
- package/components/ChainSelect/useChainSelect.js +29 -0
- package/components/Header/Header.js +1 -9
- package/components/Header/NavigationHeader.js +6 -11
- package/components/PoweredBy/PoweredBy.style.d.ts +1 -1
- package/components/PoweredBy/PoweredBy.style.js +1 -0
- package/components/SelectChainAndToken.js +1 -1
- package/components/SendToWallet/SendToWallet.js +6 -6
- package/components/Step/CircularProgress.js +3 -3
- package/components/Step/CircularProgress.style.js +1 -1
- package/components/Step/StepProcess.js +2 -6
- package/components/Step/StepProcess.style.d.ts +1 -1
- package/components/Step/StepTimer.d.ts +1 -0
- package/components/Step/StepTimer.js +6 -6
- package/components/SwapButton/SwapButton.js +6 -13
- package/components/SwapButton/types.d.ts +2 -2
- package/components/SwapRouteCard/SwapRouteCard.js +1 -1
- package/components/TokenAvatar/TokenAvatar.style.js +0 -3
- package/components/TokenList/TokenList.js +6 -2
- package/config/theme.js +24 -23
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +2 -0
- package/hooks/useChains.d.ts +1 -97
- package/hooks/useChains.js +11 -18
- package/hooks/useFeaturedTokens.js +1 -1
- package/hooks/useGasSufficiency.js +1 -2
- package/hooks/useInitializer.js +6 -0
- package/{components/Step/utils.d.ts → hooks/useProcessMessage.d.ts} +4 -0
- package/{pages/SwapPage/utils.js → hooks/useProcessMessage.js} +15 -10
- package/hooks/useRouteExecution.d.ts +1 -1
- package/hooks/useRouteExecution.js +26 -35
- package/hooks/useSwapRoutes.js +3 -4
- package/hooks/useTokenBalances.js +3 -3
- package/hooks/useTokenSearch.js +3 -2
- package/hooks/useTokens.js +3 -2
- package/hooks/useTools.js +3 -2
- package/hooks/useWidgetEvents.d.ts +3 -0
- package/hooks/useWidgetEvents.js +6 -0
- package/i18n/en/translation.json +13 -8
- package/i18n/index.d.ts +10 -5
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +14 -13
- package/pages/ActiveSwapsPage/ActiveSwapsEmpty.d.ts +2 -0
- package/pages/ActiveSwapsPage/ActiveSwapsEmpty.js +14 -0
- package/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +2 -0
- package/pages/ActiveSwapsPage/ActiveSwapsPage.js +17 -0
- package/pages/ActiveSwapsPage/index.d.ts +1 -0
- package/pages/ActiveSwapsPage/index.js +1 -0
- package/pages/MainPage/MainPage.js +2 -3
- package/pages/MainPage/MainSwapButton.js +3 -1
- package/pages/MainPage/SwapRoutes.js +4 -1
- package/pages/SelectChainPage/SelectChainPage.d.ts +3 -0
- package/pages/SelectChainPage/SelectChainPage.js +29 -0
- package/pages/SelectChainPage/SelectChainPage.style.d.ts +21 -0
- package/pages/SelectChainPage/SelectChainPage.style.js +17 -0
- package/pages/SelectChainPage/index.d.ts +1 -0
- package/pages/SelectChainPage/index.js +1 -0
- package/pages/SelectTokenPage/SelectTokenPage.d.ts +2 -4
- package/pages/SelectTokenPage/SelectTokenPage.js +2 -2
- package/pages/SelectWalletPage/SelectWalletPage.js +5 -5
- package/pages/SelectWalletPage/SelectWalletPage.style.d.ts +2 -27
- package/pages/SelectWalletPage/SelectWalletPage.style.js +4 -14
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
- package/pages/SettingsPage/EnabledBridgesSelect.js +4 -7
- package/pages/SettingsPage/EnabledExchangesSelect.js +4 -6
- package/pages/SettingsPage/RoutePrioritySelect.js +5 -1
- package/pages/SwapDetailsPage/SwapDetailsPage.js +1 -1
- package/pages/SwapPage/StatusBottomSheet.js +27 -38
- package/pages/SwapPage/SwapPage.js +5 -1
- package/providers/SDKProvider/SDKProvider.d.ts +4 -0
- package/providers/SDKProvider/SDKProvider.js +19 -0
- package/providers/SDKProvider/index.d.ts +1 -0
- package/providers/SDKProvider/index.js +1 -0
- package/providers/SwapFormProvider/SwapFormProvider.js +39 -11
- package/providers/TelemetryProvider/TelemetryProvider.d.ts +4 -0
- package/providers/TelemetryProvider/TelemetryProvider.js +7 -0
- package/providers/TelemetryProvider/index.d.ts +1 -0
- package/providers/TelemetryProvider/index.js +1 -0
- package/providers/WalletProvider/WalletProvider.d.ts +1 -4
- package/providers/WalletProvider/WalletProvider.js +10 -3
- package/providers/WidgetProvider/WidgetProvider.js +3 -18
- package/providers/index.d.ts +2 -0
- package/providers/index.js +2 -0
- package/stores/chains/index.d.ts +4 -0
- package/stores/chains/index.js +4 -0
- package/stores/chains/types.d.ts +8 -0
- package/stores/chains/types.js +1 -0
- package/stores/chains/useChainOrder.d.ts +1 -0
- package/stores/chains/useChainOrder.js +5 -0
- package/stores/chains/useChainOrderStore.d.ts +19 -0
- package/stores/chains/useChainOrderStore.js +36 -0
- package/stores/chains/useInitializeChainOrder.d.ts +1 -0
- package/stores/chains/useInitializeChainOrder.js +5 -0
- package/stores/route/index.d.ts +2 -1
- package/stores/route/index.js +2 -1
- package/stores/route/useExecutingRoutesIds.d.ts +1 -0
- package/stores/route/useExecutingRoutesIds.js +13 -0
- package/stores/route/useRouteStore.js +5 -4
- package/stores/route/utils.d.ts +4 -0
- package/stores/route/utils.js +15 -0
- package/stores/settings/useSettingsStore.js +5 -2
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +5 -0
- package/types/events.js +6 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/widget.d.ts +2 -1
- package/utils/colors.d.ts +1 -1
- package/utils/navigationRoutes.d.ts +5 -0
- package/utils/navigationRoutes.js +30 -3
- package/cjs/components/SwapButton/SwapButton.style.d.ts +0 -65
- package/cjs/components/SwapButton/SwapButton.style.js +0 -15
- package/cjs/components/SwapsInProgress/SwapsInProgress.js +0 -29
- package/cjs/components/SwapsInProgress/SwapsInProgress.style.js +0 -17
- package/cjs/components/SwapsInProgress/index.d.ts +0 -1
- package/cjs/config/lifi.d.ts +0 -4
- package/cjs/config/lifi.js +0 -14
- package/cjs/pages/SelectTokenPage/ChainSelect.js +0 -31
- package/cjs/pages/SwapPage/utils.d.ts +0 -6
- package/cjs/pages/SwapPage/utils.js +0 -93
- package/cjs/stores/route/useExecutingRoutes.d.ts +0 -2
- package/cjs/stores/route/useExecutingRoutes.js +0 -13
- package/components/Step/utils.js +0 -89
- package/components/SwapButton/SwapButton.style.d.ts +0 -65
- package/components/SwapButton/SwapButton.style.js +0 -12
- package/components/SwapsInProgress/SwapsInProgress.js +0 -25
- package/components/SwapsInProgress/SwapsInProgress.style.js +0 -14
- package/components/SwapsInProgress/index.d.ts +0 -1
- package/components/SwapsInProgress/index.js +0 -1
- package/config/lifi.d.ts +0 -4
- package/config/lifi.js +0 -7
- package/pages/SelectTokenPage/ChainSelect.js +0 -27
- package/pages/SwapPage/utils.d.ts +0 -6
- package/stores/route/useExecutingRoutes.d.ts +0 -2
- package/stores/route/useExecutingRoutes.js +0 -6
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Done as DoneIcon, Info as InfoIcon, Warning as WarningIcon, } from '@mui/icons-material';
|
|
3
3
|
import { Box, Button, Typography } from '@mui/material';
|
|
4
|
-
import { useEffect,
|
|
4
|
+
import { useEffect, useRef } from 'react';
|
|
5
5
|
import { useFormContext } from 'react-hook-form';
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
import { BottomSheet } from '../../components/BottomSheet';
|
|
8
8
|
import { Token } from '../../components/Token';
|
|
9
|
-
import { useChains, useNavigateBack, useTokenBalance } from '../../hooks';
|
|
9
|
+
import { getProcessMessage, useChains, useNavigateBack, useTokenBalance, } from '../../hooks';
|
|
10
10
|
import { SwapFormKey } from '../../providers';
|
|
11
11
|
import { IconCircle, IconContainer, iconStyles, } from './StatusBottomSheet.style';
|
|
12
|
-
import { getProcessMessage } from './utils';
|
|
13
12
|
export const StatusBottomSheet = ({ status, route, }) => {
|
|
14
|
-
var _a, _b, _c, _d, _e;
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
15
14
|
const { t } = useTranslation();
|
|
16
15
|
const { navigateBack } = useNavigateBack();
|
|
17
16
|
const ref = useRef(null);
|
|
@@ -31,41 +30,31 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
31
30
|
clearFromAmount();
|
|
32
31
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.closeDrawer();
|
|
33
32
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
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');
|
|
52
|
-
if (!step || !process) {
|
|
53
|
-
return {};
|
|
54
|
-
}
|
|
55
|
-
return getProcessMessage(t, getChainById, step, process);
|
|
33
|
+
let title;
|
|
34
|
+
let message;
|
|
35
|
+
switch (status) {
|
|
36
|
+
case 'success':
|
|
37
|
+
title = t('swap.success.title.fundsReceived');
|
|
38
|
+
message = t('swap.success.message.fundsReceived', {
|
|
39
|
+
amount: token === null || token === void 0 ? void 0 : token.amount,
|
|
40
|
+
tokenSymbol: token === null || token === void 0 ? void 0 : token.symbol,
|
|
41
|
+
chainName: (_a = getChainById(route.toChainId)) === null || _a === void 0 ? void 0 : _a.name,
|
|
42
|
+
});
|
|
43
|
+
break;
|
|
44
|
+
case 'error': {
|
|
45
|
+
const step = route.steps.find((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
46
|
+
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');
|
|
47
|
+
if (!step || !process) {
|
|
48
|
+
break;
|
|
56
49
|
}
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
const processMessage = getProcessMessage(t, getChainById, step, process);
|
|
51
|
+
title = processMessage.title;
|
|
52
|
+
message = processMessage.message;
|
|
53
|
+
break;
|
|
59
54
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
route.toChainId,
|
|
64
|
-
status,
|
|
65
|
-
t,
|
|
66
|
-
token === null || token === void 0 ? void 0 : token.amount,
|
|
67
|
-
token === null || token === void 0 ? void 0 : token.symbol,
|
|
68
|
-
]);
|
|
55
|
+
default:
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
69
58
|
useEffect(() => {
|
|
70
59
|
var _a, _b;
|
|
71
60
|
if ((status === 'success' || status === 'error') &&
|
|
@@ -74,5 +63,5 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
74
63
|
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.openDrawer();
|
|
75
64
|
}
|
|
76
65
|
}, [refetchBalance, status]);
|
|
77
|
-
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: (
|
|
66
|
+
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: "outlined", fullWidth: true, onClick: handleClose }, { children: t('button.seeDetails') })) }))) : null] })) })));
|
|
78
67
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Button } from '@mui/material';
|
|
3
3
|
import { Fragment } from 'react';
|
|
4
|
+
import { useFormContext } from 'react-hook-form';
|
|
4
5
|
import { useTranslation } from 'react-i18next';
|
|
5
6
|
import { useLocation } from 'react-router-dom';
|
|
6
7
|
import { GasSufficiencyMessage } from '../../components/GasSufficiencyMessage';
|
|
@@ -8,12 +9,14 @@ import { Step } from '../../components/Step';
|
|
|
8
9
|
import { StepDivider } from '../../components/StepDivider';
|
|
9
10
|
import { SwapButton } from '../../components/SwapButton';
|
|
10
11
|
import { useNavigateBack, useRouteExecution } from '../../hooks';
|
|
12
|
+
import { SwapFormKey } from '../../providers';
|
|
11
13
|
import { StatusBottomSheet } from './StatusBottomSheet';
|
|
12
14
|
import { Container } from './SwapPage.style';
|
|
13
15
|
export const SwapPage = () => {
|
|
14
16
|
const { t } = useTranslation();
|
|
15
17
|
const { state } = useLocation();
|
|
16
18
|
const { navigateBack } = useNavigateBack();
|
|
19
|
+
const { setValue, formState: { isValid, isValidating }, } = useFormContext();
|
|
17
20
|
const { route, status, executeRoute, restartRoute, deleteRoute } = useRouteExecution(state === null || state === void 0 ? void 0 : state.routeId);
|
|
18
21
|
const handleRemoveRoute = () => {
|
|
19
22
|
navigateBack();
|
|
@@ -22,6 +25,7 @@ export const SwapPage = () => {
|
|
|
22
25
|
const handleSwapClick = () => {
|
|
23
26
|
if (status === 'idle') {
|
|
24
27
|
executeRoute();
|
|
28
|
+
setValue(SwapFormKey.FromAmount, '');
|
|
25
29
|
}
|
|
26
30
|
if (status === 'error') {
|
|
27
31
|
restartRoute();
|
|
@@ -41,5 +45,5 @@ export const SwapPage = () => {
|
|
|
41
45
|
return (_jsxs(Fragment, { children: [_jsx(Step, { step: step, fromToken: index === 0
|
|
42
46
|
? Object.assign(Object.assign({}, step.action.fromToken), { amount: step.action.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
43
47
|
? Object.assign(Object.assign({}, step.action.toToken), { amount: (_b = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.toAmount) !== null && _b !== void 0 ? _b : step.estimate.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id));
|
|
44
|
-
}), status === 'idle' ? (_jsx(GasSufficiencyMessage, { route: route, mt: 2 })) : null, status === 'idle' || status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, currentRoute: route }) }))) : null, status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "outlined", onClick: handleRemoveRoute, fullWidth: true }, { children: t('button.removeSwap') })) }))) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null] }));
|
|
48
|
+
}), status === 'idle' ? (_jsx(GasSufficiencyMessage, { route: route, mt: 2 })) : null, status === 'idle' || status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, currentRoute: route, disable: status === 'idle' && (isValidating || !isValid) }) }))) : null, status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "outlined", onClick: handleRemoveRoute, fullWidth: true }, { children: t('button.removeSwap') })) }))) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null] }));
|
|
45
49
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import LIFI from '@lifi/sdk';
|
|
3
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
4
|
+
import { useWidgetConfig } from '../WidgetProvider';
|
|
5
|
+
let lifi;
|
|
6
|
+
const SDKContext = createContext(null);
|
|
7
|
+
export const useLiFi = () => useContext(SDKContext);
|
|
8
|
+
export const SDKProvider = ({ children, }) => {
|
|
9
|
+
const { sdkConfig, integrator } = useWidgetConfig();
|
|
10
|
+
const value = useMemo(() => {
|
|
11
|
+
const config = Object.assign(Object.assign({}, sdkConfig), { defaultRouteOptions: Object.assign(Object.assign({}, sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.defaultRouteOptions), { integrator: integrator !== null && integrator !== void 0 ? integrator : window.location.hostname }) });
|
|
12
|
+
if (!lifi) {
|
|
13
|
+
lifi = new LIFI(Object.assign({ disableVersionCheck: true }, config));
|
|
14
|
+
}
|
|
15
|
+
lifi.setConfig(config);
|
|
16
|
+
return lifi;
|
|
17
|
+
}, [integrator, sdkConfig]);
|
|
18
|
+
return _jsx(SDKContext.Provider, Object.assign({ value: value }, { children: children }));
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SDKProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SDKProvider';
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { ChainId } from '@lifi/sdk';
|
|
3
3
|
import { useEffect } from 'react';
|
|
4
4
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
5
|
+
import { useChainOrderStore, useSetChainOrder } from '../../stores/chains';
|
|
5
6
|
import { useWallet } from '../WalletProvider';
|
|
6
7
|
import { useWidgetConfig } from '../WidgetProvider';
|
|
7
8
|
import { SwapFormKey } from './types';
|
|
@@ -11,6 +12,7 @@ export const formDefaultValues = {
|
|
|
11
12
|
[SwapFormKey.TokenSearchFilter]: '',
|
|
12
13
|
};
|
|
13
14
|
export const SwapFormProvider = ({ children, }) => {
|
|
15
|
+
const [setChain] = useSetChainOrder();
|
|
14
16
|
const { account } = useWallet();
|
|
15
17
|
const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress } = useWidgetConfig();
|
|
16
18
|
const methods = useForm({
|
|
@@ -24,24 +26,50 @@ export const SwapFormProvider = ({ children, }) => {
|
|
|
24
26
|
if (!account.isActive || !account.chainId) {
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const [fromChainValue, toChainValue] = methods.getValues([
|
|
30
|
+
SwapFormKey.FromChain,
|
|
31
|
+
SwapFormKey.ToChain,
|
|
32
|
+
]);
|
|
33
|
+
const { isDirty: isFromChainDirty } = methods.getFieldState(SwapFormKey.FromChain, methods.formState);
|
|
34
|
+
const { isDirty: isToChainDirty } = methods.getFieldState(SwapFormKey.ToChain, methods.formState);
|
|
35
|
+
const { isDirty: isFromTokenDirty } = methods.getFieldState(SwapFormKey.FromToken, methods.formState);
|
|
36
|
+
const { isDirty: isToTokenDirty } = methods.getFieldState(SwapFormKey.ToToken, methods.formState);
|
|
37
|
+
// Users can switch chains in the wallet.
|
|
38
|
+
// If we don't have a chain in the ordered chain list we should add it.
|
|
39
|
+
setChain(account.chainId);
|
|
40
|
+
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
41
|
+
// we should make a recently switched chain as current.
|
|
42
|
+
const { chainOrder } = useChainOrderStore.getState();
|
|
43
|
+
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
44
|
+
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
45
|
+
if ((!fromChain && !isFromChainDirty && !isFromTokenDirty) ||
|
|
46
|
+
!hasFromChainInOrderedList) {
|
|
30
47
|
methods.setValue(SwapFormKey.FromChain, account.chainId, {
|
|
31
48
|
shouldDirty: false,
|
|
32
|
-
|
|
49
|
+
});
|
|
50
|
+
methods.setValue(SwapFormKey.FromToken, '', {
|
|
51
|
+
shouldDirty: false,
|
|
52
|
+
});
|
|
53
|
+
methods.setValue(SwapFormKey.FromAmount, '', {
|
|
54
|
+
shouldDirty: false,
|
|
33
55
|
});
|
|
34
56
|
}
|
|
35
|
-
if (!toChain &&
|
|
36
|
-
!
|
|
37
|
-
!isToChainTouched &&
|
|
38
|
-
!isFromChainDirty &&
|
|
39
|
-
!isFromChainTouched) {
|
|
57
|
+
if ((!toChain && !isToChainDirty && !isToTokenDirty) ||
|
|
58
|
+
!hasToChainInOrderedList) {
|
|
40
59
|
methods.setValue(SwapFormKey.ToChain, account.chainId, {
|
|
41
60
|
shouldDirty: false,
|
|
42
|
-
|
|
61
|
+
});
|
|
62
|
+
methods.setValue(SwapFormKey.ToToken, '', {
|
|
63
|
+
shouldDirty: false,
|
|
43
64
|
});
|
|
44
65
|
}
|
|
45
|
-
}, [
|
|
66
|
+
}, [
|
|
67
|
+
account.chainId,
|
|
68
|
+
account.isActive,
|
|
69
|
+
fromChain,
|
|
70
|
+
methods,
|
|
71
|
+
setChain,
|
|
72
|
+
toChain,
|
|
73
|
+
]);
|
|
46
74
|
return _jsx(FormProvider, Object.assign({}, methods, { children: children }));
|
|
47
75
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useWidgetConfig } from '..';
|
|
2
|
+
import { useTelemetry } from '../../hooks';
|
|
3
|
+
export const TelemetryProvider = ({ children }) => {
|
|
4
|
+
const config = useWidgetConfig();
|
|
5
|
+
useTelemetry(config === null || config === void 0 ? void 0 : config.disableTelemetry);
|
|
6
|
+
return children;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TelemetryProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TelemetryProvider';
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { Signer } from 'ethers';
|
|
2
2
|
import type { FC, PropsWithChildren } from 'react';
|
|
3
|
-
import type { WidgetWalletManagement } from '../../types';
|
|
4
3
|
import type { WalletContextProps } from './types';
|
|
5
4
|
export declare const useWallet: () => WalletContextProps;
|
|
6
|
-
export declare const WalletProvider: FC<PropsWithChildren
|
|
7
|
-
walletManagement?: WidgetWalletManagement;
|
|
8
|
-
}>>;
|
|
5
|
+
export declare const WalletProvider: FC<PropsWithChildren>;
|
|
9
6
|
export declare const extractAccountFromSigner: (signer?: Signer) => Promise<{
|
|
10
7
|
address: string | undefined;
|
|
11
8
|
isActive: boolean;
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { jsx as _jsx } 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 { useWidgetConfig } from '../WidgetProvider';
|
|
13
14
|
const stub = () => {
|
|
14
15
|
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
15
16
|
};
|
|
@@ -23,7 +24,8 @@ const initialContext = {
|
|
|
23
24
|
};
|
|
24
25
|
const WalletContext = createContext(initialContext);
|
|
25
26
|
export const useWallet = () => useContext(WalletContext);
|
|
26
|
-
export const WalletProvider = ({ children
|
|
27
|
+
export const WalletProvider = ({ children }) => {
|
|
28
|
+
const { walletManagement } = useWidgetConfig();
|
|
27
29
|
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, provider, } = useLiFiWalletManagement();
|
|
28
30
|
const [account, setAccount] = useState({});
|
|
29
31
|
const connect = useCallback((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -68,8 +70,13 @@ export const WalletProvider = ({ children, walletManagement }) => {
|
|
|
68
70
|
// keep account information up to date
|
|
69
71
|
useEffect(() => {
|
|
70
72
|
const updateAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
let account;
|
|
74
|
+
if (walletManagement) {
|
|
75
|
+
account = yield extractAccountFromSigner(walletManagement === null || walletManagement === void 0 ? void 0 : walletManagement.signer);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
account = yield extractAccountFromSigner(signer);
|
|
79
|
+
}
|
|
73
80
|
setAccount(account);
|
|
74
81
|
});
|
|
75
82
|
updateAccount();
|
|
@@ -10,20 +10,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import {
|
|
14
|
-
import { createContext, useContext,
|
|
15
|
-
import { updateLiFiConfig } from '../../config/lifi';
|
|
16
|
-
import { name, version } from '../../config/version';
|
|
17
|
-
const stub = () => {
|
|
18
|
-
throw new Error('You forgot to wrap your component in <WidgetProvider>.');
|
|
19
|
-
};
|
|
13
|
+
import { getChainByKey } from '@lifi/sdk';
|
|
14
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
20
15
|
const initialContext = {
|
|
21
16
|
disabledChains: [],
|
|
22
17
|
};
|
|
23
18
|
const WidgetContext = createContext(initialContext);
|
|
24
19
|
export const useWidgetConfig = () => useContext(WidgetContext);
|
|
25
20
|
export const WidgetProvider = (_a) => {
|
|
26
|
-
var { children } = _a, _b = _a.config, _c = _b === void 0 ? {} : _b, { fromChain, fromToken, toChain, toToken, fromAmount
|
|
21
|
+
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"]);
|
|
27
22
|
const value = useMemo(() => {
|
|
28
23
|
var _a, _b, _c, _d;
|
|
29
24
|
try {
|
|
@@ -53,15 +48,5 @@ export const WidgetProvider = (_a) => {
|
|
|
53
48
|
return config;
|
|
54
49
|
}
|
|
55
50
|
}, [config, fromAmount, fromChain, fromToken, toChain, toToken]);
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
updateLiFiConfig({
|
|
58
|
-
defaultRouteOptions: {
|
|
59
|
-
integrator: integrator !== null && integrator !== void 0 ? integrator : window.location.hostname,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
}, [integrator]);
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
checkPackageUpdates(name, version);
|
|
65
|
-
}, []);
|
|
66
51
|
return (_jsx(WidgetContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
67
52
|
};
|
package/providers/index.d.ts
CHANGED
package/providers/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useChainOrder: () => [number[], (chainId: number) => void];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ChainOrderStore } from './types';
|
|
2
|
+
export declare const maxChainToOrder = 9;
|
|
3
|
+
export declare const useChainOrderStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<ChainOrderStore>, "persist"> & {
|
|
4
|
+
persist: {
|
|
5
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ChainOrderStore, {
|
|
6
|
+
chainOrder: number[];
|
|
7
|
+
}>>) => void;
|
|
8
|
+
clearStorage: () => void;
|
|
9
|
+
rehydrate: () => Promise<void>;
|
|
10
|
+
hasHydrated: () => boolean;
|
|
11
|
+
onHydrate: (fn: (state: ChainOrderStore) => void) => () => void;
|
|
12
|
+
onFinishHydration: (fn: (state: ChainOrderStore) => void) => () => void;
|
|
13
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<ChainOrderStore, {
|
|
14
|
+
chainOrder: number[];
|
|
15
|
+
}>>;
|
|
16
|
+
};
|
|
17
|
+
}, "setState"> & {
|
|
18
|
+
setState(nextStateOrUpdater: ChainOrderStore | Partial<ChainOrderStore> | ((state: import("immer/dist/internal").WritableDraft<ChainOrderStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
import create from 'zustand';
|
|
3
|
+
import { persist } from 'zustand/middleware';
|
|
4
|
+
import { immer } from 'zustand/middleware/immer';
|
|
5
|
+
export const maxChainToOrder = 9;
|
|
6
|
+
export const useChainOrderStore = create()(persist(immer((set) => ({
|
|
7
|
+
chainOrder: [],
|
|
8
|
+
availableChains: [],
|
|
9
|
+
initializeChains: (chainIds) => set((state) => {
|
|
10
|
+
state.availableChains = chainIds;
|
|
11
|
+
state.chainOrder = state.chainOrder.filter((chainId) => chainIds.includes(chainId));
|
|
12
|
+
const chainsToAdd = chainIds.filter((chainId) => !state.chainOrder.includes(chainId));
|
|
13
|
+
if (state.chainOrder.length === maxChainToOrder ||
|
|
14
|
+
!chainsToAdd.length) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const chainsToAddLength = maxChainToOrder - state.chainOrder.length;
|
|
18
|
+
for (let index = 0; index < chainsToAddLength; index++) {
|
|
19
|
+
state.chainOrder.push(chainsToAdd[index]);
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
setChain: (chainId) => set((state) => {
|
|
23
|
+
if (state.chainOrder.includes(chainId) ||
|
|
24
|
+
!state.availableChains.includes(chainId)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
state.chainOrder.unshift(chainId);
|
|
28
|
+
if (state.chainOrder.length > maxChainToOrder) {
|
|
29
|
+
state.chainOrder.pop();
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
})), {
|
|
33
|
+
name: 'li.fi-widget-chains-order',
|
|
34
|
+
version: 0,
|
|
35
|
+
partialize: (state) => ({ chainOrder: state.chainOrder }),
|
|
36
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSetChainOrder: () => [(chainId: number) => void, (chainIds: number[]) => void];
|
package/stores/route/index.d.ts
CHANGED
package/stores/route/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useExecutingRoutesIds: (address?: string) => string[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import shallow from 'zustand/shallow';
|
|
2
|
+
import { useRouteStore } from './useRouteStore';
|
|
3
|
+
export const useExecutingRoutesIds = (address) => {
|
|
4
|
+
return useRouteStore((state) => Object.values(state.routes)
|
|
5
|
+
.filter((item) => item.route.fromAddress === address &&
|
|
6
|
+
(item.status === 'loading' || item.status === 'error'))
|
|
7
|
+
.sort((a, b) => {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
return ((_b = (_a = b === null || b === void 0 ? void 0 : b.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0) -
|
|
10
|
+
((_d = (_c = a === null || a === void 0 ? void 0 : a.route.steps[0].execution) === null || _c === void 0 ? void 0 : _c.process[0].startedAt) !== null && _d !== void 0 ? _d : 0);
|
|
11
|
+
})
|
|
12
|
+
.map(({ route }) => route.id), shallow);
|
|
13
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import create from 'zustand';
|
|
2
2
|
import { persist } from 'zustand/middleware';
|
|
3
3
|
import { immer } from 'zustand/middleware/immer';
|
|
4
|
+
import { isRouteCompleted, isRouteFailed } from './utils';
|
|
4
5
|
export const useRouteStore = create()(persist(immer((set) => ({
|
|
5
6
|
routes: {},
|
|
6
7
|
setExecutableRoute: (route) => set((state) => {
|
|
@@ -18,12 +19,12 @@ export const useRouteStore = create()(persist(immer((set) => ({
|
|
|
18
19
|
updateRoute: (route) => set((state) => {
|
|
19
20
|
if (state.routes[route.id]) {
|
|
20
21
|
state.routes[route.id].route = route;
|
|
21
|
-
const isFailed = route
|
|
22
|
+
const isFailed = isRouteFailed(route);
|
|
22
23
|
if (isFailed) {
|
|
23
24
|
state.routes[route.id].status = 'error';
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
|
-
const isDone = route
|
|
27
|
+
const isDone = isRouteCompleted(route);
|
|
27
28
|
if (isDone) {
|
|
28
29
|
state.routes[route.id].status = 'success';
|
|
29
30
|
return;
|
|
@@ -62,12 +63,12 @@ export const useRouteStore = create()(persist(immer((set) => ({
|
|
|
62
63
|
route,
|
|
63
64
|
status: 'idle',
|
|
64
65
|
};
|
|
65
|
-
const isFailed = route
|
|
66
|
+
const isFailed = isRouteFailed(route);
|
|
66
67
|
if (isFailed) {
|
|
67
68
|
state.routes[route.id].status = 'error';
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
|
-
const isDone = route
|
|
71
|
+
const isDone = isRouteCompleted(route);
|
|
71
72
|
if (isDone) {
|
|
72
73
|
state.routes[route.id].status = 'success';
|
|
73
74
|
return;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const isRouteCompleted = (route) => {
|
|
2
|
+
return route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
|
|
3
|
+
};
|
|
4
|
+
export const isRouteFailed = (route) => {
|
|
5
|
+
return route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
6
|
+
};
|
|
7
|
+
export const isRouteActive = (route) => {
|
|
8
|
+
if (!route) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const isDone = isRouteCompleted(route);
|
|
12
|
+
const isFailed = isRouteFailed(route);
|
|
13
|
+
const alreadyStarted = route.steps.some((step) => step.execution);
|
|
14
|
+
return !isDone && !isFailed && alreadyStarted;
|
|
15
|
+
};
|
|
@@ -36,12 +36,15 @@ export const useSettingsStore = create()(persist(immer((set) => ({
|
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
if (state[`_enabled${toolType}`]) {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// Add a new tools
|
|
40
|
+
const enabledTools = tools
|
|
41
|
+
.filter((tool) => !Object.prototype.hasOwnProperty.call(state[`_enabled${toolType}`], tool))
|
|
41
42
|
.reduce((values, tool) => {
|
|
42
43
|
values[tool] = true;
|
|
43
44
|
return values;
|
|
44
45
|
}, state[`_enabled${toolType}`]);
|
|
46
|
+
// Filter tools we no longer have
|
|
47
|
+
state[`_enabled${toolType}`] = Object.fromEntries(Object.entries(enabledTools).filter(([key]) => tools.includes(key)));
|
|
45
48
|
}
|
|
46
49
|
else {
|
|
47
50
|
state[`_enabled${toolType}`] = tools.reduce((values, tool) => {
|