'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
require('@dynamic-labs/utils');
require('../../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
require('react-i18next');
var arrowDown = require('../../../../../shared/assets/arrow-down.cjs');
require('@dynamic-labs/iconic');
require('../../../../../context/ViewContext/ViewContext.cjs');
require('../../../../../../../_virtual/_tslib.cjs');
var BaseButton = require('../../../../../components/BaseButton/BaseButton.cjs');
require('@dynamic-labs/wallet-connector-core');
require('../../../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('../../../../../utils/constants/colors.cjs');
require('../../../../../utils/constants/values.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../../../../shared/consts/index.cjs');
require('../../../../../components/Alert/Alert.cjs');
require('../../../../../events/dynamicEvents.cjs');
require('../../../../../context/DynamicContext/DynamicContext.cjs');
require('../../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
require('../../../../../store/state/authMode/authMode.cjs');
require('../../../../../context/CaptchaContext/CaptchaContext.cjs');
require('../../../../../context/ErrorContext/ErrorContext.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../../../store/state/nonce/nonce.cjs');
require('@dynamic-labs-sdk/client/core');
require('../../../../../client/client.cjs');
require('@dynamic-labs-sdk/client');
require('../../../../../config/ApiEndpoint.cjs');
require('@dynamic-labs/locale');
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('../../../../../context/VerificationContext/VerificationContext.cjs');
require('react-dom');
require('../../../../../utils/functions/compareChains/compareChains.cjs');
require('../../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
require('../../../../../context/ThemeContext/ThemeContext.cjs');
require('../../../../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
require('bs58');
var usePromise = require('../../../../../utils/hooks/usePromise/usePromise.cjs');
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('../../../../../views/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 Typography = require('../../../../../components/Typography/Typography.cjs');
require('../../../../../context/FooterAnimationContext/index.cjs');
require('../../../../../components/ShadowDOM/ShadowDOM.cjs');
require('../../../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
require('../../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
require('../../../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
require('../../../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
var Skeleton = require('../../../../../components/Skeleton/Skeleton.cjs');
require('../../../../../context/WalletGroupContext/WalletGroupContext.cjs');
require('../../DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('react-focus-lock');
var shortenWalletAddress = require('../../../../../shared/utils/functions/shortenWalletAddress/shortenWalletAddress.cjs');
require('../../../context/DynamicWidgetContext.cjs');
require('../../../../../components/IconButton/IconButton.cjs');
var Dropdown = require('../../../../../components/MenuList/Dropdown/Dropdown.cjs');
var DropdownMenu = require('../../../../../components/MenuList/DropdownMenu/DropdownMenu.cjs');
require('formik');
require('../../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
require('../../../../../store/state/sendBalances.cjs');
require('../../../../../components/Input/Input.cjs');
require('../../../../../components/OverlayCard/OverlayCard.cjs');
require('../../../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
require('../../../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
var PasskeyContext = require('../../../../../context/PasskeyContext/PasskeyContext.cjs');
require('../../PasskeyCard/PasskeyCard.cjs');
require('../../../views/CryptoComOnramp/CryptoComOnramp.cjs');
require('../../../../../context/OnrampContext/OnrampContext.cjs');
require('../../../../../../index.cjs');
require('../../../helpers/convertExchangeKeyAndProviderEnum.cjs');
require('qrcode');
require('../../../views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
var IconWithStatus = require('../../../../../components/IconWithStatus/IconWithStatus.cjs');
require('../../../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
require('../../../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
require('../../../../DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
require('@hcaptcha/react-hcaptcha');
require('../../../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
require('../../../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
require('../../../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
var useWalletConnectorNetwork = require('../../../../../utils/hooks/useWalletConnectorNetwork/useWalletConnectorNetwork.cjs');
require('../../../../../store/state/tokenBalances.cjs');
require('../../../../../store/state/multichainBalances.cjs');
require('../../../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
require('../../../../../components/InlineWidget/InlineWidget.cjs');
require('../../../../../components/IsBrowser/IsBrowser.cjs');
require('../../../../../components/Popper/Popper/Popper.cjs');
require('../../../../../components/Popper/PopperContext/PopperContext.cjs');
require('../../../../../store/state/connectorsInitializing/connectorsInitializing.cjs');

/**
 * If the wallet has no icon, returns its key, nicely formatted.
 */
const getNameIfNoIcon = (wallet) => {
    if (!wallet)
        return undefined;
    const noIcon = !wallet.connector.metadata.icon ||
        wallet.connector.metadata.icon.includes('unknown-wallet');
    return noIcon
        ? wallet.key
            .replace(/[-_]/g, ' ')
            .replace(/\b\w/g, (char) => char.toUpperCase())
        : undefined;
};
const ActiveWalletAddress = ({ wallet, nameServiceName, menuOption, fullWidth = false, isLoading = false, }) => {
    const { showAlert } = PasskeyContext.usePasskeyContext();
    const header = nameServiceName || getNameIfNoIcon(wallet);
    const { network } = useWalletConnectorNetwork.useWalletConnectorNetwork(wallet === null || wallet === void 0 ? void 0 : wallet.connector);
    const [showMenu, setShowMenu] = React.useState(false);
    const handleMenuClose = React.useCallback(() => {
        setShowMenu(false);
    }, [setShowMenu]);
    const handleMenuOpen = React.useCallback(() => {
        // Use setTimeout here to prevent React 17 from triggering a click event
        // when the dropdown is rendered.
        setTimeout(() => setShowMenu(true), 0);
    }, [setShowMenu]);
    const iconRef = React.useRef(null);
    const { data: address } = usePromise.usePromise(() => {
        // COSMOS wallet address changes based on which network is selected
        if ((wallet === null || wallet === void 0 ? void 0 : wallet.connector.connectedChain) === 'COSMOS') {
            return wallet === null || wallet === void 0 ? void 0 : wallet.connector.getAddress();
        }
        return wallet === null || wallet === void 0 ? void 0 : wallet.address;
    }, {
        deps: [wallet, network],
        enabled: Boolean(wallet),
    });
    const menuIcon = React.useMemo(() => (jsxRuntime.jsx("div", { ref: iconRef, className: 'active-wallet-information__handle-icon', children: showAlert() ? (jsxRuntime.jsx(IconWithStatus.IconWithStatus, { Icon: () => jsxRuntime.jsx(arrowDown.ReactComponent, { width: 24, height: 24 }), variant: 'yellow' })) : (jsxRuntime.jsx(arrowDown.ReactComponent, { width: 24, height: 24 })) })), [showAlert]);
    return (jsxRuntime.jsxs("div", { className: 'active-wallet-information__address-container', children: [jsxRuntime.jsxs(BaseButton.BaseButton, { onClick: handleMenuOpen, dataTestId: 'active-wallet-information-button', children: [jsxRuntime.jsxs("div", { className: 'active-wallet-information__handle-row', children: [jsxRuntime.jsx(Typography.Typography, { className: fullWidth
                                    ? 'active-wallet-information__handle--full-width'
                                    : 'active-wallet-information__handle', color: 'primary', variant: 'body_normal', "data-testid": 'header-text', children: header }), header && menuIcon] }), jsxRuntime.jsxs("div", { className: 'active-wallet-information__handle-row', children: [jsxRuntime.jsx(Typography.Typography, { className: 'active-wallet-information__address', weight: header ? 'regular' : 'medium', variant: header ? 'body_small' : 'body_normal', color: header ? 'secondary' : 'primary', children: isLoading ? (jsxRuntime.jsx(Skeleton.Skeleton, { className: 'active-wallet-information__address-skeleton' })) : (shortenWalletAddress.shortenWalletAddress(address)) }), !header && menuIcon] })] }), jsxRuntime.jsx(Dropdown.Dropdown, { isOpen: showMenu, onClickOutside: handleMenuClose, onScroll: handleMenuClose, anchorRef: iconRef, anchorOrigin: 'bottom-right', transformOrigin: 'top-left', children: jsxRuntime.jsx(DropdownMenu.DropdownMenu, { options: menuOption, setShowMenu: setShowMenu }) })] }));
};

exports.ActiveWalletAddress = ActiveWalletAddress;
exports.getNameIfNoIcon = getNameIfNoIcon;
