@lifi/widget 1.25.1 → 1.26.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/cjs/components/ActiveSwaps/ActiveSwapItem.js +6 -3
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +1 -1
- package/cjs/components/Header/NavigationHeader.js +1 -1
- package/cjs/components/Header/WalletHeader.js +1 -1
- package/cjs/components/ReverseTokensButton/ReverseTokensButton.style.js +1 -1
- package/cjs/components/Step/CircularProgress.d.ts +3 -3
- package/cjs/components/Step/CircularProgress.js +10 -9
- package/cjs/components/Step/CircularProgress.style.d.ts +12 -3
- package/cjs/components/Step/CircularProgress.style.js +26 -10
- package/cjs/components/Step/DestinationWalletAddress.d.ts +7 -0
- package/cjs/components/Step/DestinationWalletAddress.js +32 -0
- package/cjs/components/Step/GasStepProcess.d.ts +5 -0
- package/cjs/components/Step/GasStepProcess.js +24 -0
- package/cjs/components/Step/Step.d.ts +1 -0
- package/cjs/components/Step/Step.js +18 -6
- package/cjs/components/Step/StepList.d.ts +3 -0
- package/cjs/components/Step/StepList.js +20 -0
- package/cjs/components/Step/StepProcess.js +2 -2
- package/cjs/components/Step/index.d.ts +1 -0
- package/cjs/components/Step/index.js +1 -0
- package/cjs/components/SwapButton/SwapButton.js +1 -1
- package/cjs/components/SwapRouteCard/SwapRouteNotFoundCard.js +1 -1
- package/cjs/config/sentry.js +1 -1
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useChains.js +4 -1
- package/cjs/hooks/useProcessMessage.js +47 -5
- package/cjs/hooks/useRouteExecution.d.ts +8 -2
- package/cjs/hooks/useRouteExecution.js +14 -5
- package/cjs/hooks/useSwapRoutes.d.ts +2 -2
- package/cjs/hooks/useSwapRoutes.js +7 -0
- package/cjs/hooks/useTokenBalance.js +2 -2
- package/cjs/hooks/useTools.js +2 -0
- package/cjs/i18n/en.json +44 -28
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +10 -15
- package/cjs/pages/SwapHistoryPage/SwapHistoryEmpty.js +1 -1
- package/cjs/pages/SwapPage/ExchangeRateBottomSheet.d.ts +15 -0
- package/cjs/pages/SwapPage/ExchangeRateBottomSheet.js +71 -0
- package/cjs/pages/SwapPage/StatusBottomSheet.js +20 -4
- package/cjs/pages/SwapPage/StatusBottomSheet.style.js +4 -4
- package/cjs/pages/SwapPage/SwapPage.js +12 -14
- package/cjs/pages/SwapPage/TokenValueBottomSheet.js +3 -2
- package/cjs/utils/navigationRoutes.js +1 -0
- package/components/ActiveSwaps/ActiveSwapItem.js +6 -3
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +1 -1
- package/components/Header/NavigationHeader.js +2 -2
- package/components/Header/WalletHeader.js +1 -1
- package/components/ReverseTokensButton/ReverseTokensButton.style.js +1 -1
- package/components/Step/CircularProgress.d.ts +3 -3
- package/components/Step/CircularProgress.js +12 -11
- package/components/Step/CircularProgress.style.d.ts +12 -3
- package/components/Step/CircularProgress.style.js +27 -11
- package/components/Step/DestinationWalletAddress.d.ts +7 -0
- package/components/Step/DestinationWalletAddress.js +28 -0
- package/components/Step/GasStepProcess.d.ts +5 -0
- package/components/Step/GasStepProcess.js +20 -0
- package/components/Step/Step.d.ts +1 -0
- package/components/Step/Step.js +18 -6
- package/components/Step/StepList.d.ts +3 -0
- package/components/Step/StepList.js +16 -0
- package/components/Step/StepProcess.js +2 -2
- package/components/Step/index.d.ts +1 -0
- package/components/Step/index.js +1 -0
- package/components/SwapButton/SwapButton.js +1 -1
- package/components/SwapRouteCard/SwapRouteNotFoundCard.js +1 -1
- package/config/sentry.js +1 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useChains.js +5 -2
- package/hooks/useProcessMessage.js +47 -5
- package/hooks/useRouteExecution.d.ts +8 -2
- package/hooks/useRouteExecution.js +15 -6
- package/hooks/useSwapRoutes.d.ts +2 -2
- package/hooks/useSwapRoutes.js +7 -0
- package/hooks/useTokenBalance.js +2 -2
- package/hooks/useTools.js +2 -0
- package/i18n/en.json +44 -28
- package/package.json +9 -9
- package/pages/SwapDetailsPage/SwapDetailsPage.js +14 -19
- package/pages/SwapHistoryPage/SwapHistoryEmpty.js +1 -1
- package/pages/SwapPage/ExchangeRateBottomSheet.d.ts +15 -0
- package/pages/SwapPage/ExchangeRateBottomSheet.js +67 -0
- package/pages/SwapPage/StatusBottomSheet.js +22 -6
- package/pages/SwapPage/StatusBottomSheet.style.js +4 -4
- package/pages/SwapPage/SwapPage.js +15 -17
- package/pages/SwapPage/TokenValueBottomSheet.js +3 -2
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/utils/navigationRoutes.js +1 -0
|
@@ -18,7 +18,7 @@ const stores_1 = require("../stores");
|
|
|
18
18
|
const events_1 = require("../types/events");
|
|
19
19
|
const utils_1 = require("../utils");
|
|
20
20
|
const useWidgetEvents_1 = require("./useWidgetEvents");
|
|
21
|
-
const useRouteExecution = (routeId, executeInBackground) => {
|
|
21
|
+
const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchangeRateUpdate, }) => {
|
|
22
22
|
const lifi = (0, providers_1.useLiFi)();
|
|
23
23
|
const { account, switchChain } = (0, providers_1.useWallet)();
|
|
24
24
|
const resumedAfterMount = (0, react_1.useRef)(false);
|
|
@@ -63,6 +63,13 @@ const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
63
63
|
}
|
|
64
64
|
return account.signer;
|
|
65
65
|
});
|
|
66
|
+
const acceptExchangeRateUpdateHook = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
if (!onAcceptExchangeRateUpdate) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const accepted = yield new Promise((resolve) => onAcceptExchangeRateUpdate(resolve, params));
|
|
71
|
+
return accepted;
|
|
72
|
+
});
|
|
66
73
|
const executeRouteMutation = (0, react_query_1.useMutation)(() => {
|
|
67
74
|
if (!account.signer) {
|
|
68
75
|
throw Error('Account signer not found.');
|
|
@@ -73,6 +80,7 @@ const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
73
80
|
return lifi.executeRoute(account.signer, routeExecution.route, {
|
|
74
81
|
updateCallback,
|
|
75
82
|
switchChainHook,
|
|
83
|
+
acceptExchangeRateUpdateHook,
|
|
76
84
|
infiniteApproval: false,
|
|
77
85
|
executeInBackground,
|
|
78
86
|
});
|
|
@@ -94,6 +102,7 @@ const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
94
102
|
return lifi.resumeRoute(account.signer, resumedRoute !== null && resumedRoute !== void 0 ? resumedRoute : routeExecution.route, {
|
|
95
103
|
updateCallback,
|
|
96
104
|
switchChainHook,
|
|
105
|
+
acceptExchangeRateUpdateHook,
|
|
97
106
|
infiniteApproval: false,
|
|
98
107
|
executeInBackground,
|
|
99
108
|
});
|
|
@@ -104,8 +113,8 @@ const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
104
113
|
});
|
|
105
114
|
const executeRoute = (0, react_1.useCallback)(() => {
|
|
106
115
|
executeRouteMutation.mutateAsync(undefined, {
|
|
107
|
-
onError: () => {
|
|
108
|
-
console.warn('Execution failed!', routeId);
|
|
116
|
+
onError: (error) => {
|
|
117
|
+
console.warn('Execution failed!', routeId, error);
|
|
109
118
|
// Notification.showNotification(NotificationType.SwapExecution_ERROR);
|
|
110
119
|
},
|
|
111
120
|
onSuccess: (route) => {
|
|
@@ -116,8 +125,8 @@ const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
116
125
|
}, [executeRouteMutation, routeId]);
|
|
117
126
|
const resumeRoute = (0, react_1.useCallback)((route) => {
|
|
118
127
|
resumeRouteMutation.mutateAsync(route, {
|
|
119
|
-
onError: () => {
|
|
120
|
-
console.warn('Resumed execution failed.', routeId);
|
|
128
|
+
onError: (error) => {
|
|
129
|
+
console.warn('Resumed execution failed.', routeId, error);
|
|
121
130
|
},
|
|
122
131
|
onSuccess: (route) => {
|
|
123
132
|
console.log('Resumed execution successful.', route);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare const useSwapRoutes: () => {
|
|
2
|
-
routes: import("@lifi/
|
|
2
|
+
routes: import("@lifi/sdk").Route[] | undefined;
|
|
3
3
|
isLoading: boolean;
|
|
4
4
|
isFetching: boolean;
|
|
5
5
|
isFetched: boolean;
|
|
6
6
|
dataUpdatedAt: number;
|
|
7
7
|
refetchTime: number;
|
|
8
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@lifi/
|
|
8
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@lifi/sdk").RoutesResponse, any>>;
|
|
9
9
|
};
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.useSwapRoutes = void 0;
|
|
13
13
|
const address_1 = require("@ethersproject/address");
|
|
14
|
+
const sdk_1 = require("@lifi/sdk");
|
|
14
15
|
const react_query_1 = require("@tanstack/react-query");
|
|
15
16
|
const big_js_1 = require("big.js");
|
|
16
17
|
const react_hook_form_1 = require("react-hook-form");
|
|
@@ -110,6 +111,12 @@ const useSwapRoutes = () => {
|
|
|
110
111
|
refetchInterval,
|
|
111
112
|
staleTime: refetchTime,
|
|
112
113
|
cacheTime: refetchTime,
|
|
114
|
+
retry(failureCount, error) {
|
|
115
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === sdk_1.LifiErrorCode.NotFound) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
},
|
|
113
120
|
});
|
|
114
121
|
return {
|
|
115
122
|
routes: data === null || data === void 0 ? void 0 : data.routes,
|
|
@@ -85,8 +85,8 @@ const useTokenBalance = (token, accountAddress) => {
|
|
|
85
85
|
};
|
|
86
86
|
const refetchNewBalance = (0, react_1.useCallback)(() => {
|
|
87
87
|
queryClient.setQueryDefaults(tokenBalanceQueryKey, {
|
|
88
|
-
refetchInterval:
|
|
89
|
-
staleTime:
|
|
88
|
+
refetchInterval: 250,
|
|
89
|
+
staleTime: 250,
|
|
90
90
|
});
|
|
91
91
|
}, [queryClient, tokenBalanceQueryKey]);
|
|
92
92
|
return {
|
package/cjs/hooks/useTools.js
CHANGED
|
@@ -18,6 +18,8 @@ const useTools = () => {
|
|
|
18
18
|
.filter((exchange) => (0, providers_1.isItemAllowed)(exchange.key, exchanges))
|
|
19
19
|
.map((exchange) => exchange.key));
|
|
20
20
|
},
|
|
21
|
+
refetchInterval: 180000,
|
|
22
|
+
staleTime: 180000,
|
|
21
23
|
});
|
|
22
24
|
const formattedTools = (0, react_1.useMemo)(() => ({
|
|
23
25
|
bridges: data === null || data === void 0 ? void 0 : data.bridges.reduce((bridges, bridge) => {
|
package/cjs/i18n/en.json
CHANGED
|
@@ -69,22 +69,27 @@
|
|
|
69
69
|
},
|
|
70
70
|
"swap": {
|
|
71
71
|
"crossStepDetails": "Bridge from {{from}} to {{to}} via {{tool}}",
|
|
72
|
+
"currentAmount": "Current amount",
|
|
72
73
|
"error": {
|
|
73
74
|
"message": {
|
|
74
|
-
"
|
|
75
|
+
"slippageThreshold": "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.",
|
|
75
76
|
"transactionFailed": "Please check the block explorer for more information.",
|
|
76
|
-
"transactionNotSent": "Transaction was not sent
|
|
77
|
-
"transactionRejected": "Your signature is required to complete the transaction. {{amount, number(maximumFractionDigits: 4)}} {{tokenSymbol}} on {{chainName}} remain in your wallet."
|
|
77
|
+
"transactionNotSent": "Transaction was not sent. {{amount, number(maximumFractionDigits: 4)}} {{tokenSymbol}} on {{chainName}} remain in your wallet.",
|
|
78
|
+
"transactionRejected": "Your signature is required to complete the transaction. {{amount, number(maximumFractionDigits: 4)}} {{tokenSymbol}} on {{chainName}} remain in your wallet.",
|
|
79
|
+
"unknown": "Please try again or contact support."
|
|
78
80
|
},
|
|
79
81
|
"title": {
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
82
|
+
"balanceIsTooLow": "The balance is too low",
|
|
83
|
+
"chainSwitch": "Chain switch required",
|
|
84
|
+
"failed": "Swap failed",
|
|
85
|
+
"gasLimitIsTooLow": "The gas limit is too low",
|
|
86
|
+
"slippageNotMet": "Slippage conditions not met",
|
|
87
|
+
"transactionCanceled": "Transaction canceled",
|
|
88
|
+
"transactionFailed": "Transaction failed",
|
|
89
|
+
"transactionRejected": "Signature required",
|
|
90
|
+
"transactionUnderpriced": "Transaction is underpriced",
|
|
91
|
+
"transactionUnprepared": "Unable to prepare transaction",
|
|
92
|
+
"unknown": "Something went wrong",
|
|
88
93
|
"walletAddressInvalid": "Wallet address is invalid.",
|
|
89
94
|
"walletEnsAddressInvalid": "Wallet address is invalid or network doesn't support ENS."
|
|
90
95
|
}
|
|
@@ -94,6 +99,8 @@
|
|
|
94
99
|
"from": "From",
|
|
95
100
|
"fromAmount": "You pay",
|
|
96
101
|
"gasCost": "Gas cost",
|
|
102
|
+
"gasFeeEstimated": "estimated gas fee",
|
|
103
|
+
"gasFeePaid": "gas fee paid",
|
|
97
104
|
"inProgress": "in progress",
|
|
98
105
|
"info": {
|
|
99
106
|
"message": {
|
|
@@ -112,37 +119,43 @@
|
|
|
112
119
|
"otherTokens": "Other tokens",
|
|
113
120
|
"process": {
|
|
114
121
|
"crossChain": {
|
|
115
|
-
"actionRequired": "Please sign the transaction
|
|
116
|
-
"done": "
|
|
117
|
-
"pending": "Waiting for transaction
|
|
118
|
-
"started": "Preparing transaction
|
|
122
|
+
"actionRequired": "Please sign the transaction",
|
|
123
|
+
"done": "Bridge transaction confirmed",
|
|
124
|
+
"pending": "Waiting for bridge transaction",
|
|
125
|
+
"started": "Preparing bridge transaction"
|
|
119
126
|
},
|
|
120
127
|
"receivingChain": {
|
|
121
|
-
"done": "
|
|
122
|
-
"
|
|
128
|
+
"done": "Bridge completed",
|
|
129
|
+
"partial": "Bridge partially completed",
|
|
130
|
+
"pending": "Waiting for destination chain",
|
|
131
|
+
"refunded": "Bridge transaction refunded"
|
|
123
132
|
},
|
|
124
133
|
"swap": {
|
|
125
|
-
"actionRequired": "Please sign the transaction
|
|
126
|
-
"done": "Swap completed
|
|
127
|
-
"pending": "
|
|
128
|
-
"started": "Preparing swap
|
|
134
|
+
"actionRequired": "Please sign the transaction",
|
|
135
|
+
"done": "Swap completed",
|
|
136
|
+
"pending": "Waiting for swap transaction",
|
|
137
|
+
"started": "Preparing swap transaction"
|
|
129
138
|
},
|
|
130
139
|
"switchChain": {
|
|
131
|
-
"actionRequired": "Chain switch required
|
|
132
|
-
"done": "Chain switched successfully
|
|
140
|
+
"actionRequired": "Chain switch required",
|
|
141
|
+
"done": "Chain switched successfully"
|
|
133
142
|
},
|
|
134
143
|
"tokenAllowance": {
|
|
135
|
-
"done": "Token allowance approved
|
|
136
|
-
"pending": "Waiting for token allowance
|
|
137
|
-
"started": "Setting token allowance
|
|
144
|
+
"done": "Token allowance approved",
|
|
145
|
+
"pending": "Waiting for token allowance",
|
|
146
|
+
"started": "Setting token allowance"
|
|
138
147
|
}
|
|
139
148
|
},
|
|
149
|
+
"quotedAmount": "Quoted amount",
|
|
150
|
+
"rateChange": "Rate change",
|
|
140
151
|
"receiving": "Receiving",
|
|
141
152
|
"routes": "You get",
|
|
142
153
|
"selectChain": "Chain",
|
|
143
154
|
"selectChainAndToken": "Select chain and token",
|
|
144
155
|
"selectToken": "Token",
|
|
156
|
+
"sendToAddress": "Send to {{address}}",
|
|
145
157
|
"sendToWallet": "Send to a different wallet",
|
|
158
|
+
"sentToAddress": "Sent to {{address}}",
|
|
146
159
|
"stepBridge": "Bridge",
|
|
147
160
|
"stepSwap": "Swap",
|
|
148
161
|
"stepSwapAndBridge": "Swap and bridge",
|
|
@@ -153,6 +166,7 @@
|
|
|
153
166
|
},
|
|
154
167
|
"title": {
|
|
155
168
|
"gasSwapSuccessful": "Gas swap successful",
|
|
169
|
+
"refundIssued": "Refund issued",
|
|
156
170
|
"swapPartiallySuccessful": "Swap partially successful",
|
|
157
171
|
"swapSuccessful": "Swap successful"
|
|
158
172
|
}
|
|
@@ -179,14 +193,16 @@
|
|
|
179
193
|
"deleteSwapHistory": "Swap history is only stored locally and can't be recovered if you delete it.",
|
|
180
194
|
"highValueLoss": "The value of the received tokens is significantly lower than the swapped tokens and transaction cost.",
|
|
181
195
|
"insufficientFunds": "You don't have enough funds to execute the swap.",
|
|
182
|
-
"insufficientGas": "You need to add at least:"
|
|
196
|
+
"insufficientGas": "You need to add at least:",
|
|
197
|
+
"rateChanged": "The exchange rate has changed. By continuing the swap, you'll accept the new rate."
|
|
183
198
|
},
|
|
184
199
|
"title": {
|
|
185
200
|
"deleteActiveSwaps": "Delete all active swaps?",
|
|
186
201
|
"deleteSwap": "Delete this swap?",
|
|
187
202
|
"deleteSwapHistory": "Delete swap history?",
|
|
188
203
|
"highValueLoss": "High value loss",
|
|
189
|
-
"insufficientGas": "Insufficient gas"
|
|
204
|
+
"insufficientGas": "Insufficient gas",
|
|
205
|
+
"rateChanged": "Rate changed"
|
|
190
206
|
}
|
|
191
207
|
}
|
|
192
208
|
},
|
|
@@ -21,12 +21,11 @@ const Card_1 = require("../../components/Card");
|
|
|
21
21
|
const Dialog_1 = require("../../components/Dialog");
|
|
22
22
|
const Header_1 = require("../../components/Header");
|
|
23
23
|
const Step_1 = require("../../components/Step");
|
|
24
|
-
const StepDivider_1 = require("../../components/StepDivider");
|
|
25
24
|
const hooks_1 = require("../../hooks");
|
|
26
25
|
const stores_1 = require("../../stores");
|
|
27
26
|
const SwapDetailsPage_style_1 = require("./SwapDetailsPage.style");
|
|
28
27
|
const SwapDetailsPage = () => {
|
|
29
|
-
var _a, _b;
|
|
28
|
+
var _a, _b, _c, _d, _e, _f;
|
|
30
29
|
const { t, i18n } = (0, react_i18next_1.useTranslation)();
|
|
31
30
|
const { navigateBack } = (0, hooks_1.useNavigateBack)();
|
|
32
31
|
const { state } = (0, react_router_dom_1.useLocation)();
|
|
@@ -41,30 +40,26 @@ const SwapDetailsPage = () => {
|
|
|
41
40
|
deleteRoute(routeExecution.route.id);
|
|
42
41
|
}
|
|
43
42
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
let supportId = (_d = (_c = (_b = (_a = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process.find((process) => process.txHash)) === null || _b === void 0 ? void 0 : _b.txHash) !== null && _c !== void 0 ? _c : routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id) !== null && _d !== void 0 ? _d : '';
|
|
44
|
+
if (process.env.NODE_ENV === 'development') {
|
|
45
|
+
supportId += `_${routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id}`;
|
|
46
|
+
}
|
|
47
|
+
const copySupportId = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
yield navigator.clipboard.writeText(supportId);
|
|
47
49
|
});
|
|
48
50
|
(0, react_1.useEffect)(() => {
|
|
49
51
|
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
52
|
}, [toggleDialog]);
|
|
51
|
-
const startedAt = new Date((
|
|
53
|
+
const startedAt = new Date((_f = (_e = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps[0].execution) === null || _e === void 0 ? void 0 : _e.process[0].startedAt) !== null && _f !== void 0 ? _f : 0);
|
|
52
54
|
return ((0, jsx_runtime_1.jsxs)(SwapDetailsPage_style_1.Container, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
|
|
53
55
|
display: 'flex',
|
|
54
56
|
flex: 1,
|
|
55
57
|
justifyContent: 'space-between',
|
|
56
58
|
}, pb: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 12 }, { children: new Intl.DateTimeFormat(i18n.language, { dateStyle: 'long' }).format(startedAt) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 12 }, { children: new Intl.DateTimeFormat(i18n.language, {
|
|
57
59
|
timeStyle: 'short',
|
|
58
|
-
}).format(startedAt) }))] })), routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.
|
|
59
|
-
var _a, _b, _c, _d, _e;
|
|
60
|
-
const fromToken = index === 0
|
|
61
|
-
? Object.assign(Object.assign({}, step.action.fromToken), { amount: step.action.fromAmount }) : undefined;
|
|
62
|
-
const toToken = index === steps.length - 1
|
|
63
|
-
? Object.assign(Object.assign({}, ((_b = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.toToken) !== null && _b !== void 0 ? _b : (_c = step.action) === null || _c === void 0 ? void 0 : _c.toToken)), { amount: (_e = (_d = step.execution) === null || _d === void 0 ? void 0 : _d.toAmount) !== null && _e !== void 0 ? _e : step.estimate.toAmount }) : undefined;
|
|
64
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Step_1.Step, { step: step, fromToken: fromToken, toToken: toToken }), steps.length > 1 && index !== steps.length - 1 ? ((0, jsx_runtime_1.jsx)(StepDivider_1.StepDivider, {})) : null] }, step.id));
|
|
65
|
-
}), (0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ mt: 2 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
|
|
60
|
+
}).format(startedAt) }))] })), (0, Step_1.getStepList)(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route), (0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ mt: 2 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
|
|
66
61
|
display: 'flex',
|
|
67
62
|
flex: 1,
|
|
68
|
-
} }, { 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:
|
|
63
|
+
} }, { 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: copySupportId }, { 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: supportId }))] })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ 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') }))] })] }))] }));
|
|
69
64
|
};
|
|
70
65
|
exports.SwapDetailsPage = SwapDetailsPage;
|
|
@@ -14,6 +14,6 @@ const SwapHistoryEmpty = () => {
|
|
|
14
14
|
alignItems: 'center',
|
|
15
15
|
justifyContent: 'center',
|
|
16
16
|
paddingY: 12,
|
|
17
|
-
} }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 48 }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.
|
|
17
|
+
} }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 48 }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.ReceiptLongRounded, { fontSize: "inherit" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 18, fontWeight: 700 }, { children: t('swap.info.title.emptySwapHistory') })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2 }, { children: t('swap.info.message.emptySwapHistory') }))] })));
|
|
18
18
|
};
|
|
19
19
|
exports.SwapHistoryEmpty = SwapHistoryEmpty;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExchangeRateUpdateParams, Route } from '@lifi/sdk';
|
|
3
|
+
export interface ExchangeRateBottomSheetBase {
|
|
4
|
+
isOpen(): void;
|
|
5
|
+
open(resolver: (value: boolean) => void, data: ExchangeRateUpdateParams): void;
|
|
6
|
+
close(value?: boolean): void;
|
|
7
|
+
}
|
|
8
|
+
interface ExchangeRateBottomSheetProps {
|
|
9
|
+
data?: ExchangeRateUpdateParams;
|
|
10
|
+
onContinue?(): void;
|
|
11
|
+
onCancel?(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const ExchangeRateBottomSheet: import("react").ForwardRefExoticComponent<ExchangeRateBottomSheetProps & import("react").RefAttributes<ExchangeRateBottomSheetBase>>;
|
|
14
|
+
export declare const getTokenValueLossThreshold: (route?: Route) => boolean;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenValueLossThreshold = exports.ExchangeRateBottomSheet = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const big_js_1 = require("big.js");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const react_i18next_1 = require("react-i18next");
|
|
10
|
+
const BottomSheet_1 = require("../../components/BottomSheet");
|
|
11
|
+
const hooks_1 = require("../../hooks");
|
|
12
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
const StatusBottomSheet_style_1 = require("./StatusBottomSheet.style");
|
|
14
|
+
exports.ExchangeRateBottomSheet = (0, react_1.forwardRef)(({ onContinue, onCancel }, ref) => {
|
|
15
|
+
const [data, setData] = (0, react_1.useState)();
|
|
16
|
+
const bottomSheetRef = (0, react_1.useRef)(null);
|
|
17
|
+
const resolverRef = (0, react_1.useRef)();
|
|
18
|
+
const handleContinue = () => {
|
|
19
|
+
var _a;
|
|
20
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.close(true);
|
|
21
|
+
onContinue === null || onContinue === void 0 ? void 0 : onContinue();
|
|
22
|
+
};
|
|
23
|
+
const handleCancel = () => {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.close(false);
|
|
26
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
27
|
+
};
|
|
28
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
29
|
+
isOpen: () => { var _a; return (_a = bottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.isOpen(); },
|
|
30
|
+
open: (resolver, data) => {
|
|
31
|
+
var _a;
|
|
32
|
+
setData(data);
|
|
33
|
+
resolverRef.current = resolver;
|
|
34
|
+
(_a = bottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.open();
|
|
35
|
+
},
|
|
36
|
+
close: (value = false) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
(_a = resolverRef.current) === null || _a === void 0 ? void 0 : _a.call(resolverRef, value);
|
|
39
|
+
(_b = bottomSheetRef.current) === null || _b === void 0 ? void 0 : _b.close();
|
|
40
|
+
},
|
|
41
|
+
}), []);
|
|
42
|
+
return ((0, jsx_runtime_1.jsx)(BottomSheet_1.BottomSheet, Object.assign({ ref: bottomSheetRef }, { children: (0, jsx_runtime_1.jsx)(ExchangeRateBottomSheetContent, { data: data, onContinue: handleContinue, onCancel: handleCancel }) })));
|
|
43
|
+
});
|
|
44
|
+
const ExchangeRateBottomSheetContent = ({ data, onCancel, onContinue }) => {
|
|
45
|
+
const { t } = (0, react_i18next_1.useTranslation)();
|
|
46
|
+
const ref = (0, react_1.useRef)();
|
|
47
|
+
(0, hooks_1.useSetContentHeight)(ref);
|
|
48
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ p: 3, ref: ref }, { children: [(0, jsx_runtime_1.jsxs)(StatusBottomSheet_style_1.IconContainer, { children: [(0, jsx_runtime_1.jsx)(StatusBottomSheet_style_1.IconCircle, Object.assign({ status: "warning", mb: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.WarningRounded, { color: "warning" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: t('swap.warning.title.rateChanged') }))] }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1 }, { children: t('swap.warning.message.rateChanged') })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", mt: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: t('swap.quotedAmount') }), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ fontWeight: 600 }, { children: [t('format.number', {
|
|
49
|
+
value: (0, utils_1.formatTokenAmount)(data === null || data === void 0 ? void 0 : data.oldToAmount, data === null || data === void 0 ? void 0 : data.toToken.decimals),
|
|
50
|
+
}), ' ', data === null || data === void 0 ? void 0 : data.toToken.symbol] }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", mt: 0.25 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: t('swap.currentAmount') }), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ fontWeight: 600 }, { children: [t('format.number', {
|
|
51
|
+
value: (0, utils_1.formatTokenAmount)(data === null || data === void 0 ? void 0 : data.newToAmount, data === null || data === void 0 ? void 0 : data.toToken.decimals),
|
|
52
|
+
}), ' ', data === null || data === void 0 ? void 0 : data.toToken.symbol] }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", mt: 0.25 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: t('swap.rateChange') }), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ fontWeight: 600 }, { children: [(0, big_js_1.default)((data === null || data === void 0 ? void 0 : data.newToAmount) || 0)
|
|
53
|
+
.div((0, big_js_1.default)((data === null || data === void 0 ? void 0 : data.oldToAmount) || 0))
|
|
54
|
+
.minus(1)
|
|
55
|
+
.mul(100)
|
|
56
|
+
.round(2, big_js_1.default.roundUp)
|
|
57
|
+
.toString(), "%"] }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", mt: 3 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "text", onClick: onCancel, fullWidth: true }, { children: t('button.cancel') })), (0, jsx_runtime_1.jsx)(material_1.Box, { display: "flex", p: 1 }), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", onClick: onContinue, fullWidth: true }, { children: t('button.continue') }))] }))] })));
|
|
58
|
+
};
|
|
59
|
+
const getTokenValueLossThreshold = (route) => {
|
|
60
|
+
if (!route) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const fromAmountUSD = (0, big_js_1.default)((route === null || route === void 0 ? void 0 : route.fromAmountUSD) || 0);
|
|
64
|
+
const toAmountUSD = (0, big_js_1.default)((route === null || route === void 0 ? void 0 : route.toAmountUSD) || 0);
|
|
65
|
+
const gasCostUSD = (0, big_js_1.default)((route === null || route === void 0 ? void 0 : route.gasCostUSD) || 0);
|
|
66
|
+
if (fromAmountUSD.eq(0) && toAmountUSD.eq(0)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return toAmountUSD.div(fromAmountUSD.plus(gasCostUSD)).lt(0.9);
|
|
70
|
+
};
|
|
71
|
+
exports.getTokenValueLossThreshold = getTokenValueLossThreshold;
|
|
@@ -16,7 +16,7 @@ const stores_1 = require("../../stores");
|
|
|
16
16
|
const utils_1 = require("../../utils");
|
|
17
17
|
const StatusBottomSheet_style_1 = require("./StatusBottomSheet.style");
|
|
18
18
|
const StatusBottomSheet = ({ status, route, }) => {
|
|
19
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
20
20
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
21
21
|
const { navigateBack, navigate } = (0, hooks_1.useNavigateBack)();
|
|
22
22
|
const ref = (0, react_1.useRef)(null);
|
|
@@ -95,9 +95,25 @@ const StatusBottomSheet = ({ status, route, }) => {
|
|
|
95
95
|
handlePrimaryButton = handlePartialDone;
|
|
96
96
|
break;
|
|
97
97
|
}
|
|
98
|
+
case stores_1.RouteExecutionStatus.Done | stores_1.RouteExecutionStatus.Refunded: {
|
|
99
|
+
title = t('swap.success.title.refundIssued');
|
|
100
|
+
primaryMessage = t('swap.success.message.swapPartiallySuccessful', {
|
|
101
|
+
tool: (_o = route.steps.at(-1)) === null || _o === void 0 ? void 0 : _o.toolDetails.name,
|
|
102
|
+
tokenSymbol: (_p = route.steps.at(-1)) === null || _p === void 0 ? void 0 : _p.action.toToken.symbol,
|
|
103
|
+
});
|
|
104
|
+
if (token) {
|
|
105
|
+
secondaryMessage = t('swap.success.message.swapSuccessful', {
|
|
106
|
+
amount: token.amount,
|
|
107
|
+
tokenSymbol: token.symbol,
|
|
108
|
+
chainName: (_q = getChainById(token.chainId)) === null || _q === void 0 ? void 0 : _q.name,
|
|
109
|
+
walletAddress: (0, utils_1.shortenWalletAddress)(route.toAddress),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
98
114
|
case stores_1.RouteExecutionStatus.Failed: {
|
|
99
115
|
const step = route.steps.find((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
100
|
-
const process = (
|
|
116
|
+
const process = (_r = step === null || step === void 0 ? void 0 : step.execution) === null || _r === void 0 ? void 0 : _r.process.find((process) => process.status === 'FAILED');
|
|
101
117
|
if (!step || !process) {
|
|
102
118
|
break;
|
|
103
119
|
}
|
|
@@ -122,8 +138,8 @@ const StatusBottomSheet = ({ status, route, }) => {
|
|
|
122
138
|
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.open();
|
|
123
139
|
}
|
|
124
140
|
}, [refetch, refetchNewBalance, status]);
|
|
125
|
-
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 === stores_1.RouteExecutionStatus.Idle ? ((0, jsx_runtime_1.jsx)(icons_material_1.
|
|
126
|
-
(0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Refunded) ? ((0, jsx_runtime_1.jsx)(icons_material_1.
|
|
141
|
+
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 === stores_1.RouteExecutionStatus.Idle ? ((0, jsx_runtime_1.jsx)(icons_material_1.InfoRounded, { color: "primary" })) : null, status === stores_1.RouteExecutionStatus.Done ? ((0, jsx_runtime_1.jsx)(icons_material_1.Done, { color: "success" })) : null, (0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Partial) ||
|
|
142
|
+
(0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Refunded) ? ((0, jsx_runtime_1.jsx)(icons_material_1.WarningRounded, { color: "warning" })) : null, (0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Failed) ? ((0, jsx_runtime_1.jsx)(icons_material_1.ErrorRounded, { color: "error" })) : null] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: title })), (0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Done) ? ((0, jsx_runtime_1.jsx)(Token_1.Token, { token: toToken, py: 1, disableDescription: true })) : null] }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1 }, { children: primaryMessage })), secondaryMessage ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1 }, { children: secondaryMessage }))) : null, (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: handlePrimaryButton }, { children: [status === stores_1.RouteExecutionStatus.Idle ? t('button.ok') : null, (0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Done)
|
|
127
143
|
? t('button.done')
|
|
128
144
|
: null, status === stores_1.RouteExecutionStatus.Failed
|
|
129
145
|
? t('button.seeDetails')
|
|
@@ -7,15 +7,15 @@ const stores_1 = require("../../stores");
|
|
|
7
7
|
const getStatusColor = (status, theme) => {
|
|
8
8
|
switch (status) {
|
|
9
9
|
case stores_1.RouteExecutionStatus.Done:
|
|
10
|
-
return { color: theme.palette.success.main, alpha: 0.
|
|
10
|
+
return { color: theme.palette.success.main, alpha: 0.12, darken: 0 };
|
|
11
11
|
case stores_1.RouteExecutionStatus.Failed:
|
|
12
|
-
return { color: theme.palette.error.main, alpha: 0.
|
|
12
|
+
return { color: theme.palette.error.main, alpha: 0.12, darken: 0 };
|
|
13
13
|
case stores_1.RouteExecutionStatus.Done | stores_1.RouteExecutionStatus.Partial:
|
|
14
14
|
case stores_1.RouteExecutionStatus.Done | stores_1.RouteExecutionStatus.Refunded:
|
|
15
15
|
case 'warning':
|
|
16
|
-
return { color: theme.palette.warning.main, alpha: 0.
|
|
16
|
+
return { color: theme.palette.warning.main, alpha: 0.48, darken: 0.32 };
|
|
17
17
|
default:
|
|
18
|
-
return { color: theme.palette.primary.main, alpha: 0.
|
|
18
|
+
return { color: theme.palette.primary.main, alpha: 0.12, darken: 0 };
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
exports.IconContainer = (0, styles_1.styled)(material_1.Box)(({ theme }) => ({
|
|
@@ -19,21 +19,26 @@ const react_i18next_1 = require("react-i18next");
|
|
|
19
19
|
const react_router_dom_1 = require("react-router-dom");
|
|
20
20
|
const GasSufficiencyMessage_1 = require("../../components/GasSufficiencyMessage");
|
|
21
21
|
const Step_1 = require("../../components/Step");
|
|
22
|
-
const StepDivider_1 = require("../../components/StepDivider");
|
|
23
22
|
const SwapButton_1 = require("../../components/SwapButton");
|
|
24
23
|
const hooks_1 = require("../../hooks");
|
|
25
24
|
const providers_1 = require("../../providers");
|
|
26
25
|
const stores_1 = require("../../stores");
|
|
26
|
+
const ExchangeRateBottomSheet_1 = require("./ExchangeRateBottomSheet");
|
|
27
27
|
const StatusBottomSheet_1 = require("./StatusBottomSheet");
|
|
28
28
|
const SwapPage_style_1 = require("./SwapPage.style");
|
|
29
29
|
const TokenValueBottomSheet_1 = require("./TokenValueBottomSheet");
|
|
30
30
|
const SwapPage = () => {
|
|
31
|
+
var _a;
|
|
31
32
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
32
33
|
const { state } = (0, react_router_dom_1.useLocation)();
|
|
33
34
|
const { navigateBack } = (0, hooks_1.useNavigateBack)();
|
|
34
35
|
const tokenValueBottomSheetRef = (0, react_1.useRef)(null);
|
|
36
|
+
const exchangeRateBottomSheetRef = (0, react_1.useRef)(null);
|
|
35
37
|
const { setValue } = (0, react_hook_form_1.useFormContext)();
|
|
36
|
-
const { route, status, executeRoute, restartRoute, deleteRoute } = (0, hooks_1.useRouteExecution)(
|
|
38
|
+
const { route, status, executeRoute, restartRoute, deleteRoute } = (0, hooks_1.useRouteExecution)({
|
|
39
|
+
routeId: state === null || state === void 0 ? void 0 : state.routeId,
|
|
40
|
+
onAcceptExchangeRateUpdate: (_a = exchangeRateBottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.open,
|
|
41
|
+
});
|
|
37
42
|
const handleExecuteRoute = (0, react_1.useCallback)(() => {
|
|
38
43
|
var _a, _b;
|
|
39
44
|
if ((_a = tokenValueBottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.isOpen()) {
|
|
@@ -43,11 +48,11 @@ const SwapPage = () => {
|
|
|
43
48
|
setValue(providers_1.SwapFormKey.FromAmount, '');
|
|
44
49
|
}, [executeRoute, setValue]);
|
|
45
50
|
const handleSwapClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
var
|
|
51
|
+
var _b;
|
|
47
52
|
if (status === stores_1.RouteExecutionStatus.Idle) {
|
|
48
53
|
const thresholdExceeded = (0, TokenValueBottomSheet_1.getTokenValueLossThreshold)(route);
|
|
49
54
|
if (thresholdExceeded) {
|
|
50
|
-
(
|
|
55
|
+
(_b = tokenValueBottomSheetRef.current) === null || _b === void 0 ? void 0 : _b.open();
|
|
51
56
|
}
|
|
52
57
|
else {
|
|
53
58
|
handleExecuteRoute();
|
|
@@ -66,24 +71,17 @@ const SwapPage = () => {
|
|
|
66
71
|
case stores_1.RouteExecutionStatus.Idle:
|
|
67
72
|
return t('button.startSwap');
|
|
68
73
|
case stores_1.RouteExecutionStatus.Failed:
|
|
69
|
-
return t('button.
|
|
74
|
+
return t('button.tryAgain');
|
|
70
75
|
default:
|
|
71
76
|
return '';
|
|
72
77
|
}
|
|
73
78
|
};
|
|
74
|
-
return ((0, jsx_runtime_1.jsxs)(SwapPage_style_1.Container, { children: [
|
|
75
|
-
var _a, _b, _c, _d, _e;
|
|
76
|
-
const fromToken = index === 0
|
|
77
|
-
? Object.assign(Object.assign({}, step.action.fromToken), { amount: step.action.fromAmount }) : undefined;
|
|
78
|
-
const toToken = index === steps.length - 1
|
|
79
|
-
? Object.assign(Object.assign({}, ((_b = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.toToken) !== null && _b !== void 0 ? _b : (_c = step.action) === null || _c === void 0 ? void 0 : _c.toToken)), { amount: (_e = (_d = step.execution) === null || _d === void 0 ? void 0 : _d.toAmount) !== null && _e !== void 0 ? _e : step.estimate.toAmount }) : undefined;
|
|
80
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Step_1.Step, { step: step, fromToken: fromToken, toToken: toToken }), steps.length > 1 && index !== steps.length - 1 ? ((0, jsx_runtime_1.jsx)(StepDivider_1.StepDivider, {})) : null] }, step.id));
|
|
81
|
-
}), status === stores_1.RouteExecutionStatus.Idle ||
|
|
79
|
+
return ((0, jsx_runtime_1.jsxs)(SwapPage_style_1.Container, { children: [(0, Step_1.getStepList)(route), status === stores_1.RouteExecutionStatus.Idle ||
|
|
82
80
|
status === stores_1.RouteExecutionStatus.Failed ? ((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,
|
|
83
81
|
// disable={status === 'idle' && (isValidating || !isValid)}
|
|
84
82
|
enableLoading: true }), status === stores_1.RouteExecutionStatus.Failed ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t('button.removeSwap'), placement: "bottom-end", enterDelay: 400, arrow: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ onClick: handleRemoveRoute, sx: {
|
|
85
83
|
minWidth: 48,
|
|
86
84
|
marginLeft: 1,
|
|
87
|
-
} }, { 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, route ? ((0, jsx_runtime_1.jsx)(TokenValueBottomSheet_1.TokenValueBottomSheet, { route: route, ref: tokenValueBottomSheetRef, onContinue: handleExecuteRoute })) : null] }));
|
|
85
|
+
} }, { 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, route ? ((0, jsx_runtime_1.jsx)(TokenValueBottomSheet_1.TokenValueBottomSheet, { route: route, ref: tokenValueBottomSheetRef, onContinue: handleExecuteRoute })) : null, route ? (0, jsx_runtime_1.jsx)(ExchangeRateBottomSheet_1.ExchangeRateBottomSheet, { ref: exchangeRateBottomSheetRef }) : null] }));
|
|
88
86
|
};
|
|
89
87
|
exports.SwapPage = SwapPage;
|
|
@@ -22,11 +22,12 @@ const TokenValueBottomSheetContent = ({ route, onCancel, onContinue, }) => {
|
|
|
22
22
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
23
23
|
const ref = (0, react_1.useRef)();
|
|
24
24
|
(0, hooks_1.useSetContentHeight)(ref);
|
|
25
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ p: 3, ref: ref }, { children: [(0, jsx_runtime_1.jsxs)(StatusBottomSheet_style_1.IconContainer, { children: [(0, jsx_runtime_1.jsx)(StatusBottomSheet_style_1.IconCircle, Object.assign({ status: "warning", mb: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.
|
|
25
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ p: 3, ref: ref }, { children: [(0, jsx_runtime_1.jsxs)(StatusBottomSheet_style_1.IconContainer, { children: [(0, jsx_runtime_1.jsx)(StatusBottomSheet_style_1.IconCircle, Object.assign({ status: "warning", mb: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.WarningRounded, { color: "warning" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: t('swap.warning.title.highValueLoss') }))] }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ py: 1 }, { children: t('swap.warning.message.highValueLoss') })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", mt: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: t('swap.swapping') }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontWeight: 600 }, { children: t('format.currency', { value: route.fromAmountUSD }) }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", mt: 0.25 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: t('swap.gasCost') }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontWeight: 600 }, { children: t('format.currency', { value: route.gasCostUSD }) }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", mt: 0.25 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: t('swap.receiving') }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontWeight: 600 }, { children: t('format.currency', { value: route.toAmountUSD }) }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", mt: 0.25 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: t('swap.valueLoss') }), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ fontWeight: 600 }, { children: [(0, big_js_1.default)(route.toAmountUSD || 0)
|
|
26
26
|
.div((0, big_js_1.default)(route.fromAmountUSD || 0).plus((0, big_js_1.default)(route.gasCostUSD || 0)))
|
|
27
27
|
.minus(1)
|
|
28
28
|
.mul(100)
|
|
29
|
-
.
|
|
29
|
+
.round(2, big_js_1.default.roundUp)
|
|
30
|
+
.toString(), "%"] }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", mt: 3 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "text", onClick: onCancel, fullWidth: true }, { children: t('button.cancel') })), (0, jsx_runtime_1.jsx)(material_1.Box, { display: "flex", p: 1 }), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "contained", onClick: onContinue, fullWidth: true }, { children: t('button.continue') }))] }))] })));
|
|
30
31
|
};
|
|
31
32
|
const getTokenValueLossThreshold = (route) => {
|
|
32
33
|
if (!route) {
|
|
@@ -20,6 +20,7 @@ exports.navigationRoutesValues = Object.values(exports.navigationRoutes);
|
|
|
20
20
|
exports.stickyHeaderRoutes = [
|
|
21
21
|
exports.navigationRoutes.activeSwaps,
|
|
22
22
|
exports.navigationRoutes.fromChain,
|
|
23
|
+
exports.navigationRoutes.home,
|
|
23
24
|
exports.navigationRoutes.selectWallet,
|
|
24
25
|
exports.navigationRoutes.settings,
|
|
25
26
|
exports.navigationRoutes.swapDetails,
|