@lifi/widget 2.0.0 → 2.1.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.
Files changed (84) hide show
  1. package/cjs/components/Header/NavigationHeader.js +2 -2
  2. package/cjs/components/Header/index.d.ts +0 -1
  3. package/cjs/components/Header/index.js +0 -1
  4. package/cjs/components/Step/StepList.d.ts +2 -1
  5. package/cjs/components/Step/StepList.js +4 -2
  6. package/cjs/components/StepActions/StepActions.js +12 -3
  7. package/cjs/config/version.d.ts +1 -1
  8. package/cjs/config/version.js +1 -1
  9. package/cjs/hooks/useRoutes.js +2 -4
  10. package/cjs/i18n/en.json +2 -2
  11. package/cjs/i18n/id.json +61 -60
  12. package/cjs/i18n/it.json +61 -60
  13. package/cjs/i18n/pt.json +62 -61
  14. package/cjs/i18n/th.json +61 -60
  15. package/cjs/i18n/uk.json +50 -49
  16. package/cjs/i18n/vi.json +64 -63
  17. package/cjs/pages/ActiveTransactionsPage/ActiveTransactionsPage.js +3 -3
  18. package/cjs/pages/RoutesPage/RoutesPage.js +3 -3
  19. package/cjs/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.js +3 -3
  20. package/cjs/pages/TransactionDetailsPage/ContactSupportButton.d.ts +5 -0
  21. package/cjs/pages/TransactionDetailsPage/ContactSupportButton.js +25 -0
  22. package/cjs/pages/TransactionDetailsPage/TransactionDetailsPage.js +6 -5
  23. package/cjs/pages/TransactionHistoryPage/TransactionHistoryPage.js +3 -3
  24. package/cjs/pages/TransactionPage/ExchangeRateBottomSheet.js +2 -1
  25. package/cjs/pages/TransactionPage/StatusBottomSheet.style.js +5 -1
  26. package/cjs/pages/TransactionPage/TransactionPage.js +8 -4
  27. package/cjs/stores/StoreProvider.js +2 -1
  28. package/cjs/stores/header/index.d.ts +1 -0
  29. package/cjs/stores/header/index.js +17 -0
  30. package/cjs/{components/Header → stores/header}/types.d.ts +4 -2
  31. package/cjs/stores/header/useHeaderStore.d.ts +8 -0
  32. package/cjs/stores/header/useHeaderStore.js +56 -0
  33. package/cjs/stores/index.d.ts +2 -1
  34. package/cjs/stores/index.js +2 -1
  35. package/cjs/stores/routes/utils.d.ts +1 -0
  36. package/cjs/stores/routes/utils.js +5 -1
  37. package/cjs/types/events.d.ts +6 -1
  38. package/cjs/types/events.js +1 -0
  39. package/components/Header/NavigationHeader.js +2 -2
  40. package/components/Header/index.d.ts +0 -1
  41. package/components/Header/index.js +0 -1
  42. package/components/Step/StepList.d.ts +2 -1
  43. package/components/Step/StepList.js +4 -2
  44. package/components/StepActions/StepActions.js +12 -3
  45. package/config/version.d.ts +1 -1
  46. package/config/version.js +1 -1
  47. package/hooks/useRoutes.js +2 -4
  48. package/i18n/en.json +2 -2
  49. package/i18n/id.json +61 -60
  50. package/i18n/it.json +61 -60
  51. package/i18n/pt.json +62 -61
  52. package/i18n/th.json +61 -60
  53. package/i18n/uk.json +50 -49
  54. package/i18n/vi.json +64 -63
  55. package/package.json +15 -29
  56. package/pages/ActiveTransactionsPage/ActiveTransactionsPage.js +4 -4
  57. package/pages/RoutesPage/RoutesPage.js +4 -4
  58. package/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.js +4 -4
  59. package/pages/TransactionDetailsPage/ContactSupportButton.d.ts +5 -0
  60. package/pages/TransactionDetailsPage/ContactSupportButton.js +21 -0
  61. package/pages/TransactionDetailsPage/TransactionDetailsPage.js +7 -6
  62. package/pages/TransactionHistoryPage/TransactionHistoryPage.js +4 -4
  63. package/pages/TransactionPage/ExchangeRateBottomSheet.js +2 -1
  64. package/pages/TransactionPage/StatusBottomSheet.style.js +5 -1
  65. package/pages/TransactionPage/TransactionPage.js +9 -5
  66. package/stores/StoreProvider.js +2 -1
  67. package/stores/header/index.d.ts +1 -0
  68. package/stores/header/index.js +1 -0
  69. package/{components/Header → stores/header}/types.d.ts +4 -2
  70. package/stores/header/useHeaderStore.d.ts +8 -0
  71. package/stores/header/useHeaderStore.js +49 -0
  72. package/stores/index.d.ts +2 -1
  73. package/stores/index.js +2 -1
  74. package/stores/routes/utils.d.ts +1 -0
  75. package/stores/routes/utils.js +3 -0
  76. package/tsconfig.cjs.tsbuildinfo +1 -1
  77. package/types/events.d.ts +6 -1
  78. package/types/events.js +1 -0
  79. package/cjs/components/Header/useHeaderStore.d.ts +0 -2
  80. package/cjs/components/Header/useHeaderStore.js +0 -28
  81. package/components/Header/useHeaderStore.d.ts +0 -2
  82. package/components/Header/useHeaderStore.js +0 -25
  83. /package/cjs/{components/Header → stores/header}/types.js +0 -0
  84. /package/{components/Header → stores/header}/types.js +0 -0
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from '@mui/material';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { useWidgetEvents } from '../../hooks/';
5
+ import { WidgetEvent } from '../../types/events';
6
+ export const ContactSupportButton = ({ supportId, }) => {
7
+ const { t } = useTranslation();
8
+ const widgetEvents = useWidgetEvents();
9
+ const handleClick = () => {
10
+ if (!widgetEvents.all.has(WidgetEvent.RouteContactSupport)) {
11
+ const url = 'https://discord.gg/lifi';
12
+ const target = '_blank';
13
+ const rel = 'nofollow noreferrer';
14
+ window.open(url, target, rel);
15
+ }
16
+ else {
17
+ widgetEvents.emit(WidgetEvent.RouteContactSupport, { supportId });
18
+ }
19
+ };
20
+ return (_jsx(Button, { onClick: handleClick, fullWidth: true, children: t('button.contactSupport') }));
21
+ };
@@ -9,13 +9,13 @@ import { shallow } from 'zustand/shallow';
9
9
  import { Card, CardTitle } from '../../components/Card';
10
10
  import { ContractComponent } from '../../components/ContractComponent';
11
11
  import { Dialog } from '../../components/Dialog';
12
- import { useHeaderStore } from '../../components/Header';
13
12
  import { Insurance } from '../../components/Insurance';
14
13
  import { getStepList } from '../../components/Step';
15
14
  import { useNavigateBack } from '../../hooks';
16
15
  import { useWidgetConfig } from '../../providers';
17
- import { useRouteExecutionStore } from '../../stores';
16
+ import { useHeaderStoreContext, useRouteExecutionStore } from '../../stores';
18
17
  import { formatTokenAmount } from '../../utils';
18
+ import { ContactSupportButton } from './ContactSupportButton';
19
19
  import { Container } from './TransactionDetailsPage.style';
20
20
  export const TransactionDetailsPage = () => {
21
21
  const { t, i18n } = useTranslation();
@@ -23,6 +23,7 @@ export const TransactionDetailsPage = () => {
23
23
  const { subvariant, contractComponent, contractSecondaryComponent } = useWidgetConfig();
24
24
  const { state } = useLocation();
25
25
  const [routeExecution, deleteRoute] = useRouteExecutionStore((store) => [store.routes[state?.routeId], store.deleteRoute], shallow);
26
+ const headerStoreContext = useHeaderStoreContext();
26
27
  const [open, setOpen] = useState(false);
27
28
  const toggleDialog = useCallback(() => {
28
29
  setOpen((open) => !open);
@@ -45,8 +46,8 @@ export const TransactionDetailsPage = () => {
45
46
  await navigator.clipboard.writeText(supportId);
46
47
  };
47
48
  useEffect(() => {
48
- return useHeaderStore.getState().setAction(_jsx(IconButton, { size: "medium", edge: "end", onClick: toggleDialog, children: _jsx(DeleteIcon, {}) }));
49
- }, [toggleDialog]);
49
+ return headerStoreContext.getState().setAction(_jsx(IconButton, { size: "medium", edge: "end", onClick: toggleDialog, children: _jsx(DeleteIcon, {}) }));
50
+ }, [headerStoreContext, toggleDialog]);
50
51
  const startedAt = new Date(routeExecution?.route.steps[0].execution?.process[0].startedAt ?? 0);
51
52
  return (_jsxs(Container, { children: [_jsxs(Box, { sx: {
52
53
  display: 'flex',
@@ -54,8 +55,8 @@ export const TransactionDetailsPage = () => {
54
55
  justifyContent: 'space-between',
55
56
  }, pb: 1, children: [_jsx(Typography, { fontSize: 12, children: new Intl.DateTimeFormat(i18n.language, { dateStyle: 'long' }).format(startedAt) }), _jsx(Typography, { fontSize: 12, children: new Intl.DateTimeFormat(i18n.language, {
56
57
  timeStyle: 'short',
57
- }).format(startedAt) })] }), getStepList(routeExecution?.route), subvariant === 'nft' ? (_jsx(ContractComponent, { mt: 2, children: contractSecondaryComponent || contractComponent })) : null, routeExecution?.route?.insurance?.state === 'INSURED' ? (_jsx(Insurance, { mt: 2, status: routeExecution.status, feeAmountUsd: routeExecution.route.insurance.feeAmountUsd, insuredAmount: formatTokenAmount(routeExecution.route.toAmountMin, routeExecution.route.toToken.decimals), insuredTokenSymbol: routeExecution.route.toToken.symbol, insurableRouteId: routeExecution.route.id, insuranceCoverageId: insuranceCoverageId })) : null, _jsxs(Card, { mt: 2, children: [_jsxs(Box, { sx: {
58
+ }).format(startedAt) })] }), getStepList(routeExecution?.route, subvariant), subvariant === 'nft' ? (_jsx(ContractComponent, { mt: 2, children: contractSecondaryComponent || contractComponent })) : null, routeExecution?.route?.insurance?.state === 'INSURED' ? (_jsx(Insurance, { mt: 2, status: routeExecution.status, feeAmountUsd: routeExecution.route.insurance.feeAmountUsd, insuredAmount: formatTokenAmount(routeExecution.route.toAmountMin, routeExecution.route.toToken.decimals), insuredTokenSymbol: routeExecution.route.toToken.symbol, insurableRouteId: routeExecution.route.id, insuranceCoverageId: insuranceCoverageId })) : null, _jsxs(Card, { mt: 2, children: [_jsxs(Box, { sx: {
58
59
  display: 'flex',
59
60
  flex: 1,
60
- }, children: [_jsx(CardTitle, { flex: 1, children: t('main.supportId') }), _jsx(Box, { mr: 1, mt: 1, children: _jsx(IconButton, { size: "medium", onClick: copySupportId, children: _jsx(ContentCopyIcon, { fontSize: "small" }) }) })] }), _jsx(Typography, { variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' }, children: supportId })] }), _jsx(Box, { mt: 2, children: _jsx(Button, { href: "https://discord.gg/lifi", target: "_blank", rel: "nofollow noreferrer", fullWidth: true, children: t('button.contactSupport') }) }), _jsxs(Dialog, { open: open, onClose: toggleDialog, children: [_jsx(DialogTitle, { children: t('warning.title.deleteTransaction') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('warning.message.deleteTransactionHistory') }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: toggleDialog, children: t('button.cancel') }), _jsx(Button, { variant: "contained", onClick: handleDeleteRoute, autoFocus: true, children: t('button.delete') })] })] })] }));
61
+ }, children: [_jsx(CardTitle, { flex: 1, children: t('main.supportId') }), _jsx(Box, { mr: 1, mt: 1, children: _jsx(IconButton, { size: "medium", onClick: copySupportId, children: _jsx(ContentCopyIcon, { fontSize: "small" }) }) })] }), _jsx(Typography, { variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' }, children: supportId })] }), _jsx(Box, { mt: 2, children: _jsx(ContactSupportButton, { supportId: supportId }) }), _jsxs(Dialog, { open: open, onClose: toggleDialog, children: [_jsx(DialogTitle, { children: t('warning.title.deleteTransaction') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('warning.message.deleteTransactionHistory') }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: toggleDialog, children: t('button.cancel') }), _jsx(Button, { variant: "contained", onClick: handleDeleteRoute, autoFocus: true, children: t('button.delete') })] })] })] }));
61
62
  };
@@ -4,9 +4,8 @@ import { Button, Container, DialogActions, DialogContent, DialogContentText, Dia
4
4
  import { useCallback, useEffect, useState } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { Dialog } from '../../components/Dialog';
7
- import { useHeaderStore } from '../../components/Header';
8
7
  import { useWallet } from '../../providers';
9
- import { useRouteExecutionStore } from '../../stores';
8
+ import { useHeaderStoreContext, useRouteExecutionStore } from '../../stores';
10
9
  import { useTransactionHistory } from '../../stores/routes';
11
10
  import { TransactionHistoryEmpty } from './TransactionHistoryEmpty';
12
11
  import { TransactionHistoryItem } from './TransactionHistoryItem';
@@ -14,6 +13,7 @@ export const TransactionHistoryPage = () => {
14
13
  const { t } = useTranslation();
15
14
  const { account } = useWallet();
16
15
  const transactions = useTransactionHistory(account.address);
16
+ const headerStoreContext = useHeaderStoreContext();
17
17
  const deleteRoutes = useRouteExecutionStore((store) => store.deleteRoutes);
18
18
  const [open, setOpen] = useState(false);
19
19
  const toggleDialog = useCallback(() => {
@@ -21,9 +21,9 @@ export const TransactionHistoryPage = () => {
21
21
  }, []);
22
22
  useEffect(() => {
23
23
  if (transactions.length) {
24
- return useHeaderStore.getState().setAction(_jsx(IconButton, { size: "medium", edge: "end", onClick: toggleDialog, children: _jsx(DeleteIcon, {}) }));
24
+ return headerStoreContext.getState().setAction(_jsx(IconButton, { size: "medium", edge: "end", onClick: toggleDialog, children: _jsx(DeleteIcon, {}) }));
25
25
  }
26
- }, [transactions.length, toggleDialog]);
26
+ }, [transactions.length, toggleDialog, headerStoreContext]);
27
27
  if (!transactions.length) {
28
28
  return _jsx(TransactionHistoryEmpty, {});
29
29
  }
@@ -44,12 +44,13 @@ const ExchangeRateBottomSheetContent = ({ data, onCancel, onContinue }) => {
44
44
  const { t } = useTranslation();
45
45
  const ref = useRef();
46
46
  useSetContentHeight(ref);
47
+ const oldAmount = Big(data?.oldToAmount || 1);
47
48
  return (_jsxs(Box, { p: 3, ref: ref, children: [_jsxs(CenterContainer, { children: [_jsx(IconCircle, { status: "warning", mb: 1, children: _jsx(WarningRoundedIcon, { color: "warning" }) }), _jsx(Typography, { py: 1, fontSize: 18, fontWeight: 700, children: t('warning.title.rateChanged') })] }), _jsx(Typography, { py: 1, children: t('warning.message.rateChanged') }), _jsxs(Box, { display: "flex", justifyContent: "space-between", mt: 1, children: [_jsx(Typography, { children: t('main.quotedAmount') }), _jsxs(Typography, { fontWeight: 600, children: [t('format.number', {
48
49
  value: formatTokenAmount(data?.oldToAmount, data?.toToken.decimals, 5),
49
50
  }), ' ', data?.toToken.symbol] })] }), _jsxs(Box, { display: "flex", justifyContent: "space-between", mt: 0.25, children: [_jsx(Typography, { children: t('main.currentAmount') }), _jsxs(Typography, { fontWeight: 600, children: [t('format.number', {
50
51
  value: formatTokenAmount(data?.newToAmount, data?.toToken.decimals, 5),
51
52
  }), ' ', data?.toToken.symbol] })] }), _jsxs(Box, { display: "flex", justifyContent: "space-between", mt: 0.25, children: [_jsx(Typography, { children: t('main.rateChange') }), _jsxs(Typography, { fontWeight: 600, children: [Big(data?.newToAmount || 0)
52
- .div(Big(data?.oldToAmount || 0))
53
+ .div(oldAmount.eq(0) ? Big(1) : oldAmount)
53
54
  .minus(1)
54
55
  .mul(100)
55
56
  .round(2, Big.roundUp)
@@ -10,7 +10,11 @@ const getStatusColor = (status, theme) => {
10
10
  case RouteExecutionStatus.Done | RouteExecutionStatus.Partial:
11
11
  case RouteExecutionStatus.Done | RouteExecutionStatus.Refunded:
12
12
  case 'warning':
13
- return { color: theme.palette.warning.main, alpha: 0.48, darken: 0.32 };
13
+ return {
14
+ color: theme.palette.warning.main,
15
+ alpha: 0.48,
16
+ darken: theme.palette.mode === 'light' ? 0.32 : 0,
17
+ };
14
18
  default:
15
19
  return { color: theme.palette.primary.main, alpha: 0.12, darken: 0 };
16
20
  }
@@ -7,12 +7,11 @@ import { useTranslation } from 'react-i18next';
7
7
  import { useLocation } from 'react-router-dom';
8
8
  import { ContractComponent } from '../../components/ContractComponent';
9
9
  import { GasMessage } from '../../components/GasMessage';
10
- import { useHeaderStore } from '../../components/Header';
11
10
  import { Insurance } from '../../components/Insurance';
12
11
  import { getStepList } from '../../components/Step';
13
12
  import { useNavigateBack, useRouteExecution, useWidgetEvents, } from '../../hooks';
14
13
  import { FormKey, useWidgetConfig } from '../../providers';
15
- import { RouteExecutionStatus } from '../../stores';
14
+ import { RouteExecutionStatus, useHeaderStoreContext } from '../../stores';
16
15
  import { WidgetEvent } from '../../types/events';
17
16
  import { formatTokenAmount } from '../../utils';
18
17
  import { ExchangeRateBottomSheet } from './ExchangeRateBottomSheet';
@@ -28,6 +27,7 @@ export const TransactionPage = () => {
28
27
  const { navigateBack } = useNavigateBack();
29
28
  const { subvariant, insurance, contractComponent, contractSecondaryComponent, } = useWidgetConfig();
30
29
  const { state } = useLocation();
30
+ const headerStoreContext = useHeaderStoreContext();
31
31
  const stateRouteId = state?.routeId;
32
32
  const [routeId, setRouteId] = useState(stateRouteId);
33
33
  const tokenValueBottomSheetRef = useRef(null);
@@ -42,13 +42,13 @@ export const TransactionPage = () => {
42
42
  useEffect(() => {
43
43
  if (route && subvariant !== 'nft') {
44
44
  const transactionType = route.fromChainId === route.toChainId ? 'Swap' : 'Bridge';
45
- return useHeaderStore
45
+ return headerStoreContext
46
46
  .getState()
47
47
  .setTitle(status === RouteExecutionStatus.Idle
48
48
  ? t(`button.review${transactionType}`)
49
49
  : t(`header.${transactionType.toLowerCase()}`));
50
50
  }
51
- }, [route, status, subvariant, t]);
51
+ }, [headerStoreContext, route, status, subvariant, t]);
52
52
  if (!route) {
53
53
  return null;
54
54
  }
@@ -65,6 +65,10 @@ export const TransactionPage = () => {
65
65
  tokenValueBottomSheetRef.current?.close();
66
66
  executeRoute();
67
67
  setValue(FormKey.FromAmount, '');
68
+ if (subvariant === 'nft') {
69
+ setValue(FormKey.FromToken, '');
70
+ setValue(FormKey.ToToken, '');
71
+ }
68
72
  };
69
73
  const handleStartClick = async () => {
70
74
  if (status === RouteExecutionStatus.Idle) {
@@ -113,7 +117,7 @@ export const TransactionPage = () => {
113
117
  const getInsuranceCoverageId = () => route.steps[0].execution?.process
114
118
  .filter((process) => process.type !== 'TOKEN_ALLOWANCE')
115
119
  .find((process) => process.txHash)?.txHash ?? route.fromAddress;
116
- return (_jsxs(Container, { children: [getStepList(route), subvariant === 'nft' ? (_jsx(ContractComponent, { mt: 2, children: contractSecondaryComponent || contractComponent })) : null, insuranceAvailable ? (_jsx(Insurance, { mt: 2, status: status, insurableRouteId: stateRouteId, feeAmountUsd: route.insurance.feeAmountUsd, insuredAmount: formatTokenAmount(route.toAmountMin, route.toToken.decimals), insuredTokenSymbol: route.toToken.symbol, insuranceCoverageId: getInsuranceCoverageId(), onChange: setRouteId })) : null, status === RouteExecutionStatus.Idle ||
120
+ return (_jsxs(Container, { children: [getStepList(route, subvariant), subvariant === 'nft' ? (_jsx(ContractComponent, { mt: 2, children: contractSecondaryComponent || contractComponent })) : null, insuranceAvailable ? (_jsx(Insurance, { mt: 2, status: status, insurableRouteId: stateRouteId, feeAmountUsd: route.insurance.feeAmountUsd, insuredAmount: formatTokenAmount(route.toAmountMin, route.toToken.decimals), insuredTokenSymbol: route.toToken.symbol, insuranceCoverageId: getInsuranceCoverageId(), onChange: setRouteId })) : null, status === RouteExecutionStatus.Idle ||
117
121
  status === RouteExecutionStatus.Failed ? (_jsxs(_Fragment, { children: [_jsx(GasMessage, { mt: 2, route: route }), _jsxs(Box, { mt: 2, display: "flex", children: [_jsx(StartButton, { text: getButtonText(), onClick: handleStartClick, route: route, insurableRouteId: stateRouteId }), status === RouteExecutionStatus.Failed ? (_jsx(Tooltip, { title: t('button.removeTransaction'), placement: "bottom-end", enterDelay: 400, arrow: true, children: _jsx(Button, { onClick: handleRemoveRoute, sx: {
118
122
  minWidth: 48,
119
123
  marginLeft: 1,
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { HeaderStoreProvider } from './header';
2
3
  import { RouteExecutionStoreProvider } from './routes';
3
4
  import { SplitSubvariantStoreProvider } from './settings';
4
5
  export const StoreProvider = ({ children, config, }) => {
5
- return (_jsx(SplitSubvariantStoreProvider, { state: config.subvariant === 'split' ? 'swap' : undefined, children: _jsx(RouteExecutionStoreProvider, { namePrefix: config?.localStorageKeyPrefix, children: children }) }));
6
+ return (_jsx(SplitSubvariantStoreProvider, { state: config.subvariant === 'split' ? 'swap' : undefined, children: _jsx(HeaderStoreProvider, { namePrefix: config?.localStorageKeyPrefix, children: _jsx(RouteExecutionStoreProvider, { namePrefix: config?.localStorageKeyPrefix, children: children }) }) }));
6
7
  };
@@ -0,0 +1 @@
1
+ export * from './useHeaderStore';
@@ -0,0 +1 @@
1
+ export * from './useHeaderStore';
@@ -1,9 +1,11 @@
1
1
  /// <reference types="react" />
2
- export interface HeaderState {
2
+ import type { StoreApi, UseBoundStore } from 'zustand';
3
+ export type HeaderStore = UseBoundStore<StoreApi<HeaderState>>;
4
+ export interface HeaderStateBase {
3
5
  element?: React.ReactNode | null;
4
6
  title?: string;
5
7
  }
6
- export interface HeaderStore extends HeaderState {
8
+ export interface HeaderState extends HeaderStateBase {
7
9
  setAction(element?: React.ReactNode | null): () => void;
8
10
  setTitle(title?: string): () => void;
9
11
  removeAction(): void;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import type { PersistStoreProps, PersistStoreProviderProps } from '../types';
3
+ import type { HeaderState, HeaderStore } from './types';
4
+ export declare const HeaderStoreContext: import("react").Context<HeaderStore | null>;
5
+ export declare function HeaderStoreProvider({ children, ...props }: PersistStoreProviderProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function useHeaderStore<T>(selector: (state: HeaderState) => T, equalityFn?: (left: T, right: T) => boolean): T;
7
+ export declare function useHeaderStoreContext(): HeaderStore;
8
+ export declare const createHeaderStore: ({ namePrefix }: PersistStoreProps) => import("zustand").UseBoundStore<import("zustand").StoreApi<HeaderState>>;
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useRef } from 'react';
3
+ import { create } from 'zustand';
4
+ export const HeaderStoreContext = createContext(null);
5
+ export function HeaderStoreProvider({ children, ...props }) {
6
+ const storeRef = useRef();
7
+ if (!storeRef.current) {
8
+ storeRef.current = createHeaderStore(props);
9
+ }
10
+ return (_jsx(HeaderStoreContext.Provider, { value: storeRef.current, children: children }));
11
+ }
12
+ export function useHeaderStore(selector, equalityFn) {
13
+ const useStore = useContext(HeaderStoreContext);
14
+ if (!useStore) {
15
+ throw new Error(`You forgot to wrap your component in <${HeaderStoreProvider.name}>.`);
16
+ }
17
+ return useStore(selector, equalityFn);
18
+ }
19
+ export function useHeaderStoreContext() {
20
+ const useStore = useContext(HeaderStoreContext);
21
+ if (!useStore) {
22
+ throw new Error(`You forgot to wrap your component in <${HeaderStoreProvider.name}>.`);
23
+ }
24
+ return useStore;
25
+ }
26
+ export const createHeaderStore = ({ namePrefix }) => create((set, get) => ({
27
+ setAction: (element) => {
28
+ set(() => ({
29
+ element,
30
+ }));
31
+ return get().removeAction;
32
+ },
33
+ setTitle: (title) => {
34
+ set(() => ({
35
+ title,
36
+ }));
37
+ return get().removeTitle;
38
+ },
39
+ removeAction: () => {
40
+ set(() => ({
41
+ element: null,
42
+ }));
43
+ },
44
+ removeTitle: () => {
45
+ set(() => ({
46
+ title: undefined,
47
+ }));
48
+ },
49
+ }));
package/stores/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
+ export * from './StoreProvider';
1
2
  export * from './chains';
3
+ export * from './header';
2
4
  export * from './routes';
3
5
  export * from './settings';
4
- export * from './StoreProvider';
package/stores/index.js CHANGED
@@ -1,4 +1,5 @@
1
+ export * from './StoreProvider';
1
2
  export * from './chains';
3
+ export * from './header';
2
4
  export * from './routes';
3
5
  export * from './settings';
4
- export * from './StoreProvider';
@@ -4,4 +4,5 @@ export declare const isRoutePartiallyDone: (route: Route) => boolean;
4
4
  export declare const isRouteRefunded: (route: Route) => boolean;
5
5
  export declare const isRouteFailed: (route: Route) => boolean;
6
6
  export declare const isRouteActive: (route?: Route) => boolean;
7
+ export declare const doesRouteHaveCustomTool: (route: Route) => boolean;
7
8
  export declare const getUpdatedProcess: (currentRoute: Route, updatedRoute: Route) => Process | undefined;
@@ -20,6 +20,9 @@ export const isRouteActive = (route) => {
20
20
  const alreadyStarted = route.steps.some((step) => step.execution);
21
21
  return !isDone && !isFailed && alreadyStarted;
22
22
  };
23
+ export const doesRouteHaveCustomTool = (route) => {
24
+ return route.steps.some((step) => step.tool === 'custom' || step.toolDetails.key === 'custom');
25
+ };
23
26
  export const getUpdatedProcess = (currentRoute, updatedRoute) => {
24
27
  const processDiff = microdiff(currentRoute, updatedRoute).find((diff) => diff.path.includes('process'));
25
28
  if (!processDiff) {