@lifi/widget 2.0.0-beta.4 → 2.0.0-beta.6

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 (85) hide show
  1. package/AppDrawer.js +2 -1
  2. package/AppProvider.js +1 -1
  3. package/README.md +11 -12
  4. package/cjs/AppDrawer.js +2 -1
  5. package/cjs/AppProvider.js +1 -1
  6. package/cjs/components/ChainSelect/useChainSelect.js +6 -0
  7. package/cjs/components/Header/Header.js +2 -2
  8. package/cjs/components/Header/Header.style.js +3 -0
  9. package/cjs/components/Header/NavigationHeader.js +7 -4
  10. package/cjs/components/Header/NavigationTabs.d.ts +1 -0
  11. package/cjs/components/Header/NavigationTabs.js +26 -0
  12. package/cjs/components/Header/NavigationTabs.style.d.ts +101 -0
  13. package/cjs/components/Header/NavigationTabs.style.js +61 -0
  14. package/cjs/components/Header/WalletHeader.d.ts +1 -0
  15. package/cjs/components/Header/WalletHeader.js +15 -8
  16. package/cjs/components/Header/useHeaderActionStore.js +0 -1
  17. package/cjs/components/SelectTokenButton/SelectTokenButton.js +5 -2
  18. package/cjs/components/SwapRouteCard/SwapRouteCard.js +14 -5
  19. package/cjs/components/SwapRouteCard/SwapRouteCardEssentials.js +1 -1
  20. package/cjs/config/version.d.ts +1 -1
  21. package/cjs/config/version.js +1 -1
  22. package/cjs/hooks/index.d.ts +2 -1
  23. package/cjs/hooks/index.js +2 -1
  24. package/cjs/hooks/useContentHeight.js +3 -5
  25. package/cjs/hooks/useInitializer.js +0 -1
  26. package/cjs/hooks/useSwapOnly.d.ts +1 -0
  27. package/cjs/hooks/useSwapOnly.js +9 -0
  28. package/cjs/hooks/useSwapRoutes.js +3 -1
  29. package/cjs/i18n/en.json +3 -2
  30. package/cjs/i18n/pt.json +19 -4
  31. package/cjs/i18n/uk.json +20 -5
  32. package/cjs/pages/SelectTokenPage/SelectTokenPage.js +3 -1
  33. package/cjs/pages/SwapPage/SwapPage.js +4 -1
  34. package/cjs/providers/SwapFormProvider/FormUpdater.js +3 -0
  35. package/cjs/stores/StoreProvider.d.ts +2 -2
  36. package/cjs/stores/StoreProvider.js +3 -2
  37. package/cjs/stores/routes/RouteExecutionStore.js +0 -1
  38. package/cjs/stores/settings/index.d.ts +1 -0
  39. package/cjs/stores/settings/index.js +1 -0
  40. package/cjs/stores/settings/types.d.ts +11 -0
  41. package/cjs/stores/settings/useSplitSubvariantStore.d.ts +7 -0
  42. package/cjs/stores/settings/useSplitSubvariantStore.js +44 -0
  43. package/cjs/types/widget.d.ts +5 -1
  44. package/cjs/types/widget.js +3 -3
  45. package/components/ChainSelect/useChainSelect.js +7 -1
  46. package/components/Header/Header.js +3 -3
  47. package/components/Header/Header.style.js +3 -0
  48. package/components/Header/NavigationHeader.js +7 -4
  49. package/components/Header/NavigationTabs.d.ts +1 -0
  50. package/components/Header/NavigationTabs.js +22 -0
  51. package/components/Header/NavigationTabs.style.d.ts +101 -0
  52. package/components/Header/NavigationTabs.style.js +58 -0
  53. package/components/Header/WalletHeader.d.ts +1 -0
  54. package/components/Header/WalletHeader.js +12 -6
  55. package/components/Header/useHeaderActionStore.js +0 -1
  56. package/components/SelectTokenButton/SelectTokenButton.js +6 -3
  57. package/components/SwapRouteCard/SwapRouteCard.js +15 -6
  58. package/components/SwapRouteCard/SwapRouteCardEssentials.js +1 -1
  59. package/config/version.d.ts +1 -1
  60. package/config/version.js +1 -1
  61. package/hooks/index.d.ts +2 -1
  62. package/hooks/index.js +2 -1
  63. package/hooks/useContentHeight.js +4 -6
  64. package/hooks/useInitializer.js +0 -1
  65. package/hooks/useSwapOnly.d.ts +1 -0
  66. package/hooks/useSwapOnly.js +5 -0
  67. package/hooks/useSwapRoutes.js +3 -1
  68. package/i18n/en.json +3 -2
  69. package/i18n/pt.json +19 -4
  70. package/i18n/uk.json +20 -5
  71. package/package.json +8 -8
  72. package/pages/SelectTokenPage/SelectTokenPage.js +4 -2
  73. package/pages/SwapPage/SwapPage.js +4 -1
  74. package/providers/SwapFormProvider/FormUpdater.js +3 -0
  75. package/stores/StoreProvider.d.ts +2 -2
  76. package/stores/StoreProvider.js +3 -2
  77. package/stores/routes/RouteExecutionStore.js +0 -1
  78. package/stores/settings/index.d.ts +1 -0
  79. package/stores/settings/index.js +1 -0
  80. package/stores/settings/types.d.ts +11 -0
  81. package/stores/settings/useSplitSubvariantStore.d.ts +7 -0
  82. package/stores/settings/useSplitSubvariantStore.js +37 -0
  83. package/tsconfig.cjs.tsbuildinfo +1 -1
  84. package/types/widget.d.ts +5 -1
  85. package/types/widget.js +3 -3
package/i18n/uk.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "button": {
3
3
  "auto": "Авто",
4
+ "buy": "Придбати",
5
+ "buyNow": "Придбати",
4
6
  "cancel": "Скасувати",
5
7
  "connectWallet": "Під'єднати гаманець",
6
8
  "contactSupport": "Служба підтримки",
@@ -23,6 +25,7 @@
23
25
  "resetSettings": "Скинути налаштування",
24
26
  "restartSwap": "Перезапустити своп",
25
27
  "reviewGasSwap": "Переглянути своп газу",
28
+ "reviewPurchase": "Перегляд покупки",
26
29
  "reviewSwap": "Переглянути своп",
27
30
  "seeDetails": "Детальніше",
28
31
  "showAll": "Показати всі",
@@ -39,12 +42,16 @@
39
42
  },
40
43
  "header": {
41
44
  "activeSwaps": "Активні свопи",
45
+ "bridge": "Бридж",
42
46
  "checkout": "Розрахунок",
43
47
  "from": "Своп з",
44
48
  "gas": "Газ",
45
49
  "gasSwap": "Своп газу",
50
+ "payWith": "Сплатити за допомогою",
51
+ "purchase": "Купівля",
52
+ "purchaseDetails": "Деталі покупки",
46
53
  "routes": "Ви отримаєте",
47
- "selectChain": "Оберіть чейн",
54
+ "selectChain": "Виберіть чейн",
48
55
  "selectWallet": "Виберіть свій гаманець",
49
56
  "settings": "Налаштування",
50
57
  "swap": "Своп",
@@ -75,6 +82,7 @@
75
82
  "currentAmount": "Поточна сума",
76
83
  "error": {
77
84
  "message": {
85
+ "allowanceRequired": "Сума переказу для {{tokenSymbol}} перевищує поточну межу. Збільшіть доступну кількість у гаманці та спробуйте ще раз.",
78
86
  "slippageThreshold": "Прослизання перевищує визначений поріг. Будь ласка, зробіть запит на новий маршрут, щоб отримати нову пропозицію.",
79
87
  "transactionFailed": "Будь ласка, перевірте провідник блоків для отримання додаткової інформації.",
80
88
  "transactionNotSent": "Транзакція не була відправлена. {{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} на {{chainName}} все ще знаходяться у вашому гаманці.",
@@ -82,6 +90,7 @@
82
90
  "unknown": "Будь ласка, спробуйте ще раз або зверніться до служби підтримки."
83
91
  },
84
92
  "title": {
93
+ "allowanceRequired": "Недостатня дозволена кількість",
85
94
  "balanceIsTooLow": "Баланс занадто низький",
86
95
  "chainSwitch": "Потрібно переключити чейн.",
87
96
  "failed": "Помилка обміну.",
@@ -131,7 +140,6 @@
131
140
  "onChain": "на {{chainName}}",
132
141
  "otherTokens": "Інші токени",
133
142
  "ownedBy": "Власник",
134
- "payWith": "Оплатити з",
135
143
  "process": {
136
144
  "crossChain": {
137
145
  "actionRequired": "Будь ласка, підпишіть транзакцію",
@@ -139,6 +147,9 @@
139
147
  "pending": "Очікування бридж транзакції",
140
148
  "started": "Підготовка бридж транзакції"
141
149
  },
150
+ "nft": {
151
+ "done": "Придбано NFT"
152
+ },
142
153
  "receivingChain": {
143
154
  "done": "Бридж завершено",
144
155
  "partial": "Бридж частково завершено",
@@ -165,24 +176,27 @@
165
176
  "rateChange": "Зміна курсу",
166
177
  "receiving": "Отримання",
167
178
  "refuelStepDetails": "Отримати газ через {{tool}}",
168
- "routes": "Ви отримаєте",
169
- "selectChain": "Чейн",
179
+ "selectChain": "Виберіть чейн",
170
180
  "selectChainAndToken": "Виберіть чейн і токен",
171
- "selectToken": "Токен",
181
+ "selectToken": "Виберіть токен",
172
182
  "sendToAddress": "Відправити на {{address}}",
173
183
  "sendToWallet": "Надіслати на інший гаманець",
174
184
  "sentToAddress": "Відправлено на {{address}}",
175
185
  "stepBridge": "Бридж",
186
+ "stepBridgeAndBuy": "Бридж та покупка",
176
187
  "stepDetails": "{{tool}} через LI.FI",
177
188
  "stepSwap": "Своп",
178
189
  "stepSwapAndBridge": "Своп та бридж",
190
+ "stepSwapAndBuy": "Своп та покупка",
179
191
  "success": {
180
192
  "message": {
181
193
  "swapPartiallySuccessful": "Ми намагалися завершити своп, але {{tool}} не вистачило ліквідності токену {{tokenSymbol}}.",
194
+ "purchaseSuccessful": "Тепер ви маєте {{assetName}} в {{walletAddress}} гаманці на ланцюжку {{chainName}}.",
182
195
  "swapSuccessful": "Зараз є {{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} у гаманці {{walletAddress}} на чейні {{chainName}}."
183
196
  },
184
197
  "title": {
185
198
  "gasSwapSuccessful": "Своп газу успішний",
199
+ "purchaseSuccessful": "Покупка успішна",
186
200
  "refundIssued": "Здійснено повернення коштів",
187
201
  "swapPartiallySuccessful": "Своп частково успішний",
188
202
  "swapSuccessful": "Своп успішний"
@@ -237,6 +251,7 @@
237
251
  },
238
252
  "numberOfSteps": "Кількість кроків свопу. Кожен крок може містити 1-3 транзакції, які потребують підпису.",
239
253
  "progressToNextUpdate": "Зображені дані автоматично оновляться через {{value}} секунд. Натисніть тут, щоб оновити вручну.",
254
+ "recommended": "Дешевий маршрут, який балансує складність і легкість використання.",
240
255
  "settingsModified": "Налаштування (змінено)"
241
256
  },
242
257
  "wallet": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.6",
4
4
  "description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -37,17 +37,17 @@
37
37
  "lifi"
38
38
  ],
39
39
  "dependencies": {
40
- "@emotion/react": "^11.10.6",
41
- "@emotion/styled": "^11.10.6",
40
+ "@emotion/react": "^11.10.8",
41
+ "@emotion/styled": "^11.10.8",
42
42
  "@ethersproject/abstract-signer": "^5.7.0",
43
43
  "@ethersproject/address": "^5.7.0",
44
44
  "@ethersproject/experimental": "^5.7.0",
45
45
  "@ethersproject/providers": "^5.7.2",
46
46
  "@lifi/sdk": "^2.0.0-beta.11",
47
- "@lifi/wallet-management": "^2.0.0-beta.3",
47
+ "@lifi/wallet-management": "^2.0.0-beta.5",
48
48
  "@mui/icons-material": "^5.11.16",
49
- "@mui/lab": "^5.0.0-alpha.128",
50
- "@mui/material": "^5.12.2",
49
+ "@mui/lab": "^5.0.0-alpha.129",
50
+ "@mui/material": "^5.12.3",
51
51
  "@tanstack/react-query": "^4.29.5",
52
52
  "@tanstack/react-virtual": "^3.0.0-beta.54",
53
53
  "big.js": "^6.2.1",
@@ -60,10 +60,10 @@
60
60
  "react-hook-form": "^7.43.9",
61
61
  "react-i18next": "^12.2.2",
62
62
  "react-intersection-observer": "^9.4.3",
63
- "react-router-dom": "^6.10.0",
63
+ "react-router-dom": "^6.11.1",
64
64
  "react-timer-hook": "^3.0.5",
65
65
  "uuid": "^9.0.0",
66
- "zustand": "^4.3.7"
66
+ "zustand": "^4.3.8"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@types/react": "^18.0.0",
@@ -3,7 +3,7 @@ import { Box, Container } from '@mui/material';
3
3
  import { useLayoutEffect, useRef, useState } from 'react';
4
4
  import { ChainSelect } from '../../components/ChainSelect';
5
5
  import { TokenList } from '../../components/TokenList';
6
- import { useContentHeight, useNavigateBack, useScrollableOverflowHidden, } from '../../hooks';
6
+ import { useContentHeight, useNavigateBack, useScrollableOverflowHidden, useSwapOnly, } from '../../hooks';
7
7
  import { SearchTokenInput } from './SearchTokenInput';
8
8
  const minTokenListHeight = 360;
9
9
  export const SelectTokenPage = ({ formType }) => {
@@ -12,8 +12,10 @@ export const SelectTokenPage = ({ formType }) => {
12
12
  const headerRef = useRef(null);
13
13
  const contentHeight = useContentHeight();
14
14
  const [tokenListHeight, setTokenListHeight] = useState(0);
15
+ const swapOnly = useSwapOnly();
15
16
  useLayoutEffect(() => {
16
17
  setTokenListHeight(Math.max(contentHeight - (headerRef.current?.offsetHeight ?? 0), minTokenListHeight));
17
18
  }, [contentHeight]);
18
- return (_jsxs(Container, { disableGutters: true, children: [_jsxs(Box, { pt: 1, pb: 2, px: 3, ref: headerRef, children: [_jsx(ChainSelect, { formType: formType }), _jsx(Box, { mt: 2, children: _jsx(SearchTokenInput, {}) })] }), _jsx(TokenList, { height: tokenListHeight, onClick: navigateBack, formType: formType })] }));
19
+ const hideChainSelect = swapOnly && formType === 'to';
20
+ return (_jsxs(Container, { disableGutters: true, children: [_jsxs(Box, { pt: 1, pb: 2, px: 3, ref: headerRef, children: [!hideChainSelect ? _jsx(ChainSelect, { formType: formType }) : null, _jsx(Box, { mt: !hideChainSelect ? 2 : 0, children: _jsx(SearchTokenInput, {}) })] }), _jsx(TokenList, { height: tokenListHeight, onClick: navigateBack, formType: formType })] }));
19
21
  };
@@ -27,9 +27,12 @@ export const SwapPage = () => {
27
27
  const [routeId, setRouteId] = useState(stateRouteId);
28
28
  const tokenValueBottomSheetRef = useRef(null);
29
29
  const exchangeRateBottomSheetRef = useRef(null);
30
+ const onAcceptExchangeRateUpdate = (resolver, data) => {
31
+ exchangeRateBottomSheetRef.current?.open(resolver, data);
32
+ };
30
33
  const { route, status, executeRoute, restartRoute, deleteRoute } = useRouteExecution({
31
34
  routeId: routeId,
32
- onAcceptExchangeRateUpdate: exchangeRateBottomSheetRef.current?.open,
35
+ onAcceptExchangeRateUpdate,
33
36
  });
34
37
  const handleExecuteRoute = useCallback(() => {
35
38
  if (tokenValueBottomSheetRef.current?.isOpen()) {
@@ -23,6 +23,7 @@ export const FormUpdater = ({ defaultValues }) => {
23
23
  const { isTouched: isToTokenTouched } = getFieldState(SwapFormKey.ToToken);
24
24
  const { isTouched: isFromAmountTouched } = getFieldState(SwapFormKey.FromAmount);
25
25
  if (!fromChain && !isFromChainTouched && !isFromTokenTouched) {
26
+ resetField(SwapFormKey.FromChain, { defaultValue: account.chainId });
26
27
  setValue(SwapFormKey.FromChain, account.chainId);
27
28
  setValue(SwapFormKey.FromToken, '');
28
29
  if (isFromAmountTouched) {
@@ -30,6 +31,7 @@ export const FormUpdater = ({ defaultValues }) => {
30
31
  }
31
32
  }
32
33
  if (!toChain && !isToChainTouched && !isToTokenTouched) {
34
+ resetField(SwapFormKey.ToChain, { defaultValue: account.chainId });
33
35
  setValue(SwapFormKey.ToChain, account.chainId);
34
36
  setValue(SwapFormKey.ToToken, '');
35
37
  }
@@ -40,6 +42,7 @@ export const FormUpdater = ({ defaultValues }) => {
40
42
  fromChain,
41
43
  getFieldState,
42
44
  getValues,
45
+ resetField,
43
46
  setValue,
44
47
  toChain,
45
48
  ]);
@@ -1,3 +1,3 @@
1
1
  import type { PropsWithChildren } from 'react';
2
- import type { PersistStoreProviderProps } from './types';
3
- export declare const StoreProvider: React.FC<PropsWithChildren<PersistStoreProviderProps>>;
2
+ import type { WidgetConfigProps } from '../types';
3
+ export declare const StoreProvider: React.FC<PropsWithChildren<WidgetConfigProps>>;
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { RouteExecutionStoreProvider } from './routes';
3
- export const StoreProvider = ({ children, namePrefix }) => {
4
- return (_jsx(RouteExecutionStoreProvider, { namePrefix: namePrefix, children: children }));
3
+ import { SplitSubvariantStoreProvider } from './settings';
4
+ export const StoreProvider = ({ children, config, }) => {
5
+ return (_jsx(SplitSubvariantStoreProvider, { state: config.subvariant === 'split' ? 'swap' : undefined, children: _jsx(RouteExecutionStoreProvider, { namePrefix: config?.localStorageKeyPrefix, children: children }) }));
5
6
  };
@@ -1,5 +1,4 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- /* eslint-disable no-underscore-dangle */
3
2
  import { createContext, useContext, useRef } from 'react';
4
3
  import { createRouteExecutionStore } from './createRouteExecutionStore';
5
4
  export const RouteExecutionStoreContext = createContext(null);
@@ -3,3 +3,4 @@ export * from './useAppearance';
3
3
  export * from './useSendToWalletStore';
4
4
  export * from './useSettings';
5
5
  export * from './useSettingsStore';
6
+ export * from './useSplitSubvariantStore';
@@ -3,3 +3,4 @@ export * from './useAppearance';
3
3
  export * from './useSendToWalletStore';
4
4
  export * from './useSettings';
5
5
  export * from './useSettingsStore';
6
+ export * from './useSplitSubvariantStore';
@@ -1,4 +1,6 @@
1
1
  import type { Order } from '@lifi/sdk';
2
+ import type { PropsWithChildren } from 'react';
3
+ import type { StoreApi, UseBoundStore } from 'zustand';
2
4
  import type { Appearance, WidgetConfig } from '../../types';
3
5
  export type ValueSetter<S> = <K extends keyof S>(key: K, value: S[Extract<K, string>]) => void;
4
6
  export type ValuesSetter<S> = <K extends keyof S>(values: Record<K, S[Extract<K, string>]>) => void;
@@ -32,3 +34,12 @@ export interface SendToWalletStore extends SendToWalletState {
32
34
  toggleSendToWallet(): void;
33
35
  setSendToWallet(value: boolean): void;
34
36
  }
37
+ export interface SplitSubvariantState {
38
+ state?: 'swap' | 'bridge';
39
+ setState(state: 'swap' | 'bridge'): void;
40
+ }
41
+ export type SplitSubvariantStore = UseBoundStore<StoreApi<SplitSubvariantState>>;
42
+ export interface SplitSubvariantProps {
43
+ state?: 'swap' | 'bridge';
44
+ }
45
+ export type SplitSubvariantProviderProps = PropsWithChildren<SplitSubvariantProps>;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import type { SplitSubvariantProps, SplitSubvariantProviderProps, SplitSubvariantState, SplitSubvariantStore } from './types';
3
+ export declare const SplitSubvariantStoreContext: import("react").Context<SplitSubvariantStore | null>;
4
+ export declare function SplitSubvariantStoreProvider({ children, ...props }: SplitSubvariantProviderProps): JSX.Element;
5
+ export declare function useSplitSubvariantStore<T>(selector: (state: SplitSubvariantState) => T, equalityFn?: (left: T, right: T) => boolean): T;
6
+ export declare function useSplitSubvariantStoreContext(): SplitSubvariantStore;
7
+ export declare const createSplitSubvariantStore: ({ state }: SplitSubvariantProps) => import("zustand").UseBoundStore<import("zustand").StoreApi<SplitSubvariantState>>;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useRef } from 'react';
3
+ import { create } from 'zustand';
4
+ export const SplitSubvariantStoreContext = createContext(null);
5
+ const shouldRecreateStore = (store, props) => {
6
+ const { state } = store.getState();
7
+ return (!state && props.state) || (state && !props.state);
8
+ };
9
+ export function SplitSubvariantStoreProvider({ children, ...props }) {
10
+ const storeRef = useRef();
11
+ if (!storeRef.current || shouldRecreateStore(storeRef.current, props)) {
12
+ storeRef.current = createSplitSubvariantStore(props);
13
+ }
14
+ return (_jsx(SplitSubvariantStoreContext.Provider, { value: storeRef.current, children: children }));
15
+ }
16
+ export function useSplitSubvariantStore(selector, equalityFn) {
17
+ const useStore = useContext(SplitSubvariantStoreContext);
18
+ if (!useStore) {
19
+ throw new Error(`You forgot to wrap your component in <${SplitSubvariantStoreProvider.name}>.`);
20
+ }
21
+ return useStore(selector, equalityFn);
22
+ }
23
+ export function useSplitSubvariantStoreContext() {
24
+ const useStore = useContext(SplitSubvariantStoreContext);
25
+ if (!useStore) {
26
+ throw new Error(`You forgot to wrap your component in <${SplitSubvariantStoreProvider.name}>.`);
27
+ }
28
+ return useStore;
29
+ }
30
+ export const createSplitSubvariantStore = ({ state }) => create((set) => ({
31
+ state,
32
+ setState(state) {
33
+ set(() => ({
34
+ state,
35
+ }));
36
+ },
37
+ }));