UNPKG

@dynamic-labs/sdk-react-core

Version:

A React SDK for implementing wallet web3 authentication and authorization to your website.

163 lines (160 loc) 11.1 kB
'use client' import { jsx, jsxs, Fragment } from 'react/jsx-runtime'; import { useState, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { StorageService } from '@dynamic-labs/utils'; import { ReactComponent as SvgNoWalletFound } from '../../assets/no-wallet-found.js'; import { ErrorContainer } from '../../components/ErrorContainer/ErrorContainer.js'; import { Search } from '../../components/Search/Search.js'; import { Skeleton } from '../../components/Skeleton/Skeleton.js'; import '../../context/DynamicContext/DynamicContext.js'; import '../../store/state/loadingAndLifecycle/loadingAndLifecycle.js'; import '@dynamic-labs/sdk-api-core'; import '../../shared/logger.js'; import '@dynamic-labs/iconic'; import '@dynamic-labs/wallet-connector-core'; import '../../context/ViewContext/ViewContext.js'; import '@dynamic-labs/wallet-book'; import { WALLET_PICKER_SEARCH_KEY, LAST_USED_WALLET } from '../../utils/constants/localStorage.js'; import '../../utils/constants/colors.js'; import '../../utils/constants/values.js'; import '../../shared/consts/index.js'; import '../../events/dynamicEvents.js'; import '../../../../_virtual/_tslib.js'; import '../../context/CaptchaContext/CaptchaContext.js'; import { useErrorContext } from '../../context/ErrorContext/ErrorContext.js'; import '@dynamic-labs/multi-wallet'; import 'react-international-phone'; import '../../store/state/nonce/nonce.js'; import '../../store/state/projectSettings/projectSettings.js'; import '../../config/ApiEndpoint.js'; import '../../store/state/user/user.js'; import '../../locale/locale.js'; import '../../store/state/dynamicContextProps/dynamicContextProps.js'; import '../../store/state/primaryWalletId/primaryWalletId.js'; import '../../store/state/connectedWalletsInfo/connectedWalletsInfo.js'; import '../../context/AccessDeniedContext/AccessDeniedContext.js'; import '../../context/AccountExistsContext/AccountExistsContext.js'; import '../../context/UserWalletsContext/UserWalletsContext.js'; import '../../store/state/authMode/authMode.js'; import '../../context/VerificationContext/VerificationContext.js'; import 'react-dom'; import '../../utils/functions/compareChains/compareChains.js'; import '../Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js'; import '../../context/ThemeContext/ThemeContext.js'; import '../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.js'; import 'bs58'; import '@dynamic-labs/types'; import '../../context/SocialRedirectContext/SocialRedirectContext.js'; import '../../context/LoadingContext/LoadingContext.js'; import '../../context/WalletContext/WalletContext.js'; import '../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js'; import 'yup'; import '../../context/MockContext/MockContext.js'; import '../CollectUserDataView/useFields.js'; import '../../context/FieldsStateContext/FieldsStateContext.js'; import '../../context/UserFieldEditorContext/UserFieldEditorContext.js'; import '@dynamic-labs/rpc-providers'; import '../../store/state/walletOptions/walletOptions.js'; import { classNames } from '../../utils/functions/classNames/classNames.js'; import '../../components/Accordion/components/AccordionItem/AccordionItem.js'; import '../../components/Alert/Alert.js'; import '../../components/ShadowDOM/ShadowDOM.js'; import '../../components/IconButton/IconButton.js'; import '../../components/InlineWidget/InlineWidget.js'; import '../../components/Input/Input.js'; import '../../components/IsBrowser/IsBrowser.js'; import '../../components/MenuList/Dropdown/Dropdown.js'; import '../../components/OverlayCard/OverlayCard.js'; import '../../components/Transition/ZoomTransition/ZoomTransition.js'; import '../../components/Transition/SlideInUpTransition/SlideInUpTransition.js'; import '../../components/Transition/OpacityTransition/OpacityTransition.js'; import '../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js'; import '../../components/Popper/Popper/Popper.js'; import '../../components/Popper/PopperContext/PopperContext.js'; import 'react-focus-lock'; import 'qrcode'; import 'formik'; import '../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js'; import { DefaultFooter } from '../../layout/DynamicAuthLayout/DefaultFooter/DefaultFooter.js'; import { useEffectOnce } from '../../utils/hooks/useEffectOnce/useEffectOnce.js'; import { useWalletList } from '../../utils/hooks/useWalletList/useWalletList.js'; import { SearchNotFoundMessage } from './SearchNotFoundMessage/SearchNotFoundMessage.js'; import { WalletListGridTabs } from './WalletListGridTabs/WalletListGridTabs.js'; import { WalletListItem } from './WalletListItem/WalletListItem.js'; import '../../context/IpConfigurationContext/IpConfigurationContext.js'; import '../../context/ConnectWithOtpContext/ConnectWithOtpContext.js'; import '../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js'; import '@hcaptcha/react-hcaptcha'; import '../../widgets/DynamicWidget/context/DynamicWidgetContext.js'; import '../../context/FooterAnimationContext/index.js'; import '../../context/ErrorContext/hooks/useErrorText/useErrorText.js'; import '../../context/PasskeyContext/PasskeyContext.js'; import '../../context/WalletGroupContext/WalletGroupContext.js'; import '../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.js'; import '../../store/state/sendBalances.js'; import '../../store/state/connectorsInitializing/connectorsInitializing.js'; import '../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js'; import '../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js'; import '../TransactionConfirmationView/TransactionConfirmationView.js'; import '../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js'; import '../../context/OnrampContext/OnrampContext.js'; import '../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js'; import '../../../index.js'; import '../../store/state/tokenBalances.js'; import '../../shared/utils/functions/getInitialUrl/getInitialUrl.js'; import { useInternalDynamicContext } from '../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js'; const WalletList = ({ isWalletConnectList = false, onSelectWallet, viewWalletsFilter, showDefaultFooter, scrollContainerClassName, }) => { var _a, _b; /** * Clear search key on unmount */ useEffectOnce(() => () => StorageService === null || StorageService === void 0 ? void 0 : StorageService.setItem(WALLET_PICKER_SEARCH_KEY, '')); const { walletConnectorOptions, projectSettings, defaultNumberOfWalletsToShow, selectedTabIndex, setSelectedTabIndex, tabsItems, } = useInternalDynamicContext(); const { error } = useErrorContext(); const [footerBorderIsVisible, setFooterBorderIsVisible] = useState(true); const { t } = useTranslation(); const [filterValue, setFilterValue] = useState((_a = StorageService.getItem(WALLET_PICKER_SEARCH_KEY)) !== null && _a !== void 0 ? _a : ''); const { numberOfWallets, walletsList, recommendedWallets: effectiveRecommendedWallets, } = useWalletList({ isWalletConnectList, lastUsedWalletKey: (_b = StorageService.getItem(LAST_USED_WALLET)) !== null && _b !== void 0 ? _b : undefined, searchFilter: filterValue, viewWalletsFilter, }); const isSearchEnabled = Boolean(filterValue) || (numberOfWallets > defaultNumberOfWalletsToShow && walletsList.length !== numberOfWallets); const isTabsEnabled = Boolean(tabsItems === null || tabsItems === void 0 ? void 0 : tabsItems.length); const walletListScrollRef = useRef(null); /* istanbul ignore next */ const handleScroll = () => { const element = walletListScrollRef.current; if (!element) { return; } if ((element === null || element === void 0 ? void 0 : element.scrollTop) > (element === null || element === void 0 ? void 0 : element.clientHeight) * 1.25) { setFooterBorderIsVisible(false); } else { setFooterBorderIsVisible(true); } }; const handleFilterValueChange = (value) => { StorageService.setItem(WALLET_PICKER_SEARCH_KEY, value); setFilterValue(value); }; const searchContainer = !projectSettings ? (jsx(Skeleton, { className: 'wallet-list__search-skeleton' })) : (isSearchEnabled && (jsx("div", { className: classNames('wallet-list__search-container', { 'wallet-list__search-container--scroll': !error, }), children: jsx(Search, { copykey: 'dyn_wallet_list.search.label', label: t('dyn_wallet_list.search.label', { numberOfWallets }), value: filterValue, onChange: ({ target: { value } }) => handleFilterValueChange(value), onClickClear: () => handleFilterValueChange('') }) }))); return (jsxs(Fragment, { children: [isTabsEnabled && (jsx("div", { className: 'wallet-list__tabs-container', children: jsx(WalletListGridTabs // The tabsItems nullable assertion is safe here because isTabsEnabled is true // eslint-disable-next-line @typescript-eslint/no-non-null-assertion , { // The tabsItems nullable assertion is safe here because isTabsEnabled is true // eslint-disable-next-line @typescript-eslint/no-non-null-assertion items: tabsItems, value: selectedTabIndex || 0, onSelect: setSelectedTabIndex }) })), searchContainer, Boolean(error) && (jsx(ErrorContainer, { className: 'wallet-list__error-container', withIcon: false, children: error })), jsxs("div", { className: classNames('wallet-list__scroll-container', scrollContainerClassName, { 'wallet-list__scroll-container--error': Boolean(error), 'wallet-list__scroll-container--fixed-height': isTabsEnabled, }), "data-testid": 'wallet-list-scroll-container', ref: walletListScrollRef, onScroll: handleScroll, children: [!projectSettings ? (jsx(Skeleton, { count: 10, className: 'wallet-list__tile-skeleton' })) : (jsxs(Fragment, { children: [walletConnectorOptions.length === 0 && (jsx(ErrorContainer, { copykey: 'dyn_wallet_list.configuration_mismatch', children: t('dyn_wallet_list.configuration_mismatch') })), walletConnectorOptions.length && walletsList.length === 0 ? (jsx(SearchNotFoundMessage, { title: t('dyn_wallet_list.search.not_found.title'), subtitle: t('dyn_wallet_list.search.not_found.description'), image: jsx(SvgNoWalletFound, {}) })) : (walletsList.map((wallet, index) => (jsx(WalletListItem, { wallet: wallet, onResetSearchValue: () => handleFilterValueChange(''), recommendedWallets: effectiveRecommendedWallets, onSelectWallet: onSelectWallet }, `${wallet.key}_${index}`))))] })), isSearchEnabled && !filterValue && projectSettings && (jsx(SearchNotFoundMessage, {}))] }), showDefaultFooter && (jsx(DefaultFooter, { hideBorder: !footerBorderIsVisible }))] })); }; export { WalletList };