@lifi/widget 3.7.0-beta.7 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AppProvider.tsx +6 -4
- package/AppRoutes.tsx +14 -2
- package/CHANGELOG.md +22 -0
- package/_esm/AppProvider.js +3 -2
- package/_esm/AppProvider.js.map +1 -1
- package/_esm/AppRoutes.js +9 -2
- package/_esm/AppRoutes.js.map +1 -1
- package/_esm/components/ActiveTransactions/ActiveTransactions.style.js +1 -1
- package/_esm/components/ActiveTransactions/ActiveTransactions.style.js.map +1 -1
- package/_esm/components/AmountInput/AmountInputEndAdornment.js +3 -1
- package/_esm/components/AmountInput/AmountInputEndAdornment.js.map +1 -1
- package/_esm/components/AppContainer.js +10 -5
- package/_esm/components/AppContainer.js.map +1 -1
- package/_esm/components/Avatar/AccountAvatar.d.ts +1 -1
- package/_esm/components/Avatar/AccountAvatar.js +1 -1
- package/_esm/components/Avatar/AccountAvatar.js.map +1 -1
- package/_esm/components/Avatar/Avatar.d.ts +0 -1
- package/_esm/components/Avatar/Avatar.js +4 -7
- package/_esm/components/Avatar/Avatar.js.map +1 -1
- package/_esm/components/Avatar/Avatar.style.d.ts +3 -6
- package/_esm/components/Avatar/Avatar.style.js +6 -19
- package/_esm/components/Avatar/Avatar.style.js.map +1 -1
- package/_esm/components/Avatar/TokenAvatar.js +1 -1
- package/_esm/components/Avatar/TokenAvatar.js.map +1 -1
- package/_esm/components/BaseTransactionButton/BaseTransactionButton.js +5 -3
- package/_esm/components/BaseTransactionButton/BaseTransactionButton.js.map +1 -1
- package/_esm/components/ChainSelect/useChainSelect.js +1 -5
- package/_esm/components/ChainSelect/useChainSelect.js.map +1 -1
- package/_esm/components/FeeBreakdownTooltip.js +1 -4
- package/_esm/components/FeeBreakdownTooltip.js.map +1 -1
- package/_esm/components/FullPageContainer.d.ts +2 -0
- package/_esm/components/FullPageContainer.js +9 -0
- package/_esm/components/FullPageContainer.js.map +1 -0
- package/_esm/components/Header/EVMDisconnectIconButton.d.ts +4 -0
- package/_esm/components/Header/EVMDisconnectIconButton.js +12 -0
- package/_esm/components/Header/EVMDisconnectIconButton.js.map +1 -0
- package/_esm/components/Header/Header.js +23 -3
- package/_esm/components/Header/Header.js.map +1 -1
- package/_esm/components/Header/NavigationHeader.js +1 -1
- package/_esm/components/Header/NavigationHeader.js.map +1 -1
- package/_esm/components/Header/SVMDisconnectIconButton.d.ts +1 -0
- package/_esm/components/Header/SVMDisconnectIconButton.js +12 -0
- package/_esm/components/Header/SVMDisconnectIconButton.js.map +1 -0
- package/_esm/components/Header/WalletHeader.js +9 -5
- package/_esm/components/Header/WalletHeader.js.map +1 -1
- package/_esm/components/Header/WalletMenu.js +18 -10
- package/_esm/components/Header/WalletMenu.js.map +1 -1
- package/_esm/components/Header/WalletMenu.style.js +1 -5
- package/_esm/components/Header/WalletMenu.style.js.map +1 -1
- package/_esm/components/PageContainer.d.ts +2 -1
- package/_esm/components/PageContainer.js.map +1 -1
- package/_esm/components/PageEntered.d.ts +1 -0
- package/_esm/components/PageEntered.js +13 -0
- package/_esm/components/PageEntered.js.map +1 -0
- package/_esm/components/Routes/RoutesExpanded.js +1 -1
- package/_esm/components/Routes/RoutesExpanded.js.map +1 -1
- package/_esm/components/Search/SearchInput.d.ts +11 -0
- package/_esm/components/Search/SearchInput.js +21 -0
- package/_esm/components/Search/SearchInput.js.map +1 -0
- package/_esm/components/Search/SearchInput.style.d.ts +12 -0
- package/_esm/components/Search/SearchInput.style.js +38 -0
- package/_esm/components/Search/SearchInput.style.js.map +1 -0
- package/_esm/components/Search/SearchNotFound.d.ts +6 -0
- package/_esm/components/Search/SearchNotFound.js +5 -0
- package/_esm/components/Search/SearchNotFound.js.map +1 -0
- package/_esm/components/Search/SearchNotFound.style.d.ts +14 -0
- package/_esm/components/Search/SearchNotFound.style.js +29 -0
- package/_esm/components/Search/SearchNotFound.style.js.map +1 -0
- package/_esm/components/SendToWallet/SendToWalletButton.js +1 -1
- package/_esm/components/SendToWallet/SendToWalletButton.js.map +1 -1
- package/_esm/components/Skeleton/WidgetSkeleton.js +3 -4
- package/_esm/components/Skeleton/WidgetSkeleton.js.map +1 -1
- package/_esm/components/Skeleton/WidgetSkeleton.style.d.ts +3 -0
- package/_esm/components/Skeleton/WidgetSkeleton.style.js +20 -1
- package/_esm/components/Skeleton/WidgetSkeleton.style.js.map +1 -1
- package/_esm/components/SmallAvatar.d.ts +10 -0
- package/_esm/components/SmallAvatar.js +19 -0
- package/_esm/components/SmallAvatar.js.map +1 -0
- package/_esm/components/StepActions/StepActions.js +1 -1
- package/_esm/components/StepActions/StepActions.js.map +1 -1
- package/_esm/components/Tabs/Tabs.style.d.ts +1 -1
- package/_esm/components/Token/Token.js +1 -1
- package/_esm/components/Token/Token.js.map +1 -1
- package/_esm/components/TokenList/TokenList.js +2 -5
- package/_esm/components/TokenList/TokenList.js.map +1 -1
- package/_esm/components/TokenList/TokenListItem.js +5 -11
- package/_esm/components/TokenList/TokenListItem.js.map +1 -1
- package/_esm/components/TokenList/TokenNotFound.js +5 -13
- package/_esm/components/TokenList/TokenNotFound.js.map +1 -1
- package/_esm/components/TokenList/VirtualizedTokenList.js +1 -1
- package/_esm/components/TokenList/VirtualizedTokenList.js.map +1 -1
- package/_esm/components/TokenList/types.d.ts +3 -3
- package/_esm/components/TokenRate/TokenRate.js +2 -2
- package/_esm/components/TokenRate/TokenRate.js.map +1 -1
- package/_esm/config/version.d.ts +1 -1
- package/_esm/config/version.js +1 -1
- package/_esm/config/version.js.map +1 -1
- package/_esm/hooks/useAccount.d.ts +45 -0
- package/_esm/hooks/useAccount.js +56 -0
- package/_esm/hooks/useAccount.js.map +1 -0
- package/_esm/hooks/useAvailableChains.d.ts +1 -2
- package/_esm/hooks/useAvailableChains.js +8 -9
- package/_esm/hooks/useAvailableChains.js.map +1 -1
- package/_esm/hooks/useChains.d.ts +3 -4
- package/_esm/hooks/useChains.js +3 -5
- package/_esm/hooks/useChains.js.map +1 -1
- package/_esm/hooks/useFromTokenSufficiency.js +1 -1
- package/_esm/hooks/useFromTokenSufficiency.js.map +1 -1
- package/_esm/hooks/useGasSufficiency.js +3 -3
- package/_esm/hooks/useGasSufficiency.js.map +1 -1
- package/_esm/hooks/useProcessMessage.js +0 -4
- package/_esm/hooks/useProcessMessage.js.map +1 -1
- package/_esm/hooks/useRouteExecution.js +1 -1
- package/_esm/hooks/useRouteExecution.js.map +1 -1
- package/_esm/hooks/useRoutes.js +3 -2
- package/_esm/hooks/useRoutes.js.map +1 -1
- package/_esm/hooks/useScrollableContainer.d.ts +0 -1
- package/_esm/hooks/useScrollableContainer.js +1 -2
- package/_esm/hooks/useScrollableContainer.js.map +1 -1
- package/_esm/hooks/useSetContentHeight.js +9 -6
- package/_esm/hooks/useSetContentHeight.js.map +1 -1
- package/_esm/hooks/useTokenBalance.js +1 -1
- package/_esm/hooks/useTokenBalance.js.map +1 -1
- package/_esm/hooks/useTokenBalances.js +1 -1
- package/_esm/hooks/useTokenBalances.js.map +1 -1
- package/_esm/hooks/useTokens.js +1 -1
- package/_esm/hooks/useTokens.js.map +1 -1
- package/_esm/hooks/useTransactionDetails.js +1 -1
- package/_esm/hooks/useTransactionDetails.js.map +1 -1
- package/_esm/hooks/useTransactionHistory.js +1 -1
- package/_esm/hooks/useTransactionHistory.js.map +1 -1
- package/_esm/hooks/useWallets.d.ts +6 -0
- package/_esm/hooks/useWallets.js +80 -0
- package/_esm/hooks/useWallets.js.map +1 -0
- package/_esm/i18n/en.json +11 -4
- package/_esm/index.d.ts +2 -0
- package/_esm/index.js +2 -0
- package/_esm/index.js.map +1 -1
- package/_esm/pages/RoutesPage/RoutesPage.js +1 -1
- package/_esm/pages/RoutesPage/RoutesPage.js.map +1 -1
- package/_esm/pages/SelectChainPage/SelectChainPage.js +27 -8
- package/_esm/pages/SelectChainPage/SelectChainPage.js.map +1 -1
- package/_esm/pages/SelectEnabledToolsPage.js +38 -16
- package/_esm/pages/SelectEnabledToolsPage.js.map +1 -1
- package/_esm/pages/SelectTokenPage/SearchTokenInput.js +2 -12
- package/_esm/pages/SelectTokenPage/SearchTokenInput.js.map +1 -1
- package/_esm/pages/SelectTokenPage/SelectTokenPage.js +2 -2
- package/_esm/pages/SelectTokenPage/SelectTokenPage.js.map +1 -1
- package/_esm/pages/SelectTokenPage/useTokenListHeight.js +8 -14
- package/_esm/pages/SelectTokenPage/useTokenListHeight.js.map +1 -1
- package/_esm/pages/SelectWalletPage/EVMListItemButton.d.ts +9 -0
- package/_esm/pages/SelectWalletPage/EVMListItemButton.js +39 -0
- package/_esm/pages/SelectWalletPage/EVMListItemButton.js.map +1 -0
- package/_esm/pages/SelectWalletPage/SVMListItemButton.d.ts +6 -0
- package/_esm/pages/SelectWalletPage/SVMListItemButton.js +32 -0
- package/_esm/pages/SelectWalletPage/SVMListItemButton.js.map +1 -0
- package/_esm/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -0
- package/_esm/pages/SelectWalletPage/SelectWalletPage.js +41 -0
- package/_esm/pages/SelectWalletPage/SelectWalletPage.js.map +1 -0
- package/_esm/pages/SendToWallet/ConnectedWalletsPage.js +1 -1
- package/_esm/pages/SendToWallet/ConnectedWalletsPage.js.map +1 -1
- package/_esm/pages/SendToWallet/SendToWalletPage.js +1 -1
- package/_esm/pages/SendToWallet/SendToWalletPage.js.map +1 -1
- package/_esm/pages/TransactionPage/StatusBottomSheet.js +5 -5
- package/_esm/pages/TransactionPage/StatusBottomSheet.js.map +1 -1
- package/_esm/providers/I18nProvider/types.d.ts +2 -2
- package/_esm/providers/WalletProvider/SDKProviders.js +7 -15
- package/_esm/providers/WalletProvider/SDKProviders.js.map +1 -1
- package/_esm/providers/WalletProvider/WalletProvider.d.ts +0 -1
- package/_esm/providers/WalletProvider/WalletProvider.js +1 -14
- package/_esm/providers/WalletProvider/WalletProvider.js.map +1 -1
- package/_esm/providers/WalletProvider/useHasExternalWalletProvider.d.ts +1 -1
- package/_esm/providers/WalletProvider/useHasExternalWalletProvider.js +3 -8
- package/_esm/providers/WalletProvider/useHasExternalWalletProvider.js.map +1 -1
- package/_esm/providers/WidgetProvider/WidgetProvider.js +1 -2
- package/_esm/providers/WidgetProvider/WidgetProvider.js.map +1 -1
- package/_esm/providers/WidgetProvider/types.d.ts +2 -0
- package/_esm/stores/form/FormUpdater.js +1 -1
- package/_esm/stores/form/FormUpdater.js.map +1 -1
- package/_esm/stores/form/types.d.ts +4 -4
- package/_esm/stores/header/types.d.ts +2 -0
- package/_esm/stores/header/useHeaderStore.d.ts +7 -1
- package/_esm/stores/header/useHeaderStore.js +26 -2
- package/_esm/stores/header/useHeaderStore.js.map +1 -1
- package/_esm/stores/routes/useExecutingRoutesIds.js +1 -1
- package/_esm/stores/routes/useExecutingRoutesIds.js.map +1 -1
- package/_esm/stores/settings/types.d.ts +1 -1
- package/_esm/stores/settings/useSettingsStore.js +22 -9
- package/_esm/stores/settings/useSettingsStore.js.map +1 -1
- package/_esm/themes/createTheme.js +1 -2
- package/_esm/themes/createTheme.js.map +1 -1
- package/_esm/types/events.d.ts +6 -6
- package/_esm/types/events.js +3 -2
- package/_esm/types/events.js.map +1 -1
- package/_esm/utils/chainType.js +3 -2
- package/_esm/utils/chainType.js.map +1 -1
- package/_esm/utils/converters.js +2 -1
- package/_esm/utils/converters.js.map +1 -1
- package/_esm/utils/elements.d.ts +5 -2
- package/_esm/utils/elements.js +6 -1
- package/_esm/utils/elements.js.map +1 -1
- package/_esm/utils/fees.js +5 -9
- package/_esm/utils/fees.js.map +1 -1
- package/_esm/utils/format.js +1 -1
- package/_esm/utils/format.js.map +1 -1
- package/_esm/utils/navigationRoutes.d.ts +3 -1
- package/_esm/utils/navigationRoutes.js +3 -0
- package/_esm/utils/navigationRoutes.js.map +1 -1
- package/_esm/utils/svm.d.ts +1 -0
- package/_esm/utils/svm.js +11 -0
- package/_esm/utils/svm.js.map +1 -0
- package/_esm/utils/wallet.js +1 -1
- package/components/ActiveTransactions/ActiveTransactions.style.ts +1 -1
- package/components/AmountInput/AmountInputEndAdornment.tsx +5 -1
- package/components/AppContainer.tsx +15 -10
- package/components/Avatar/AccountAvatar.tsx +2 -2
- package/components/Avatar/Avatar.style.tsx +7 -20
- package/components/Avatar/Avatar.tsx +4 -12
- package/components/Avatar/TokenAvatar.tsx +1 -1
- package/components/BaseTransactionButton/BaseTransactionButton.tsx +5 -3
- package/components/ChainSelect/useChainSelect.ts +1 -10
- package/components/FeeBreakdownTooltip.tsx +1 -4
- package/components/FullPageContainer.tsx +14 -0
- package/components/Header/EVMDisconnectIconButton.tsx +24 -0
- package/components/Header/Header.tsx +28 -3
- package/components/Header/NavigationHeader.tsx +1 -1
- package/components/Header/SVMDisconnectIconButton.tsx +19 -0
- package/components/Header/WalletHeader.tsx +12 -11
- package/components/Header/WalletMenu.style.tsx +1 -5
- package/components/Header/WalletMenu.tsx +32 -22
- package/components/PageContainer.ts +2 -1
- package/components/PageEntered.ts +14 -0
- package/components/Routes/RoutesExpanded.tsx +2 -1
- package/components/Search/SearchInput.style.tsx +46 -0
- package/components/Search/SearchInput.tsx +57 -0
- package/components/Search/SearchNotFound.style.tsx +36 -0
- package/components/Search/SearchNotFound.tsx +23 -0
- package/components/SendToWallet/SendToWalletButton.tsx +1 -1
- package/components/Skeleton/WidgetSkeleton.style.tsx +21 -1
- package/components/Skeleton/WidgetSkeleton.tsx +10 -9
- package/components/SmallAvatar.tsx +25 -0
- package/components/StepActions/StepActions.tsx +1 -1
- package/components/Token/Token.tsx +1 -1
- package/components/TokenList/TokenList.tsx +2 -9
- package/components/TokenList/TokenListItem.tsx +7 -15
- package/components/TokenList/TokenNotFound.tsx +7 -27
- package/components/TokenList/VirtualizedTokenList.tsx +1 -1
- package/components/TokenList/types.ts +3 -3
- package/components/TokenRate/TokenRate.tsx +2 -2
- package/config/version.ts +1 -1
- package/hooks/useAccount.ts +109 -0
- package/hooks/useAvailableChains.ts +10 -9
- package/hooks/useChains.ts +3 -6
- package/hooks/useFromTokenSufficiency.ts +1 -1
- package/hooks/useGasSufficiency.ts +3 -5
- package/hooks/useProcessMessage.ts +0 -4
- package/hooks/useRouteExecution.ts +1 -1
- package/hooks/useRoutes.ts +3 -2
- package/hooks/useScrollableContainer.ts +1 -6
- package/hooks/useSetContentHeight.ts +10 -6
- package/hooks/useTokenBalance.ts +1 -1
- package/hooks/useTokenBalances.ts +1 -1
- package/hooks/useTokens.ts +1 -2
- package/hooks/useTransactionDetails.ts +1 -1
- package/hooks/useTransactionHistory.ts +1 -1
- package/hooks/useWallets.ts +147 -0
- package/i18n/en.json +11 -4
- package/index.ts +2 -0
- package/package.json +4 -3
- package/pages/RoutesPage/RoutesPage.tsx +1 -1
- package/pages/SelectChainPage/SelectChainPage.tsx +62 -23
- package/pages/SelectEnabledToolsPage.tsx +94 -37
- package/pages/SelectTokenPage/SearchTokenInput.tsx +8 -26
- package/pages/SelectTokenPage/SelectTokenPage.tsx +3 -3
- package/pages/SelectTokenPage/useTokenListHeight.ts +14 -21
- package/pages/SelectWalletPage/EVMListItemButton.tsx +74 -0
- package/pages/SelectWalletPage/SVMListItemButton.tsx +47 -0
- package/pages/SelectWalletPage/SelectWalletPage.tsx +90 -0
- package/pages/SendToWallet/ConnectedWalletsPage.tsx +2 -2
- package/pages/SendToWallet/SendToWalletPage.tsx +1 -1
- package/pages/TransactionPage/StatusBottomSheet.tsx +6 -8
- package/providers/I18nProvider/types.ts +2 -2
- package/providers/WalletProvider/SDKProviders.tsx +7 -25
- package/providers/WalletProvider/WalletProvider.tsx +3 -24
- package/providers/WalletProvider/useHasExternalWalletProvider.ts +5 -11
- package/providers/WidgetProvider/WidgetProvider.tsx +1 -2
- package/providers/WidgetProvider/types.ts +2 -0
- package/stores/form/FormUpdater.tsx +1 -1
- package/stores/form/types.ts +4 -4
- package/stores/header/types.ts +2 -0
- package/stores/header/useHeaderStore.tsx +40 -2
- package/stores/routes/useExecutingRoutesIds.ts +1 -1
- package/stores/settings/types.ts +1 -1
- package/stores/settings/useSettingsStore.ts +30 -9
- package/themes/createTheme.ts +1 -3
- package/types/events.ts +5 -5
- package/utils/chainType.ts +3 -2
- package/utils/converters.ts +2 -1
- package/utils/elements.ts +21 -1
- package/utils/fees.ts +13 -15
- package/utils/format.ts +1 -1
- package/utils/navigationRoutes.ts +7 -1
- package/utils/svm.ts +10 -0
- package/utils/wallet.ts +1 -1
- package/_esm/components/Avatar/SmallAvatar.d.ts +0 -4
- package/_esm/components/Avatar/SmallAvatar.js +0 -12
- package/_esm/components/Avatar/SmallAvatar.js.map +0 -1
- package/_esm/components/Header/DisconnectIconButton.d.ts +0 -4
- package/_esm/components/Header/DisconnectIconButton.js +0 -12
- package/_esm/components/Header/DisconnectIconButton.js.map +0 -1
- package/_esm/hooks/useHeaderHeight.d.ts +0 -6
- package/_esm/hooks/useHeaderHeight.js +0 -23
- package/_esm/hooks/useHeaderHeight.js.map +0 -1
- package/_esm/providers/WalletProvider/UTXOBaseProvider.d.ts +0 -2
- package/_esm/providers/WalletProvider/UTXOBaseProvider.js +0 -17
- package/_esm/providers/WalletProvider/UTXOBaseProvider.js.map +0 -1
- package/_esm/providers/WalletProvider/UTXOExternalContext.d.ts +0 -1
- package/_esm/providers/WalletProvider/UTXOExternalContext.js +0 -3
- package/_esm/providers/WalletProvider/UTXOExternalContext.js.map +0 -1
- package/_esm/providers/WalletProvider/UTXOProvider.d.ts +0 -3
- package/_esm/providers/WalletProvider/UTXOProvider.js +0 -18
- package/_esm/providers/WalletProvider/UTXOProvider.js.map +0 -1
- package/components/Avatar/SmallAvatar.tsx +0 -16
- package/components/Header/DisconnectIconButton.tsx +0 -18
- package/hooks/useHeaderHeight.ts +0 -27
- package/providers/WalletProvider/UTXOBaseProvider.tsx +0 -28
- package/providers/WalletProvider/UTXOExternalContext.ts +0 -3
- package/providers/WalletProvider/UTXOProvider.tsx +0 -26
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import type { MutableRefObject } from 'react';
|
|
2
2
|
import { useLayoutEffect } from 'react';
|
|
3
|
+
import { getRelativeContainer } from '../utils/elements.js';
|
|
3
4
|
import { useDefaultElementId } from './useDefaultElementId.js';
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
// NOTE: this hook is implicitly tied to the widget height functionality in the
|
|
7
|
+
// AppExpandedContainer, RelativeContainer and CssBaselineContainer components as defined in AppContainer.ts
|
|
8
|
+
// CSS changes in those components can have implications for the functionality in this hook
|
|
5
9
|
|
|
6
10
|
export const useSetContentHeight = (
|
|
7
11
|
ref: MutableRefObject<HTMLElement | undefined>,
|
|
8
12
|
) => {
|
|
9
13
|
const elementId = useDefaultElementId();
|
|
10
14
|
useLayoutEffect(() => {
|
|
11
|
-
const
|
|
15
|
+
const relativeContainer = getRelativeContainer(elementId);
|
|
12
16
|
if (
|
|
13
|
-
!
|
|
17
|
+
!relativeContainer ||
|
|
14
18
|
!ref.current ||
|
|
15
|
-
ref.current?.clientHeight <=
|
|
19
|
+
ref.current?.clientHeight <= relativeContainer?.clientHeight
|
|
16
20
|
) {
|
|
17
21
|
return;
|
|
18
22
|
}
|
|
19
|
-
|
|
23
|
+
relativeContainer.style.minHeight = `${ref.current.clientHeight}px`;
|
|
20
24
|
return () => {
|
|
21
|
-
|
|
25
|
+
relativeContainer.style.removeProperty('min-height');
|
|
22
26
|
};
|
|
23
27
|
}, [elementId, ref]);
|
|
24
28
|
};
|
package/hooks/useTokenBalance.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ExtendedChain } from '@lifi/sdk';
|
|
2
2
|
import { getTokenBalances, type Token, type TokenAmount } from '@lifi/sdk';
|
|
3
|
-
import { useAccount } from '@lifi/wallet-management';
|
|
4
3
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
5
4
|
import { useCallback, useMemo } from 'react';
|
|
5
|
+
import { useAccount } from './useAccount.js';
|
|
6
6
|
|
|
7
7
|
const defaultRefetchInterval = 30_000;
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getTokenBalances } from '@lifi/sdk';
|
|
2
|
-
import { useAccount } from '@lifi/wallet-management';
|
|
3
2
|
import { useQuery } from '@tanstack/react-query';
|
|
4
3
|
import { formatUnits } from 'viem';
|
|
5
4
|
import type { TokenAmount } from '../types/token.js';
|
|
5
|
+
import { useAccount } from './useAccount.js';
|
|
6
6
|
import { useTokens } from './useTokens.js';
|
|
7
7
|
|
|
8
8
|
const defaultRefetchInterval = 32_000;
|
package/hooks/useTokens.ts
CHANGED
|
@@ -9,8 +9,7 @@ export const useTokens = (selectedChainId?: number) => {
|
|
|
9
9
|
const { tokens: configTokens } = useWidgetConfig();
|
|
10
10
|
const { data, isLoading } = useQuery({
|
|
11
11
|
queryKey: ['tokens'],
|
|
12
|
-
queryFn: () =>
|
|
13
|
-
getTokens({ chainTypes: [ChainType.EVM, ChainType.SVM, ChainType.UTXO] }),
|
|
12
|
+
queryFn: () => getTokens({ chainTypes: [ChainType.EVM, ChainType.SVM] }),
|
|
14
13
|
refetchInterval: 3_600_000,
|
|
15
14
|
staleTime: 3_600_000,
|
|
16
15
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { FullStatusData } from '@lifi/sdk';
|
|
2
2
|
import { getStatus, type StatusResponse } from '@lifi/sdk';
|
|
3
|
-
import { useAccount } from '@lifi/wallet-management';
|
|
4
3
|
import {
|
|
5
4
|
keepPreviousData,
|
|
6
5
|
useQuery,
|
|
7
6
|
useQueryClient,
|
|
8
7
|
} from '@tanstack/react-query';
|
|
8
|
+
import { useAccount } from './useAccount.js';
|
|
9
9
|
|
|
10
10
|
export const useTransactionDetails = (transactionHash?: string) => {
|
|
11
11
|
const { account, accounts } = useAccount();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { FullStatusData, StatusResponse } from '@lifi/sdk';
|
|
2
2
|
import { getTransactionHistory, type ExtendedTransactionInfo } from '@lifi/sdk';
|
|
3
|
-
import { useAccount } from '@lifi/wallet-management';
|
|
4
3
|
import type { QueryFunction } from '@tanstack/react-query';
|
|
5
4
|
import { useQueries } from '@tanstack/react-query';
|
|
5
|
+
import { useAccount } from './useAccount.js';
|
|
6
6
|
|
|
7
7
|
export const useTransactionHistory = () => {
|
|
8
8
|
const { accounts } = useAccount();
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { ChainType } from '@lifi/sdk';
|
|
2
|
+
import type { CreateConnectorFnExtended } from '@lifi/wallet-management';
|
|
3
|
+
import {
|
|
4
|
+
createCoinbaseConnector,
|
|
5
|
+
createMetaMaskConnector,
|
|
6
|
+
createWalletConnectConnector,
|
|
7
|
+
getWalletPriority,
|
|
8
|
+
isWalletInstalled,
|
|
9
|
+
} from '@lifi/wallet-management';
|
|
10
|
+
import type { Theme } from '@mui/material';
|
|
11
|
+
import { useMediaQuery } from '@mui/material';
|
|
12
|
+
import { WalletReadyState } from '@solana/wallet-adapter-base';
|
|
13
|
+
import type { Wallet } from '@solana/wallet-adapter-react';
|
|
14
|
+
import { useWallet } from '@solana/wallet-adapter-react';
|
|
15
|
+
import { useMemo } from 'react';
|
|
16
|
+
import type { Connector } from 'wagmi';
|
|
17
|
+
import { useConnect, useAccount as useWagmiAccount } from 'wagmi';
|
|
18
|
+
import { defaultCoinbaseConfig } from '../config/coinbase.js';
|
|
19
|
+
import { defaultMetaMaskConfig } from '../config/metaMask.js';
|
|
20
|
+
import { defaultWalletConnectConfig } from '../config/walletConnect.js';
|
|
21
|
+
import type { WidgetChains, WidgetWalletConfig } from '../types/widget.js';
|
|
22
|
+
import { isItemAllowed } from '../utils/item.js';
|
|
23
|
+
|
|
24
|
+
export const useWallets = (
|
|
25
|
+
walletConfig?: WidgetWalletConfig,
|
|
26
|
+
chains?: WidgetChains,
|
|
27
|
+
) => {
|
|
28
|
+
const account = useWagmiAccount();
|
|
29
|
+
const { connectors } = useConnect();
|
|
30
|
+
const { wallets: solanaWallets } = useWallet();
|
|
31
|
+
|
|
32
|
+
const isDesktopView = useMediaQuery((theme: Theme) =>
|
|
33
|
+
theme.breakpoints.up('sm'),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const wallets = useMemo(() => {
|
|
37
|
+
const evmConnectors: (CreateConnectorFnExtended | Connector)[] =
|
|
38
|
+
Array.from(connectors);
|
|
39
|
+
if (
|
|
40
|
+
!connectors.some((connector) =>
|
|
41
|
+
connector.id.toLowerCase().includes('walletconnect'),
|
|
42
|
+
)
|
|
43
|
+
) {
|
|
44
|
+
evmConnectors.unshift(
|
|
45
|
+
createWalletConnectConnector(
|
|
46
|
+
walletConfig?.walletConnect ?? defaultWalletConnectConfig,
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (
|
|
51
|
+
!connectors.some((connector) =>
|
|
52
|
+
connector.id.toLowerCase().includes('coinbase'),
|
|
53
|
+
) &&
|
|
54
|
+
!isWalletInstalled('coinbase')
|
|
55
|
+
) {
|
|
56
|
+
evmConnectors.unshift(
|
|
57
|
+
createCoinbaseConnector(
|
|
58
|
+
walletConfig?.coinbase ?? defaultCoinbaseConfig,
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (
|
|
63
|
+
!connectors.some((connector) =>
|
|
64
|
+
connector.id.toLowerCase().includes('metamask'),
|
|
65
|
+
) &&
|
|
66
|
+
!isWalletInstalled('metaMask')
|
|
67
|
+
) {
|
|
68
|
+
evmConnectors.unshift(
|
|
69
|
+
createMetaMaskConnector(
|
|
70
|
+
walletConfig?.metaMask ?? defaultMetaMaskConfig,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const evmInstalled = isItemAllowed(ChainType.EVM, chains?.types)
|
|
75
|
+
? evmConnectors.filter(
|
|
76
|
+
(connector) =>
|
|
77
|
+
isWalletInstalled(connector.id!) &&
|
|
78
|
+
// We should not show already connected connectors
|
|
79
|
+
account.connector?.id !== connector.id,
|
|
80
|
+
)
|
|
81
|
+
: [];
|
|
82
|
+
const evmNotDetected = isItemAllowed(ChainType.EVM, chains?.types)
|
|
83
|
+
? evmConnectors.filter((connector) => !isWalletInstalled(connector.id!))
|
|
84
|
+
: [];
|
|
85
|
+
const svmInstalled = isItemAllowed(ChainType.SVM, chains?.types)
|
|
86
|
+
? solanaWallets?.filter(
|
|
87
|
+
(connector) =>
|
|
88
|
+
connector.adapter.readyState === WalletReadyState.Installed &&
|
|
89
|
+
// We should not show already connected connectors
|
|
90
|
+
!connector.adapter.connected,
|
|
91
|
+
)
|
|
92
|
+
: [];
|
|
93
|
+
const svmNotDetected = isItemAllowed(ChainType.SVM, chains?.types)
|
|
94
|
+
? solanaWallets?.filter(
|
|
95
|
+
(connector) =>
|
|
96
|
+
connector.adapter.readyState !== WalletReadyState.Installed,
|
|
97
|
+
)
|
|
98
|
+
: [];
|
|
99
|
+
|
|
100
|
+
const installedWallets = [...evmInstalled, ...svmInstalled].sort(
|
|
101
|
+
walletComparator,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
if (isDesktopView) {
|
|
105
|
+
const notDetectedWallets = [...evmNotDetected, ...svmNotDetected].sort(
|
|
106
|
+
walletComparator,
|
|
107
|
+
);
|
|
108
|
+
installedWallets.push(...notDetectedWallets);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return installedWallets;
|
|
112
|
+
}, [
|
|
113
|
+
account.connector?.id,
|
|
114
|
+
chains?.types,
|
|
115
|
+
connectors,
|
|
116
|
+
isDesktopView,
|
|
117
|
+
solanaWallets,
|
|
118
|
+
walletConfig?.coinbase,
|
|
119
|
+
walletConfig?.metaMask,
|
|
120
|
+
walletConfig?.walletConnect,
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
return wallets;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const walletComparator = (
|
|
127
|
+
a: CreateConnectorFnExtended | Connector | Wallet,
|
|
128
|
+
b: CreateConnectorFnExtended | Connector | Wallet,
|
|
129
|
+
) => {
|
|
130
|
+
let aId = (a as Connector).id || (a as Wallet).adapter?.name;
|
|
131
|
+
let bId = (b as Connector).id || (b as Wallet).adapter?.name;
|
|
132
|
+
|
|
133
|
+
const priorityA = getWalletPriority(aId);
|
|
134
|
+
const priorityB = getWalletPriority(bId);
|
|
135
|
+
|
|
136
|
+
if (priorityA !== priorityB) {
|
|
137
|
+
return priorityA - priorityB;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (aId < bId) {
|
|
141
|
+
return -1;
|
|
142
|
+
}
|
|
143
|
+
if (aId > bId) {
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
146
|
+
return 0;
|
|
147
|
+
};
|
package/i18n/en.json
CHANGED
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"bridgeReview": "Review bridge",
|
|
17
17
|
"buy": "Buy",
|
|
18
18
|
"cancel": "Cancel",
|
|
19
|
+
"changeWallet": "Change wallet",
|
|
19
20
|
"checkoutReview": "Review purchase",
|
|
20
21
|
"close": "Close",
|
|
21
22
|
"confirm": "Confirm",
|
|
22
|
-
"connectAnotherWallet": "Connect another wallet",
|
|
23
23
|
"connectWallet": "Connect wallet",
|
|
24
24
|
"contactSupport": "Contact support",
|
|
25
25
|
"continue": "Continue",
|
|
@@ -82,6 +82,9 @@
|
|
|
82
82
|
"autoRefuel": "You're low on {{chainName}} gas. By continuing, you'll get enough gas to complete the transaction.",
|
|
83
83
|
"emptyActiveTransactions": "Transactions in progress will appear here. Once completed, find them in transaction history.",
|
|
84
84
|
"emptyTokenList": "We couldn't find tokens on {{chainName}} chain or you don't have any. Please search by contract address if your token doesn't appear or choose another chain.",
|
|
85
|
+
"emptyChainList": "We couldn't find any chains that match your search",
|
|
86
|
+
"emptyBridgesList": "We couldn't find any bridges that match your search",
|
|
87
|
+
"emptyExchangesList": "We couldn't find any exchanges that match your search",
|
|
85
88
|
"emptyTransactionHistory": "Transaction history is only stored locally and will be deleted if you clear your browser data.",
|
|
86
89
|
"fundsToExchange": "Funds sent to an exchange may be lost",
|
|
87
90
|
"toAddressIsRequired": "Please provide the destination wallet address to which the funds will be transferred.",
|
|
@@ -139,7 +142,6 @@
|
|
|
139
142
|
"signatureRejected": "Your signature is required to complete the transaction. {{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} on {{chainName}} remain in your wallet.",
|
|
140
143
|
"slippageThreshold": "The slippage is larger than the defined threshold. Please request a new quote.",
|
|
141
144
|
"transactionCanceled": "Transaction was canceled.",
|
|
142
|
-
"transactionConflict": "Transaction couldn't be processed because it's conflicting with another pending transaction using the same funds. Please wait for the pending transaction to be confirmed or check your transaction history before trying again.",
|
|
143
145
|
"transactionExpired": "The block height has exceeded the maximum allowed limit or blockhash is no longer recent enough.",
|
|
144
146
|
"transactionFailed": "Please check the block explorer for more information.",
|
|
145
147
|
"transactionNotSent": "Transaction was not sent.",
|
|
@@ -159,7 +161,6 @@
|
|
|
159
161
|
"signatureRejected": "Signature required",
|
|
160
162
|
"slippageNotMet": "Slippage conditions not met",
|
|
161
163
|
"transactionCanceled": "Transaction canceled",
|
|
162
|
-
"transactionConflict": "Transaction conflict",
|
|
163
164
|
"transactionExpired": "Transaction expired",
|
|
164
165
|
"transactionFailed": "Transaction failed",
|
|
165
166
|
"transactionSimulationFailed": "Transaction simulation failed",
|
|
@@ -277,7 +278,10 @@
|
|
|
277
278
|
"tokenOnChain": "{{tokenSymbol}} on {{chainName}}",
|
|
278
279
|
"tokenOnChainAmount": "{{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} on {{chainName}}",
|
|
279
280
|
"tokenSearch": "Search by token name or address",
|
|
280
|
-
"valueLoss": "Value loss"
|
|
281
|
+
"valueLoss": "Value loss",
|
|
282
|
+
"searchChains": "Search by chain name",
|
|
283
|
+
"searchBridges": "Search by bridge name",
|
|
284
|
+
"searchExchanges": "Search by exchange name"
|
|
281
285
|
},
|
|
282
286
|
"settings": {
|
|
283
287
|
"theme": "Theme",
|
|
@@ -305,5 +309,8 @@
|
|
|
305
309
|
"noBookmarkedWallets": "No bookmarked wallets",
|
|
306
310
|
"noConnectedWallets": "No connected wallets",
|
|
307
311
|
"noRecentWallets": "No recent wallets"
|
|
312
|
+
},
|
|
313
|
+
"wallet": {
|
|
314
|
+
"extensionNotFound": "Please make sure that only the {{name}} browser extension is active before choosing this wallet."
|
|
308
315
|
}
|
|
309
316
|
}
|
package/index.ts
CHANGED
|
@@ -8,7 +8,9 @@ export * from './components/ContractComponent/NFT/types.js';
|
|
|
8
8
|
export * from './components/Skeleton/WidgetSkeleton.js';
|
|
9
9
|
export { defaultMaxHeight } from './config/constants.js';
|
|
10
10
|
export * from './config/version.js';
|
|
11
|
+
export { useAccount } from './hooks/useAccount.js';
|
|
11
12
|
export { useAvailableChains } from './hooks/useAvailableChains.js';
|
|
13
|
+
export { useWallets, walletComparator } from './hooks/useWallets.js';
|
|
12
14
|
export { useWidgetEvents, widgetEvents } from './hooks/useWidgetEvents.js';
|
|
13
15
|
export * from './stores/form/types.js';
|
|
14
16
|
export { useFieldActions } from './stores/form/useFieldActions.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "3.7.0
|
|
3
|
+
"version": "3.7.0",
|
|
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
|
"type": "module",
|
|
6
6
|
"main": "./_esm/index.js",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@emotion/react": "^11.13.3",
|
|
36
36
|
"@emotion/styled": "^11.13.0",
|
|
37
|
-
"@lifi/sdk": "^3.3
|
|
38
|
-
"@lifi/wallet-management": "^3.
|
|
37
|
+
"@lifi/sdk": "^3.2.3",
|
|
38
|
+
"@lifi/wallet-management": "^3.1.7",
|
|
39
39
|
"@mui/icons-material": "^5.16.7",
|
|
40
40
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
41
41
|
"@mui/material": "^5.16.7",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"react-i18next": "^15.0.2",
|
|
53
53
|
"react-intersection-observer": "^9.13.1",
|
|
54
54
|
"react-router-dom": "^6.26.2",
|
|
55
|
+
"uuid": "^10.0.0",
|
|
55
56
|
"viem": "^2.21.16",
|
|
56
57
|
"wagmi": "^2.12.16",
|
|
57
58
|
"zustand": "^4.5.5"
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable react/no-array-index-key */
|
|
2
2
|
import type { Route } from '@lifi/sdk';
|
|
3
|
-
import { useAccount } from '@lifi/wallet-management';
|
|
4
3
|
import type { BoxProps } from '@mui/material';
|
|
5
4
|
import { useMemo } from 'react';
|
|
6
5
|
import { useTranslation } from 'react-i18next';
|
|
@@ -8,6 +7,7 @@ import { ProgressToNextUpdate } from '../../components/ProgressToNextUpdate.js';
|
|
|
8
7
|
import { RouteCard } from '../../components/RouteCard/RouteCard.js';
|
|
9
8
|
import { RouteCardSkeleton } from '../../components/RouteCard/RouteCardSkeleton.js';
|
|
10
9
|
import { RouteNotFoundCard } from '../../components/RouteCard/RouteNotFoundCard.js';
|
|
10
|
+
import { useAccount } from '../../hooks/useAccount.js';
|
|
11
11
|
import { useHeader } from '../../hooks/useHeader.js';
|
|
12
12
|
import { useNavigateBack } from '../../hooks/useNavigateBack.js';
|
|
13
13
|
import { useRoutes } from '../../hooks/useRoutes.js';
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type { ExtendedChain } from '@lifi/sdk';
|
|
2
|
-
import { Avatar,
|
|
2
|
+
import { Avatar, debounce, ListItemAvatar } from '@mui/material';
|
|
3
|
+
import { type FormEventHandler, useState } from 'react';
|
|
3
4
|
import { useTranslation } from 'react-i18next';
|
|
4
5
|
import { useChainSelect } from '../../components/ChainSelect/useChainSelect.js';
|
|
6
|
+
import { FullPageContainer } from '../../components/FullPageContainer.js';
|
|
5
7
|
import { ListItemButton } from '../../components/ListItemButton.js';
|
|
6
8
|
import { ListItemText } from '../../components/ListItemText.js';
|
|
7
|
-
import {
|
|
9
|
+
import { StickySearchInput } from '../../components/Search/SearchInput.js';
|
|
10
|
+
import { SearchList } from '../../components/Search/SearchInput.style.js';
|
|
11
|
+
import { SearchNotFound } from '../../components/Search/SearchNotFound.js';
|
|
8
12
|
import { useTokenSelect } from '../../components/TokenList/useTokenSelect.js';
|
|
13
|
+
import { useDefaultElementId } from '../../hooks/useDefaultElementId.js';
|
|
9
14
|
import { useHeader } from '../../hooks/useHeader.js';
|
|
10
15
|
import { useNavigateBack } from '../../hooks/useNavigateBack.js';
|
|
16
|
+
import { useScrollableContainer } from '../../hooks/useScrollableContainer.js';
|
|
11
17
|
import type { SelectChainPageProps } from './types.js';
|
|
12
18
|
|
|
13
19
|
export const SelectChainPage: React.FC<SelectChainPageProps> = ({
|
|
@@ -17,8 +23,11 @@ export const SelectChainPage: React.FC<SelectChainPageProps> = ({
|
|
|
17
23
|
const { navigateBack } = useNavigateBack();
|
|
18
24
|
const { chains, setCurrentChain } = useChainSelect(formType);
|
|
19
25
|
const selectToken = useTokenSelect(formType, navigateBack);
|
|
26
|
+
const elementId = useDefaultElementId();
|
|
27
|
+
const scrollableContainer = useScrollableContainer(elementId);
|
|
20
28
|
|
|
21
29
|
const { t } = useTranslation();
|
|
30
|
+
|
|
22
31
|
useHeader(t('header.selectChain'));
|
|
23
32
|
|
|
24
33
|
const handleClick = async (chain: ExtendedChain) => {
|
|
@@ -30,27 +39,57 @@ export const SelectChainPage: React.FC<SelectChainPageProps> = ({
|
|
|
30
39
|
}
|
|
31
40
|
};
|
|
32
41
|
|
|
42
|
+
const [filteredChains, setFilteredChains] = useState<ExtendedChain[]>(
|
|
43
|
+
chains ?? [],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const handleSearchInputChange: FormEventHandler<HTMLInputElement> = (e) => {
|
|
47
|
+
const value = (e.target as HTMLInputElement).value;
|
|
48
|
+
|
|
49
|
+
if (!value) {
|
|
50
|
+
setFilteredChains(chains ?? []);
|
|
51
|
+
} else {
|
|
52
|
+
setFilteredChains(
|
|
53
|
+
chains
|
|
54
|
+
? chains.filter((chain) =>
|
|
55
|
+
chain.name.toLowerCase().includes(value.toLowerCase()),
|
|
56
|
+
)
|
|
57
|
+
: [],
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (scrollableContainer) {
|
|
62
|
+
scrollableContainer.scrollTop = 0;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const debouncedSearchInputChange = debounce(handleSearchInputChange, 250);
|
|
67
|
+
|
|
33
68
|
return (
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
<FullPageContainer disableGutters>
|
|
70
|
+
<StickySearchInput
|
|
71
|
+
onChange={debouncedSearchInputChange}
|
|
72
|
+
placeholder={t('main.searchChains')}
|
|
73
|
+
/>
|
|
74
|
+
{filteredChains.length ? (
|
|
75
|
+
<SearchList>
|
|
76
|
+
{filteredChains.map((chain) => (
|
|
77
|
+
<ListItemButton key={chain.id} onClick={() => handleClick(chain)}>
|
|
78
|
+
<ListItemAvatar>
|
|
79
|
+
<Avatar src={chain.logoURI} alt={chain.name}>
|
|
80
|
+
{chain.name[0]}
|
|
81
|
+
</Avatar>
|
|
82
|
+
</ListItemAvatar>
|
|
83
|
+
<ListItemText primary={chain.name} />
|
|
84
|
+
</ListItemButton>
|
|
85
|
+
))}
|
|
86
|
+
</SearchList>
|
|
87
|
+
) : (
|
|
88
|
+
<SearchNotFound
|
|
89
|
+
message={t('info.message.emptyChainList')}
|
|
90
|
+
adjustForStickySearchInput
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
</FullPageContainer>
|
|
55
94
|
);
|
|
56
95
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToolsResponse } from '@lifi/sdk';
|
|
1
2
|
import {
|
|
2
3
|
Check,
|
|
3
4
|
CheckBoxOutlineBlankOutlined,
|
|
@@ -6,20 +7,25 @@ import {
|
|
|
6
7
|
} from '@mui/icons-material';
|
|
7
8
|
import {
|
|
8
9
|
Avatar,
|
|
10
|
+
debounce,
|
|
9
11
|
IconButton,
|
|
10
|
-
List,
|
|
11
12
|
ListItemAvatar,
|
|
12
13
|
Tooltip,
|
|
13
14
|
useTheme,
|
|
14
15
|
} from '@mui/material';
|
|
15
16
|
import type { MouseEventHandler } from 'react';
|
|
16
|
-
import { useMemo } from 'react';
|
|
17
|
+
import { type FormEventHandler, useMemo, useState } from 'react';
|
|
17
18
|
import { useTranslation } from 'react-i18next';
|
|
18
19
|
import { shallow } from 'zustand/shallow';
|
|
20
|
+
import { FullPageContainer } from '../components/FullPageContainer.js';
|
|
19
21
|
import { ListItemText } from '../components/ListItemText.js';
|
|
20
|
-
import {
|
|
22
|
+
import { StickySearchInput } from '../components/Search/SearchInput.js';
|
|
23
|
+
import { SearchList } from '../components/Search/SearchInput.style.js';
|
|
24
|
+
import { SearchNotFound } from '../components/Search/SearchNotFound.js';
|
|
21
25
|
import { SettingsListItemButton } from '../components/SettingsListItemButton.js';
|
|
26
|
+
import { useDefaultElementId } from '../hooks/useDefaultElementId.js';
|
|
22
27
|
import { useHeader } from '../hooks/useHeader.js';
|
|
28
|
+
import { useScrollableContainer } from '../hooks/useScrollableContainer.js';
|
|
23
29
|
import { useTools } from '../hooks/useTools.js';
|
|
24
30
|
import { useSettingsStore } from '../stores/settings/useSettingsStore.js';
|
|
25
31
|
|
|
@@ -27,18 +33,22 @@ interface SelectAllCheckboxProps {
|
|
|
27
33
|
allCheckboxesSelected: boolean;
|
|
28
34
|
onClick: MouseEventHandler;
|
|
29
35
|
anyCheckboxesSelected: boolean;
|
|
36
|
+
noCheckboxesAvailable: boolean;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
const SelectAllCheckbox: React.FC<SelectAllCheckboxProps> = ({
|
|
33
40
|
allCheckboxesSelected,
|
|
34
41
|
anyCheckboxesSelected,
|
|
42
|
+
noCheckboxesAvailable,
|
|
35
43
|
onClick,
|
|
36
44
|
}) => {
|
|
37
45
|
const { t } = useTranslation();
|
|
38
46
|
const theme = useTheme();
|
|
39
|
-
const tooltipTitle =
|
|
40
|
-
?
|
|
41
|
-
:
|
|
47
|
+
const tooltipTitle = noCheckboxesAvailable
|
|
48
|
+
? undefined
|
|
49
|
+
: allCheckboxesSelected
|
|
50
|
+
? t('tooltip.deselectAll')
|
|
51
|
+
: t('tooltip.selectAll');
|
|
42
52
|
|
|
43
53
|
return (
|
|
44
54
|
<Tooltip title={tooltipTitle}>
|
|
@@ -59,33 +69,54 @@ const SelectAllCheckbox: React.FC<SelectAllCheckboxProps> = ({
|
|
|
59
69
|
);
|
|
60
70
|
};
|
|
61
71
|
|
|
72
|
+
type ToolCollectionTypes =
|
|
73
|
+
| ToolsResponse['exchanges']
|
|
74
|
+
| ToolsResponse['bridges'];
|
|
75
|
+
|
|
62
76
|
export const SelectEnabledToolsPage: React.FC<{
|
|
63
77
|
type: 'Bridges' | 'Exchanges';
|
|
64
78
|
}> = ({ type }) => {
|
|
65
79
|
const typeKey = type.toLowerCase() as 'bridges' | 'exchanges';
|
|
66
80
|
const { tools } = useTools();
|
|
67
|
-
const [enabledTools, disabledTools, setToolValue,
|
|
81
|
+
const [enabledTools, disabledTools, setToolValue, toggleToolKeys] =
|
|
68
82
|
useSettingsStore(
|
|
69
83
|
(state) => [
|
|
70
84
|
state[`_enabled${type}`],
|
|
71
85
|
state[`disabled${type}`],
|
|
72
86
|
state.setToolValue,
|
|
73
|
-
state.
|
|
87
|
+
state.toggleToolKeys,
|
|
74
88
|
],
|
|
75
89
|
shallow,
|
|
76
90
|
);
|
|
77
91
|
|
|
78
92
|
const { t } = useTranslation();
|
|
93
|
+
const elementId = useDefaultElementId();
|
|
94
|
+
const scrollableContainer = useScrollableContainer(elementId);
|
|
95
|
+
const [filteredTools, setFilteredTools] = useState<ToolCollectionTypes>(
|
|
96
|
+
tools?.[typeKey] ?? [],
|
|
97
|
+
);
|
|
79
98
|
|
|
80
99
|
const headerAction = useMemo(
|
|
81
100
|
() => (
|
|
82
101
|
<SelectAllCheckbox
|
|
83
|
-
allCheckboxesSelected={
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
allCheckboxesSelected={
|
|
103
|
+
!!filteredTools.length &&
|
|
104
|
+
filteredTools.every((tool) => !disabledTools.includes(tool.key))
|
|
105
|
+
}
|
|
106
|
+
anyCheckboxesSelected={
|
|
107
|
+
!!filteredTools.length &&
|
|
108
|
+
filteredTools.some((tool) => disabledTools.includes(tool.key))
|
|
109
|
+
}
|
|
110
|
+
noCheckboxesAvailable={!filteredTools.length}
|
|
111
|
+
onClick={() =>
|
|
112
|
+
toggleToolKeys(
|
|
113
|
+
type,
|
|
114
|
+
filteredTools.map((tool) => tool.key),
|
|
115
|
+
)
|
|
116
|
+
}
|
|
86
117
|
/>
|
|
87
118
|
),
|
|
88
|
-
[disabledTools
|
|
119
|
+
[disabledTools, toggleToolKeys, type, filteredTools],
|
|
89
120
|
);
|
|
90
121
|
|
|
91
122
|
useHeader(t(`settings.enabled${type}`), headerAction);
|
|
@@ -94,31 +125,57 @@ export const SelectEnabledToolsPage: React.FC<{
|
|
|
94
125
|
setToolValue(type, key, !enabledTools[key]);
|
|
95
126
|
};
|
|
96
127
|
|
|
128
|
+
const handleSearchInputChange: FormEventHandler<HTMLInputElement> = (e) => {
|
|
129
|
+
const value = (e.target as HTMLInputElement).value;
|
|
130
|
+
|
|
131
|
+
if (!value) {
|
|
132
|
+
setFilteredTools(tools?.[typeKey] ?? []);
|
|
133
|
+
} else {
|
|
134
|
+
setFilteredTools(
|
|
135
|
+
(tools?.[typeKey]
|
|
136
|
+
? tools[typeKey].filter((tool) =>
|
|
137
|
+
tool.name.toLowerCase().includes(value.toLowerCase()),
|
|
138
|
+
)
|
|
139
|
+
: []) as ToolCollectionTypes,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (scrollableContainer) {
|
|
144
|
+
scrollableContainer.scrollTop = 0;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const debouncedSearchInputChange = debounce(handleSearchInputChange, 250);
|
|
149
|
+
|
|
97
150
|
return (
|
|
98
|
-
<
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
151
|
+
<FullPageContainer disableGutters>
|
|
152
|
+
<StickySearchInput
|
|
153
|
+
onChange={debouncedSearchInputChange}
|
|
154
|
+
placeholder={t(`main.search${type}`)}
|
|
155
|
+
/>
|
|
156
|
+
{filteredTools.length ? (
|
|
157
|
+
<SearchList>
|
|
158
|
+
{filteredTools.map((tool) => (
|
|
159
|
+
<SettingsListItemButton
|
|
160
|
+
key={tool.name}
|
|
161
|
+
onClick={() => handleClick(tool.key)}
|
|
162
|
+
>
|
|
163
|
+
<ListItemAvatar>
|
|
164
|
+
<Avatar src={tool.logoURI} alt={tool.name}>
|
|
165
|
+
{tool.name[0]}
|
|
166
|
+
</Avatar>
|
|
167
|
+
</ListItemAvatar>
|
|
168
|
+
<ListItemText primary={tool.name} />
|
|
169
|
+
{enabledTools[tool.key] && <Check color="primary" />}
|
|
170
|
+
</SettingsListItemButton>
|
|
171
|
+
))}
|
|
172
|
+
</SearchList>
|
|
173
|
+
) : (
|
|
174
|
+
<SearchNotFound
|
|
175
|
+
message={t(`info.message.empty${type}List`)}
|
|
176
|
+
adjustForStickySearchInput
|
|
177
|
+
/>
|
|
178
|
+
)}
|
|
179
|
+
</FullPageContainer>
|
|
123
180
|
);
|
|
124
181
|
};
|