@lifi/widget 1.23.1 → 1.25.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/AppDrawer.style.d.ts +1 -1
- package/AppProvider.js +1 -1
- package/cjs/AppDrawer.style.d.ts +1 -1
- package/cjs/AppProvider.js +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwapItem.js +2 -1
- package/cjs/components/BottomSheet/types.d.ts +1 -1
- package/cjs/components/Card/Card.d.ts +2 -2
- package/cjs/components/Card/CardTitle.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.js +6 -1
- package/cjs/components/ChainSelect/useChainSelect.d.ts +3 -1
- package/cjs/components/ChainSelect/useChainSelect.js +12 -3
- package/cjs/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/cjs/components/StepActions/StepActions.js +2 -2
- package/cjs/components/SwapInput/FitInputText.d.ts +3 -0
- package/cjs/components/SwapInput/FitInputText.js +19 -0
- package/cjs/components/SwapInput/FormPriceHelperText.d.ts +1 -3
- package/cjs/components/SwapInput/FormPriceHelperText.js +1 -1
- package/cjs/components/SwapInput/SwapInput.js +12 -24
- package/cjs/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +3 -0
- package/cjs/components/SwapInput/{SwapInputAdornment.js → SwapInputEndAdornment.js} +3 -3
- package/cjs/components/SwapInput/SwapInputStartAdornment.d.ts +3 -0
- package/cjs/components/SwapInput/SwapInputStartAdornment.js +21 -0
- package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/cjs/components/SwapRoutes/SwapRoutes.style.d.ts +1 -1
- package/cjs/components/Token/Token.style.d.ts +1 -1
- package/cjs/components/TokenList/useTokenSelect.js +12 -9
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useGasSufficiency.js +1 -1
- package/cjs/hooks/useRouteExecution.js +1 -1
- package/cjs/hooks/useSwapRoutes.js +12 -9
- package/cjs/hooks/useTelemetry.js +3 -1
- package/cjs/hooks/useTools.d.ts +5 -2
- package/cjs/i18n/en.json +3 -1
- package/cjs/i18n/uk.json +11 -6
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +2 -1
- package/cjs/pages/SettingsPage/SlippageInput.js +2 -1
- package/cjs/pages/SwapHistoryPage/SwapHistoryItem.js +4 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.js +63 -15
- package/cjs/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.style.js +5 -2
- package/cjs/pages/SwapPage/SwapPage.js +8 -6
- package/cjs/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
- package/cjs/providers/I18nProvider/types.d.ts +5 -5
- package/cjs/providers/SwapFormProvider/FormUpdater.d.ts +5 -0
- package/cjs/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js} +24 -21
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +12 -7
- package/cjs/providers/SwapFormProvider/types.d.ts +2 -2
- package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -1
- package/cjs/providers/WalletProvider/WalletProvider.js +1 -2
- package/cjs/providers/WalletProvider/types.d.ts +3 -3
- package/cjs/providers/WidgetProvider/WidgetProvider.js +4 -0
- package/cjs/providers/WidgetProvider/types.d.ts +1 -1
- package/cjs/stores/routes/types.d.ts +8 -1
- package/cjs/stores/routes/types.js +10 -0
- package/cjs/stores/routes/useExecutingRoutesIds.js +3 -1
- package/cjs/stores/routes/useRouteExecutionStore.js +53 -18
- package/cjs/stores/routes/useSwapHistory.js +4 -1
- package/cjs/stores/routes/utils.d.ts +3 -1
- package/cjs/stores/routes/utils.js +12 -4
- package/cjs/stores/settings/types.d.ts +6 -6
- package/cjs/stores/settings/useSettingsStore.d.ts +12 -9
- package/cjs/stores/settings/useSettingsStore.js +22 -5
- package/cjs/types/events.d.ts +1 -1
- package/cjs/types/widget.d.ts +13 -8
- package/cjs/utils/enum.d.ts +1 -0
- package/cjs/utils/enum.js +5 -0
- package/cjs/utils/index.d.ts +1 -0
- package/cjs/utils/index.js +1 -0
- package/cjs/utils/navigationRoutes.d.ts +1 -1
- package/components/ActiveSwaps/ActiveSwapItem.js +2 -1
- package/components/BottomSheet/types.d.ts +1 -1
- package/components/Card/Card.d.ts +2 -2
- package/components/Card/CardTitle.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.js +6 -1
- package/components/ChainSelect/useChainSelect.d.ts +3 -1
- package/components/ChainSelect/useChainSelect.js +13 -4
- package/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/components/StepActions/StepActions.js +2 -2
- package/components/SwapInput/FitInputText.d.ts +3 -0
- package/components/SwapInput/FitInputText.js +16 -0
- package/components/SwapInput/FormPriceHelperText.d.ts +1 -3
- package/components/SwapInput/FormPriceHelperText.js +1 -1
- package/components/SwapInput/SwapInput.js +16 -28
- package/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/components/SwapInput/SwapInputEndAdornment.d.ts +3 -0
- package/components/SwapInput/{SwapInputAdornment.js → SwapInputEndAdornment.js} +1 -1
- package/components/SwapInput/SwapInputStartAdornment.d.ts +3 -0
- package/components/SwapInput/SwapInputStartAdornment.js +17 -0
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/components/SwapRoutes/SwapRoutes.style.d.ts +1 -1
- package/components/Token/Token.style.d.ts +1 -1
- package/components/TokenList/useTokenSelect.js +13 -10
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useGasSufficiency.js +2 -2
- package/hooks/useRouteExecution.js +2 -2
- package/hooks/useSwapRoutes.js +12 -9
- package/hooks/useTelemetry.js +3 -1
- package/hooks/useTools.d.ts +5 -2
- package/i18n/en.json +3 -1
- package/i18n/uk.json +11 -6
- package/package.json +13 -13
- package/pages/SettingsPage/RoutePrioritySelect.js +2 -1
- package/pages/SettingsPage/SlippageInput.js +2 -1
- package/pages/SwapHistoryPage/SwapHistoryItem.js +4 -2
- package/pages/SwapPage/StatusBottomSheet.js +64 -16
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -2
- package/pages/SwapPage/StatusBottomSheet.style.js +5 -2
- package/pages/SwapPage/SwapPage.js +8 -6
- package/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
- package/providers/I18nProvider/types.d.ts +5 -5
- package/providers/SwapFormProvider/FormUpdater.d.ts +5 -0
- package/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js} +23 -20
- package/providers/SwapFormProvider/SwapFormProvider.js +12 -7
- package/providers/SwapFormProvider/types.d.ts +2 -2
- package/providers/WalletProvider/WalletProvider.d.ts +1 -1
- package/providers/WalletProvider/WalletProvider.js +2 -3
- package/providers/WalletProvider/types.d.ts +3 -3
- package/providers/WidgetProvider/WidgetProvider.js +5 -1
- package/providers/WidgetProvider/types.d.ts +1 -1
- package/stores/routes/types.d.ts +8 -1
- package/stores/routes/types.js +9 -1
- package/stores/routes/useExecutingRoutesIds.js +3 -1
- package/stores/routes/useRouteExecutionStore.js +51 -16
- package/stores/routes/useSwapHistory.js +4 -1
- package/stores/routes/utils.d.ts +3 -1
- package/stores/routes/utils.js +8 -2
- package/stores/settings/types.d.ts +6 -6
- package/stores/settings/useSettingsStore.d.ts +12 -9
- package/stores/settings/useSettingsStore.js +20 -4
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +1 -1
- package/types/widget.d.ts +13 -8
- package/utils/enum.d.ts +1 -0
- package/utils/enum.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/navigationRoutes.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputAdornment.d.ts +0 -3
- package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +0 -5
- package/components/SwapInput/SwapInputAdornment.d.ts +0 -3
- package/providers/WalletProvider/WalletFormUpdate.d.ts +0 -5
package/cjs/i18n/uk.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"delete": "Видалити",
|
|
11
11
|
"disconnectWallet": "Відключити гаманець",
|
|
12
12
|
"done": "Готово",
|
|
13
|
+
"getGas": "Отримати газ",
|
|
13
14
|
"hide": "Сховати",
|
|
14
15
|
"lifiSwap": "LI.FI Swap",
|
|
15
16
|
"light": "Світла",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"reviewSwap": "Переглянути своп",
|
|
22
23
|
"seeDetails": "Детальніше",
|
|
23
24
|
"showAll": "Показати всі",
|
|
25
|
+
"startGasSwap": "Почати своп газу",
|
|
24
26
|
"startSwap": "Почати своп",
|
|
25
27
|
"swap": "Своп",
|
|
26
28
|
"tryAgain": "Спробувати ще раз"
|
|
@@ -32,6 +34,8 @@
|
|
|
32
34
|
"header": {
|
|
33
35
|
"activeSwaps": "Активні свопи",
|
|
34
36
|
"from": "Своп з",
|
|
37
|
+
"gas": "Газ",
|
|
38
|
+
"gasSwap": "Своп газу",
|
|
35
39
|
"routes": "Ви отримуєте",
|
|
36
40
|
"selectChain": "Оберіть чейн",
|
|
37
41
|
"selectWallet": "Виберіть свій гаманець",
|
|
@@ -64,7 +68,7 @@
|
|
|
64
68
|
"slippage": "Прослизання"
|
|
65
69
|
},
|
|
66
70
|
"swap": {
|
|
67
|
-
"crossStepDetails": "
|
|
71
|
+
"crossStepDetails": "Брідж з {{from}} до {{to}} через {{tool}}",
|
|
68
72
|
"error": {
|
|
69
73
|
"message": {
|
|
70
74
|
"slippageTooLarge": "Прослизання більше визначеного порогу. Будь ласка, оберіть новий маршрут, щоб отримати свіжу пропозицію.",
|
|
@@ -85,7 +89,7 @@
|
|
|
85
89
|
"walletEnsAddressInvalid": "Адреса гаманця недійсна або мережа не підтримує ENS."
|
|
86
90
|
}
|
|
87
91
|
},
|
|
88
|
-
"estimatedTime": "{{value}}
|
|
92
|
+
"estimatedTime": "{{value}}х",
|
|
89
93
|
"featuredTokens": "Рекомендовані токени",
|
|
90
94
|
"from": "З",
|
|
91
95
|
"fromAmount": "Ви платите",
|
|
@@ -139,14 +143,15 @@
|
|
|
139
143
|
"selectChainAndToken": "Виберіть чейн і токен",
|
|
140
144
|
"selectToken": "Токен",
|
|
141
145
|
"sendToWallet": "Надіслати на інший гаманець",
|
|
142
|
-
"stepBridge": "
|
|
146
|
+
"stepBridge": "Брідж",
|
|
143
147
|
"stepSwap": "Своп",
|
|
144
|
-
"stepSwapAndBridge": "Своп
|
|
148
|
+
"stepSwapAndBridge": "Своп та брідж",
|
|
145
149
|
"success": {
|
|
146
150
|
"message": {
|
|
147
151
|
"swapSuccessful": "Зараз у гаманці {{walletAddress}} на чейні {{chainName}} є {{amount, number(maximumFractionDigits: 4)}} {{tokenSymbol}}."
|
|
148
152
|
},
|
|
149
153
|
"title": {
|
|
154
|
+
"gasSwapSuccessful": "Своп газу успішний",
|
|
150
155
|
"swapSuccessful": "Своп успішний"
|
|
151
156
|
}
|
|
152
157
|
},
|
|
@@ -154,10 +159,10 @@
|
|
|
154
159
|
"swapStepDetails": "Своп на {{chain}} через {{tool}}",
|
|
155
160
|
"swapping": "Обмін",
|
|
156
161
|
"tags": {
|
|
157
|
-
"ALTERNATIVE": "
|
|
162
|
+
"ALTERNATIVE": "АЛЬТЕРНАТИВА",
|
|
158
163
|
"CHEAPEST": "ДЕШЕВИЙ",
|
|
159
164
|
"FASTEST": "ШВИДКИЙ",
|
|
160
|
-
"RECOMMENDED": "
|
|
165
|
+
"RECOMMENDED": "РЕКОМЕНДУЄМО",
|
|
161
166
|
"SAFEST": "БЕЗПЕЧНИЙ"
|
|
162
167
|
},
|
|
163
168
|
"to": "До",
|
|
@@ -13,7 +13,8 @@ const RoutePrioritySelect = () => {
|
|
|
13
13
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
14
14
|
const setValue = (0, stores_1.useSettingsStore)((state) => state.setValue);
|
|
15
15
|
const { routePriority } = (0, stores_1.useSettings)(['routePriority']);
|
|
16
|
-
|
|
16
|
+
const value = routePriority !== null && routePriority !== void 0 ? routePriority : '';
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)(Card_1.Card, { children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, { children: t(`settings.routePriority`) }), (0, jsx_runtime_1.jsx)(material_1.FormControl, Object.assign({ fullWidth: true }, { children: (0, jsx_runtime_1.jsx)(Select_1.Select, Object.assign({ MenuProps: { elevation: 2 }, value: value, onChange: (event) => setValue('routePriority', event.target.value), IconComponent: icons_material_1.KeyboardArrowDown, dense: true }, { children: sdk_1.Orders.map((order) => {
|
|
17
18
|
const tag = t(`swap.tags.${order.toUpperCase()}`);
|
|
18
19
|
const tagName = `${tag[0]}${tag.slice(1).toLowerCase()}`;
|
|
19
20
|
return ((0, jsx_runtime_1.jsx)(material_1.MenuItem, Object.assign({ value: order }, { children: tagName }), order));
|
|
@@ -22,8 +22,9 @@ const SlippageInput = () => {
|
|
|
22
22
|
const { value } = event.target;
|
|
23
23
|
setValue('slippage', (0, utils_1.formatSlippage)(value, defaultValue.current));
|
|
24
24
|
};
|
|
25
|
+
const value = slippage !== null && slippage !== void 0 ? slippage : '';
|
|
25
26
|
return ((0, jsx_runtime_1.jsxs)(Card_1.Card, { children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, { children: t(`settings.slippage`) }), (0, jsx_runtime_1.jsx)(material_1.FormControl, Object.assign({ fullWidth: true }, { children: (0, jsx_runtime_1.jsx)(Input_1.Input, { size: "small", placeholder: t(`settings.slippage`), endAdornment: (0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "end" }, { children: "%" })), autoComplete: "off", inputProps: {
|
|
26
27
|
inputMode: 'decimal',
|
|
27
|
-
}, onChange: handleChange, onBlur: handleBlur, value:
|
|
28
|
+
}, onChange: handleChange, onBlur: handleBlur, value: value }) }))] }));
|
|
28
29
|
};
|
|
29
30
|
exports.SlippageInput = SlippageInput;
|
|
@@ -9,7 +9,7 @@ const Card_1 = require("../../components/Card");
|
|
|
9
9
|
const Token_1 = require("../../components/Token");
|
|
10
10
|
const utils_1 = require("../../utils");
|
|
11
11
|
const SwapHistoryItem = ({ route }) => {
|
|
12
|
-
var _a, _b, _c, _d, _e;
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
13
13
|
const { i18n } = (0, react_i18next_1.useTranslation)();
|
|
14
14
|
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
15
15
|
const handleClick = () => {
|
|
@@ -18,12 +18,14 @@ const SwapHistoryItem = ({ route }) => {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
const startedAt = new Date((_b = (_a = route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0);
|
|
21
|
+
const fromToken = Object.assign(Object.assign({}, route.fromToken), { amount: route.fromAmount });
|
|
22
|
+
const toToken = Object.assign(Object.assign({}, ((_e = (_d = (_c = route.steps.at(-1)) === null || _c === void 0 ? void 0 : _c.execution) === null || _d === void 0 ? void 0 : _d.toToken) !== null && _e !== void 0 ? _e : route.toToken)), { amount: (_h = (_g = (_f = route.steps.at(-1)) === null || _f === void 0 ? void 0 : _f.execution) === null || _g === void 0 ? void 0 : _g.toAmount) !== null && _h !== void 0 ? _h : route.toAmount });
|
|
21
23
|
return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ onClick: handleClick }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
|
|
22
24
|
display: 'flex',
|
|
23
25
|
flex: 1,
|
|
24
26
|
justifyContent: 'space-between',
|
|
25
27
|
}, pt: 1.75, px: 2 }, { 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, {
|
|
26
28
|
timeStyle: 'short',
|
|
27
|
-
}).format(startedAt) }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ py: 1 }, { children: [(0, jsx_runtime_1.jsx)(Token_1.Token, { token:
|
|
29
|
+
}).format(startedAt) }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ py: 1 }, { children: [(0, jsx_runtime_1.jsx)(Token_1.Token, { token: fromToken, px: 2, pt: 1, connected: true }), (0, jsx_runtime_1.jsx)(Token_1.TokenDivider, {}), (0, jsx_runtime_1.jsx)(Token_1.Token, { token: toToken, px: 2, pt: 0.5, pb: 1 })] }))] })));
|
|
28
30
|
};
|
|
29
31
|
exports.SwapHistoryItem = SwapHistoryItem;
|
|
@@ -12,16 +12,18 @@ const BottomSheet_1 = require("../../components/BottomSheet");
|
|
|
12
12
|
const Token_1 = require("../../components/Token");
|
|
13
13
|
const hooks_1 = require("../../hooks");
|
|
14
14
|
const providers_1 = require("../../providers");
|
|
15
|
+
const stores_1 = require("../../stores");
|
|
15
16
|
const utils_1 = require("../../utils");
|
|
16
17
|
const StatusBottomSheet_style_1 = require("./StatusBottomSheet.style");
|
|
17
18
|
const StatusBottomSheet = ({ status, route, }) => {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
19
20
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
20
21
|
const { navigateBack, navigate } = (0, hooks_1.useNavigateBack)();
|
|
21
22
|
const ref = (0, react_1.useRef)(null);
|
|
22
23
|
const { getChainById } = (0, hooks_1.useChains)();
|
|
23
24
|
const { setValue } = (0, react_hook_form_1.useFormContext)();
|
|
24
|
-
const
|
|
25
|
+
const toToken = Object.assign(Object.assign({}, ((_c = (_b = (_a = route.steps.at(-1)) === null || _a === void 0 ? void 0 : _a.execution) === null || _b === void 0 ? void 0 : _b.toToken) !== null && _c !== void 0 ? _c : route.toToken)), { amount: (_h = (_f = (_e = (_d = route.steps.at(-1)) === null || _d === void 0 ? void 0 : _d.execution) === null || _e === void 0 ? void 0 : _e.toAmount) !== null && _f !== void 0 ? _f : (_g = route.steps.at(-1)) === null || _g === void 0 ? void 0 : _g.estimate.toAmount) !== null && _h !== void 0 ? _h : route.toAmount });
|
|
26
|
+
const { token, refetch, refetchNewBalance, refetchAllBalances } = (0, hooks_1.useTokenBalance)(toToken, route.toAddress);
|
|
25
27
|
const clearFromAmount = () => {
|
|
26
28
|
refetchAllBalances();
|
|
27
29
|
setValue(providers_1.SwapFormKey.FromAmount, '');
|
|
@@ -30,6 +32,22 @@ const StatusBottomSheet = ({ status, route, }) => {
|
|
|
30
32
|
clearFromAmount();
|
|
31
33
|
navigateBack();
|
|
32
34
|
};
|
|
35
|
+
const handlePartialDone = () => {
|
|
36
|
+
clearFromAmount();
|
|
37
|
+
if (toToken.chainId !== route.toToken.chainId &&
|
|
38
|
+
toToken.address !== route.toToken.address) {
|
|
39
|
+
setValue(providers_1.SwapFormKey.FromAmount, (0, utils_1.formatTokenAmount)(toToken.amount, toToken.decimals), { shouldTouch: true });
|
|
40
|
+
setValue(providers_1.SwapFormKey.FromChain, toToken.chainId, { shouldTouch: true });
|
|
41
|
+
setValue(providers_1.SwapFormKey.FromToken, toToken.address, { shouldTouch: true });
|
|
42
|
+
setValue(providers_1.SwapFormKey.ToChain, route.toToken.chainId, {
|
|
43
|
+
shouldTouch: true,
|
|
44
|
+
});
|
|
45
|
+
setValue(providers_1.SwapFormKey.ToToken, route.toToken.address, {
|
|
46
|
+
shouldTouch: true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
navigateBack();
|
|
50
|
+
};
|
|
33
51
|
const handleClose = () => {
|
|
34
52
|
var _a;
|
|
35
53
|
clearFromAmount();
|
|
@@ -43,26 +61,50 @@ const StatusBottomSheet = ({ status, route, }) => {
|
|
|
43
61
|
});
|
|
44
62
|
};
|
|
45
63
|
let title;
|
|
46
|
-
let
|
|
64
|
+
let primaryMessage;
|
|
65
|
+
let secondaryMessage;
|
|
66
|
+
let handlePrimaryButton = handleDone;
|
|
47
67
|
switch (status) {
|
|
48
|
-
case
|
|
68
|
+
case stores_1.RouteExecutionStatus.Done: {
|
|
49
69
|
title = t('swap.success.title.swapSuccessful');
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
if (token) {
|
|
71
|
+
primaryMessage = t('swap.success.message.swapSuccessful', {
|
|
72
|
+
amount: token.amount,
|
|
73
|
+
tokenSymbol: token.symbol,
|
|
74
|
+
chainName: (_j = getChainById(token.chainId)) === null || _j === void 0 ? void 0 : _j.name,
|
|
75
|
+
walletAddress: (0, utils_1.shortenWalletAddress)(route.toAddress),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
handlePrimaryButton = handleDone;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case stores_1.RouteExecutionStatus.Done | stores_1.RouteExecutionStatus.Partial: {
|
|
82
|
+
title = t('swap.success.title.swapPartiallySuccessful');
|
|
83
|
+
primaryMessage = t('swap.success.message.swapPartiallySuccessful', {
|
|
84
|
+
tool: (_k = route.steps.at(-1)) === null || _k === void 0 ? void 0 : _k.toolDetails.name,
|
|
85
|
+
tokenSymbol: (_l = route.steps.at(-1)) === null || _l === void 0 ? void 0 : _l.action.toToken.symbol,
|
|
55
86
|
});
|
|
87
|
+
if (token) {
|
|
88
|
+
secondaryMessage = t('swap.success.message.swapSuccessful', {
|
|
89
|
+
amount: token.amount,
|
|
90
|
+
tokenSymbol: token.symbol,
|
|
91
|
+
chainName: (_m = getChainById(token.chainId)) === null || _m === void 0 ? void 0 : _m.name,
|
|
92
|
+
walletAddress: (0, utils_1.shortenWalletAddress)(route.toAddress),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
handlePrimaryButton = handlePartialDone;
|
|
56
96
|
break;
|
|
57
|
-
|
|
97
|
+
}
|
|
98
|
+
case stores_1.RouteExecutionStatus.Failed: {
|
|
58
99
|
const step = route.steps.find((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
59
|
-
const process = (
|
|
100
|
+
const process = (_o = step === null || step === void 0 ? void 0 : step.execution) === null || _o === void 0 ? void 0 : _o.process.find((process) => process.status === 'FAILED');
|
|
60
101
|
if (!step || !process) {
|
|
61
102
|
break;
|
|
62
103
|
}
|
|
63
104
|
const processMessage = (0, hooks_1.getProcessMessage)(t, getChainById, step, process);
|
|
64
105
|
title = processMessage.title;
|
|
65
|
-
|
|
106
|
+
primaryMessage = processMessage.message;
|
|
107
|
+
handlePrimaryButton = handleClose;
|
|
66
108
|
break;
|
|
67
109
|
}
|
|
68
110
|
default:
|
|
@@ -70,15 +112,21 @@ const StatusBottomSheet = ({ status, route, }) => {
|
|
|
70
112
|
}
|
|
71
113
|
(0, react_1.useEffect)(() => {
|
|
72
114
|
var _a, _b;
|
|
73
|
-
|
|
115
|
+
const hasSuccessFlag = (0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Done);
|
|
116
|
+
if ((hasSuccessFlag || (0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Failed)) &&
|
|
74
117
|
!((_a = ref.current) === null || _a === void 0 ? void 0 : _a.isOpen())) {
|
|
75
|
-
if (
|
|
118
|
+
if (hasSuccessFlag) {
|
|
76
119
|
refetchNewBalance();
|
|
77
120
|
refetch();
|
|
78
121
|
}
|
|
79
122
|
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.open();
|
|
80
123
|
}
|
|
81
124
|
}, [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 ===
|
|
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.Info, { 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) ||
|
|
126
|
+
(0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Refunded) ? ((0, jsx_runtime_1.jsx)(icons_material_1.Warning, { color: "warning" })) : null, (0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Failed) ? ((0, jsx_runtime_1.jsx)(icons_material_1.Warning, { 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
|
+
? t('button.done')
|
|
128
|
+
: null, status === stores_1.RouteExecutionStatus.Failed
|
|
129
|
+
? t('button.seeDetails')
|
|
130
|
+
: null] })) })), (0, utils_1.hasEnumFlag)(status, stores_1.RouteExecutionStatus.Done) ? ((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", onClick: handleSeeDetails, fullWidth: true }, { children: t('button.seeDetails') })) }))) : null] })) })));
|
|
83
131
|
};
|
|
84
132
|
exports.StatusBottomSheet = StatusBottomSheet;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Theme } from '@mui/material';
|
|
3
|
-
import
|
|
3
|
+
import { RouteExecutionStatus } from '../../stores';
|
|
4
|
+
type StatusColor = RouteExecutionStatus | 'warning';
|
|
4
5
|
export declare const IconContainer: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
|
|
5
6
|
children?: import("react").ReactNode;
|
|
6
7
|
component?: import("react").ElementType<any> | undefined;
|
|
@@ -17,5 +18,6 @@ export declare const IconCircle: import("@emotion/styled").StyledComponent<impor
|
|
|
17
18
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
18
19
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
19
20
|
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "ref" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "component"> & import("@mui/system").MUIStyledCommonProps<Theme> & {
|
|
20
|
-
status:
|
|
21
|
+
status: StatusColor;
|
|
21
22
|
}, {}, {}>;
|
|
23
|
+
export {};
|
|
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IconCircle = exports.IconContainer = void 0;
|
|
4
4
|
const material_1 = require("@mui/material");
|
|
5
5
|
const styles_1 = require("@mui/material/styles");
|
|
6
|
+
const stores_1 = require("../../stores");
|
|
6
7
|
const getStatusColor = (status, theme) => {
|
|
7
8
|
switch (status) {
|
|
8
|
-
case
|
|
9
|
+
case stores_1.RouteExecutionStatus.Done:
|
|
9
10
|
return { color: theme.palette.success.main, alpha: 0.15, darken: 0 };
|
|
10
|
-
case
|
|
11
|
+
case stores_1.RouteExecutionStatus.Failed:
|
|
11
12
|
return { color: theme.palette.error.main, alpha: 0.2, darken: 0 };
|
|
13
|
+
case stores_1.RouteExecutionStatus.Done | stores_1.RouteExecutionStatus.Partial:
|
|
14
|
+
case stores_1.RouteExecutionStatus.Done | stores_1.RouteExecutionStatus.Refunded:
|
|
12
15
|
case 'warning':
|
|
13
16
|
return { color: theme.palette.warning.main, alpha: 0.7, darken: 0.4 };
|
|
14
17
|
default:
|
|
@@ -23,6 +23,7 @@ const StepDivider_1 = require("../../components/StepDivider");
|
|
|
23
23
|
const SwapButton_1 = require("../../components/SwapButton");
|
|
24
24
|
const hooks_1 = require("../../hooks");
|
|
25
25
|
const providers_1 = require("../../providers");
|
|
26
|
+
const stores_1 = require("../../stores");
|
|
26
27
|
const StatusBottomSheet_1 = require("./StatusBottomSheet");
|
|
27
28
|
const SwapPage_style_1 = require("./SwapPage.style");
|
|
28
29
|
const TokenValueBottomSheet_1 = require("./TokenValueBottomSheet");
|
|
@@ -43,7 +44,7 @@ const SwapPage = () => {
|
|
|
43
44
|
}, [executeRoute, setValue]);
|
|
44
45
|
const handleSwapClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
46
|
var _a;
|
|
46
|
-
if (status ===
|
|
47
|
+
if (status === stores_1.RouteExecutionStatus.Idle) {
|
|
47
48
|
const thresholdExceeded = (0, TokenValueBottomSheet_1.getTokenValueLossThreshold)(route);
|
|
48
49
|
if (thresholdExceeded) {
|
|
49
50
|
(_a = tokenValueBottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.open();
|
|
@@ -52,7 +53,7 @@ const SwapPage = () => {
|
|
|
52
53
|
handleExecuteRoute();
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
if (status ===
|
|
56
|
+
if (status === stores_1.RouteExecutionStatus.Failed) {
|
|
56
57
|
restartRoute();
|
|
57
58
|
}
|
|
58
59
|
});
|
|
@@ -62,9 +63,9 @@ const SwapPage = () => {
|
|
|
62
63
|
};
|
|
63
64
|
const getSwapButtonText = () => {
|
|
64
65
|
switch (status) {
|
|
65
|
-
case
|
|
66
|
+
case stores_1.RouteExecutionStatus.Idle:
|
|
66
67
|
return t('button.startSwap');
|
|
67
|
-
case
|
|
68
|
+
case stores_1.RouteExecutionStatus.Failed:
|
|
68
69
|
return t('button.restartSwap');
|
|
69
70
|
default:
|
|
70
71
|
return '';
|
|
@@ -77,9 +78,10 @@ const SwapPage = () => {
|
|
|
77
78
|
const toToken = index === steps.length - 1
|
|
78
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;
|
|
79
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));
|
|
80
|
-
}), status ===
|
|
81
|
+
}), status === stores_1.RouteExecutionStatus.Idle ||
|
|
82
|
+
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,
|
|
81
83
|
// disable={status === 'idle' && (isValidating || !isValid)}
|
|
82
|
-
enableLoading: true }), status ===
|
|
84
|
+
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: {
|
|
83
85
|
minWidth: 48,
|
|
84
86
|
marginLeft: 1,
|
|
85
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] }));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const Stack: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
3
3
|
ref?: import("react").Ref<unknown> | undefined;
|
|
4
4
|
children?: import("react").ReactNode;
|
|
5
|
-
direction?: import("@mui/system").ResponsiveStyleValue<"
|
|
5
|
+
direction?: import("@mui/system").ResponsiveStyleValue<"column" | "column-reverse" | "row" | "row-reverse"> | undefined;
|
|
6
6
|
spacing?: import("@mui/system").ResponsiveStyleValue<string | number> | undefined;
|
|
7
7
|
divider?: import("react").ReactNode;
|
|
8
8
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type * as languages from '../../i18n';
|
|
2
|
-
export
|
|
2
|
+
export type PartialResource<T> = T extends object ? {
|
|
3
3
|
[P in keyof T]?: PartialResource<T[P]>;
|
|
4
4
|
} : T;
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export type LanguageKey = keyof typeof languages;
|
|
6
|
+
export type LanguageResources = {
|
|
7
7
|
[language in LanguageKey]?: PartialResource<typeof languages.en>;
|
|
8
8
|
} | {
|
|
9
9
|
[language: string]: PartialResource<typeof languages.en>;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type LanguageTranslationResource = {
|
|
12
12
|
[namespace in 'translation']: PartialResource<typeof languages.en>;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type LanguageTranslationResources = {
|
|
15
15
|
[language: string]: LanguageTranslationResource;
|
|
16
16
|
};
|
package/cjs/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js}
RENAMED
|
@@ -1,50 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FormUpdater = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_hook_form_1 = require("react-hook-form");
|
|
7
|
-
const stores_1 = require("../../stores");
|
|
8
7
|
const SwapFormProvider_1 = require("../SwapFormProvider");
|
|
8
|
+
const WalletProvider_1 = require("../WalletProvider");
|
|
9
9
|
const WidgetProvider_1 = require("../WidgetProvider");
|
|
10
|
-
const
|
|
10
|
+
const FormUpdater = ({ defaultValues }) => {
|
|
11
11
|
const { fromChain, toChain, chains, disabledChains } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
12
|
-
const {
|
|
12
|
+
const { account } = (0, WalletProvider_1.useWallet)();
|
|
13
|
+
const { setValue, getValues, getFieldState, resetField,
|
|
13
14
|
// Subscription to touchedFields is required by getFieldState to work
|
|
14
15
|
formState: { touchedFields }, } = (0, react_hook_form_1.useFormContext)();
|
|
16
|
+
const previousDefaultValues = (0, react_1.useRef)(defaultValues);
|
|
15
17
|
// Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
|
|
16
18
|
(0, react_1.useEffect)(() => {
|
|
17
19
|
const chainAllowed = account.chainId && (0, WidgetProvider_1.isItemAllowed)(account.chainId, chains, disabledChains);
|
|
18
20
|
if (!account.isActive || !account.chainId || !chainAllowed) {
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
21
|
-
const [fromChainValue, toChainValue] = getValues([
|
|
22
|
-
SwapFormProvider_1.SwapFormKey.FromChain,
|
|
23
|
-
SwapFormProvider_1.SwapFormKey.ToChain,
|
|
24
|
-
]);
|
|
25
23
|
const { isTouched: isFromChainTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.FromChain);
|
|
26
24
|
const { isTouched: isToChainTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.ToChain);
|
|
27
25
|
const { isTouched: isFromTokenTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.FromToken);
|
|
28
26
|
const { isTouched: isToTokenTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.ToToken);
|
|
29
27
|
const { isTouched: isFromAmountTouched } = getFieldState(SwapFormProvider_1.SwapFormKey.FromAmount);
|
|
30
|
-
|
|
31
|
-
// Users can switch chains in the wallet.
|
|
32
|
-
// If we don't have a chain in the ordered chain list we should add it.
|
|
33
|
-
setChain(account.chainId);
|
|
34
|
-
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
35
|
-
// we should make a recently switched chain as current.
|
|
36
|
-
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
37
|
-
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
38
|
-
if ((!fromChain && !isFromChainTouched && !isFromTokenTouched) ||
|
|
39
|
-
!hasFromChainInOrderedList) {
|
|
28
|
+
if (!fromChain && !isFromChainTouched && !isFromTokenTouched) {
|
|
40
29
|
setValue(SwapFormProvider_1.SwapFormKey.FromChain, account.chainId);
|
|
41
30
|
setValue(SwapFormProvider_1.SwapFormKey.FromToken, '');
|
|
42
31
|
if (isFromAmountTouched) {
|
|
43
32
|
setValue(SwapFormProvider_1.SwapFormKey.FromAmount, '');
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
|
-
if (
|
|
47
|
-
!hasToChainInOrderedList) {
|
|
35
|
+
if (!toChain && !isToChainTouched && !isToTokenTouched) {
|
|
48
36
|
setValue(SwapFormProvider_1.SwapFormKey.ToChain, account.chainId);
|
|
49
37
|
setValue(SwapFormProvider_1.SwapFormKey.ToToken, '');
|
|
50
38
|
}
|
|
@@ -59,6 +47,21 @@ const WalletFormUpdate = ({ account, }) => {
|
|
|
59
47
|
setValue,
|
|
60
48
|
toChain,
|
|
61
49
|
]);
|
|
50
|
+
(0, react_1.useEffect)(() => {
|
|
51
|
+
Object.keys(defaultValues).forEach((key) => {
|
|
52
|
+
if (previousDefaultValues.current[key] !== defaultValues[key]) {
|
|
53
|
+
const value = defaultValues[key] ||
|
|
54
|
+
// set the chain to the current user one if it is not present in the config
|
|
55
|
+
(key === SwapFormProvider_1.SwapFormKey.FromChain || key === SwapFormProvider_1.SwapFormKey.ToChain
|
|
56
|
+
? account.chainId || ''
|
|
57
|
+
: '');
|
|
58
|
+
setValue(key, value);
|
|
59
|
+
resetField(key, { defaultValue: value });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
previousDefaultValues.current = defaultValues;
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
+
}, [defaultValues, getValues, resetField, setValue]);
|
|
62
65
|
return null;
|
|
63
66
|
};
|
|
64
|
-
exports.
|
|
67
|
+
exports.FormUpdater = FormUpdater;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SwapFormProvider = exports.formDefaultValues = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
5
6
|
const react_hook_form_1 = require("react-hook-form");
|
|
6
7
|
const WidgetProvider_1 = require("../WidgetProvider");
|
|
8
|
+
const FormUpdater_1 = require("./FormUpdater");
|
|
7
9
|
const types_1 = require("./types");
|
|
8
10
|
const URLSearchParamsBuilder_1 = require("./URLSearchParamsBuilder");
|
|
9
11
|
exports.formDefaultValues = {
|
|
@@ -13,14 +15,17 @@ exports.formDefaultValues = {
|
|
|
13
15
|
};
|
|
14
16
|
const SwapFormProvider = ({ children, }) => {
|
|
15
17
|
const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress, buildSwapUrl, } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
18
|
+
const defaultValues = (0, react_1.useMemo)(() => (Object.assign(Object.assign({}, exports.formDefaultValues), { fromChain,
|
|
19
|
+
fromToken, fromAmount: (typeof fromAmount === 'number'
|
|
20
|
+
? fromAmount === null || fromAmount === void 0 ? void 0 : fromAmount.toPrecision()
|
|
21
|
+
: fromAmount) || exports.formDefaultValues.fromAmount, toChain,
|
|
22
|
+
toToken,
|
|
23
|
+
toAddress })), [fromAmount, fromChain, fromToken, toAddress, toChain, toToken]);
|
|
16
24
|
const methods = (0, react_hook_form_1.useForm)({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
: fromAmount) || exports.formDefaultValues.fromAmount, toChain,
|
|
21
|
-
toToken,
|
|
22
|
-
toAddress }),
|
|
25
|
+
// TODO: revisit after RHF release values support
|
|
26
|
+
// values,
|
|
27
|
+
defaultValues,
|
|
23
28
|
});
|
|
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] })));
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)(react_hook_form_1.FormProvider, Object.assign({}, methods, { children: [(0, jsx_runtime_1.jsx)(FormUpdater_1.FormUpdater, { defaultValues: defaultValues }), buildSwapUrl ? (0, jsx_runtime_1.jsx)(URLSearchParamsBuilder_1.URLSearchParamsBuilder, {}) : null, children] })));
|
|
25
30
|
};
|
|
26
31
|
exports.SwapFormProvider = SwapFormProvider;
|
|
@@ -7,7 +7,7 @@ export declare enum SwapFormKey {
|
|
|
7
7
|
ToToken = "toToken",
|
|
8
8
|
TokenSearchFilter = "tokenSearchFilter"
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export type SwapFormValues = {
|
|
11
11
|
[SwapFormKey.FromAmount]: string;
|
|
12
12
|
[SwapFormKey.FromChain]: number;
|
|
13
13
|
[SwapFormKey.FromToken]: string;
|
|
@@ -16,7 +16,7 @@ export declare type SwapFormValues = {
|
|
|
16
16
|
[SwapFormKey.ToToken]: string;
|
|
17
17
|
[SwapFormKey.TokenSearchFilter]: string;
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type SwapFormType = 'from' | 'to';
|
|
20
20
|
export declare const SwapFormKeyHelper: {
|
|
21
21
|
getChainKey: (formType: SwapFormType) => 'fromChain' | 'toChain';
|
|
22
22
|
getTokenKey: (formType: SwapFormType) => 'fromToken' | 'toToken';
|
|
@@ -14,7 +14,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
14
14
|
const wallet_management_1 = require("@lifi/wallet-management");
|
|
15
15
|
const react_1 = require("react");
|
|
16
16
|
const WidgetProvider_1 = require("../WidgetProvider");
|
|
17
|
-
const WalletFormUpdate_1 = require("./WalletFormUpdate");
|
|
18
17
|
const stub = () => {
|
|
19
18
|
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
20
19
|
};
|
|
@@ -95,7 +94,7 @@ const WalletProvider = ({ children }) => {
|
|
|
95
94
|
account,
|
|
96
95
|
provider,
|
|
97
96
|
}), [account, addChain, addToken, connect, disconnect, provider, switchChain]);
|
|
98
|
-
return ((0, jsx_runtime_1.
|
|
97
|
+
return ((0, jsx_runtime_1.jsx)(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
99
98
|
};
|
|
100
99
|
exports.WalletProvider = WalletProvider;
|
|
101
100
|
const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Signer } from '@ethersproject/abstract-signer';
|
|
2
|
+
import type { Provider } from '@ethersproject/providers';
|
|
2
3
|
import type { Token } from '@lifi/sdk';
|
|
3
4
|
import type { Wallet } from '@lifi/wallet-management';
|
|
4
|
-
import type { Signer } from 'ethers';
|
|
5
5
|
export interface WalletContextProps {
|
|
6
6
|
account: WalletAccount;
|
|
7
|
-
provider?:
|
|
7
|
+
provider?: Provider;
|
|
8
8
|
addChain(chainId: number): Promise<boolean>;
|
|
9
9
|
addToken(chainId: number, token: Token): Promise<void>;
|
|
10
10
|
disconnect(): void;
|
|
@@ -15,6 +15,7 @@ exports.WidgetProvider = exports.useWidgetConfig = void 0;
|
|
|
15
15
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
16
|
const sdk_1 = require("@lifi/sdk");
|
|
17
17
|
const react_1 = require("react");
|
|
18
|
+
const stores_1 = require("../../stores");
|
|
18
19
|
const utils_1 = require("../../utils");
|
|
19
20
|
const initialContext = {
|
|
20
21
|
disabledChains: [],
|
|
@@ -59,6 +60,9 @@ const WidgetProvider = (_a) => {
|
|
|
59
60
|
return config;
|
|
60
61
|
}
|
|
61
62
|
}, [config, fromAmount, fromChain, fromToken, toChain, toToken]);
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
(0, stores_1.setDefaultSettings)(value);
|
|
65
|
+
}, [value]);
|
|
62
66
|
return ((0, jsx_runtime_1.jsx)(WidgetContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
63
67
|
};
|
|
64
68
|
exports.WidgetProvider = WidgetProvider;
|
|
@@ -7,7 +7,14 @@ export interface RouteExecutionStore {
|
|
|
7
7
|
deleteRoute: (routeId: string) => void;
|
|
8
8
|
deleteRoutes: (type: 'completed' | 'active') => void;
|
|
9
9
|
}
|
|
10
|
-
export declare
|
|
10
|
+
export declare enum RouteExecutionStatus {
|
|
11
|
+
Idle = 0,
|
|
12
|
+
Pending = 1,
|
|
13
|
+
Done = 2,
|
|
14
|
+
Failed = 4,
|
|
15
|
+
Partial = 8,
|
|
16
|
+
Refunded = 16
|
|
17
|
+
}
|
|
11
18
|
export interface RouteExecution {
|
|
12
19
|
route: Route;
|
|
13
20
|
status: RouteExecutionStatus;
|