@lifi/widget 1.18.8 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +3 -3
- package/cjs/App.js +3 -3
- package/cjs/components/ActiveSwaps/ActiveSwaps.js +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
- package/cjs/components/AppContainer.d.ts +11 -1
- package/cjs/components/AppContainer.js +3 -6
- package/cjs/components/BottomSheet/BottomSheet.js +9 -32
- package/cjs/components/BottomSheet/types.d.ts +2 -2
- package/cjs/components/Card/Card.js +1 -1
- package/cjs/components/Card/CardHeader.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.js +1 -1
- package/cjs/components/ChainSelect/useChainSelect.js +2 -4
- package/cjs/components/Dialog.d.ts +22 -1
- package/cjs/components/Dialog.js +23 -20
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +19 -22
- package/cjs/components/Header/NavigationHeader.js +1 -1
- package/cjs/components/Header/WalletHeader.js +2 -2
- package/cjs/components/PoweredBy/PoweredBy.js +1 -1
- package/cjs/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
- package/cjs/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
- package/cjs/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/cjs/components/SendToWallet/SendToWallet.d.ts +1 -0
- package/cjs/components/SendToWallet/SendToWallet.js +10 -5
- package/cjs/components/SendToWallet/SendToWalletButton.js +2 -2
- package/cjs/components/Step/StepProcess.js +1 -1
- package/cjs/components/SwapButton/SwapButton.js +4 -4
- package/cjs/components/SwapButton/types.d.ts +2 -0
- package/cjs/components/SwapInput/SwapInput.js +6 -2
- package/cjs/components/SwapInput/SwapInputAdornment.js +4 -2
- package/cjs/components/SwapInput/SwapInputAdornment.style.js +1 -13
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +8 -4
- package/cjs/components/SwapRoutes/SwapRoutes.js +4 -4
- package/cjs/components/SwapRoutes/SwapRoutes.style.d.ts +14 -14
- package/cjs/components/SwapRoutes/SwapRoutes.style.js +13 -13
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +17 -12
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.js +13 -0
- package/cjs/components/Token/Token.js +5 -5
- package/cjs/components/Token/Token.style.d.ts +10 -0
- package/cjs/components/Token/Token.style.js +13 -7
- package/cjs/components/TokenList/TokenList.js +10 -7
- package/cjs/config/theme.js +22 -8
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +1 -0
- package/cjs/hooks/index.js +1 -0
- package/cjs/hooks/useExpandableVariant.d.ts +1 -0
- package/cjs/hooks/useExpandableVariant.js +14 -0
- package/cjs/hooks/useGasSufficiency.d.ts +3 -2
- package/cjs/hooks/useGasSufficiency.js +50 -26
- package/cjs/hooks/useSwapRoutes.js +4 -2
- package/cjs/hooks/useToken.js +5 -2
- package/cjs/hooks/useTokenBalance.js +15 -10
- package/cjs/hooks/useTokenSearch.d.ts +1 -3
- package/cjs/hooks/useTokenSearch.js +3 -5
- package/cjs/i18n/en/translation.json +9 -8
- package/cjs/i18n/index.d.ts +6 -5
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.js +21 -4
- package/cjs/pages/MainPage/MainPage.js +3 -3
- package/cjs/pages/SelectWalletPage/SelectWalletPage.js +1 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
- package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/cjs/pages/SwapPage/SwapPage.js +4 -4
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +3 -2
- package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
- package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.js +46 -0
- package/cjs/providers/SwapFormProvider/types.d.ts +4 -4
- package/cjs/providers/SwapFormProvider/types.js +2 -2
- package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
- package/cjs/providers/WalletProvider/WalletFormUpdate.js +64 -0
- package/cjs/providers/WalletProvider/WalletProvider.js +3 -58
- package/cjs/providers/WidgetProvider/WidgetProvider.js +12 -5
- package/cjs/stores/routes/index.d.ts +1 -1
- package/cjs/stores/routes/index.js +1 -1
- package/cjs/stores/routes/types.d.ts +4 -4
- package/cjs/stores/routes/useRecommendedRouteStore.d.ts +4 -0
- package/cjs/stores/routes/{useSelectedRouteStore.js → useRecommendedRouteStore.js} +4 -4
- package/cjs/stores/routes/useRouteExecutionStore.js +10 -2
- package/cjs/stores/settings/useSettingsStore.js +5 -2
- package/cjs/types/widget.d.ts +1 -0
- package/components/ActiveSwaps/ActiveSwaps.js +3 -3
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
- package/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
- package/components/AppContainer.d.ts +11 -1
- package/components/AppContainer.js +2 -4
- package/components/BottomSheet/BottomSheet.js +9 -32
- package/components/BottomSheet/types.d.ts +2 -2
- package/components/Card/Card.js +1 -1
- package/components/Card/CardHeader.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.js +1 -1
- package/components/ChainSelect/useChainSelect.js +2 -4
- package/components/Dialog.d.ts +22 -1
- package/components/Dialog.js +22 -19
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +21 -24
- package/components/Header/NavigationHeader.js +2 -2
- package/components/Header/WalletHeader.js +2 -2
- package/components/PoweredBy/PoweredBy.js +1 -1
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
- package/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
- package/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/components/SendToWallet/SendToWallet.d.ts +1 -0
- package/components/SendToWallet/SendToWallet.js +9 -5
- package/components/SendToWallet/SendToWalletButton.js +2 -2
- package/components/Step/StepProcess.js +1 -1
- package/components/SwapButton/SwapButton.js +4 -4
- package/components/SwapButton/types.d.ts +2 -0
- package/components/SwapInput/SwapInput.js +6 -2
- package/components/SwapInput/SwapInputAdornment.js +4 -2
- package/components/SwapInput/SwapInputAdornment.style.js +2 -14
- package/components/SwapRouteCard/SwapRouteCard.js +9 -5
- package/components/SwapRoutes/SwapRoutes.js +4 -4
- package/components/SwapRoutes/SwapRoutes.style.d.ts +14 -14
- package/components/SwapRoutes/SwapRoutes.style.js +13 -13
- package/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
- package/components/SwapRoutes/SwapRoutesExpanded.js +16 -12
- package/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
- package/components/SwapRoutes/useSetRecommendedRoute.js +9 -0
- package/components/Token/Token.js +7 -7
- package/components/Token/Token.style.d.ts +10 -0
- package/components/Token/Token.style.js +12 -6
- package/components/TokenList/TokenList.js +10 -7
- package/config/theme.js +22 -8
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useExpandableVariant.d.ts +1 -0
- package/hooks/useExpandableVariant.js +10 -0
- package/hooks/useGasSufficiency.d.ts +3 -2
- package/hooks/useGasSufficiency.js +50 -26
- package/hooks/useSwapRoutes.js +4 -2
- package/hooks/useToken.js +5 -2
- package/hooks/useTokenBalance.js +15 -10
- package/hooks/useTokenSearch.d.ts +1 -3
- package/hooks/useTokenSearch.js +3 -5
- package/i18n/en/translation.json +9 -8
- package/i18n/index.d.ts +6 -5
- package/package.json +11 -11
- package/pages/ActiveSwapsPage/ActiveSwapsPage.js +24 -7
- package/pages/MainPage/MainPage.js +3 -3
- package/pages/SelectWalletPage/SelectWalletPage.js +1 -1
- package/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
- package/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/pages/SwapPage/SwapPage.js +5 -5
- package/providers/SwapFormProvider/SwapFormProvider.js +4 -3
- package/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
- package/providers/SwapFormProvider/URLSearchParamsBuilder.js +42 -0
- package/providers/SwapFormProvider/types.d.ts +4 -4
- package/providers/SwapFormProvider/types.js +2 -2
- package/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
- package/providers/WalletProvider/WalletFormUpdate.js +60 -0
- package/providers/WalletProvider/WalletProvider.js +5 -60
- package/providers/WidgetProvider/WidgetProvider.js +12 -5
- package/stores/routes/index.d.ts +1 -1
- package/stores/routes/index.js +1 -1
- package/stores/routes/types.d.ts +4 -4
- package/stores/routes/useRecommendedRouteStore.d.ts +4 -0
- package/stores/routes/useRecommendedRouteStore.js +9 -0
- package/stores/routes/useRouteExecutionStore.js +10 -2
- package/stores/settings/useSettingsStore.js +5 -2
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +1 -0
- package/cjs/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
- package/cjs/components/SwapRoutes/useSetSelectedRoute.js +0 -13
- package/cjs/stores/routes/useSelectedRouteStore.d.ts +0 -4
- package/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
- package/components/SwapRoutes/useSetSelectedRoute.js +0 -9
- package/stores/routes/useSelectedRouteStore.d.ts +0 -4
- package/stores/routes/useSelectedRouteStore.js +0 -9
|
@@ -10,23 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.useGasSufficiency = void 0;
|
|
13
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
13
14
|
const big_js_1 = require("big.js");
|
|
14
|
-
const react_1 = require("react");
|
|
15
15
|
const _1 = require(".");
|
|
16
16
|
const providers_1 = require("../providers");
|
|
17
|
+
const stores_1 = require("../stores");
|
|
17
18
|
const useTokenBalance_1 = require("./useTokenBalance");
|
|
19
|
+
const refetchInterval = 30000;
|
|
18
20
|
const useGasSufficiency = (route) => {
|
|
19
21
|
const { account } = (0, providers_1.useWallet)();
|
|
20
22
|
const { getChainById } = (0, _1.useChains)();
|
|
21
23
|
const { token: fromToken, getTokenBalancesWithRetry } = (0, useTokenBalance_1.useTokenBalance)(route === null || route === void 0 ? void 0 : route.fromToken);
|
|
22
|
-
const
|
|
23
|
-
const checkInsufficientGas = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const { data: insufficientGas, isInitialLoading: insufficientGasLoading } = (0, react_query_1.useQuery)(['gas-sufficiency-check', account.address, route === null || route === void 0 ? void 0 : route.id], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
25
|
var _a, _b;
|
|
25
26
|
if (!account.address || !route) {
|
|
26
|
-
|
|
27
|
-
return;
|
|
27
|
+
return null;
|
|
28
28
|
}
|
|
29
|
-
const gasCosts = route.steps
|
|
29
|
+
const gasCosts = route.steps
|
|
30
|
+
.filter((step) => !step.execution || step.execution.status !== 'DONE')
|
|
31
|
+
.reduce((groupedGasCosts, step) => {
|
|
30
32
|
if (step.estimate.gasCosts) {
|
|
31
33
|
const { token } = step.estimate.gasCosts[0];
|
|
32
34
|
const gasCostAmount = step.estimate.gasCosts
|
|
@@ -40,7 +42,6 @@ const useGasSufficiency = (route) => {
|
|
|
40
42
|
gasAmount,
|
|
41
43
|
tokenAmount: gasAmount,
|
|
42
44
|
token,
|
|
43
|
-
chain: getChainById(token.chainId),
|
|
44
45
|
};
|
|
45
46
|
return groupedGasCosts;
|
|
46
47
|
}
|
|
@@ -51,42 +52,65 @@ const useGasSufficiency = (route) => {
|
|
|
51
52
|
}
|
|
52
53
|
const tokenBalances = yield getTokenBalancesWithRetry(account.address, Object.values(gasCosts).map((item) => item.token));
|
|
53
54
|
if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
|
|
54
|
-
|
|
55
|
-
return;
|
|
55
|
+
return null;
|
|
56
56
|
}
|
|
57
57
|
[route.fromChainId, route.toChainId].forEach((chainId) => {
|
|
58
58
|
var _a, _b, _c, _d, _e, _f;
|
|
59
59
|
if (gasCosts[chainId]) {
|
|
60
60
|
const gasTokenBalance = (0, big_js_1.default)((_b = (_a = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.find((t) => t.chainId === gasCosts[chainId].token.chainId &&
|
|
61
61
|
t.address === gasCosts[chainId].token.address)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
|
|
62
|
-
const
|
|
62
|
+
const insufficient = gasTokenBalance.lte(0) ||
|
|
63
63
|
gasTokenBalance.lt((_c = gasCosts[chainId].gasAmount) !== null && _c !== void 0 ? _c : (0, big_js_1.default)(0)) ||
|
|
64
64
|
gasTokenBalance.lt((_d = gasCosts[chainId].tokenAmount) !== null && _d !== void 0 ? _d : (0, big_js_1.default)(0));
|
|
65
|
-
const
|
|
65
|
+
const insufficientAmount = insufficient
|
|
66
66
|
? (_f = (_e = gasCosts[chainId].tokenAmount) === null || _e === void 0 ? void 0 : _e.minus(gasTokenBalance)) !== null && _f !== void 0 ? _f : gasCosts[chainId].gasAmount.minus(gasTokenBalance)
|
|
67
67
|
: undefined;
|
|
68
|
-
gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient
|
|
68
|
+
gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient, insufficientAmount: insufficientAmount === null || insufficientAmount === void 0 ? void 0 : insufficientAmount.round(5, big_js_1.default.roundUp), chain: insufficient ? getChainById(chainId) : undefined });
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
const gasCostResult = Object.values(gasCosts).filter((gasCost) => gasCost.insufficient);
|
|
72
|
-
|
|
73
|
-
}),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
return gasCostResult;
|
|
73
|
+
}), {
|
|
74
|
+
enabled: Boolean(account.address && route),
|
|
75
|
+
refetchIntervalInBackground: true,
|
|
76
|
+
refetchInterval,
|
|
77
|
+
staleTime: refetchInterval,
|
|
78
|
+
cacheTime: refetchInterval,
|
|
79
|
+
});
|
|
80
|
+
const { data: insufficientFunds, isInitialLoading: insufficientFundsLoading, } = (0, react_query_1.useQuery)(['funds-sufficiency-check', account.address, route === null || route === void 0 ? void 0 : route.id], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
var _c, _d, _e, _f;
|
|
82
|
+
if (!account.address || !fromToken || !route || (0, stores_1.isRouteCompleted)(route)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
let currentTokenBalance = (0, big_js_1.default)((_c = fromToken === null || fromToken === void 0 ? void 0 : fromToken.amount) !== null && _c !== void 0 ? _c : 0);
|
|
86
|
+
const currentAction = (_d = route.steps.filter((step) => !step.execution || step.execution.status !== 'DONE')[0]) === null || _d === void 0 ? void 0 : _d.action;
|
|
87
|
+
if (fromToken.chainId === currentAction.fromToken.chainId &&
|
|
88
|
+
fromToken.address === currentAction.fromToken.address &&
|
|
89
|
+
currentTokenBalance.gt(0)) {
|
|
90
|
+
const insufficientFunds = (0, big_js_1.default)(route.fromAmount)
|
|
91
|
+
.div(Math.pow(10, route.fromToken.decimals))
|
|
92
|
+
.gt(currentTokenBalance);
|
|
93
|
+
return insufficientFunds;
|
|
78
94
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
const tokenBalances = yield getTokenBalancesWithRetry(account.address, [
|
|
96
|
+
currentAction.fromToken,
|
|
97
|
+
]);
|
|
98
|
+
currentTokenBalance = (0, big_js_1.default)((_f = (_e = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances[0]) === null || _e === void 0 ? void 0 : _e.amount) !== null && _f !== void 0 ? _f : 0);
|
|
99
|
+
const insufficientFunds = (0, big_js_1.default)(currentAction.fromAmount)
|
|
100
|
+
.div(Math.pow(10, currentAction.fromToken.decimals))
|
|
101
|
+
.gt(currentTokenBalance);
|
|
102
|
+
return insufficientFunds;
|
|
103
|
+
}), {
|
|
104
|
+
enabled: Boolean(account.address && route && fromToken),
|
|
105
|
+
refetchIntervalInBackground: true,
|
|
106
|
+
refetchInterval,
|
|
107
|
+
staleTime: refetchInterval,
|
|
108
|
+
cacheTime: refetchInterval,
|
|
109
|
+
});
|
|
87
110
|
return {
|
|
88
111
|
insufficientGas,
|
|
89
112
|
insufficientFunds,
|
|
113
|
+
isLoading: insufficientGasLoading || insufficientFundsLoading,
|
|
90
114
|
};
|
|
91
115
|
};
|
|
92
116
|
exports.useGasSufficiency = useGasSufficiency;
|
|
@@ -77,16 +77,18 @@ const useSwapRoutes = () => {
|
|
|
77
77
|
catch (_d) {
|
|
78
78
|
toWalletAddress = (0, address_1.isAddress)(toAddress) ? toAddress : fromAddress;
|
|
79
79
|
}
|
|
80
|
+
const fromAmount = (0, big_js_1.default)(Number(fromTokenAmount) * Math.pow(10, ((_c = token === null || token === void 0 ? void 0 : token.decimals) !== null && _c !== void 0 ? _c : 0))).toString();
|
|
81
|
+
const formattedSlippage = parseFloat(slippage) / 100;
|
|
80
82
|
return lifi.getRoutes({
|
|
81
83
|
fromChainId,
|
|
82
|
-
fromAmount
|
|
84
|
+
fromAmount,
|
|
83
85
|
fromTokenAddress,
|
|
84
86
|
toChainId,
|
|
85
87
|
toTokenAddress,
|
|
86
88
|
fromAddress,
|
|
87
89
|
toAddress: toWalletAddress,
|
|
88
90
|
options: {
|
|
89
|
-
slippage:
|
|
91
|
+
slippage: formattedSlippage,
|
|
90
92
|
bridges: {
|
|
91
93
|
allow: enabledBridges,
|
|
92
94
|
},
|
package/cjs/hooks/useToken.js
CHANGED
|
@@ -3,15 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useToken = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useTokens_1 = require("./useTokens");
|
|
6
|
+
const useTokenSearch_1 = require("./useTokenSearch");
|
|
6
7
|
const useToken = (chainId, tokenAddress) => {
|
|
7
8
|
const { tokens, isLoading } = (0, useTokens_1.useTokens)(chainId);
|
|
8
9
|
const token = (0, react_1.useMemo)(() => {
|
|
9
10
|
const token = tokens === null || tokens === void 0 ? void 0 : tokens.find((token) => token.address === tokenAddress && token.chainId === chainId);
|
|
10
11
|
return token;
|
|
11
12
|
}, [chainId, tokenAddress, tokens]);
|
|
13
|
+
const tokenSearchEnabled = !isLoading && !token;
|
|
14
|
+
const { token: searchedToken, isLoading: isSearchedTokenLoading } = (0, useTokenSearch_1.useTokenSearch)(chainId, tokenAddress, tokenSearchEnabled);
|
|
12
15
|
return {
|
|
13
|
-
token,
|
|
14
|
-
isLoading,
|
|
16
|
+
token: token !== null && token !== void 0 ? token : searchedToken,
|
|
17
|
+
isLoading: isLoading || (tokenSearchEnabled && isSearchedTokenLoading),
|
|
15
18
|
};
|
|
16
19
|
};
|
|
17
20
|
exports.useToken = useToken;
|
|
@@ -21,18 +21,23 @@ const useTokenBalance = (token, accountAddress) => {
|
|
|
21
21
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
22
22
|
const walletAddress = accountAddress !== null && accountAddress !== void 0 ? accountAddress : account.address;
|
|
23
23
|
const getTokenBalancesWithRetry = (0, react_1.useCallback)((accountAddress, tokens, depth = 0) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
try {
|
|
25
|
+
const tokenBalances = yield lifi.getTokenBalances(accountAddress, tokens);
|
|
26
|
+
if (!tokenBalances.every((token) => token.blockNumber)) {
|
|
27
|
+
if (depth > 10) {
|
|
28
|
+
console.warn('Token balance backoff depth exceeded.');
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
yield new Promise((resolve) => {
|
|
32
|
+
setTimeout(resolve, Math.pow(1.5, depth) * 100);
|
|
33
|
+
});
|
|
34
|
+
return getTokenBalancesWithRetry(accountAddress, tokens, depth + 1);
|
|
29
35
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
return tokenBalances;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
//
|
|
34
40
|
}
|
|
35
|
-
return tokenBalances;
|
|
36
41
|
}), [lifi]);
|
|
37
42
|
const tokenBalanceQueryKey = (0, react_1.useMemo)(() => ['token-balance', walletAddress, token === null || token === void 0 ? void 0 : token.chainId, token === null || token === void 0 ? void 0 : token.address], [token === null || token === void 0 ? void 0 : token.address, token === null || token === void 0 ? void 0 : token.chainId, walletAddress]);
|
|
38
43
|
const { data, isLoading, refetch } = (0, react_query_1.useQuery)(tokenBalanceQueryKey, ({ queryKey: [, accountAddress] }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Token } from '../types';
|
|
2
|
-
export declare const useTokenSearch: (
|
|
2
|
+
export declare const useTokenSearch: (chainId: number, token: string, enabled?: boolean) => {
|
|
3
3
|
token: Token | undefined;
|
|
4
4
|
isLoading: boolean;
|
|
5
|
-
isFetching: boolean;
|
|
6
|
-
isFetched: boolean;
|
|
7
5
|
};
|
|
@@ -12,10 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.useTokenSearch = void 0;
|
|
13
13
|
const react_query_1 = require("@tanstack/react-query");
|
|
14
14
|
const providers_1 = require("../providers");
|
|
15
|
-
const useTokenSearch = (
|
|
15
|
+
const useTokenSearch = (chainId, token, enabled) => {
|
|
16
16
|
const lifi = (0, providers_1.useLiFi)();
|
|
17
17
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
18
|
-
const { data, isLoading
|
|
18
|
+
const { data, isLoading } = (0, react_query_1.useQuery)(['token-search', chainId, token], ({ queryKey: [, chainId, token], signal }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
const data = yield lifi.getToken(chainId, token, {
|
|
20
20
|
signal,
|
|
21
21
|
});
|
|
@@ -29,14 +29,12 @@ const useTokenSearch = (token, chainId, enabled) => {
|
|
|
29
29
|
}
|
|
30
30
|
return data;
|
|
31
31
|
}), {
|
|
32
|
-
enabled,
|
|
32
|
+
enabled: Boolean(chainId && token && enabled),
|
|
33
33
|
retry: false,
|
|
34
34
|
});
|
|
35
35
|
return {
|
|
36
36
|
token: data,
|
|
37
37
|
isLoading,
|
|
38
|
-
isFetching,
|
|
39
|
-
isFetched,
|
|
40
38
|
};
|
|
41
39
|
};
|
|
42
40
|
exports.useTokenSearch = useTokenSearch;
|
|
@@ -44,10 +44,6 @@
|
|
|
44
44
|
"routes": "You get",
|
|
45
45
|
"approximateCurrency": "\u2248 {{value, currency(currency: USD)}}",
|
|
46
46
|
"currency": "{{value, currency(currency: USD)}}",
|
|
47
|
-
"sendToRecipient": "Send to recipient",
|
|
48
|
-
"addressConfirmation": "I confirm that the address above is correct",
|
|
49
|
-
"gas": "gas fee",
|
|
50
|
-
"minutes": "minutes",
|
|
51
47
|
"tokenSearch": "Search your token",
|
|
52
48
|
"selectChain": "Chain",
|
|
53
49
|
"selectToken": "Token",
|
|
@@ -58,7 +54,7 @@
|
|
|
58
54
|
"stepSwap": "Swap",
|
|
59
55
|
"stepBridge": "Bridge",
|
|
60
56
|
"stepSwapAndBridge": "Swap and bridge",
|
|
61
|
-
"estimatedTime": "
|
|
57
|
+
"estimatedTime": "{{value}}m",
|
|
62
58
|
"crossStepDetails": "Bridge from {{from}} to {{to}} via {{tool}}",
|
|
63
59
|
"swapStepDetails": "Swap on {{chain}} via {{tool}}",
|
|
64
60
|
"tokenOnChain": "{{tokenSymbol}} on {{chainName}}",
|
|
@@ -98,12 +94,14 @@
|
|
|
98
94
|
"title": {
|
|
99
95
|
"insufficientGas": "Insufficient gas",
|
|
100
96
|
"deleteSwap": "Delete this swap?",
|
|
101
|
-
"deleteSwapHistory": "Delete swap history?"
|
|
97
|
+
"deleteSwapHistory": "Delete swap history?",
|
|
98
|
+
"deleteActiveSwaps": "Delete all active swaps?"
|
|
102
99
|
},
|
|
103
100
|
"message": {
|
|
104
101
|
"insufficientFunds": "You don't have enough funds to execute the swap.",
|
|
105
102
|
"insufficientGas": "You need to add at least:",
|
|
106
|
-
"
|
|
103
|
+
"deleteSwapHistory": "Swap history is only stored locally and can't be recovered if you delete it.",
|
|
104
|
+
"deleteActiveSwaps": "Active swaps are only stored locally and can't be recovered if you delete them."
|
|
107
105
|
}
|
|
108
106
|
},
|
|
109
107
|
"error": {
|
|
@@ -179,6 +177,9 @@
|
|
|
179
177
|
"title": "404",
|
|
180
178
|
"text": "We couldn't find this page."
|
|
181
179
|
},
|
|
182
|
-
"progressToNextUpdate": "Displayed data will auto-refresh after {{value}} seconds. Click
|
|
180
|
+
"progressToNextUpdate": "Displayed data will auto-refresh after {{value}} seconds. Click here to update manually.",
|
|
181
|
+
"numberOfSteps": "A number of swap steps. Each step can contain 1-3 transactions that require a signature.",
|
|
182
|
+
"estimatedTime": "Estimated time in minutes.",
|
|
183
|
+
"estimatedNetworkFee": "Estimated network fee."
|
|
183
184
|
}
|
|
184
185
|
}
|
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`,
|