@lifi/widget 1.16.0 → 1.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AppDrawer.d.ts +3 -3
- package/AppProvider.d.ts +0 -4
- package/AppProvider.js +2 -10
- package/README.md +1 -1
- package/cjs/AppDrawer.d.ts +3 -3
- package/cjs/AppProvider.d.ts +0 -4
- package/cjs/AppProvider.js +3 -12
- package/cjs/components/AppContainer.js +2 -2
- package/cjs/components/ChainSelect/ChainSelect.style.js +4 -4
- package/cjs/components/ChainSelect/useChainSelect.d.ts +2 -2
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +3 -3
- package/cjs/components/Header/useHeaderActionStore.d.ts +0 -2
- package/cjs/components/Header/useHeaderActionStore.js +1 -5
- package/cjs/components/SelectChainAndToken.js +5 -5
- package/cjs/components/SwapButton/SwapButton.js +3 -23
- package/cjs/components/TokenList/TokenList.js +1 -1
- package/cjs/components/TokenList/TokenList.style.js +4 -3
- package/cjs/components/TokenList/TokenListItem.js +1 -1
- package/cjs/components/TokenList/TokenNotFound.d.ts +2 -1
- package/cjs/components/TokenList/TokenNotFound.js +12 -2
- package/cjs/components/TokenList/types.d.ts +2 -2
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useChains.js +23 -10
- package/cjs/hooks/useFeaturedTokens.d.ts +1 -1
- package/cjs/hooks/useFeaturedTokens.js +6 -3
- package/cjs/hooks/useGasSufficiency.d.ts +1 -1
- package/cjs/hooks/useGasSufficiency.js +39 -28
- package/cjs/hooks/useInitializer.js +6 -0
- package/cjs/hooks/useRouteExecution.js +28 -12
- package/cjs/hooks/useSwapRoutes.js +10 -11
- package/cjs/hooks/useToken.d.ts +0 -1
- package/cjs/hooks/useToken.js +1 -2
- package/cjs/hooks/useTokenBalances.d.ts +1 -2
- package/cjs/hooks/useTokenBalances.js +5 -6
- package/cjs/hooks/useTokenSearch.js +3 -2
- package/cjs/hooks/useTokens.d.ts +1 -2
- package/cjs/hooks/useTokens.js +32 -9
- package/cjs/hooks/useTools.js +11 -5
- package/cjs/hooks/useWidgetEvents.d.ts +3 -3
- package/cjs/hooks/useWidgetEvents.js +2 -2
- package/cjs/i18n/en/translation.json +2 -3
- package/cjs/i18n/index.d.ts +1 -2
- package/cjs/index.d.ts +2 -1
- package/cjs/pages/MainPage/MainSwapButton.js +1 -1
- package/cjs/pages/SettingsPage/AdvancedPreferences.js +1 -1
- package/cjs/pages/SettingsPage/GasPriceSelect.js +1 -1
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +1 -1
- package/cjs/pages/SettingsPage/ShowDestinationWallet.js +1 -1
- package/cjs/pages/SettingsPage/SlippageInput.js +1 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -3
- package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -3
- package/cjs/pages/SwapPage/SwapPage.js +11 -2
- package/cjs/pages/SwapRoutesPage/SwapRoutesPage.js +4 -3
- package/cjs/providers/SDKProvider/SDKProvider.d.ts +4 -0
- package/cjs/providers/SDKProvider/SDKProvider.js +27 -0
- package/cjs/providers/SDKProvider/index.d.ts +1 -0
- package/cjs/providers/SDKProvider/index.js +17 -0
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +4 -58
- package/cjs/providers/SwapFormProvider/types.d.ts +5 -5
- package/cjs/providers/TelemetryProvider/TelemetryProvider.d.ts +4 -0
- package/cjs/providers/TelemetryProvider/TelemetryProvider.js +11 -0
- package/cjs/providers/TelemetryProvider/index.d.ts +1 -0
- package/cjs/providers/TelemetryProvider/index.js +17 -0
- package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -4
- package/cjs/providers/WalletProvider/WalletProvider.js +59 -1
- package/cjs/providers/WidgetProvider/WidgetProvider.js +1 -12
- package/cjs/providers/WidgetProvider/index.d.ts +1 -0
- package/cjs/providers/WidgetProvider/index.js +1 -0
- package/cjs/providers/WidgetProvider/utils.d.ts +4 -0
- package/cjs/providers/WidgetProvider/utils.js +13 -0
- package/cjs/providers/index.d.ts +2 -0
- package/cjs/providers/index.js +2 -0
- package/cjs/stores/chains/index.d.ts +0 -1
- package/cjs/stores/chains/index.js +0 -1
- package/cjs/stores/chains/types.d.ts +1 -1
- package/cjs/stores/chains/useChainOrderStore.js +17 -14
- package/cjs/stores/route/utils.d.ts +2 -1
- package/cjs/stores/route/utils.js +17 -1
- package/cjs/stores/settings/index.d.ts +0 -1
- package/cjs/stores/settings/index.js +0 -1
- package/cjs/stores/settings/useAppearance.js +3 -1
- package/cjs/types/events.d.ts +15 -3
- package/cjs/types/events.js +4 -3
- package/cjs/types/widget.d.ts +29 -22
- package/cjs/utils/colors.d.ts +1 -1
- package/components/AppContainer.js +1 -1
- package/components/ChainSelect/ChainSelect.style.js +4 -4
- package/components/ChainSelect/useChainSelect.d.ts +2 -2
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +3 -3
- package/components/Header/useHeaderActionStore.d.ts +0 -2
- package/components/Header/useHeaderActionStore.js +0 -3
- package/components/SelectChainAndToken.js +1 -1
- package/components/SwapButton/SwapButton.js +5 -25
- package/components/TokenList/TokenList.js +1 -1
- package/components/TokenList/TokenList.style.js +4 -3
- package/components/TokenList/TokenListItem.js +1 -1
- package/components/TokenList/TokenNotFound.d.ts +2 -1
- package/components/TokenList/TokenNotFound.js +12 -2
- package/components/TokenList/types.d.ts +2 -2
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useChains.js +24 -11
- package/hooks/useFeaturedTokens.d.ts +1 -1
- package/hooks/useFeaturedTokens.js +6 -3
- package/hooks/useGasSufficiency.d.ts +1 -1
- package/hooks/useGasSufficiency.js +35 -24
- package/hooks/useInitializer.js +6 -0
- package/hooks/useRouteExecution.js +28 -12
- package/hooks/useSwapRoutes.js +3 -4
- package/hooks/useToken.d.ts +0 -1
- package/hooks/useToken.js +1 -2
- package/hooks/useTokenBalances.d.ts +1 -2
- package/hooks/useTokenBalances.js +4 -5
- package/hooks/useTokenSearch.js +3 -2
- package/hooks/useTokens.d.ts +1 -2
- package/hooks/useTokens.js +32 -9
- package/hooks/useTools.js +11 -5
- package/hooks/useWidgetEvents.d.ts +3 -3
- package/hooks/useWidgetEvents.js +2 -2
- package/i18n/en/translation.json +2 -3
- package/i18n/index.d.ts +1 -2
- package/index.d.ts +2 -1
- package/package.json +9 -8
- package/pages/MainPage/MainSwapButton.js +1 -1
- package/pages/SettingsPage/AdvancedPreferences.js +2 -2
- package/pages/SettingsPage/GasPriceSelect.js +2 -2
- package/pages/SettingsPage/RoutePrioritySelect.js +2 -2
- package/pages/SettingsPage/ShowDestinationWallet.js +2 -2
- package/pages/SettingsPage/SlippageInput.js +2 -2
- package/pages/SwapDetailsPage/SwapDetailsPage.js +3 -4
- package/pages/SwapHistoryPage/SwapHistoryPage.js +3 -4
- package/pages/SwapPage/SwapPage.js +11 -2
- package/pages/SwapRoutesPage/SwapRoutesPage.js +5 -4
- package/providers/SDKProvider/SDKProvider.d.ts +4 -0
- package/providers/SDKProvider/SDKProvider.js +19 -0
- package/providers/SDKProvider/index.d.ts +1 -0
- package/providers/SDKProvider/index.js +1 -0
- package/providers/SwapFormProvider/SwapFormProvider.js +4 -58
- package/providers/SwapFormProvider/types.d.ts +5 -5
- package/providers/TelemetryProvider/TelemetryProvider.d.ts +4 -0
- package/providers/TelemetryProvider/TelemetryProvider.js +7 -0
- package/providers/TelemetryProvider/index.d.ts +1 -0
- package/providers/TelemetryProvider/index.js +1 -0
- package/providers/WalletProvider/WalletProvider.d.ts +1 -4
- package/providers/WalletProvider/WalletProvider.js +59 -1
- package/providers/WidgetProvider/WidgetProvider.js +3 -14
- package/providers/WidgetProvider/index.d.ts +1 -0
- package/providers/WidgetProvider/index.js +1 -0
- package/providers/WidgetProvider/utils.d.ts +4 -0
- package/providers/WidgetProvider/utils.js +9 -0
- package/providers/index.d.ts +2 -0
- package/providers/index.js +2 -0
- package/stores/chains/index.d.ts +0 -1
- package/stores/chains/index.js +0 -1
- package/stores/chains/types.d.ts +1 -1
- package/stores/chains/useChainOrderStore.js +17 -14
- package/stores/route/utils.d.ts +2 -1
- package/stores/route/utils.js +12 -0
- package/stores/settings/index.d.ts +0 -1
- package/stores/settings/index.js +0 -1
- package/stores/settings/useAppearance.js +3 -1
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +15 -3
- package/types/events.js +4 -3
- package/types/widget.d.ts +29 -22
- package/utils/colors.d.ts +1 -1
- package/cjs/config/lifi.d.ts +0 -4
- package/cjs/config/lifi.js +0 -14
- package/cjs/stores/chains/useInitializeChainOrder.d.ts +0 -1
- package/cjs/stores/chains/useInitializeChainOrder.js +0 -12
- package/cjs/stores/settings/useSetSettings.d.ts +0 -5
- package/cjs/stores/settings/useSetSettings.js +0 -12
- package/config/lifi.d.ts +0 -4
- package/config/lifi.js +0 -7
- package/stores/chains/useInitializeChainOrder.d.ts +0 -1
- package/stores/chains/useInitializeChainOrder.js +0 -5
- package/stores/settings/useSetSettings.d.ts +0 -5
- package/stores/settings/useSetSettings.js +0 -5
|
@@ -8,7 +8,7 @@ const Switch_1 = require("../../components/Switch");
|
|
|
8
8
|
const stores_1 = require("../../stores");
|
|
9
9
|
const ShowDestinationWallet = () => {
|
|
10
10
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
11
|
-
const
|
|
11
|
+
const setValue = (0, stores_1.useSettingsStore)((state) => state.setValue);
|
|
12
12
|
const { showDestinationWallet } = (0, stores_1.useSettings)(['showDestinationWallet']);
|
|
13
13
|
const onChange = (_, checked) => {
|
|
14
14
|
setValue('showDestinationWallet', checked);
|
|
@@ -11,8 +11,8 @@ const stores_1 = require("../../stores");
|
|
|
11
11
|
const utils_1 = require("../../utils");
|
|
12
12
|
const SlippageInput = () => {
|
|
13
13
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
14
|
-
const [setValue] = (0, stores_1.useSetSettings)();
|
|
15
14
|
const { slippage } = (0, stores_1.useSettings)(['slippage']);
|
|
15
|
+
const setValue = (0, stores_1.useSettingsStore)((state) => state.setValue);
|
|
16
16
|
const defaultValue = (0, react_1.useRef)(slippage);
|
|
17
17
|
const handleChange = (event) => {
|
|
18
18
|
const { value } = event.target;
|
|
@@ -32,7 +32,6 @@ const SwapDetailsPage = () => {
|
|
|
32
32
|
var _a, _b;
|
|
33
33
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
34
34
|
const { navigateBack } = (0, hooks_1.useNavigateBack)();
|
|
35
|
-
const setHeaderAction = (0, Header_1.useSetHeaderAction)();
|
|
36
35
|
const { state } = (0, react_router_dom_1.useLocation)();
|
|
37
36
|
const [routeExecution, deleteRoute] = (0, stores_1.useRouteStore)((store) => [store.routes[state === null || state === void 0 ? void 0 : state.routeId], store.deleteRoute], shallow_1.default);
|
|
38
37
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
@@ -50,8 +49,8 @@ const SwapDetailsPage = () => {
|
|
|
50
49
|
yield navigator.clipboard.writeText((_c = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id) !== null && _c !== void 0 ? _c : '');
|
|
51
50
|
});
|
|
52
51
|
(0, react_1.useEffect)(() => {
|
|
53
|
-
return
|
|
54
|
-
}, [
|
|
52
|
+
return Header_1.useHeaderActionStore.getState().setAction((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.DeleteOutline, {}) })));
|
|
53
|
+
}, [toggleDialog]);
|
|
55
54
|
const startedAt = new Date((_b = (_a = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0);
|
|
56
55
|
return ((0, jsx_runtime_1.jsxs)(SwapDetailsPage_style_1.Container, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
|
|
57
56
|
display: 'flex',
|
|
@@ -18,14 +18,13 @@ const SwapHistoryPage = () => {
|
|
|
18
18
|
const { account } = (0, providers_1.useWallet)();
|
|
19
19
|
const swaps = (0, route_1.useSwapHistory)(account.address);
|
|
20
20
|
const deleteRoutes = (0, stores_1.useRouteStore)((store) => store.deleteRoutes);
|
|
21
|
-
const setHeaderAction = (0, Header_1.useSetHeaderAction)();
|
|
22
21
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
23
22
|
const toggleDialog = (0, react_1.useCallback)(() => {
|
|
24
23
|
setOpen((open) => !open);
|
|
25
24
|
}, []);
|
|
26
25
|
(0, react_1.useEffect)(() => {
|
|
27
|
-
return
|
|
28
|
-
}, [
|
|
26
|
+
return Header_1.useHeaderActionStore.getState().setAction((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.DeleteOutline, {}) })));
|
|
27
|
+
}, [toggleDialog]);
|
|
29
28
|
if (!swaps.length) {
|
|
30
29
|
return (0, jsx_runtime_1.jsx)(SwapHistoryEmpty_1.SwapHistoryEmpty, {});
|
|
31
30
|
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.SwapPage = void 0;
|
|
4
13
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
@@ -25,7 +34,7 @@ const SwapPage = () => {
|
|
|
25
34
|
navigateBack();
|
|
26
35
|
deleteRoute();
|
|
27
36
|
};
|
|
28
|
-
const handleSwapClick = () => {
|
|
37
|
+
const handleSwapClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
38
|
if (status === 'idle') {
|
|
30
39
|
executeRoute();
|
|
31
40
|
setValue(providers_1.SwapFormKey.FromAmount, '');
|
|
@@ -33,7 +42,7 @@ const SwapPage = () => {
|
|
|
33
42
|
if (status === 'error') {
|
|
34
43
|
restartRoute();
|
|
35
44
|
}
|
|
36
|
-
};
|
|
45
|
+
});
|
|
37
46
|
// eslint-disable-next-line consistent-return
|
|
38
47
|
const getSwapButtonText = () => {
|
|
39
48
|
if (status === 'idle') {
|
|
@@ -14,7 +14,6 @@ const SwapRoutesPage_style_1 = require("./SwapRoutesPage.style");
|
|
|
14
14
|
const SwapRoutesPage = () => {
|
|
15
15
|
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
16
16
|
const { pathname } = (0, react_router_dom_1.useLocation)();
|
|
17
|
-
const setHeaderAction = (0, Header_1.useSetHeaderAction)();
|
|
18
17
|
const { routes: swapRoutes, isLoading, isFetching, dataUpdatedAt, refetchTime, refetch, } = (0, hooks_1.useSwapRoutes)();
|
|
19
18
|
const setExecutableRoute = (0, stores_1.useSetExecutableRoute)();
|
|
20
19
|
const handleRouteClick = (route) => {
|
|
@@ -31,8 +30,10 @@ const SwapRoutesPage = () => {
|
|
|
31
30
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
31
|
}, []);
|
|
33
32
|
(0, react_1.useEffect)(() => {
|
|
34
|
-
return
|
|
35
|
-
|
|
33
|
+
return Header_1.useHeaderActionStore
|
|
34
|
+
.getState()
|
|
35
|
+
.setAction((0, jsx_runtime_1.jsx)(ProgressToNextUpdate_1.ProgressToNextUpdate, { updatedAt: dataUpdatedAt || new Date().getTime(), timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: { marginRight: -1 }, size: "medium", edge: "end" }));
|
|
36
|
+
}, [dataUpdatedAt, isFetching, refetch, refetchTime]);
|
|
36
37
|
const routeNotFound = !(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching;
|
|
37
38
|
return ((0, jsx_runtime_1.jsx)(SwapRoutesPage_style_1.Stack, Object.assign({ direction: "column", spacing: 2, flex: 1 }, { children: routeNotFound ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, {}, index)))) : (swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.map((route) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { route: route, onClick: () => handleRouteClick(route) }, route.id)))) })));
|
|
38
39
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SDKProvider = exports.useLiFi = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const sdk_1 = __importDefault(require("@lifi/sdk"));
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const WidgetProvider_1 = require("../WidgetProvider");
|
|
11
|
+
let lifi;
|
|
12
|
+
const SDKContext = (0, react_1.createContext)(null);
|
|
13
|
+
const useLiFi = () => (0, react_1.useContext)(SDKContext);
|
|
14
|
+
exports.useLiFi = useLiFi;
|
|
15
|
+
const SDKProvider = ({ children, }) => {
|
|
16
|
+
const { sdkConfig, integrator } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
17
|
+
const value = (0, react_1.useMemo)(() => {
|
|
18
|
+
const config = Object.assign(Object.assign({}, sdkConfig), { defaultRouteOptions: Object.assign(Object.assign({}, sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.defaultRouteOptions), { integrator: integrator !== null && integrator !== void 0 ? integrator : window.location.hostname }) });
|
|
19
|
+
if (!lifi) {
|
|
20
|
+
lifi = new sdk_1.default(Object.assign({ disableVersionCheck: true }, config));
|
|
21
|
+
}
|
|
22
|
+
lifi.setConfig(config);
|
|
23
|
+
return lifi;
|
|
24
|
+
}, [integrator, sdkConfig]);
|
|
25
|
+
return (0, jsx_runtime_1.jsx)(SDKContext.Provider, Object.assign({ value: value }, { children: children }));
|
|
26
|
+
};
|
|
27
|
+
exports.SDKProvider = SDKProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SDKProvider';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./SDKProvider"), exports);
|
|
@@ -2,11 +2,7 @@
|
|
|
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 sdk_1 = require("@lifi/sdk");
|
|
6
|
-
const react_1 = require("react");
|
|
7
5
|
const react_hook_form_1 = require("react-hook-form");
|
|
8
|
-
const chains_1 = require("../../stores/chains");
|
|
9
|
-
const WalletProvider_1 = require("../WalletProvider");
|
|
10
6
|
const WidgetProvider_1 = require("../WidgetProvider");
|
|
11
7
|
const types_1 = require("./types");
|
|
12
8
|
exports.formDefaultValues = {
|
|
@@ -15,65 +11,15 @@ exports.formDefaultValues = {
|
|
|
15
11
|
[types_1.SwapFormKey.TokenSearchFilter]: '',
|
|
16
12
|
};
|
|
17
13
|
const SwapFormProvider = ({ children, }) => {
|
|
18
|
-
const [setChain] = (0, chains_1.useSetChainOrder)();
|
|
19
|
-
const { account } = (0, WalletProvider_1.useWallet)();
|
|
20
14
|
const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
21
15
|
const methods = (0, react_hook_form_1.useForm)({
|
|
22
|
-
defaultValues: Object.assign(Object.assign({}, exports.formDefaultValues), { fromChain
|
|
16
|
+
defaultValues: Object.assign(Object.assign({}, exports.formDefaultValues), { fromChain,
|
|
17
|
+
fromToken, fromAmount: (typeof fromAmount === 'number'
|
|
23
18
|
? fromAmount === null || fromAmount === void 0 ? void 0 : fromAmount.toPrecision()
|
|
24
|
-
: fromAmount) || exports.formDefaultValues.fromAmount, toChain
|
|
19
|
+
: fromAmount) || exports.formDefaultValues.fromAmount, toChain,
|
|
20
|
+
toToken,
|
|
25
21
|
toAddress }),
|
|
26
22
|
});
|
|
27
|
-
// Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
|
|
28
|
-
(0, react_1.useEffect)(() => {
|
|
29
|
-
if (!account.isActive || !account.chainId) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const [fromChainValue, toChainValue] = methods.getValues([
|
|
33
|
-
types_1.SwapFormKey.FromChain,
|
|
34
|
-
types_1.SwapFormKey.ToChain,
|
|
35
|
-
]);
|
|
36
|
-
const { isDirty: isFromChainDirty } = methods.getFieldState(types_1.SwapFormKey.FromChain, methods.formState);
|
|
37
|
-
const { isDirty: isToChainDirty } = methods.getFieldState(types_1.SwapFormKey.ToChain, methods.formState);
|
|
38
|
-
const { isDirty: isFromTokenDirty } = methods.getFieldState(types_1.SwapFormKey.FromToken, methods.formState);
|
|
39
|
-
const { isDirty: isToTokenDirty } = methods.getFieldState(types_1.SwapFormKey.ToToken, methods.formState);
|
|
40
|
-
// Users can switch chains in the wallet.
|
|
41
|
-
// If we don't have a chain in the ordered chain list we should add it.
|
|
42
|
-
setChain(account.chainId);
|
|
43
|
-
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
44
|
-
// we should make a recently switched chain as current.
|
|
45
|
-
const { chainOrder } = chains_1.useChainOrderStore.getState();
|
|
46
|
-
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
47
|
-
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
48
|
-
if ((!fromChain && !isFromChainDirty && !isFromTokenDirty) ||
|
|
49
|
-
!hasFromChainInOrderedList) {
|
|
50
|
-
methods.setValue(types_1.SwapFormKey.FromChain, account.chainId, {
|
|
51
|
-
shouldDirty: false,
|
|
52
|
-
});
|
|
53
|
-
methods.setValue(types_1.SwapFormKey.FromToken, '', {
|
|
54
|
-
shouldDirty: false,
|
|
55
|
-
});
|
|
56
|
-
methods.setValue(types_1.SwapFormKey.FromAmount, '', {
|
|
57
|
-
shouldDirty: false,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if ((!toChain && !isToChainDirty && !isToTokenDirty) ||
|
|
61
|
-
!hasToChainInOrderedList) {
|
|
62
|
-
methods.setValue(types_1.SwapFormKey.ToChain, account.chainId, {
|
|
63
|
-
shouldDirty: false,
|
|
64
|
-
});
|
|
65
|
-
methods.setValue(types_1.SwapFormKey.ToToken, '', {
|
|
66
|
-
shouldDirty: false,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}, [
|
|
70
|
-
account.chainId,
|
|
71
|
-
account.isActive,
|
|
72
|
-
fromChain,
|
|
73
|
-
methods,
|
|
74
|
-
setChain,
|
|
75
|
-
toChain,
|
|
76
|
-
]);
|
|
77
23
|
return (0, jsx_runtime_1.jsx)(react_hook_form_1.FormProvider, Object.assign({}, methods, { children: children }));
|
|
78
24
|
};
|
|
79
25
|
exports.SwapFormProvider = SwapFormProvider;
|
|
@@ -16,12 +16,12 @@ export declare type SwapFormValues = {
|
|
|
16
16
|
[SwapFormKey.ToToken]: string;
|
|
17
17
|
[SwapFormKey.ToAddress]: string;
|
|
18
18
|
};
|
|
19
|
-
export declare type
|
|
19
|
+
export declare type SwapFormType = 'from' | 'to';
|
|
20
20
|
export declare const SwapFormKeyHelper: {
|
|
21
|
-
getChainKey: (formType:
|
|
22
|
-
getTokenKey: (formType:
|
|
23
|
-
getAmountKey: (formType:
|
|
21
|
+
getChainKey: (formType: SwapFormType) => 'fromChain' | 'toChain';
|
|
22
|
+
getTokenKey: (formType: SwapFormType) => 'fromToken' | 'toToken';
|
|
23
|
+
getAmountKey: (formType: SwapFormType) => 'fromAmount' | 'toAmount';
|
|
24
24
|
};
|
|
25
25
|
export interface SwapFormTypeProps {
|
|
26
|
-
formType:
|
|
26
|
+
formType: SwapFormType;
|
|
27
27
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelemetryProvider = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const hooks_1 = require("../../hooks");
|
|
6
|
+
const TelemetryProvider = ({ children }) => {
|
|
7
|
+
const config = (0, __1.useWidgetConfig)();
|
|
8
|
+
(0, hooks_1.useTelemetry)(config === null || config === void 0 ? void 0 : config.disableTelemetry);
|
|
9
|
+
return children;
|
|
10
|
+
};
|
|
11
|
+
exports.TelemetryProvider = TelemetryProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TelemetryProvider';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TelemetryProvider"), exports);
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { Signer } from 'ethers';
|
|
2
2
|
import type { FC, PropsWithChildren } from 'react';
|
|
3
|
-
import type { WidgetWalletManagement } from '../../types';
|
|
4
3
|
import type { WalletContextProps } from './types';
|
|
5
4
|
export declare const useWallet: () => WalletContextProps;
|
|
6
|
-
export declare const WalletProvider: FC<PropsWithChildren
|
|
7
|
-
walletManagement?: WidgetWalletManagement;
|
|
8
|
-
}>>;
|
|
5
|
+
export declare const WalletProvider: FC<PropsWithChildren>;
|
|
9
6
|
export declare const extractAccountFromSigner: (signer?: Signer) => Promise<{
|
|
10
7
|
address: string | undefined;
|
|
11
8
|
isActive: boolean;
|
|
@@ -13,6 +13,10 @@ exports.extractAccountFromSigner = exports.WalletProvider = exports.useWallet =
|
|
|
13
13
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
14
14
|
const wallet_management_1 = require("@lifi/wallet-management");
|
|
15
15
|
const react_1 = require("react");
|
|
16
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
17
|
+
const chains_1 = require("../../stores/chains");
|
|
18
|
+
const SwapFormProvider_1 = require("../SwapFormProvider");
|
|
19
|
+
const WidgetProvider_1 = require("../WidgetProvider");
|
|
16
20
|
const stub = () => {
|
|
17
21
|
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
18
22
|
};
|
|
@@ -27,7 +31,9 @@ const initialContext = {
|
|
|
27
31
|
const WalletContext = (0, react_1.createContext)(initialContext);
|
|
28
32
|
const useWallet = () => (0, react_1.useContext)(WalletContext);
|
|
29
33
|
exports.useWallet = useWallet;
|
|
30
|
-
const WalletProvider = ({ children
|
|
34
|
+
const WalletProvider = ({ children }) => {
|
|
35
|
+
const { walletManagement, fromChain, toChain, chains, disabledChains } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
36
|
+
const methods = (0, react_hook_form_1.useFormContext)();
|
|
31
37
|
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, provider, } = (0, wallet_management_1.useLiFiWalletManagement)();
|
|
32
38
|
const [account, setAccount] = (0, react_1.useState)({});
|
|
33
39
|
const connect = (0, react_1.useCallback)((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -92,6 +98,58 @@ const WalletProvider = ({ children, walletManagement }) => {
|
|
|
92
98
|
account,
|
|
93
99
|
provider,
|
|
94
100
|
}), [account, addChain, addToken, connect, disconnect, provider, switchChain]);
|
|
101
|
+
// Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
|
|
102
|
+
(0, react_1.useEffect)(() => {
|
|
103
|
+
const chainAllowed = account.chainId && (0, WidgetProvider_1.isItemAllowed)(account.chainId, chains, disabledChains);
|
|
104
|
+
if (!account.isActive || !account.chainId || !chainAllowed) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const [fromChainValue, toChainValue] = methods.getValues([
|
|
108
|
+
SwapFormProvider_1.SwapFormKey.FromChain,
|
|
109
|
+
SwapFormProvider_1.SwapFormKey.ToChain,
|
|
110
|
+
]);
|
|
111
|
+
const { isDirty: isFromChainDirty } = methods.getFieldState(SwapFormProvider_1.SwapFormKey.FromChain, methods.formState);
|
|
112
|
+
const { isDirty: isToChainDirty } = methods.getFieldState(SwapFormProvider_1.SwapFormKey.ToChain, methods.formState);
|
|
113
|
+
const { isDirty: isFromTokenDirty } = methods.getFieldState(SwapFormProvider_1.SwapFormKey.FromToken, methods.formState);
|
|
114
|
+
const { isDirty: isToTokenDirty } = methods.getFieldState(SwapFormProvider_1.SwapFormKey.ToToken, methods.formState);
|
|
115
|
+
const { chainOrder, setChain } = chains_1.useChainOrderStore.getState();
|
|
116
|
+
// Users can switch chains in the wallet.
|
|
117
|
+
// If we don't have a chain in the ordered chain list we should add it.
|
|
118
|
+
setChain(account.chainId);
|
|
119
|
+
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
120
|
+
// we should make a recently switched chain as current.
|
|
121
|
+
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
122
|
+
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
123
|
+
if ((!fromChain && !isFromChainDirty && !isFromTokenDirty) ||
|
|
124
|
+
!hasFromChainInOrderedList) {
|
|
125
|
+
methods.setValue(SwapFormProvider_1.SwapFormKey.FromChain, account.chainId, {
|
|
126
|
+
shouldDirty: false,
|
|
127
|
+
});
|
|
128
|
+
methods.setValue(SwapFormProvider_1.SwapFormKey.FromToken, '', {
|
|
129
|
+
shouldDirty: false,
|
|
130
|
+
});
|
|
131
|
+
methods.setValue(SwapFormProvider_1.SwapFormKey.FromAmount, '', {
|
|
132
|
+
shouldDirty: false,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if ((!toChain && !isToChainDirty && !isToTokenDirty) ||
|
|
136
|
+
!hasToChainInOrderedList) {
|
|
137
|
+
methods.setValue(SwapFormProvider_1.SwapFormKey.ToChain, account.chainId, {
|
|
138
|
+
shouldDirty: false,
|
|
139
|
+
});
|
|
140
|
+
methods.setValue(SwapFormProvider_1.SwapFormKey.ToToken, '', {
|
|
141
|
+
shouldDirty: false,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}, [
|
|
145
|
+
account.chainId,
|
|
146
|
+
account.isActive,
|
|
147
|
+
chains,
|
|
148
|
+
disabledChains,
|
|
149
|
+
fromChain,
|
|
150
|
+
methods,
|
|
151
|
+
toChain,
|
|
152
|
+
]);
|
|
95
153
|
return ((0, jsx_runtime_1.jsx)(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
96
154
|
};
|
|
97
155
|
exports.WalletProvider = WalletProvider;
|
|
@@ -15,11 +15,6 @@ 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 lifi_1 = require("../../config/lifi");
|
|
19
|
-
const version_1 = require("../../config/version");
|
|
20
|
-
const stub = () => {
|
|
21
|
-
throw new Error('You forgot to wrap your component in <WidgetProvider>.');
|
|
22
|
-
};
|
|
23
18
|
const initialContext = {
|
|
24
19
|
disabledChains: [],
|
|
25
20
|
};
|
|
@@ -27,7 +22,7 @@ const WidgetContext = (0, react_1.createContext)(initialContext);
|
|
|
27
22
|
const useWidgetConfig = () => (0, react_1.useContext)(WidgetContext);
|
|
28
23
|
exports.useWidgetConfig = useWidgetConfig;
|
|
29
24
|
const WidgetProvider = (_a) => {
|
|
30
|
-
var { children } = _a, _b = _a.config, _c = _b === void 0 ? {} : _b, { fromChain, fromToken, toChain, toToken, fromAmount
|
|
25
|
+
var { children } = _a, _b = _a.config, _c = _b === void 0 ? {} : _b, { fromChain, fromToken, toChain, toToken, fromAmount } = _c, config = __rest(_c, ["fromChain", "fromToken", "toChain", "toToken", "fromAmount"]);
|
|
31
26
|
const value = (0, react_1.useMemo)(() => {
|
|
32
27
|
var _a, _b, _c, _d;
|
|
33
28
|
try {
|
|
@@ -57,12 +52,6 @@ const WidgetProvider = (_a) => {
|
|
|
57
52
|
return config;
|
|
58
53
|
}
|
|
59
54
|
}, [config, fromAmount, fromChain, fromToken, toChain, toToken]);
|
|
60
|
-
(0, react_1.useEffect)(() => {
|
|
61
|
-
(0, lifi_1.updateLiFiConfig)(Object.assign(Object.assign({}, sdkConfig), { defaultRouteOptions: Object.assign(Object.assign({}, sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.defaultRouteOptions), { integrator: integrator !== null && integrator !== void 0 ? integrator : window.location.hostname }) }));
|
|
62
|
-
}, [integrator, sdkConfig]);
|
|
63
|
-
(0, react_1.useEffect)(() => {
|
|
64
|
-
(0, sdk_1.checkPackageUpdates)(version_1.name, version_1.version);
|
|
65
|
-
}, []);
|
|
66
55
|
return ((0, jsx_runtime_1.jsx)(WidgetContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
67
56
|
};
|
|
68
57
|
exports.WidgetProvider = WidgetProvider;
|
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
18
19
|
__exportStar(require("./WidgetProvider"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isItemAllowed = void 0;
|
|
4
|
+
const isItemAllowed = (chainId, chains,
|
|
5
|
+
/** @deprecated Remove in the next major release */
|
|
6
|
+
disabledChains) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
if ((_a = chains === null || chains === void 0 ? void 0 : chains.allow) === null || _a === void 0 ? void 0 : _a.length) {
|
|
9
|
+
return chains.allow.includes(chainId);
|
|
10
|
+
}
|
|
11
|
+
return !((disabledChains === null || disabledChains === void 0 ? void 0 : disabledChains.includes(chainId)) || ((_b = chains === null || chains === void 0 ? void 0 : chains.deny) === null || _b === void 0 ? void 0 : _b.includes(chainId)));
|
|
12
|
+
};
|
|
13
|
+
exports.isItemAllowed = isItemAllowed;
|
package/cjs/providers/index.d.ts
CHANGED
package/cjs/providers/index.js
CHANGED
|
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./SDKProvider"), exports);
|
|
17
18
|
__exportStar(require("./SwapFormProvider"), exports);
|
|
19
|
+
__exportStar(require("./TelemetryProvider"), exports);
|
|
18
20
|
__exportStar(require("./ThemeProvider"), exports);
|
|
19
21
|
__exportStar(require("./WalletProvider"), exports);
|
|
20
22
|
__exportStar(require("./WidgetProvider"), exports);
|
|
@@ -17,4 +17,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./useChainOrder"), exports);
|
|
19
19
|
__exportStar(require("./useChainOrderStore"), exports);
|
|
20
|
-
__exportStar(require("./useInitializeChainOrder"), exports);
|
|
@@ -9,22 +9,25 @@ const zustand_1 = __importDefault(require("zustand"));
|
|
|
9
9
|
const middleware_1 = require("zustand/middleware");
|
|
10
10
|
const immer_1 = require("zustand/middleware/immer");
|
|
11
11
|
exports.maxChainToOrder = 9;
|
|
12
|
-
exports.useChainOrderStore = (0, zustand_1.default)()((0, middleware_1.persist)((0, immer_1.immer)((set) => ({
|
|
12
|
+
exports.useChainOrderStore = (0, zustand_1.default)()((0, middleware_1.persist)((0, immer_1.immer)((set, get) => ({
|
|
13
13
|
chainOrder: [],
|
|
14
14
|
availableChains: [],
|
|
15
|
-
initializeChains: (chainIds) =>
|
|
16
|
-
state
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
initializeChains: (chainIds) => {
|
|
16
|
+
set((state) => {
|
|
17
|
+
state.availableChains = chainIds;
|
|
18
|
+
state.chainOrder = state.chainOrder.filter((chainId) => chainIds.includes(chainId));
|
|
19
|
+
const chainsToAdd = chainIds.filter((chainId) => !state.chainOrder.includes(chainId));
|
|
20
|
+
if (state.chainOrder.length === exports.maxChainToOrder ||
|
|
21
|
+
!chainsToAdd.length) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const chainsToAddLength = exports.maxChainToOrder - state.chainOrder.length;
|
|
25
|
+
for (let index = 0; index < chainsToAddLength; index++) {
|
|
26
|
+
state.chainOrder.push(chainsToAdd[index]);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return get().chainOrder;
|
|
30
|
+
},
|
|
28
31
|
setChain: (chainId) => set((state) => {
|
|
29
32
|
if (state.chainOrder.includes(chainId) ||
|
|
30
33
|
!state.availableChains.includes(chainId)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Route } from '@lifi/sdk';
|
|
1
|
+
import type { Process, Route } from '@lifi/sdk';
|
|
2
2
|
export declare const isRouteCompleted: (route: Route) => boolean;
|
|
3
3
|
export declare const isRouteFailed: (route: Route) => boolean;
|
|
4
4
|
export declare const isRouteActive: (route?: Route) => boolean;
|
|
5
|
+
export declare const getUpdatedProcess: (currentRoute: Route, updatedRoute: Route) => Process | undefined;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRouteActive = exports.isRouteFailed = exports.isRouteCompleted = void 0;
|
|
6
|
+
exports.getUpdatedProcess = exports.isRouteActive = exports.isRouteFailed = exports.isRouteCompleted = void 0;
|
|
7
|
+
const microdiff_1 = __importDefault(require("microdiff"));
|
|
4
8
|
const isRouteCompleted = (route) => {
|
|
5
9
|
return route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
|
|
6
10
|
};
|
|
@@ -19,3 +23,15 @@ const isRouteActive = (route) => {
|
|
|
19
23
|
return !isDone && !isFailed && alreadyStarted;
|
|
20
24
|
};
|
|
21
25
|
exports.isRouteActive = isRouteActive;
|
|
26
|
+
const getUpdatedProcess = (currentRoute, updatedRoute) => {
|
|
27
|
+
const processDiff = (0, microdiff_1.default)(currentRoute, updatedRoute).find((diff) => diff.path.includes('process'));
|
|
28
|
+
if (!processDiff) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
// e.g. ['steps', 0, 'execution', 'process', 0]
|
|
32
|
+
const process = processDiff.path
|
|
33
|
+
.slice(0, processDiff.path.findIndex((path) => path === 'process') + 2)
|
|
34
|
+
.reduce((obj, path) => obj[path], updatedRoute);
|
|
35
|
+
return process;
|
|
36
|
+
};
|
|
37
|
+
exports.getUpdatedProcess = getUpdatedProcess;
|
|
@@ -16,6 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./useAppearance"), exports);
|
|
19
|
-
__exportStar(require("./useSetSettings"), exports);
|
|
20
19
|
__exportStar(require("./useSettings"), exports);
|
|
21
20
|
__exportStar(require("./useSettingsStore"), exports);
|
|
@@ -8,7 +8,9 @@ const shallow_1 = __importDefault(require("zustand/shallow"));
|
|
|
8
8
|
const useSettingsStore_1 = require("./useSettingsStore");
|
|
9
9
|
const useAppearance = () => {
|
|
10
10
|
const [appearance, setValue] = (0, useSettingsStore_1.useSettingsStore)((state) => [state.appearance, state.setValue], shallow_1.default);
|
|
11
|
-
const setAppearance = (appearance) =>
|
|
11
|
+
const setAppearance = (appearance) => {
|
|
12
|
+
setValue('appearance', appearance);
|
|
13
|
+
};
|
|
12
14
|
return [appearance, setAppearance];
|
|
13
15
|
};
|
|
14
16
|
exports.useAppearance = useAppearance;
|