@lifi/widget 1.13.7 → 1.15.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 (152) hide show
  1. package/cjs/components/Header/Header.js +2 -2
  2. package/cjs/components/Header/NavigationHeader.js +5 -7
  3. package/cjs/components/Header/WalletHeader.js +4 -5
  4. package/cjs/components/ReverseTokensButton/ReverseTokensButton.js +10 -10
  5. package/cjs/components/SelectTokenButton/SelectTokenButton.d.ts +1 -1
  6. package/cjs/components/SelectTokenButton/SelectTokenButton.js +3 -3
  7. package/cjs/components/{SwapInProgress/SwapInProgress.d.ts → SendToWallet/SendToWallet.d.ts} +1 -1
  8. package/cjs/components/SendToWallet/SendToWallet.js +53 -0
  9. package/cjs/components/SendToWallet/SendToWallet.style.d.ts +19 -0
  10. package/cjs/components/SendToWallet/SendToWallet.style.js +15 -0
  11. package/cjs/components/SendToWallet/index.d.ts +1 -0
  12. package/cjs/components/{SwapInProgress → SendToWallet}/index.js +1 -1
  13. package/cjs/components/Step/StepTimer.js +1 -1
  14. package/cjs/components/SwapButton/SwapButton.js +11 -8
  15. package/cjs/components/SwapInput/FormPriceHelperText.d.ts +1 -1
  16. package/cjs/components/SwapInput/FormPriceHelperText.js +4 -4
  17. package/cjs/components/SwapInput/SwapInput.d.ts +1 -1
  18. package/cjs/components/SwapInput/SwapInput.js +4 -4
  19. package/cjs/components/SwapInput/SwapInputAdornment.d.ts +1 -1
  20. package/cjs/components/SwapInput/SwapInputAdornment.js +4 -4
  21. package/cjs/components/SwapRouteCard/SwapRouteCard.js +4 -3
  22. package/cjs/components/SwapRouteCard/SwapRouteCard.style.js +3 -3
  23. package/cjs/components/SwapsInProgress/SwapsInProgress.d.ts +3 -0
  24. package/cjs/components/SwapsInProgress/SwapsInProgress.js +29 -0
  25. package/cjs/components/{SwapInProgress/SwapInProgress.style.d.ts → SwapsInProgress/SwapsInProgress.style.d.ts} +0 -0
  26. package/cjs/components/{SwapInProgress/SwapInProgress.style.js → SwapsInProgress/SwapsInProgress.style.js} +0 -0
  27. package/cjs/components/SwapsInProgress/index.d.ts +1 -0
  28. package/cjs/components/SwapsInProgress/index.js +17 -0
  29. package/cjs/components/TokenList/TokenList.js +10 -11
  30. package/cjs/components/TokenList/VirtualizedTokenList.js +1 -1
  31. package/cjs/components/TokenList/types.d.ts +1 -1
  32. package/cjs/config/lifi.js +3 -1
  33. package/cjs/config/version.d.ts +1 -1
  34. package/cjs/config/version.js +1 -1
  35. package/cjs/hooks/index.d.ts +1 -0
  36. package/cjs/hooks/index.js +1 -0
  37. package/cjs/hooks/useNavigateBack.d.ts +4 -0
  38. package/cjs/hooks/useNavigateBack.js +18 -0
  39. package/cjs/hooks/useSwapRoutes.js +18 -7
  40. package/cjs/i18n/en/translation.json +13 -8
  41. package/cjs/i18n/index.d.ts +11 -6
  42. package/cjs/pages/MainPage/MainPage.js +3 -2
  43. package/cjs/pages/SelectTokenPage/ChainSelect.d.ts +1 -1
  44. package/cjs/pages/SelectTokenPage/ChainSelect.js +11 -12
  45. package/cjs/pages/SelectTokenPage/SearchTokenInput.js +3 -3
  46. package/cjs/pages/SelectTokenPage/SelectTokenPage.d.ts +1 -1
  47. package/cjs/pages/SelectTokenPage/SelectTokenPage.js +2 -6
  48. package/cjs/pages/SelectWalletPage/SelectWalletPage.js +6 -6
  49. package/cjs/pages/SettingsPage/AdvancedPreferences.js +2 -2
  50. package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.js +2 -2
  51. package/cjs/pages/SettingsPage/SettingsPage.js +2 -1
  52. package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +2 -0
  53. package/cjs/pages/SettingsPage/ShowDestinationWallet.js +22 -0
  54. package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +3 -2
  55. package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
  56. package/cjs/pages/SwapPage/StatusBottomSheet.js +4 -5
  57. package/cjs/pages/SwapPage/SwapPage.js +2 -2
  58. package/cjs/pages/SwapRoutesPage/SwapRoutesPage.js +1 -1
  59. package/cjs/providers/SwapFormProvider/SwapFormProvider.d.ts +1 -0
  60. package/cjs/providers/SwapFormProvider/SwapFormProvider.js +10 -4
  61. package/cjs/providers/SwapFormProvider/types.d.ts +3 -1
  62. package/cjs/providers/SwapFormProvider/types.js +1 -0
  63. package/cjs/providers/WalletProvider/WalletProvider.js +5 -4
  64. package/cjs/providers/WalletProvider/types.d.ts +4 -2
  65. package/cjs/providers/WidgetProvider/WidgetProvider.js +4 -0
  66. package/cjs/providers/index.d.ts +4 -0
  67. package/cjs/providers/index.js +20 -0
  68. package/cjs/stores/route/useRouteStore.js +36 -0
  69. package/cjs/stores/settings/types.d.ts +2 -1
  70. package/cjs/stores/settings/useSettingsStore.d.ts +4 -2
  71. package/cjs/stores/settings/useSettingsStore.js +1 -0
  72. package/cjs/types/widget.d.ts +1 -0
  73. package/cjs/utils/format.js +7 -2
  74. package/components/Header/Header.js +1 -1
  75. package/components/Header/NavigationHeader.js +5 -7
  76. package/components/Header/WalletHeader.js +1 -2
  77. package/components/ReverseTokensButton/ReverseTokensButton.js +1 -1
  78. package/components/SelectTokenButton/SelectTokenButton.d.ts +1 -1
  79. package/components/SelectTokenButton/SelectTokenButton.js +1 -1
  80. package/components/{SwapInProgress/SwapInProgress.d.ts → SendToWallet/SendToWallet.d.ts} +1 -1
  81. package/components/SendToWallet/SendToWallet.js +49 -0
  82. package/components/SendToWallet/SendToWallet.style.d.ts +19 -0
  83. package/components/SendToWallet/SendToWallet.style.js +12 -0
  84. package/components/SendToWallet/index.d.ts +1 -0
  85. package/components/SendToWallet/index.js +1 -0
  86. package/components/Step/StepTimer.js +1 -1
  87. package/components/SwapButton/SwapButton.js +9 -6
  88. package/components/SwapInput/FormPriceHelperText.d.ts +1 -1
  89. package/components/SwapInput/FormPriceHelperText.js +1 -1
  90. package/components/SwapInput/SwapInput.d.ts +1 -1
  91. package/components/SwapInput/SwapInput.js +1 -1
  92. package/components/SwapInput/SwapInputAdornment.d.ts +1 -1
  93. package/components/SwapInput/SwapInputAdornment.js +1 -1
  94. package/components/SwapRouteCard/SwapRouteCard.js +4 -3
  95. package/components/SwapRouteCard/SwapRouteCard.style.js +3 -3
  96. package/components/SwapsInProgress/SwapsInProgress.d.ts +3 -0
  97. package/components/{SwapInProgress/SwapInProgress.js → SwapsInProgress/SwapsInProgress.js} +4 -4
  98. package/components/{SwapInProgress/SwapInProgress.style.d.ts → SwapsInProgress/SwapsInProgress.style.d.ts} +0 -0
  99. package/components/{SwapInProgress/SwapInProgress.style.js → SwapsInProgress/SwapsInProgress.style.js} +0 -0
  100. package/components/SwapsInProgress/index.d.ts +1 -0
  101. package/components/SwapsInProgress/index.js +1 -0
  102. package/components/TokenList/TokenList.js +1 -2
  103. package/components/TokenList/VirtualizedTokenList.js +1 -1
  104. package/components/TokenList/types.d.ts +1 -1
  105. package/config/lifi.js +3 -1
  106. package/config/version.d.ts +1 -1
  107. package/config/version.js +1 -1
  108. package/hooks/index.d.ts +1 -0
  109. package/hooks/index.js +1 -0
  110. package/hooks/useNavigateBack.d.ts +4 -0
  111. package/hooks/useNavigateBack.js +14 -0
  112. package/hooks/useSwapRoutes.js +18 -7
  113. package/i18n/en/translation.json +13 -8
  114. package/i18n/index.d.ts +11 -6
  115. package/package.json +9 -12
  116. package/pages/MainPage/MainPage.js +3 -2
  117. package/pages/SelectTokenPage/ChainSelect.d.ts +1 -1
  118. package/pages/SelectTokenPage/ChainSelect.js +9 -10
  119. package/pages/SelectTokenPage/SearchTokenInput.js +1 -1
  120. package/pages/SelectTokenPage/SelectTokenPage.d.ts +1 -1
  121. package/pages/SelectTokenPage/SelectTokenPage.js +3 -7
  122. package/pages/SelectWalletPage/SelectWalletPage.js +5 -5
  123. package/pages/SettingsPage/AdvancedPreferences.js +2 -2
  124. package/pages/SettingsPage/ColorSchemeButtonGroup.js +1 -1
  125. package/pages/SettingsPage/SettingsPage.js +2 -1
  126. package/pages/SettingsPage/ShowDestinationWallet.d.ts +2 -0
  127. package/pages/SettingsPage/ShowDestinationWallet.js +18 -0
  128. package/pages/SwapDetailsPage/SwapDetailsPage.js +4 -3
  129. package/pages/SwapHistoryPage/SwapHistoryPage.js +1 -1
  130. package/pages/SwapPage/StatusBottomSheet.js +4 -5
  131. package/pages/SwapPage/SwapPage.js +4 -4
  132. package/pages/SwapRoutesPage/SwapRoutesPage.js +1 -1
  133. package/providers/SwapFormProvider/SwapFormProvider.d.ts +1 -0
  134. package/providers/SwapFormProvider/SwapFormProvider.js +10 -4
  135. package/providers/SwapFormProvider/types.d.ts +3 -1
  136. package/providers/SwapFormProvider/types.js +1 -0
  137. package/providers/WalletProvider/WalletProvider.js +5 -4
  138. package/providers/WalletProvider/types.d.ts +4 -2
  139. package/providers/WidgetProvider/WidgetProvider.js +5 -1
  140. package/providers/index.d.ts +4 -0
  141. package/providers/index.js +4 -0
  142. package/stores/route/useRouteStore.js +36 -0
  143. package/stores/settings/types.d.ts +2 -1
  144. package/stores/settings/useSettingsStore.d.ts +4 -2
  145. package/stores/settings/useSettingsStore.js +1 -0
  146. package/tsconfig.cjs.tsbuildinfo +1 -1
  147. package/types/widget.d.ts +1 -0
  148. package/utils/format.js +7 -2
  149. package/cjs/components/SwapInProgress/SwapInProgress.js +0 -29
  150. package/cjs/components/SwapInProgress/index.d.ts +0 -1
  151. package/components/SwapInProgress/index.d.ts +0 -1
  152. package/components/SwapInProgress/index.js +0 -1
@@ -7,15 +7,17 @@ import { useWidgetConfig } from '../WidgetProvider';
7
7
  import { SwapFormKey } from './types';
8
8
  export const formDefaultValues = {
9
9
  [SwapFormKey.FromAmount]: '',
10
+ [SwapFormKey.ToAddress]: '',
10
11
  [SwapFormKey.TokenSearchFilter]: '',
11
12
  };
12
13
  export const SwapFormProvider = ({ children, }) => {
13
14
  const { account } = useWallet();
14
- const { fromChain, fromToken, fromAmount, toChain, toToken } = useWidgetConfig();
15
+ const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress } = useWidgetConfig();
15
16
  const methods = useForm({
16
17
  defaultValues: Object.assign(Object.assign({}, formDefaultValues), { fromChain: fromChain !== null && fromChain !== void 0 ? fromChain : ChainId.ETH, fromToken, fromAmount: (typeof fromAmount === 'number'
17
18
  ? fromAmount === null || fromAmount === void 0 ? void 0 : fromAmount.toPrecision()
18
- : fromAmount) || formDefaultValues.fromAmount, toChain: toChain !== null && toChain !== void 0 ? toChain : ChainId.ETH, toToken }),
19
+ : fromAmount) || formDefaultValues.fromAmount, toChain: toChain !== null && toChain !== void 0 ? toChain : ChainId.ETH, toToken,
20
+ toAddress }),
19
21
  });
20
22
  // Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
21
23
  useEffect(() => {
@@ -23,14 +25,18 @@ export const SwapFormProvider = ({ children, }) => {
23
25
  return;
24
26
  }
25
27
  const { isDirty: isFromChainDirty, isTouched: isFromChainTouched } = methods.getFieldState(SwapFormKey.FromChain, methods.formState);
28
+ const { isDirty: isToChainDirty, isTouched: isToChainTouched } = methods.getFieldState(SwapFormKey.ToChain, methods.formState);
26
29
  if (!fromChain && !isFromChainDirty && !isFromChainTouched) {
27
30
  methods.setValue(SwapFormKey.FromChain, account.chainId, {
28
31
  shouldDirty: false,
29
32
  shouldTouch: false,
30
33
  });
31
34
  }
32
- const { isDirty: isToChainDirty, isTouched: isToChainTouched } = methods.getFieldState(SwapFormKey.ToChain, methods.formState);
33
- if (!toChain && !isToChainDirty && !isToChainTouched) {
35
+ if (!toChain &&
36
+ !isToChainDirty &&
37
+ !isToChainTouched &&
38
+ !isFromChainDirty &&
39
+ !isFromChainTouched) {
34
40
  methods.setValue(SwapFormKey.ToChain, account.chainId, {
35
41
  shouldDirty: false,
36
42
  shouldTouch: false,
@@ -4,7 +4,8 @@ export declare enum SwapFormKey {
4
4
  FromToken = "fromToken",
5
5
  TokenSearchFilter = "tokenSearchFilter",
6
6
  ToChain = "toChain",
7
- ToToken = "toToken"
7
+ ToToken = "toToken",
8
+ ToAddress = "toAddress"
8
9
  }
9
10
  export declare type SwapFormValues = {
10
11
  [SwapFormKey.FromAmount]: string;
@@ -13,6 +14,7 @@ export declare type SwapFormValues = {
13
14
  [SwapFormKey.TokenSearchFilter]: string;
14
15
  [SwapFormKey.ToChain]: number;
15
16
  [SwapFormKey.ToToken]: string;
17
+ [SwapFormKey.ToAddress]: string;
16
18
  };
17
19
  export declare type SwapFormDirection = 'from' | 'to';
18
20
  export declare const SwapFormKeyHelper: {
@@ -6,6 +6,7 @@ export var SwapFormKey;
6
6
  SwapFormKey["TokenSearchFilter"] = "tokenSearchFilter";
7
7
  SwapFormKey["ToChain"] = "toChain";
8
8
  SwapFormKey["ToToken"] = "toToken";
9
+ SwapFormKey["ToAddress"] = "toAddress";
9
10
  })(SwapFormKey || (SwapFormKey = {}));
10
11
  export const SwapFormKeyHelper = {
11
12
  getChainKey: (formType) => `${formType}Chain`,
@@ -24,7 +24,7 @@ const initialContext = {
24
24
  const WalletContext = createContext(initialContext);
25
25
  export const useWallet = () => useContext(WalletContext);
26
26
  export const WalletProvider = ({ children, walletManagement }) => {
27
- const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, } = useLiFiWalletManagement();
27
+ const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, provider, } = useLiFiWalletManagement();
28
28
  const [account, setAccount] = useState({});
29
29
  const connect = useCallback((wallet) => __awaiter(void 0, void 0, void 0, function* () {
30
30
  if (walletManagement) {
@@ -81,16 +81,17 @@ export const WalletProvider = ({ children, walletManagement }) => {
81
81
  addChain,
82
82
  addToken,
83
83
  account,
84
- }), [account, addChain, addToken, connect, disconnect, switchChain]);
84
+ provider,
85
+ }), [account, addChain, addToken, connect, disconnect, provider, switchChain]);
85
86
  return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
86
87
  };
87
88
  export const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
88
89
  try {
89
90
  return {
90
- address: (yield (signer === null || signer === void 0 ? void 0 : signer.getAddress())) || undefined,
91
+ address: yield (signer === null || signer === void 0 ? void 0 : signer.getAddress()),
91
92
  isActive: (signer && !!(yield signer.getAddress()) === null) || !!signer,
92
93
  signer,
93
- chainId: (yield (signer === null || signer === void 0 ? void 0 : signer.getChainId())) || undefined,
94
+ chainId: yield (signer === null || signer === void 0 ? void 0 : signer.getChainId()),
94
95
  };
95
96
  }
96
97
  catch (error) {
@@ -1,8 +1,10 @@
1
+ import type { Web3Provider } from '@ethersproject/providers';
1
2
  import type { Token } from '@lifi/sdk';
2
3
  import type { Wallet } from '@lifi/wallet-management';
3
4
  import type { Signer } from 'ethers';
4
5
  export interface WalletContextProps {
5
6
  account: WalletAccount;
7
+ provider?: Web3Provider;
6
8
  addChain(chainId: number): Promise<boolean>;
7
9
  addToken(chainId: number, token: Token): Promise<void>;
8
10
  disconnect(): void;
@@ -10,8 +12,8 @@ export interface WalletContextProps {
10
12
  connect(wallet?: Wallet | undefined): Promise<void>;
11
13
  }
12
14
  export interface WalletAccount {
13
- address?: string;
14
15
  isActive?: boolean;
15
- signer?: Signer;
16
16
  chainId?: number;
17
+ address?: string;
18
+ signer?: Signer;
17
19
  }
@@ -10,9 +10,10 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { getChainByKey } from '@lifi/sdk';
13
+ import { checkPackageUpdates, getChainByKey } from '@lifi/sdk';
14
14
  import { createContext, useContext, useEffect, useMemo } from 'react';
15
15
  import { updateLiFiConfig } from '../../config/lifi';
16
+ import { name, version } from '../../config/version';
16
17
  const stub = () => {
17
18
  throw new Error('You forgot to wrap your component in <WidgetProvider>.');
18
19
  };
@@ -59,5 +60,8 @@ export const WidgetProvider = (_a) => {
59
60
  },
60
61
  });
61
62
  }, [integrator]);
63
+ useEffect(() => {
64
+ checkPackageUpdates(name, version);
65
+ }, []);
62
66
  return (_jsx(WidgetContext.Provider, Object.assign({ value: value }, { children: children })));
63
67
  };
@@ -0,0 +1,4 @@
1
+ export * from './SwapFormProvider';
2
+ export * from './ThemeProvider';
3
+ export * from './WalletProvider';
4
+ export * from './WidgetProvider';
@@ -0,0 +1,4 @@
1
+ export * from './SwapFormProvider';
2
+ export * from './ThemeProvider';
3
+ export * from './WalletProvider';
4
+ export * from './WidgetProvider';
@@ -48,4 +48,40 @@ export const useRouteStore = create()(persist(immer((set) => ({
48
48
  })), {
49
49
  name: 'li.fi-widget-routes',
50
50
  partialize: (state) => ({ routes: state.routes }),
51
+ merge: (persistedState, currentState) => {
52
+ const state = Object.assign(Object.assign({}, currentState), persistedState);
53
+ try {
54
+ const routeString = localStorage.getItem('routes');
55
+ if (routeString) {
56
+ const routes = JSON.parse(routeString);
57
+ routes.forEach((route) => {
58
+ if (state.routes[route.id]) {
59
+ return;
60
+ }
61
+ state.routes[route.id] = {
62
+ route,
63
+ status: 'idle',
64
+ };
65
+ const isFailed = route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
66
+ if (isFailed) {
67
+ state.routes[route.id].status = 'error';
68
+ return;
69
+ }
70
+ const isDone = route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
71
+ if (isDone) {
72
+ state.routes[route.id].status = 'success';
73
+ return;
74
+ }
75
+ const isLoading = route.steps.some((step) => step.execution);
76
+ if (isLoading) {
77
+ state.routes[route.id].status = 'loading';
78
+ }
79
+ });
80
+ }
81
+ }
82
+ catch (error) {
83
+ console.log(error);
84
+ }
85
+ return state;
86
+ },
51
87
  }));
@@ -7,9 +7,10 @@ export declare const SettingsToolTypes: SettingsToolType[];
7
7
  export interface SettingsState {
8
8
  advancedPreferences: boolean;
9
9
  appearance: Appearance;
10
+ gasPrice: string;
10
11
  routePriority: Order;
12
+ showDestinationWallet: boolean;
11
13
  slippage: string;
12
- gasPrice: string;
13
14
  enabledBridges?: string[];
14
15
  _enabledBridges?: Record<string, boolean>;
15
16
  enabledExchanges?: string[];
@@ -8,9 +8,10 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
8
8
  setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifi/types").Bridge, "key"> | Pick<import("@lifi/types").Exchange, "key">)[]): void;
9
9
  advancedPreferences: boolean;
10
10
  appearance: import("../..").Appearance;
11
+ gasPrice: string;
11
12
  routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
13
+ showDestinationWallet: boolean;
12
14
  slippage: string;
13
- gasPrice: string;
14
15
  _enabledBridges?: Record<string, boolean> | undefined;
15
16
  _enabledExchanges?: Record<string, boolean> | undefined;
16
17
  }>>) => void;
@@ -26,9 +27,10 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
26
27
  setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifi/types").Bridge, "key"> | Pick<import("@lifi/types").Exchange, "key">)[]): void;
27
28
  advancedPreferences: boolean;
28
29
  appearance: import("../..").Appearance;
30
+ gasPrice: string;
29
31
  routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
32
+ showDestinationWallet: boolean;
30
33
  slippage: string;
31
- gasPrice: string;
32
34
  _enabledBridges?: Record<string, boolean> | undefined;
33
35
  _enabledExchanges?: Record<string, boolean> | undefined;
34
36
  }>>;
@@ -16,6 +16,7 @@ import { immer } from 'zustand/middleware/immer';
16
16
  import { SettingsToolTypes } from './types';
17
17
  export const useSettingsStore = create()(persist(immer((set) => ({
18
18
  advancedPreferences: false,
19
+ showDestinationWallet: false,
19
20
  appearance: 'auto',
20
21
  gasPrice: 'normal',
21
22
  routePriority: 'RECOMMENDED',