'use client'
'use strict';

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

var _tslib = require('../../../../../../_virtual/_tslib.cjs');
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var reactI18next = require('react-i18next');
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
var classNames = require('../../../../utils/functions/classNames/classNames.cjs');
require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
var copy = require('../../../../shared/assets/copy.cjs');
var eyeOutline = require('../../../../shared/assets/eye-outline.cjs');
var key = require('../../../../shared/assets/key.cjs');
var unlink = require('../../../../shared/assets/unlink.cjs');
var walletV2 = require('../../../../shared/assets/wallet-v2.cjs');
require('@dynamic-labs/iconic');
var ViewContext = require('../../../../context/ViewContext/ViewContext.cjs');
var logger = require('../../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('@dynamic-labs/utils');
require('../../../../utils/constants/colors.cjs');
require('../../../../utils/constants/values.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../../../shared/consts/index.cjs');
var Alert = require('../../../../components/Alert/Alert.cjs');
require('../../../../events/dynamicEvents.cjs');
require('../../../../context/DynamicContext/DynamicContext.cjs');
require('../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
var authMode = require('../../../../store/state/authMode/authMode.cjs');
var useInternalDynamicContext = require('../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.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');
var useProjectSettings = require('../../../../client/extension/projectSettings/useProjectSettings/useProjectSettings.cjs');
require('@dynamic-labs/locale');
require('../../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
var primaryWalletId = 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');
var useSmartWallets = require('../../../../utils/hooks/useSmartWallets/useSmartWallets.cjs');
require('../../../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
var useIsTurnkeyWallet = require('../../../../utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.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');
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 AuthProviderIcon = require('../../../../components/AuthProviderIcon/AuthProviderIcon.cjs');
var helpers = require('../../helpers/helpers.cjs');
var DynamicWidgetContext = require('../../context/DynamicWidgetContext.cjs');
require('../../../../components/IconButton/IconButton.cjs');
require('../../../../components/MenuList/Dropdown/Dropdown.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');
var useFetchNameService = require('../../hooks/useFetchNameService/useFetchNameService.cjs');
require('../../../../context/OnrampContext/OnrampContext.cjs');
require('../../../../../index.cjs');
require('../../helpers/convertExchangeKeyAndProviderEnum.cjs');
require('qrcode');
require('../../views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
var NetworkPicker = require('../../../../components/NetworkPicker/NetworkPicker.cjs');
var StatusDot = require('../../../../components/StatusDot/StatusDot.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');
require('../../../../store/state/connectorsInitializing/connectorsInitializing.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');
var ActiveWalletBalance = require('../ActiveWalletBalance/ActiveWalletBalance.cjs');
var WalletDetailsCard = require('../WalletDetailsCard/WalletDetailsCard.cjs');
var ActiveBitcoinWalletAddresses = require('./ActiveBitcoinWalletAddresses/ActiveBitcoinWalletAddresses.cjs');
var ActiveWalletAddress = require('./ActiveWalletAddress/ActiveWalletAddress.cjs');

const ICON_SIZE = 32;
const DROPDOWN_ICON_SIZE = 16;
const ActiveWalletInformation = ({ isLoading = false, }) => {
    var _a, _b, _c;
    const { t } = reactI18next.useTranslation();
    /** Controls the [WalletDetailsCard] open state */
    const [detailsCardOpen, setDetailsCardOpen] = React.useState(false);
    const { primaryWallet, network, user, removeWallet } = useInternalDynamicContext.useInternalDynamicContext();
    const { clearStackAndPushInitialView } = ViewContext.useViewContext();
    const authMode$1 = authMode.useAuthMode();
    const projectSettings = useProjectSettings.useProjectSettings();
    const { setDynamicWidgetView, headerAlert } = DynamicWidgetContext.useWidgetContext();
    const { isTurnkeyWalletWithoutAuthenticator } = useIsTurnkeyWallet.useIsTurnkeyWallet();
    const address = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address;
    const nameService = useFetchNameService.useFetchNameService(primaryWallet !== null && primaryWallet !== void 0 ? primaryWallet : undefined);
    const { getEOAWallet } = useSmartWallets.useSmartWallets();
    const { data: testnet } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () { return Boolean(yield (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.isTestnet())); }), { deps: [network], initialData: false });
    const exportKeysOption = helpers.getExportKeysOption(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
    const { showAlert } = PasskeyContext.usePasskeyContext();
    const wallet = (_a = (primaryWallet && getEOAWallet(primaryWallet))) !== null && _a !== void 0 ? _a : primaryWallet;
    const isBitcoin = primaryWallet && walletConnectorCore.isBitcoinConnector(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
    const isEmbeddedWallet = Boolean(wallet && ((_c = (_b = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _b === void 0 ? void 0 : _b.key) === null || _c === void 0 ? void 0 : _c.startsWith('turnkey')));
    const openDetailsCard = React.useCallback(() => {
        setTimeout(() => setDetailsCardOpen(true), 0);
    }, []);
    const removePrimaryWallet = React.useCallback(() => {
        const primaryWalletId$1 = primaryWalletId.getPrimaryWalletId();
        if (primaryWalletId$1) {
            removeWallet(primaryWalletId$1, clearStackAndPushInitialView);
        }
    }, [removeWallet, clearStackAndPushInitialView]);
    const options = [
        {
            Icon: jsxRuntime.jsx(copy.ReactComponent, { width: DROPDOWN_ICON_SIZE, height: DROPDOWN_ICON_SIZE }),
            callback: () => (nameService === null || nameService === void 0 ? void 0 : nameService.name) && navigator.clipboard.writeText(nameService === null || nameService === void 0 ? void 0 : nameService.name),
            copykey: 'dyn_active_wallet_info.options.copy_ens',
            hide: !(nameService === null || nameService === void 0 ? void 0 : nameService.name),
            text: t('dyn_active_wallet_info.options.copy_ens'),
        },
        {
            Icon: (jsxRuntime.jsx(eyeOutline.ReactComponent, { width: DROPDOWN_ICON_SIZE, height: DROPDOWN_ICON_SIZE })),
            callback: openDetailsCard,
            copykey: 'dyn_active_wallet_info.options.view_address',
            hide: !address,
            text: t('dyn_active_wallet_info.options.view_address'),
        },
        {
            Icon: (jsxRuntime.jsx(unlink.ReactComponent, { width: DROPDOWN_ICON_SIZE, height: DROPDOWN_ICON_SIZE })),
            callback: removePrimaryWallet,
            copykey: 'dyn_active_wallet_info.options.disconnect',
            hide: !address || authMode$1 !== 'connect-only',
            text: t('dyn_active_wallet_info.options.disconnect'),
        },
        {
            Icon: (jsxRuntime.jsx(walletV2.ReactComponent, { width: DROPDOWN_ICON_SIZE, height: DROPDOWN_ICON_SIZE })),
            callback: () => setDynamicWidgetView('settings'),
            copykey: 'dyn_active_wallet_info.options.settings',
            endSlot: showAlert() ? jsxRuntime.jsx(StatusDot.StatusDot, { variant: 'yellow' }) : undefined,
            hide: !isEmbeddedWallet,
            text: t('dyn_active_wallet_info.options.settings'),
        },
        {
            Icon: (jsxRuntime.jsx(key.ReactComponent, { width: DROPDOWN_ICON_SIZE, height: DROPDOWN_ICON_SIZE })),
            callback: exportKeysOption ||
                (() => logger.logger.info('No option to export private keys')),
            copykey: 'dyn_active_wallet_info.options.export',
            hide: !exportKeysOption,
            text: t('dyn_active_wallet_info.options.export'),
        },
    ];
    const showTestnetAlert = testnet && !isTurnkeyWalletWithoutAuthenticator;
    const shouldHideNetwork = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.hideNetworkInDynamicWidget;
    const activeWalletAddress = () => {
        if (isBitcoin) {
            return (jsxRuntime.jsx(ActiveBitcoinWalletAddresses.ActiveBitcoinWalletAddresses, { wallet: primaryWallet, menuOption: options }));
        }
        else {
            return (jsxRuntime.jsx(ActiveWalletAddress.ActiveWalletAddress, { wallet: primaryWallet, nameServiceName: (nameService === null || nameService === void 0 ? void 0 : nameService.name) || (user === null || user === void 0 ? void 0 : user.email), menuOption: options, isLoading: isLoading, fullWidth: shouldHideNetwork }));
        }
    };
    if (isLoading) {
        return (jsxRuntime.jsxs("div", { className: 'active-wallet-information-container active-wallet-information-container--loading', "data-testid": 'active-wallet-information', children: [jsxRuntime.jsx("div", { className: 'active-wallet-information active-wallet-information--loading', children: jsxRuntime.jsxs("div", { className: 'active-wallet-information__header', children: [jsxRuntime.jsx("div", { className: 'active-wallet-information__avatar', children: jsxRuntime.jsx("div", { className: 'active-wallet-information__wallet-img', children: jsxRuntime.jsx(Skeleton.Skeleton, { className: 'active-wallet-information__skeleton-avatar' }) }) }), jsxRuntime.jsxs("div", { className: 'active-wallet-information__details', children: [jsxRuntime.jsxs("div", { className: 'active-wallet-information__addresses-container active-wallet-information__addresses-container--loading', children: [jsxRuntime.jsx("div", { className: 'active-wallet-information__handle-row', children: jsxRuntime.jsx(Skeleton.Skeleton, { className: 'active-wallet-information__skeleton-handle' }) }), jsxRuntime.jsx("div", { className: 'active-wallet-information__handle-row', children: jsxRuntime.jsx(Skeleton.Skeleton, { className: 'active-wallet-information__skeleton-address' }) })] }), !shouldHideNetwork && (jsxRuntime.jsx("div", { className: 'active-wallet-information__network-picker', children: jsxRuntime.jsx(Skeleton.Skeleton, { className: 'active-wallet-information__skeleton-network' }) }))] })] }) }), jsxRuntime.jsx(ActiveWalletBalance.ActiveWalletBalance, { isLoading: isLoading })] }));
    }
    return (jsxRuntime.jsxs("div", { className: 'active-wallet-information-container', "data-testid": 'active-wallet-information', children: [jsxRuntime.jsxs("div", { className: 'active-wallet-information', children: [jsxRuntime.jsxs("div", { className: 'active-wallet-information__header', children: [jsxRuntime.jsx("div", { className: 'active-wallet-information__avatar', children: (nameService === null || nameService === void 0 ? void 0 : nameService.avatar) ? (jsxRuntime.jsx("div", { className: 'active-wallet-information__avatar__name-service', children: jsxRuntime.jsx("img", { src: nameService === null || nameService === void 0 ? void 0 : nameService.avatar, alt: '' }) })) : (jsxRuntime.jsx("div", { className: 'active-wallet-information__wallet-img', children: jsxRuntime.jsx(AuthProviderIcon.AuthProviderIcon, { iconSize: ICON_SIZE }) })) }), jsxRuntime.jsxs("div", { className: 'active-wallet-information__details', children: [jsxRuntime.jsx("div", { className: classNames.classNames('active-wallet-information__addresses-container', {
                                            'active-wallet-information__addresses-container--centered': !(nameService === null || nameService === void 0 ? void 0 : nameService.name),
                                        }), children: activeWalletAddress() }), address && (jsxRuntime.jsx(WalletDetailsCard.WalletDetailsCard, { open: detailsCardOpen, address: address, onClose: () => setDetailsCardOpen(false) })), !shouldHideNetwork && (jsxRuntime.jsx(NetworkPicker.NetworkPicker, { currentNetwork: network, connector: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, mainClassName: 'active-wallet-information__network-picker', buttonClassName: 'active-wallet-information__network-picker-button', showNetworkName: true, isLoading: isLoading }))] })] }), headerAlert && (jsxRuntime.jsx(Alert.Alert, { variant: headerAlert.variant, children: headerAlert.content })), showTestnetAlert && (jsxRuntime.jsx(Alert.Alert, { variant: 'warning', copykey: 'dyn_active_wallet_info.testnet_warning', children: t('dyn_active_wallet_info.testnet_warning') }))] }), jsxRuntime.jsx(ActiveWalletBalance.ActiveWalletBalance, {})] }));
};

exports.ActiveWalletInformation = ActiveWalletInformation;
