@lifi/widget 1.18.9 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +3 -3
- package/cjs/App.js +3 -3
- package/cjs/components/ActiveSwaps/ActiveSwaps.js +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
- package/cjs/components/AppContainer.d.ts +11 -1
- package/cjs/components/AppContainer.js +3 -6
- package/cjs/components/BottomSheet/BottomSheet.js +9 -32
- package/cjs/components/BottomSheet/types.d.ts +2 -2
- package/cjs/components/Card/Card.js +1 -1
- package/cjs/components/Card/CardHeader.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.js +1 -1
- package/cjs/components/ChainSelect/useChainSelect.js +2 -4
- package/cjs/components/Dialog.d.ts +22 -1
- package/cjs/components/Dialog.js +23 -20
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +19 -22
- package/cjs/components/Header/NavigationHeader.js +1 -1
- package/cjs/components/Header/WalletHeader.js +2 -2
- package/cjs/components/PoweredBy/PoweredBy.js +1 -1
- package/cjs/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
- package/cjs/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
- package/cjs/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/cjs/components/SendToWallet/SendToWallet.d.ts +1 -0
- package/cjs/components/SendToWallet/SendToWallet.js +10 -5
- package/cjs/components/SendToWallet/SendToWalletButton.js +2 -2
- package/cjs/components/Step/StepProcess.js +1 -1
- package/cjs/components/SwapButton/SwapButton.js +4 -4
- package/cjs/components/SwapButton/types.d.ts +2 -0
- package/cjs/components/SwapInput/SwapInput.js +6 -2
- package/cjs/components/SwapInput/SwapInputAdornment.js +4 -2
- package/cjs/components/SwapInput/SwapInputAdornment.style.js +1 -13
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +7 -6
- package/cjs/components/SwapRoutes/SwapRoutes.js +4 -4
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +17 -12
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.js +13 -0
- package/cjs/components/TokenList/TokenList.js +9 -6
- package/cjs/config/theme.js +22 -8
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +1 -0
- package/cjs/hooks/index.js +1 -0
- package/cjs/hooks/useExpandableVariant.d.ts +1 -0
- package/cjs/hooks/useExpandableVariant.js +14 -0
- package/cjs/hooks/useGasSufficiency.d.ts +3 -2
- package/cjs/hooks/useGasSufficiency.js +50 -26
- package/cjs/hooks/useSwapRoutes.js +4 -2
- package/cjs/hooks/useTokenBalance.js +2 -2
- package/cjs/i18n/en/translation.json +8 -7
- package/cjs/i18n/index.d.ts +6 -5
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.js +21 -4
- package/cjs/pages/MainPage/MainPage.js +3 -3
- package/cjs/pages/SelectWalletPage/SelectWalletPage.js +1 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
- package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/cjs/pages/SwapPage/SwapPage.js +4 -4
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +3 -2
- package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
- package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.js +46 -0
- package/cjs/providers/SwapFormProvider/types.d.ts +4 -4
- package/cjs/providers/SwapFormProvider/types.js +2 -2
- package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
- package/cjs/providers/WalletProvider/WalletFormUpdate.js +64 -0
- package/cjs/providers/WalletProvider/WalletProvider.js +3 -58
- package/cjs/providers/WidgetProvider/WidgetProvider.js +12 -5
- package/cjs/stores/routes/index.d.ts +1 -1
- package/cjs/stores/routes/index.js +1 -1
- package/cjs/stores/routes/types.d.ts +4 -4
- package/cjs/stores/routes/useRecommendedRouteStore.d.ts +4 -0
- package/cjs/stores/routes/{useSelectedRouteStore.js → useRecommendedRouteStore.js} +4 -4
- package/cjs/stores/routes/useRouteExecutionStore.js +9 -2
- package/cjs/types/widget.d.ts +1 -0
- package/components/ActiveSwaps/ActiveSwaps.js +3 -3
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
- package/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
- package/components/AppContainer.d.ts +11 -1
- package/components/AppContainer.js +2 -4
- package/components/BottomSheet/BottomSheet.js +9 -32
- package/components/BottomSheet/types.d.ts +2 -2
- package/components/Card/Card.js +1 -1
- package/components/Card/CardHeader.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.js +1 -1
- package/components/ChainSelect/useChainSelect.js +2 -4
- package/components/Dialog.d.ts +22 -1
- package/components/Dialog.js +22 -19
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +21 -24
- package/components/Header/NavigationHeader.js +2 -2
- package/components/Header/WalletHeader.js +2 -2
- package/components/PoweredBy/PoweredBy.js +1 -1
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
- package/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
- package/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/components/SendToWallet/SendToWallet.d.ts +1 -0
- package/components/SendToWallet/SendToWallet.js +9 -5
- package/components/SendToWallet/SendToWalletButton.js +2 -2
- package/components/Step/StepProcess.js +1 -1
- package/components/SwapButton/SwapButton.js +4 -4
- package/components/SwapButton/types.d.ts +2 -0
- package/components/SwapInput/SwapInput.js +6 -2
- package/components/SwapInput/SwapInputAdornment.js +4 -2
- package/components/SwapInput/SwapInputAdornment.style.js +2 -14
- package/components/SwapRouteCard/SwapRouteCard.js +8 -7
- package/components/SwapRoutes/SwapRoutes.js +4 -4
- package/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
- package/components/SwapRoutes/SwapRoutesExpanded.js +16 -12
- package/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
- package/components/SwapRoutes/useSetRecommendedRoute.js +9 -0
- package/components/TokenList/TokenList.js +9 -6
- package/config/theme.js +22 -8
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useExpandableVariant.d.ts +1 -0
- package/hooks/useExpandableVariant.js +10 -0
- package/hooks/useGasSufficiency.d.ts +3 -2
- package/hooks/useGasSufficiency.js +50 -26
- package/hooks/useSwapRoutes.js +4 -2
- package/hooks/useTokenBalance.js +2 -2
- package/i18n/en/translation.json +8 -7
- package/i18n/index.d.ts +6 -5
- package/package.json +11 -11
- package/pages/ActiveSwapsPage/ActiveSwapsPage.js +24 -7
- package/pages/MainPage/MainPage.js +3 -3
- package/pages/SelectWalletPage/SelectWalletPage.js +1 -1
- package/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
- package/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/pages/SwapPage/SwapPage.js +5 -5
- package/providers/SwapFormProvider/SwapFormProvider.js +4 -3
- package/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
- package/providers/SwapFormProvider/URLSearchParamsBuilder.js +42 -0
- package/providers/SwapFormProvider/types.d.ts +4 -4
- package/providers/SwapFormProvider/types.js +2 -2
- package/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
- package/providers/WalletProvider/WalletFormUpdate.js +60 -0
- package/providers/WalletProvider/WalletProvider.js +5 -60
- package/providers/WidgetProvider/WidgetProvider.js +12 -5
- package/stores/routes/index.d.ts +1 -1
- package/stores/routes/index.js +1 -1
- package/stores/routes/types.d.ts +4 -4
- package/stores/routes/useRecommendedRouteStore.d.ts +4 -0
- package/stores/routes/useRecommendedRouteStore.js +9 -0
- package/stores/routes/useRouteExecutionStore.js +9 -2
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +1 -0
- package/cjs/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
- package/cjs/components/SwapRoutes/useSetSelectedRoute.js +0 -13
- package/cjs/stores/routes/useSelectedRouteStore.d.ts +0 -4
- package/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
- package/components/SwapRoutes/useSetSelectedRoute.js +0 -9
- package/stores/routes/useSelectedRouteStore.d.ts +0 -4
- package/stores/routes/useSelectedRouteStore.js +0 -9
package/cjs/i18n/index.d.ts
CHANGED
|
@@ -47,10 +47,6 @@ export declare const resources: {
|
|
|
47
47
|
routes: string;
|
|
48
48
|
approximateCurrency: string;
|
|
49
49
|
currency: string;
|
|
50
|
-
sendToRecipient: string;
|
|
51
|
-
addressConfirmation: string;
|
|
52
|
-
gas: string;
|
|
53
|
-
minutes: string;
|
|
54
50
|
tokenSearch: string;
|
|
55
51
|
selectChain: string;
|
|
56
52
|
selectToken: string;
|
|
@@ -102,11 +98,13 @@ export declare const resources: {
|
|
|
102
98
|
insufficientGas: string;
|
|
103
99
|
deleteSwap: string;
|
|
104
100
|
deleteSwapHistory: string;
|
|
101
|
+
deleteActiveSwaps: string;
|
|
105
102
|
};
|
|
106
103
|
message: {
|
|
107
104
|
insufficientFunds: string;
|
|
108
105
|
insufficientGas: string;
|
|
109
|
-
|
|
106
|
+
deleteSwapHistory: string;
|
|
107
|
+
deleteActiveSwaps: string;
|
|
110
108
|
};
|
|
111
109
|
};
|
|
112
110
|
error: {
|
|
@@ -183,6 +181,9 @@ export declare const resources: {
|
|
|
183
181
|
text: string;
|
|
184
182
|
};
|
|
185
183
|
progressToNextUpdate: string;
|
|
184
|
+
numberOfSteps: string;
|
|
185
|
+
estimatedTime: string;
|
|
186
|
+
estimatedNetworkFee: string;
|
|
186
187
|
};
|
|
187
188
|
};
|
|
188
189
|
};
|
|
@@ -2,20 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActiveSwapsPage = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
/* eslint-disable consistent-return */
|
|
6
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
5
7
|
const material_1 = require("@mui/material");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const react_i18next_1 = require("react-i18next");
|
|
6
10
|
const ActiveSwaps_1 = require("../../components/ActiveSwaps");
|
|
11
|
+
const Dialog_1 = require("../../components/Dialog");
|
|
12
|
+
const Header_1 = require("../../components/Header");
|
|
7
13
|
const providers_1 = require("../../providers");
|
|
8
14
|
const stores_1 = require("../../stores");
|
|
9
15
|
const ActiveSwapsEmpty_1 = require("./ActiveSwapsEmpty");
|
|
10
16
|
const ActiveSwapsPage = () => {
|
|
17
|
+
const { t } = (0, react_i18next_1.useTranslation)();
|
|
11
18
|
const { account } = (0, providers_1.useWallet)();
|
|
12
19
|
const executingRoutes = (0, stores_1.useExecutingRoutesIds)(account.address);
|
|
20
|
+
const deleteRoutes = (0, stores_1.useRouteExecutionStore)((store) => store.deleteRoutes);
|
|
21
|
+
const [open, setOpen] = (0, react_1.useState)(false);
|
|
22
|
+
const toggleDialog = (0, react_1.useCallback)(() => {
|
|
23
|
+
setOpen((open) => !open);
|
|
24
|
+
}, []);
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
if (executingRoutes.length) {
|
|
27
|
+
return Header_1.useHeaderActionStore.getState().setAction((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium", edge: "end", onClick: toggleDialog }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.DeleteOutline, {}) })));
|
|
28
|
+
}
|
|
29
|
+
}, [executingRoutes.length, toggleDialog]);
|
|
13
30
|
if (!executingRoutes.length) {
|
|
14
31
|
return (0, jsx_runtime_1.jsx)(ActiveSwapsEmpty_1.ActiveSwapsEmpty, {});
|
|
15
32
|
}
|
|
16
|
-
return ((0, jsx_runtime_1.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Container, Object.assign({ disableGutters: true }, { children: [(0, jsx_runtime_1.jsx)(material_1.List, Object.assign({ sx: {
|
|
34
|
+
paddingLeft: 1.5,
|
|
35
|
+
paddingRight: 1.5,
|
|
36
|
+
} }, { children: executingRoutes.map((routeId) => ((0, jsx_runtime_1.jsx)(ActiveSwaps_1.ActiveSwapItem, { routeId: routeId }, routeId))) })), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, Object.assign({ open: open, onClose: toggleDialog }, { children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: t('swap.warning.title.deleteActiveSwaps') }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('swap.warning.message.deleteActiveSwaps') }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ onClick: toggleDialog }, { children: t('button.cancel') })), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", onClick: () => deleteRoutes('active'), autoFocus: true }, { children: t('button.delete') }))] })] }))] })));
|
|
20
37
|
};
|
|
21
38
|
exports.ActiveSwapsPage = ActiveSwapsPage;
|
|
@@ -9,11 +9,11 @@ const SelectChainAndToken_1 = require("../../components/SelectChainAndToken");
|
|
|
9
9
|
const SendToWallet_1 = require("../../components/SendToWallet");
|
|
10
10
|
const SwapInput_1 = require("../../components/SwapInput");
|
|
11
11
|
const SwapRoutes_1 = require("../../components/SwapRoutes");
|
|
12
|
-
const
|
|
12
|
+
const hooks_1 = require("../../hooks");
|
|
13
13
|
const MainPage_style_1 = require("./MainPage.style");
|
|
14
14
|
const MainSwapButton_1 = require("./MainSwapButton");
|
|
15
15
|
const MainPage = () => {
|
|
16
|
-
const
|
|
17
|
-
return ((0, jsx_runtime_1.jsxs)(MainPage_style_1.FormContainer, Object.assign({ disableGutters: true }, { children: [(0, jsx_runtime_1.jsx)(ActiveSwaps_1.ActiveSwaps, { mx: 3, mt: 1, mb: 2 }), (0, jsx_runtime_1.jsx)(SelectChainAndToken_1.SelectChainAndToken, { mt: 1, mx: 3, mb: 3 }), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mx: 3, mb: 3 }, { children: (0, jsx_runtime_1.jsx)(SwapInput_1.SwapInput, { formType: "from" }) })),
|
|
16
|
+
const expandable = (0, hooks_1.useExpandableVariant)();
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)(MainPage_style_1.FormContainer, Object.assign({ disableGutters: true }, { children: [(0, jsx_runtime_1.jsx)(ActiveSwaps_1.ActiveSwaps, { mx: 3, mt: 1, mb: 2 }), (0, jsx_runtime_1.jsx)(SelectChainAndToken_1.SelectChainAndToken, { mt: 1, mx: 3, mb: 3 }), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mx: 3, mb: 3 }, { children: (0, jsx_runtime_1.jsx)(SwapInput_1.SwapInput, { formType: "from" }) })), !expandable ? (0, jsx_runtime_1.jsx)(SwapRoutes_1.SwapRoutes, { mx: 3, mb: 3 }) : null, (0, jsx_runtime_1.jsx)(GasSufficiencyMessage_1.GasSufficiencyMessage, { mx: 3, mb: 3 }), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ mx: 3, mb: 1 }, { children: [(0, jsx_runtime_1.jsx)(SendToWallet_1.SendToWallet, { mb: 3 }), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: { display: 'flex' } }, { children: [(0, jsx_runtime_1.jsx)(MainSwapButton_1.MainSwapButton, {}), (0, jsx_runtime_1.jsx)(SendToWallet_1.SendToWalletButton, {})] }))] }))] })));
|
|
18
18
|
};
|
|
19
19
|
exports.MainPage = MainPage;
|
|
@@ -48,6 +48,6 @@ const SelectWalletPage = () => {
|
|
|
48
48
|
paddingRight: 1.5,
|
|
49
49
|
} }, { children: wallet_management_1.supportedWallets.map((wallet) => ((0, jsx_runtime_1.jsxs)(SelectWalletPage_style_1.ListItemButton, Object.assign({ onClick: () => handleConnect(wallet), disableRipple: true }, { children: [(0, jsx_runtime_1.jsx)(material_1.ListItemAvatar, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, Object.assign({ src: wallet.icon.src || wallet.icon, alt: wallet.name }, { children: wallet.name[0] })) }), (0, jsx_runtime_1.jsx)(SelectWalletPage_style_1.ListItemText, { primary: wallet.name })] }), wallet.name))) })), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, Object.assign({ open: walletIdentity.show, onClose: closeDialog }, { children: [(0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('wallet.extensionNotFound', {
|
|
50
50
|
name: (_a = walletIdentity.wallet) === null || _a === void 0 ? void 0 : _a.name,
|
|
51
|
-
}) }) }), (0, jsx_runtime_1.jsx)(material_1.DialogActions, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ onClick: closeDialog, autoFocus: true }, { children: t('button.ok') })) })] }))] })));
|
|
51
|
+
}) }) }), (0, jsx_runtime_1.jsx)(material_1.DialogActions, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", onClick: closeDialog, autoFocus: true }, { children: t('button.ok') })) })] }))] })));
|
|
52
52
|
};
|
|
53
53
|
exports.SelectWalletPage = SelectWalletPage;
|
|
@@ -46,7 +46,7 @@ const SwapDetailsPage = () => {
|
|
|
46
46
|
yield navigator.clipboard.writeText((_c = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id) !== null && _c !== void 0 ? _c : '');
|
|
47
47
|
});
|
|
48
48
|
(0, react_1.useEffect)(() => {
|
|
49
|
-
return Header_1.useHeaderActionStore.getState().setAction((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium",
|
|
49
|
+
return Header_1.useHeaderActionStore.getState().setAction((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium", edge: "end", onClick: toggleDialog }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.DeleteOutline, {}) })));
|
|
50
50
|
}, [toggleDialog]);
|
|
51
51
|
const startedAt = new Date((_b = (_a = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0);
|
|
52
52
|
return ((0, jsx_runtime_1.jsxs)(SwapDetailsPage_style_1.Container, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
|
|
@@ -61,6 +61,6 @@ const SwapDetailsPage = () => {
|
|
|
61
61
|
}), (0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ mt: 2 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
|
|
62
62
|
display: 'flex',
|
|
63
63
|
flex: 1,
|
|
64
|
-
} }, { children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, Object.assign({ flex: 1 }, { children: t('swap.supportId') })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mr: 1, mt: 1 }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium",
|
|
64
|
+
} }, { children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, Object.assign({ flex: 1 }, { children: t('swap.supportId') })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mr: 1, mt: 1 }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium", onClick: copyRouteId }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.ContentCopy, { fontSize: "small" }) })) }))] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' } }, { children: routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id }))] })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", href: "https://discord.com/channels/849912621360218112/863689862514343946", target: "_blank", rel: "nofollow noreferrer", fullWidth: true }, { children: t('button.contactSupport') })) })), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, Object.assign({ open: open, onClose: toggleDialog }, { children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: t('swap.warning.title.deleteSwap') }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ onClick: toggleDialog }, { children: t('button.cancel') })), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", onClick: handleDeleteRoute, autoFocus: true }, { children: t('button.delete') }))] })] }))] }));
|
|
65
65
|
};
|
|
66
66
|
exports.SwapDetailsPage = SwapDetailsPage;
|
|
@@ -25,12 +25,12 @@ const SwapHistoryPage = () => {
|
|
|
25
25
|
}, []);
|
|
26
26
|
(0, react_1.useEffect)(() => {
|
|
27
27
|
if (swaps.length) {
|
|
28
|
-
return Header_1.useHeaderActionStore.getState().setAction((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium",
|
|
28
|
+
return Header_1.useHeaderActionStore.getState().setAction((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium", edge: "end", onClick: toggleDialog }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.DeleteOutline, {}) })));
|
|
29
29
|
}
|
|
30
30
|
}, [swaps.length, toggleDialog]);
|
|
31
31
|
if (!swaps.length) {
|
|
32
32
|
return (0, jsx_runtime_1.jsx)(SwapHistoryEmpty_1.SwapHistoryEmpty, {});
|
|
33
33
|
}
|
|
34
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Container, { children: [(0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ spacing: 2, mt: 1 }, { children: swaps.length ? (swaps.map(({ route }) => ((0, jsx_runtime_1.jsx)(SwapHistoryItem_1.SwapHistoryItem, { route: route }, route.id)))) : ((0, jsx_runtime_1.jsx)(SwapHistoryEmpty_1.SwapHistoryEmpty, {})) })), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, Object.assign({ open: open, onClose: toggleDialog }, { children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: t('swap.warning.title.deleteSwapHistory') }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('swap.warning.message.
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Container, { children: [(0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ spacing: 2, mt: 1 }, { children: swaps.length ? (swaps.map(({ route }) => ((0, jsx_runtime_1.jsx)(SwapHistoryItem_1.SwapHistoryItem, { route: route }, route.id)))) : ((0, jsx_runtime_1.jsx)(SwapHistoryEmpty_1.SwapHistoryEmpty, {})) })), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, Object.assign({ open: open, onClose: toggleDialog }, { children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: t('swap.warning.title.deleteSwapHistory') }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ onClick: toggleDialog }, { children: t('button.cancel') })), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", onClick: () => deleteRoutes('completed'), autoFocus: true }, { children: t('button.delete') }))] })] }))] }));
|
|
35
35
|
};
|
|
36
36
|
exports.SwapHistoryPage = SwapHistoryPage;
|
|
@@ -20,8 +20,8 @@ const StatusBottomSheet = ({ status, route, }) => {
|
|
|
20
20
|
const { navigateBack, navigate } = (0, hooks_1.useNavigateBack)();
|
|
21
21
|
const ref = (0, react_1.useRef)(null);
|
|
22
22
|
const { getChainById } = (0, hooks_1.useChains)();
|
|
23
|
-
const { token, refetch, refetchNewBalance, refetchAllBalances } = (0, hooks_1.useTokenBalance)(route.toToken, route.toAddress);
|
|
24
23
|
const { setValue } = (0, react_hook_form_1.useFormContext)();
|
|
24
|
+
const { token, refetch, refetchNewBalance, refetchAllBalances } = (0, hooks_1.useTokenBalance)(route.toToken, route.toAddress);
|
|
25
25
|
const clearFromAmount = () => {
|
|
26
26
|
refetchAllBalances();
|
|
27
27
|
setValue(providers_1.SwapFormKey.FromAmount, '');
|
|
@@ -33,7 +33,7 @@ const StatusBottomSheet = ({ status, route, }) => {
|
|
|
33
33
|
const handleClose = () => {
|
|
34
34
|
var _a;
|
|
35
35
|
clearFromAmount();
|
|
36
|
-
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.
|
|
36
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
37
37
|
};
|
|
38
38
|
const handleSeeDetails = () => {
|
|
39
39
|
handleClose();
|
|
@@ -76,9 +76,9 @@ const StatusBottomSheet = ({ status, route, }) => {
|
|
|
76
76
|
refetchNewBalance();
|
|
77
77
|
refetch();
|
|
78
78
|
}
|
|
79
|
-
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.
|
|
79
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.open();
|
|
80
80
|
}
|
|
81
81
|
}, [refetch, refetchNewBalance, status]);
|
|
82
|
-
return ((0, jsx_runtime_1.jsx)(BottomSheet_1.BottomSheet, Object.assign({ ref: ref }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ p: 3 }, { children: [(0, jsx_runtime_1.jsxs)(StatusBottomSheet_style_1.IconContainer, { children: [(0, jsx_runtime_1.jsxs)(StatusBottomSheet_style_1.IconCircle, Object.assign({ status: status, mb: 1 }, { children: [status === 'idle' ? ((0, jsx_runtime_1.jsx)(icons_material_1.Info, { color: "primary", sx: StatusBottomSheet_style_1.iconStyles })) : null, status === 'success' ? ((0, jsx_runtime_1.jsx)(icons_material_1.Done, { color: "success", sx: StatusBottomSheet_style_1.iconStyles })) : null, status === 'error' ? ((0, jsx_runtime_1.jsx)(icons_material_1.Warning, { color: "error", sx: StatusBottomSheet_style_1.iconStyles })) : null] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: title })), status === 'success' ? ((0, jsx_runtime_1.jsx)(Token_1.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] }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ pt: 2, pb: 1 }, { children: message })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsxs)(material_1.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' ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "
|
|
82
|
+
return ((0, jsx_runtime_1.jsx)(BottomSheet_1.BottomSheet, Object.assign({ ref: ref }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ p: 3 }, { children: [(0, jsx_runtime_1.jsxs)(StatusBottomSheet_style_1.IconContainer, { children: [(0, jsx_runtime_1.jsxs)(StatusBottomSheet_style_1.IconCircle, Object.assign({ status: status, mb: 1 }, { children: [status === 'idle' ? ((0, jsx_runtime_1.jsx)(icons_material_1.Info, { color: "primary", sx: StatusBottomSheet_style_1.iconStyles })) : null, status === 'success' ? ((0, jsx_runtime_1.jsx)(icons_material_1.Done, { color: "success", sx: StatusBottomSheet_style_1.iconStyles })) : null, status === 'error' ? ((0, jsx_runtime_1.jsx)(icons_material_1.Warning, { color: "error", sx: StatusBottomSheet_style_1.iconStyles })) : null] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: title })), status === 'success' ? ((0, jsx_runtime_1.jsx)(Token_1.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] }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ pt: 2, pb: 1 }, { children: message })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsxs)(material_1.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' ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "text", fullWidth: true, onClick: handleSeeDetails }, { children: t('button.seeDetails') })) }))) : null] })) })));
|
|
83
83
|
};
|
|
84
84
|
exports.StatusBottomSheet = StatusBottomSheet;
|
|
@@ -58,9 +58,9 @@ const SwapPage = () => {
|
|
|
58
58
|
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Step_1.Step, { step: step, fromToken: index === 0
|
|
59
59
|
? Object.assign(Object.assign({}, step.action.fromToken), { amount: step.action.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
60
60
|
? 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 ? ((0, jsx_runtime_1.jsx)(StepDivider_1.StepDivider, {})) : null] }, step.id));
|
|
61
|
-
}), status === 'idle' ? ((0, jsx_runtime_1.jsx)(GasSufficiencyMessage_1.GasSufficiencyMessage, { route: route, mt: 2 })
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
}), status === 'idle' || status === 'error' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(GasSufficiencyMessage_1.GasSufficiencyMessage, { route: route, mt: 2 }), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ mt: 2, display: "flex" }, { children: [(0, jsx_runtime_1.jsx)(SwapButton_1.SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, currentRoute: route, disable: status === 'idle' && (isValidating || !isValid), enableLoading: true }), status === 'error' ? ((0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ onClick: handleRemoveRoute, sx: {
|
|
62
|
+
minWidth: 48,
|
|
63
|
+
marginLeft: 1,
|
|
64
|
+
} }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.Delete, {}) }))) : null] }))] })) : null, route && status ? ((0, jsx_runtime_1.jsx)(StatusBottomSheet_1.StatusBottomSheet, { status: status, route: route })) : null] }));
|
|
65
65
|
};
|
|
66
66
|
exports.SwapPage = SwapPage;
|
|
@@ -5,13 +5,14 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_hook_form_1 = require("react-hook-form");
|
|
6
6
|
const WidgetProvider_1 = require("../WidgetProvider");
|
|
7
7
|
const types_1 = require("./types");
|
|
8
|
+
const URLSearchParamsBuilder_1 = require("./URLSearchParamsBuilder");
|
|
8
9
|
exports.formDefaultValues = {
|
|
9
10
|
[types_1.SwapFormKey.FromAmount]: '',
|
|
10
11
|
[types_1.SwapFormKey.ToAddress]: '',
|
|
11
12
|
[types_1.SwapFormKey.TokenSearchFilter]: '',
|
|
12
13
|
};
|
|
13
14
|
const SwapFormProvider = ({ children, }) => {
|
|
14
|
-
const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
15
|
+
const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress, buildSwapUrl, } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
15
16
|
const methods = (0, react_hook_form_1.useForm)({
|
|
16
17
|
defaultValues: Object.assign(Object.assign({}, exports.formDefaultValues), { fromChain,
|
|
17
18
|
fromToken, fromAmount: (typeof fromAmount === 'number'
|
|
@@ -20,6 +21,6 @@ const SwapFormProvider = ({ children, }) => {
|
|
|
20
21
|
toToken,
|
|
21
22
|
toAddress }),
|
|
22
23
|
});
|
|
23
|
-
return (0, jsx_runtime_1.
|
|
24
|
+
return ((0, jsx_runtime_1.jsxs)(react_hook_form_1.FormProvider, Object.assign({}, methods, { children: [buildSwapUrl ? (0, jsx_runtime_1.jsx)(URLSearchParamsBuilder_1.URLSearchParamsBuilder, {}) : null, children] })));
|
|
24
25
|
};
|
|
25
26
|
exports.SwapFormProvider = SwapFormProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const URLSearchParamsBuilder: () => null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.URLSearchParamsBuilder = void 0;
|
|
15
|
+
const react_1 = require("react");
|
|
16
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
17
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
18
|
+
const types_1 = require("./types");
|
|
19
|
+
const formValueKeys = [
|
|
20
|
+
types_1.SwapFormKey.FromAmount,
|
|
21
|
+
types_1.SwapFormKey.FromChain,
|
|
22
|
+
types_1.SwapFormKey.FromToken,
|
|
23
|
+
types_1.SwapFormKey.ToAddress,
|
|
24
|
+
types_1.SwapFormKey.ToChain,
|
|
25
|
+
types_1.SwapFormKey.ToToken,
|
|
26
|
+
];
|
|
27
|
+
const URLSearchParamsBuilder = () => {
|
|
28
|
+
const { pathname } = (0, react_router_dom_1.useLocation)();
|
|
29
|
+
const touchedFields = __rest((0, react_hook_form_1.useFormState)().touchedFields, []);
|
|
30
|
+
const values = (0, react_hook_form_1.useWatch)({ name: formValueKeys });
|
|
31
|
+
(0, react_1.useEffect)(() => {
|
|
32
|
+
const url = new URL(window.location);
|
|
33
|
+
formValueKeys.forEach((key, index) => {
|
|
34
|
+
if (touchedFields[key] && values[index]) {
|
|
35
|
+
url.searchParams.set(key, values[index]);
|
|
36
|
+
}
|
|
37
|
+
else if (url.searchParams.has(key) && !values[index]) {
|
|
38
|
+
url.searchParams.delete(key);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
url.searchParams.sort();
|
|
42
|
+
window.history.replaceState(window.history.state, '', url);
|
|
43
|
+
}, [pathname, touchedFields, values]);
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
exports.URLSearchParamsBuilder = URLSearchParamsBuilder;
|
|
@@ -2,19 +2,19 @@ export declare enum SwapFormKey {
|
|
|
2
2
|
FromAmount = "fromAmount",
|
|
3
3
|
FromChain = "fromChain",
|
|
4
4
|
FromToken = "fromToken",
|
|
5
|
-
|
|
5
|
+
ToAddress = "toAddress",
|
|
6
6
|
ToChain = "toChain",
|
|
7
7
|
ToToken = "toToken",
|
|
8
|
-
|
|
8
|
+
TokenSearchFilter = "tokenSearchFilter"
|
|
9
9
|
}
|
|
10
10
|
export declare type SwapFormValues = {
|
|
11
11
|
[SwapFormKey.FromAmount]: string;
|
|
12
12
|
[SwapFormKey.FromChain]: number;
|
|
13
13
|
[SwapFormKey.FromToken]: string;
|
|
14
|
-
[SwapFormKey.
|
|
14
|
+
[SwapFormKey.ToAddress]: string;
|
|
15
15
|
[SwapFormKey.ToChain]: number;
|
|
16
16
|
[SwapFormKey.ToToken]: string;
|
|
17
|
-
[SwapFormKey.
|
|
17
|
+
[SwapFormKey.TokenSearchFilter]: string;
|
|
18
18
|
};
|
|
19
19
|
export declare type SwapFormType = 'from' | 'to';
|
|
20
20
|
export declare const SwapFormKeyHelper: {
|
|
@@ -6,10 +6,10 @@ var SwapFormKey;
|
|
|
6
6
|
SwapFormKey["FromAmount"] = "fromAmount";
|
|
7
7
|
SwapFormKey["FromChain"] = "fromChain";
|
|
8
8
|
SwapFormKey["FromToken"] = "fromToken";
|
|
9
|
-
SwapFormKey["
|
|
9
|
+
SwapFormKey["ToAddress"] = "toAddress";
|
|
10
10
|
SwapFormKey["ToChain"] = "toChain";
|
|
11
11
|
SwapFormKey["ToToken"] = "toToken";
|
|
12
|
-
SwapFormKey["
|
|
12
|
+
SwapFormKey["TokenSearchFilter"] = "tokenSearchFilter";
|
|
13
13
|
})(SwapFormKey = exports.SwapFormKey || (exports.SwapFormKey = {}));
|
|
14
14
|
exports.SwapFormKeyHelper = {
|
|
15
15
|
getChainKey: (formType) => `${formType}Chain`,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WalletFormUpdate = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
7
|
+
const stores_1 = require("../../stores");
|
|
8
|
+
const SwapFormProvider_1 = require("../SwapFormProvider");
|
|
9
|
+
const WidgetProvider_1 = require("../WidgetProvider");
|
|
10
|
+
const WalletFormUpdate = ({ account, }) => {
|
|
11
|
+
const { fromChain, toChain, chains, disabledChains } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
12
|
+
const { setValue, getValues, getFieldState,
|
|
13
|
+
// Subscription to touchedFields is required by getFieldState to work
|
|
14
|
+
formState: { touchedFields }, } = (0, react_hook_form_1.useFormContext)();
|
|
15
|
+
// Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
const chainAllowed = account.chainId && (0, WidgetProvider_1.isItemAllowed)(account.chainId, chains, disabledChains);
|
|
18
|
+
if (!account.isActive || !account.chainId || !chainAllowed) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const [fromChainValue, toChainValue] = getValues([
|
|
22
|
+
SwapFormProvider_1.SwapFormKey.FromChain,
|
|
23
|
+
SwapFormProvider_1.SwapFormKey.ToChain,
|
|
24
|
+
]);
|
|
25
|
+
const { isTouched: isFromChainTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.FromChain);
|
|
26
|
+
const { isTouched: isToChainTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.ToChain);
|
|
27
|
+
const { isTouched: isFromTokenTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.FromToken);
|
|
28
|
+
const { isTouched: isToTokenTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.ToToken);
|
|
29
|
+
const { isTouched: isFromAmountTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.FromAmount);
|
|
30
|
+
const { chainOrder, setChain } = stores_1.useChainOrderStore.getState();
|
|
31
|
+
// Users can switch chains in the wallet.
|
|
32
|
+
// If we don't have a chain in the ordered chain list we should add it.
|
|
33
|
+
setChain(account.chainId);
|
|
34
|
+
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
35
|
+
// we should make a recently switched chain as current.
|
|
36
|
+
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
37
|
+
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
38
|
+
if ((!fromChain && !isFromChainTouched && !isFromTokenTouched) ||
|
|
39
|
+
!hasFromChainInOrderedList) {
|
|
40
|
+
setValue(SwapFormProvider_1.SwapFormKey.FromChain, account.chainId);
|
|
41
|
+
setValue(SwapFormProvider_1.SwapFormKey.FromToken, '');
|
|
42
|
+
if (isFromAmountTouched) {
|
|
43
|
+
setValue(SwapFormProvider_1.SwapFormKey.FromAmount, '');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if ((!toChain && !isToChainTouched && !isToTokenTouched) ||
|
|
47
|
+
!hasToChainInOrderedList) {
|
|
48
|
+
setValue(SwapFormProvider_1.SwapFormKey.ToChain, account.chainId);
|
|
49
|
+
setValue(SwapFormProvider_1.SwapFormKey.ToToken, '');
|
|
50
|
+
}
|
|
51
|
+
}, [
|
|
52
|
+
account.chainId,
|
|
53
|
+
account.isActive,
|
|
54
|
+
chains,
|
|
55
|
+
disabledChains,
|
|
56
|
+
fromChain,
|
|
57
|
+
getFieldState,
|
|
58
|
+
getValues,
|
|
59
|
+
setValue,
|
|
60
|
+
toChain,
|
|
61
|
+
]);
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
exports.WalletFormUpdate = WalletFormUpdate;
|
|
@@ -13,10 +13,8 @@ exports.extractAccountFromSigner = exports.WalletProvider = exports.useWallet =
|
|
|
13
13
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
14
14
|
const wallet_management_1 = require("@lifi/wallet-management");
|
|
15
15
|
const react_1 = require("react");
|
|
16
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
17
|
-
const stores_1 = require("../../stores");
|
|
18
|
-
const SwapFormProvider_1 = require("../SwapFormProvider");
|
|
19
16
|
const WidgetProvider_1 = require("../WidgetProvider");
|
|
17
|
+
const WalletFormUpdate_1 = require("./WalletFormUpdate");
|
|
20
18
|
const stub = () => {
|
|
21
19
|
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
22
20
|
};
|
|
@@ -32,8 +30,7 @@ const WalletContext = (0, react_1.createContext)(initialContext);
|
|
|
32
30
|
const useWallet = () => (0, react_1.useContext)(WalletContext);
|
|
33
31
|
exports.useWallet = useWallet;
|
|
34
32
|
const WalletProvider = ({ children }) => {
|
|
35
|
-
const { walletManagement
|
|
36
|
-
const methods = (0, react_hook_form_1.useFormContext)();
|
|
33
|
+
const { walletManagement } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
37
34
|
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, provider, } = (0, wallet_management_1.useLiFiWalletManagement)();
|
|
38
35
|
const [account, setAccount] = (0, react_1.useState)({});
|
|
39
36
|
const connect = (0, react_1.useCallback)((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -98,59 +95,7 @@ const WalletProvider = ({ children }) => {
|
|
|
98
95
|
account,
|
|
99
96
|
provider,
|
|
100
97
|
}), [account, addChain, addToken, connect, disconnect, provider, switchChain]);
|
|
101
|
-
|
|
102
|
-
(0, react_1.useEffect)(() => {
|
|
103
|
-
const chainAllowed = account.chainId && (0, WidgetProvider_1.isItemAllowed)(account.chainId, chains, disabledChains);
|
|
104
|
-
if (!account.isActive || !account.chainId || !chainAllowed) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const [fromChainValue, toChainValue] = methods.getValues([
|
|
108
|
-
SwapFormProvider_1.SwapFormKey.FromChain,
|
|
109
|
-
SwapFormProvider_1.SwapFormKey.ToChain,
|
|
110
|
-
]);
|
|
111
|
-
const { isDirty: isFromChainDirty } = methods.getFieldState(SwapFormProvider_1.SwapFormKey.FromChain, methods.formState);
|
|
112
|
-
const { isDirty: isToChainDirty } = methods.getFieldState(SwapFormProvider_1.SwapFormKey.ToChain, methods.formState);
|
|
113
|
-
const { isDirty: isFromTokenDirty } = methods.getFieldState(SwapFormProvider_1.SwapFormKey.FromToken, methods.formState);
|
|
114
|
-
const { isDirty: isToTokenDirty } = methods.getFieldState(SwapFormProvider_1.SwapFormKey.ToToken, methods.formState);
|
|
115
|
-
const { chainOrder, setChain } = stores_1.useChainOrderStore.getState();
|
|
116
|
-
// Users can switch chains in the wallet.
|
|
117
|
-
// If we don't have a chain in the ordered chain list we should add it.
|
|
118
|
-
setChain(account.chainId);
|
|
119
|
-
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
120
|
-
// we should make a recently switched chain as current.
|
|
121
|
-
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
122
|
-
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
123
|
-
if ((!fromChain && !isFromChainDirty && !isFromTokenDirty) ||
|
|
124
|
-
!hasFromChainInOrderedList) {
|
|
125
|
-
methods.setValue(SwapFormProvider_1.SwapFormKey.FromChain, account.chainId, {
|
|
126
|
-
shouldDirty: false,
|
|
127
|
-
});
|
|
128
|
-
methods.setValue(SwapFormProvider_1.SwapFormKey.FromToken, '', {
|
|
129
|
-
shouldDirty: false,
|
|
130
|
-
});
|
|
131
|
-
methods.setValue(SwapFormProvider_1.SwapFormKey.FromAmount, '', {
|
|
132
|
-
shouldDirty: false,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
if ((!toChain && !isToChainDirty && !isToTokenDirty) ||
|
|
136
|
-
!hasToChainInOrderedList) {
|
|
137
|
-
methods.setValue(SwapFormProvider_1.SwapFormKey.ToChain, account.chainId, {
|
|
138
|
-
shouldDirty: false,
|
|
139
|
-
});
|
|
140
|
-
methods.setValue(SwapFormProvider_1.SwapFormKey.ToToken, '', {
|
|
141
|
-
shouldDirty: false,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}, [
|
|
145
|
-
account.chainId,
|
|
146
|
-
account.isActive,
|
|
147
|
-
chains,
|
|
148
|
-
disabledChains,
|
|
149
|
-
fromChain,
|
|
150
|
-
methods,
|
|
151
|
-
toChain,
|
|
152
|
-
]);
|
|
153
|
-
return ((0, jsx_runtime_1.jsx)(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
98
|
+
return ((0, jsx_runtime_1.jsxs)(WalletContext.Provider, Object.assign({ value: value }, { children: [(0, jsx_runtime_1.jsx)(WalletFormUpdate_1.WalletFormUpdate, { account: account }), children] })));
|
|
154
99
|
};
|
|
155
100
|
exports.WalletProvider = WalletProvider;
|
|
156
101
|
const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -15,6 +15,7 @@ exports.WidgetProvider = exports.useWidgetConfig = void 0;
|
|
|
15
15
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
16
|
const sdk_1 = require("@lifi/sdk");
|
|
17
17
|
const react_1 = require("react");
|
|
18
|
+
const utils_1 = require("../../utils");
|
|
18
19
|
const initialContext = {
|
|
19
20
|
disabledChains: [],
|
|
20
21
|
};
|
|
@@ -24,27 +25,33 @@ exports.useWidgetConfig = useWidgetConfig;
|
|
|
24
25
|
const WidgetProvider = (_a) => {
|
|
25
26
|
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"]);
|
|
26
27
|
const value = (0, react_1.useMemo)(() => {
|
|
27
|
-
var _a, _b, _c, _d;
|
|
28
|
+
var _a, _b, _c, _d, _e, _f;
|
|
28
29
|
try {
|
|
29
30
|
const searchParams = Object.fromEntries(new URLSearchParams(window === null || window === void 0 ? void 0 : window.location.search));
|
|
31
|
+
// Prevent using fromToken/toToken params if chain is not selected
|
|
32
|
+
['from', 'to'].forEach((key) => {
|
|
33
|
+
if (searchParams[`${key}Token`] && !searchParams[`${key}Chain`]) {
|
|
34
|
+
delete searchParams[`${key}Token`];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
30
37
|
return Object.assign(Object.assign({}, config), { fromChain: (searchParams.fromChain &&
|
|
31
38
|
isNaN(parseInt(searchParams.fromChain, 10))) ||
|
|
32
39
|
typeof fromChain === 'string'
|
|
33
|
-
? (0, sdk_1.getChainByKey)((_a = (searchParams.fromChain || fromChain)) === null || _a === void 0 ? void 0 : _a.toLowerCase()).id
|
|
40
|
+
? (_b = (0, sdk_1.getChainByKey)((_a = (searchParams.fromChain || fromChain)) === null || _a === void 0 ? void 0 : _a.toLowerCase())) === null || _b === void 0 ? void 0 : _b.id
|
|
34
41
|
: (searchParams.fromChain &&
|
|
35
42
|
!isNaN(parseInt(searchParams.fromChain, 10))) ||
|
|
36
43
|
typeof fromChain === 'number'
|
|
37
44
|
? parseInt(searchParams.fromChain, 10) || fromChain
|
|
38
45
|
: undefined, toChain: (searchParams.toChain && isNaN(parseInt(searchParams.toChain, 10))) ||
|
|
39
46
|
typeof toChain === 'string'
|
|
40
|
-
? (0, sdk_1.getChainByKey)((
|
|
47
|
+
? (_d = (0, sdk_1.getChainByKey)((_c = (searchParams.toChain || toChain)) === null || _c === void 0 ? void 0 : _c.toLowerCase())) === null || _d === void 0 ? void 0 : _d.id
|
|
41
48
|
: (searchParams.toChain &&
|
|
42
49
|
!isNaN(parseInt(searchParams.toChain, 10))) ||
|
|
43
50
|
typeof toChain === 'number'
|
|
44
51
|
? parseInt(searchParams.toChain, 10) || toChain
|
|
45
|
-
: undefined, fromToken: ((
|
|
52
|
+
: undefined, fromToken: ((_e = searchParams.fromToken) === null || _e === void 0 ? void 0 : _e.toLowerCase()) || (fromToken === null || fromToken === void 0 ? void 0 : fromToken.toLowerCase()), toToken: ((_f = searchParams.toToken) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || (toToken === null || toToken === void 0 ? void 0 : toToken.toLowerCase()), fromAmount: typeof searchParams.fromAmount === 'string' &&
|
|
46
53
|
!isNaN(parseFloat(searchParams.fromAmount))
|
|
47
|
-
? searchParams.fromAmount
|
|
54
|
+
? (0, utils_1.formatAmount)(searchParams.fromAmount)
|
|
48
55
|
: fromAmount });
|
|
49
56
|
}
|
|
50
57
|
catch (e) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export * from './useExecutingRoutesIds';
|
|
3
|
+
export * from './useRecommendedRouteStore';
|
|
3
4
|
export * from './useRouteExecutionStore';
|
|
4
|
-
export * from './useSelectedRouteStore';
|
|
5
5
|
export * from './useSetExecutableRoute';
|
|
6
6
|
export * from './useSwapHistory';
|
|
7
7
|
export * from './utils';
|
|
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./useExecutingRoutesIds"), exports);
|
|
19
|
+
__exportStar(require("./useRecommendedRouteStore"), exports);
|
|
19
20
|
__exportStar(require("./useRouteExecutionStore"), exports);
|
|
20
|
-
__exportStar(require("./useSelectedRouteStore"), exports);
|
|
21
21
|
__exportStar(require("./useSetExecutableRoute"), exports);
|
|
22
22
|
__exportStar(require("./useSwapHistory"), exports);
|
|
23
23
|
__exportStar(require("./utils"), exports);
|
|
@@ -5,14 +5,14 @@ export interface RouteExecutionStore {
|
|
|
5
5
|
updateRoute: (route: Route) => void;
|
|
6
6
|
restartRoute: (routeId: string) => void;
|
|
7
7
|
deleteRoute: (routeId: string) => void;
|
|
8
|
-
deleteRoutes: () => void;
|
|
8
|
+
deleteRoutes: (type: 'completed' | 'active') => void;
|
|
9
9
|
}
|
|
10
10
|
export declare type RouteExecutionStatus = 'error' | 'idle' | 'loading' | 'success';
|
|
11
11
|
export interface RouteExecution {
|
|
12
12
|
route: Route;
|
|
13
13
|
status: RouteExecutionStatus;
|
|
14
14
|
}
|
|
15
|
-
export interface
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export interface RecommendedRouteStore {
|
|
16
|
+
recommendedRoute?: Route;
|
|
17
|
+
setRecommendedRoute: (route?: Route) => void;
|
|
18
18
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RecommendedRouteStore } from './types';
|
|
2
|
+
export declare const useRecommendedRouteStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<RecommendedRouteStore>, "setState"> & {
|
|
3
|
+
setState(nextStateOrUpdater: RecommendedRouteStore | Partial<RecommendedRouteStore> | ((state: import("immer/dist/internal").WritableDraft<RecommendedRouteStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
4
|
+
}>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.useRecommendedRouteStore = void 0;
|
|
4
4
|
const zustand_1 = require("zustand");
|
|
5
5
|
const immer_1 = require("zustand/middleware/immer");
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.useRecommendedRouteStore = (0, zustand_1.default)()((0, immer_1.immer)((set) => ({
|
|
7
|
+
setRecommendedRoute: (route) => {
|
|
8
8
|
set((state) => {
|
|
9
|
-
state.
|
|
9
|
+
state.recommendedRoute = route;
|
|
10
10
|
});
|
|
11
11
|
},
|
|
12
12
|
})));
|
|
@@ -46,8 +46,15 @@ exports.useRouteExecutionStore = (0, zustand_1.default)()((0, middleware_1.persi
|
|
|
46
46
|
delete state.routes[routeId];
|
|
47
47
|
}
|
|
48
48
|
}),
|
|
49
|
-
deleteRoutes: () => set((state) => {
|
|
50
|
-
state.routes
|
|
49
|
+
deleteRoutes: (type) => set((state) => {
|
|
50
|
+
Object.keys(state.routes)
|
|
51
|
+
.filter((routeId) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
return type === 'completed'
|
|
54
|
+
? ((_a = state.routes[routeId]) === null || _a === void 0 ? void 0 : _a.status) === 'success'
|
|
55
|
+
: ((_b = state.routes[routeId]) === null || _b === void 0 ? void 0 : _b.status) !== 'success';
|
|
56
|
+
})
|
|
57
|
+
.forEach((routeId) => delete state.routes[routeId]);
|
|
51
58
|
}),
|
|
52
59
|
})), {
|
|
53
60
|
name: 'li.fi-widget-routes',
|