UNPKG

@dynamic-labs/sdk-react-core

Version:

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

167 lines (162 loc) 11.9 kB
'use client' 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var jsxRuntime = require('react/jsx-runtime'); var React = require('react'); var reactI18next = require('react-i18next'); var utils = require('@dynamic-labs/utils'); var noWalletFound = require('../../assets/no-wallet-found.cjs'); var ErrorContainer = require('../../components/ErrorContainer/ErrorContainer.cjs'); var Search = require('../../components/Search/Search.cjs'); var Skeleton = require('../../components/Skeleton/Skeleton.cjs'); require('../../context/DynamicContext/DynamicContext.cjs'); require('../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs'); require('@dynamic-labs/sdk-api-core'); require('../../shared/logger.cjs'); require('@dynamic-labs/iconic'); require('@dynamic-labs/wallet-connector-core'); require('../../context/ViewContext/ViewContext.cjs'); require('@dynamic-labs/wallet-book'); var localStorage = require('../../utils/constants/localStorage.cjs'); require('../../utils/constants/colors.cjs'); require('../../utils/constants/values.cjs'); require('../../shared/consts/index.cjs'); require('../../events/dynamicEvents.cjs'); require('../../../../_virtual/_tslib.cjs'); require('../../context/CaptchaContext/CaptchaContext.cjs'); var ErrorContext = require('../../context/ErrorContext/ErrorContext.cjs'); require('@dynamic-labs/multi-wallet'); require('react-international-phone'); require('../../store/state/nonce/nonce.cjs'); require('../../store/state/projectSettings/projectSettings.cjs'); require('../../config/ApiEndpoint.cjs'); require('../../store/state/user/user.cjs'); require('../../locale/locale.cjs'); require('../../store/state/dynamicContextProps/dynamicContextProps.cjs'); require('../../store/state/primaryWalletId/primaryWalletId.cjs'); require('../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs'); require('../../context/AccessDeniedContext/AccessDeniedContext.cjs'); require('../../context/AccountExistsContext/AccountExistsContext.cjs'); require('../../context/UserWalletsContext/UserWalletsContext.cjs'); require('../../store/state/authMode/authMode.cjs'); require('../../context/VerificationContext/VerificationContext.cjs'); require('react-dom'); require('../../utils/functions/compareChains/compareChains.cjs'); require('../Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs'); require('../../context/ThemeContext/ThemeContext.cjs'); require('../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs'); require('bs58'); require('@dynamic-labs/types'); require('../../context/SocialRedirectContext/SocialRedirectContext.cjs'); require('../../context/LoadingContext/LoadingContext.cjs'); require('../../context/WalletContext/WalletContext.cjs'); require('../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs'); require('yup'); require('../../context/MockContext/MockContext.cjs'); require('../CollectUserDataView/useFields.cjs'); require('../../context/FieldsStateContext/FieldsStateContext.cjs'); require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs'); require('@dynamic-labs/rpc-providers'); require('../../store/state/walletOptions/walletOptions.cjs'); var classNames = require('../../utils/functions/classNames/classNames.cjs'); require('../../components/Accordion/components/AccordionItem/AccordionItem.cjs'); require('../../components/Alert/Alert.cjs'); require('../../components/ShadowDOM/ShadowDOM.cjs'); require('../../components/IconButton/IconButton.cjs'); require('../../components/InlineWidget/InlineWidget.cjs'); require('../../components/Input/Input.cjs'); require('../../components/IsBrowser/IsBrowser.cjs'); require('../../components/MenuList/Dropdown/Dropdown.cjs'); require('../../components/OverlayCard/OverlayCard.cjs'); require('../../components/Transition/ZoomTransition/ZoomTransition.cjs'); require('../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs'); require('../../components/Transition/OpacityTransition/OpacityTransition.cjs'); require('../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs'); require('../../components/Popper/Popper/Popper.cjs'); require('../../components/Popper/PopperContext/PopperContext.cjs'); require('react-focus-lock'); require('qrcode'); require('formik'); require('../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs'); var DefaultFooter = require('../../layout/DynamicAuthLayout/DefaultFooter/DefaultFooter.cjs'); var useEffectOnce = require('../../utils/hooks/useEffectOnce/useEffectOnce.cjs'); var useWalletList = require('../../utils/hooks/useWalletList/useWalletList.cjs'); var SearchNotFoundMessage = require('./SearchNotFoundMessage/SearchNotFoundMessage.cjs'); var WalletListGridTabs = require('./WalletListGridTabs/WalletListGridTabs.cjs'); var WalletListItem = require('./WalletListItem/WalletListItem.cjs'); require('../../context/IpConfigurationContext/IpConfigurationContext.cjs'); require('../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs'); require('../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs'); require('@hcaptcha/react-hcaptcha'); require('../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs'); require('../../context/FooterAnimationContext/index.cjs'); require('../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs'); require('../../context/PasskeyContext/PasskeyContext.cjs'); require('../../context/WalletGroupContext/WalletGroupContext.cjs'); require('../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs'); require('../../store/state/sendBalances.cjs'); require('../../store/state/connectorsInitializing/connectorsInitializing.cjs'); require('../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs'); require('../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs'); require('../TransactionConfirmationView/TransactionConfirmationView.cjs'); require('../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs'); require('../../context/OnrampContext/OnrampContext.cjs'); require('../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs'); require('../../../index.cjs'); require('../../store/state/tokenBalances.cjs'); require('../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs'); var useInternalDynamicContext = require('../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs'); const WalletList = ({ isWalletConnectList = false, onSelectWallet, viewWalletsFilter, showDefaultFooter, scrollContainerClassName, }) => { var _a, _b; /** * Clear search key on unmount */ useEffectOnce.useEffectOnce(() => () => utils.StorageService === null || utils.StorageService === void 0 ? void 0 : utils.StorageService.setItem(localStorage.WALLET_PICKER_SEARCH_KEY, '')); const { walletConnectorOptions, projectSettings, defaultNumberOfWalletsToShow, selectedTabIndex, setSelectedTabIndex, tabsItems, } = useInternalDynamicContext.useInternalDynamicContext(); const { error } = ErrorContext.useErrorContext(); const [footerBorderIsVisible, setFooterBorderIsVisible] = React.useState(true); const { t } = reactI18next.useTranslation(); const [filterValue, setFilterValue] = React.useState((_a = utils.StorageService.getItem(localStorage.WALLET_PICKER_SEARCH_KEY)) !== null && _a !== void 0 ? _a : ''); const { numberOfWallets, walletsList, recommendedWallets: effectiveRecommendedWallets, } = useWalletList.useWalletList({ isWalletConnectList, lastUsedWalletKey: (_b = utils.StorageService.getItem(localStorage.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 = React.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) => { utils.StorageService.setItem(localStorage.WALLET_PICKER_SEARCH_KEY, value); setFilterValue(value); }; const searchContainer = !projectSettings ? (jsxRuntime.jsx(Skeleton.Skeleton, { className: 'wallet-list__search-skeleton' })) : (isSearchEnabled && (jsxRuntime.jsx("div", { className: classNames.classNames('wallet-list__search-container', { 'wallet-list__search-container--scroll': !error, }), children: jsxRuntime.jsx(Search.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 (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isTabsEnabled && (jsxRuntime.jsx("div", { className: 'wallet-list__tabs-container', children: jsxRuntime.jsx(WalletListGridTabs.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) && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, { className: 'wallet-list__error-container', withIcon: false, children: error })), jsxRuntime.jsxs("div", { className: classNames.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 ? (jsxRuntime.jsx(Skeleton.Skeleton, { count: 10, className: 'wallet-list__tile-skeleton' })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [walletConnectorOptions.length === 0 && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, { copykey: 'dyn_wallet_list.configuration_mismatch', children: t('dyn_wallet_list.configuration_mismatch') })), walletConnectorOptions.length && walletsList.length === 0 ? (jsxRuntime.jsx(SearchNotFoundMessage.SearchNotFoundMessage, { title: t('dyn_wallet_list.search.not_found.title'), subtitle: t('dyn_wallet_list.search.not_found.description'), image: jsxRuntime.jsx(noWalletFound.ReactComponent, {}) })) : (walletsList.map((wallet, index) => (jsxRuntime.jsx(WalletListItem.WalletListItem, { wallet: wallet, onResetSearchValue: () => handleFilterValueChange(''), recommendedWallets: effectiveRecommendedWallets, onSelectWallet: onSelectWallet }, `${wallet.key}_${index}`))))] })), isSearchEnabled && !filterValue && projectSettings && (jsxRuntime.jsx(SearchNotFoundMessage.SearchNotFoundMessage, {}))] }), showDefaultFooter && (jsxRuntime.jsx(DefaultFooter.DefaultFooter, { hideBorder: !footerBorderIsVisible }))] })); }; exports.WalletList = WalletList;