'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 iconic = require('@dynamic-labs/iconic');
var walletBook = require('@dynamic-labs/wallet-book');
var classNames = require('../../../../utils/functions/classNames/classNames.cjs');
require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
var chevronDown = require('../../../../shared/assets/chevron-down.cjs');
var footerInfoIcon = require('../../../../shared/assets/footer-info-icon.cjs');
var switchToggle = require('../../../../shared/assets/switch-toggle.cjs');
require('../../../../context/ViewContext/ViewContext.cjs');
require('../../../../../../_virtual/_tslib.cjs');
require('@dynamic-labs/wallet-connector-core');
require('../../../../shared/logger.cjs');
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');
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');
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');
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');
var useIconThemeVariant = require('../../../../utils/hooks/useIconThemeVariant/useIconThemeVariant.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('../../../../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');
var Tooltip = require('../../../../components/Tooltip/Tooltip.cjs');
require('../../../../context/WalletGroupContext/WalletGroupContext.cjs');
require('../../components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('react-focus-lock');
require('../../../../context/ThemeContext/ThemeContext.cjs');
var Icon = require('../../../../components/Icon/Icon.cjs');
var shortenWalletAddress = require('../../../../shared/utils/functions/shortenWalletAddress/shortenWalletAddress.cjs');
var DynamicWidgetContext = require('../../context/DynamicWidgetContext.cjs');
require('../../../../components/IconButton/IconButton.cjs');
var ModalHeader = require('../../../../components/ModalHeader/ModalHeader.cjs');
var TypographyButton = require('../../../../components/TypographyButton/TypographyButton.cjs');
require('../../../../components/MenuList/Dropdown/Dropdown.cjs');
var Image = require('../../../../components/Image/Image.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');
require('../../../../context/PasskeyContext/PasskeyContext.cjs');
require('../../components/PasskeyCard/PasskeyCard.cjs');
require('../CryptoComOnramp/CryptoComOnramp.cjs');
require('../../../../context/OnrampContext/OnrampContext.cjs');
require('../../../../../index.cjs');
var convertExchangeKeyAndProviderEnum = require('../../helpers/convertExchangeKeyAndProviderEnum.cjs');
require('qrcode');
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');
var useSubmitExchangeFunding = require('../../../../utils/hooks/useSubmitExchangeFunding/useSubmitExchangeFunding.cjs');
require('../../../../components/InlineWidget/InlineWidget.cjs');
require('../../../../components/IsBrowser/IsBrowser.cjs');
require('../../../../components/Popper/Popper/Popper.cjs');
require('../../../../components/Popper/PopperContext/PopperContext.cjs');
var FormattedInput = require('./FormattedInput/FormattedInput.cjs');
var formattedInputEmitter = require('./FormattedInput/formattedInputEmitter.cjs');
var TokenSelectScreen = require('./TokenSelectScreen/TokenSelectScreen.cjs');
var consts = require('./consts.cjs');
var calculateFiatBalance = require('./utils/calculateFiatBalance/calculateFiatBalance.cjs');
var convert = require('./utils/convert/convert.cjs');
var formatValue = require('./utils/formatValue/formatValue.cjs');
var isFiatToken = require('./utils/isFiatToken/isFiatToken.cjs');
var isNonZero = require('./utils/isNonZero/isNonZero.cjs');
var respectsMinimum = require('./utils/respectsMinimum/respectsMinimum.cjs');
var useExchangeRatesForFunding = require('./utils/useExchangeRatesForFunding/useExchangeRatesForFunding.cjs');
var useExchangeTokensForFunding = require('./utils/useExchangeTokensForFunding/useExchangeTokensForFunding.cjs');
var useSubmitWalletFunding = require('./utils/useSubmitWalletFunding/useSubmitWalletFunding.cjs');
var useTokensForFunding = require('./utils/useTokensForFunding/useTokensForFunding.cjs');
var createFundingButtons = require('./utils/createFundingButtons/createFundingButtons.cjs');
var parseQuickSuggestions = require('./utils/parseQuickSuggestions/parseQuickSuggestions.cjs');
var useFundingHandlers = require('./utils/useFundingHandlers/useFundingHandlers.cjs');
var useFundingDisplay = require('./utils/useFundingDisplay/useFundingDisplay.cjs');

const defaultQuickSuggestions = {
    token: 'USD',
    values: [25, 100, 500],
};
const rulesThatHideQuickSuggestions = ['exact', 'minimum'];
const rulesThatDisableTokenSelect = ['exact', 'exact-with-amount'];
const inputEmitter = formattedInputEmitter.createFormattedInputEmitter();
const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wallet, exchange, fundingWithExchange = false, accounts, quickSuggestions = defaultQuickSuggestions, network, destinationAddress, onBack, hideBackButton = false, }) => {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    // For now we hardcode the default value, soon we will fetch this from project settings
    const initialToken = initialTokenRaw !== null && initialTokenRaw !== void 0 ? initialTokenRaw : {
        rule: 'recommended',
        value: 'USDC',
    };
    /** Whether the amount specified in the prop refers to the token amount instead of the fiat amount */
    const isInitialAmountValueForToken = (initialToken === null || initialToken === void 0 ? void 0 : initialToken.rule) === 'exact-with-amount';
    const minimum = (initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.rule) === 'minimum'
        ? {
            token: isInitialAmountValueForToken
                ? initialToken.value
                : 'USD',
            value: initialAmount.value.toString(),
        }
        : undefined;
    const { t } = reactI18next.useTranslation();
    const [hasUserInteracted, setHasUserInteracted] = React.useState(false);
    const [conversionErrorIconRef, setConversionErrorIconRef] = React.useState(null);
    const { primaryWallet, setShowAuthFlow, setShowDynamicUserProfile } = useInternalDynamicContext.useInternalDynamicContext();
    const iconThemeVariant = useIconThemeVariant.useIconThemeVariant();
    const provider = exchange
        ? convertExchangeKeyAndProviderEnum.convertExchangeKeytoProviderEnum(exchange)
        : undefined;
    const { setDynamicWidgetView } = DynamicWidgetContext.useWidgetContext();
    const { isLoading: tokenBalancesLoadingWallet, tokens: tokenBalancesWallet } = useTokensForFunding.useTokensForFunding({
        wallet: wallet,
    });
    const { tokens: tokenBalancesExchange } = useExchangeTokensForFunding.useExchangeTokensForFunding({
        accounts: accounts !== null && accounts !== void 0 ? accounts : [],
    });
    const tokenBalances = fundingWithExchange
        ? tokenBalancesExchange
        : tokenBalancesWallet;
    const tokenBalancesLoading = fundingWithExchange
        ? false
        : tokenBalancesLoadingWallet;
    const exchangeRates = useExchangeRatesForFunding.useExchangeRatesForFunding({
        // Initialize amounts after exchange rates are fetched
        onFetch: (exchangeRates) => {
            if (tokenAmount === undefined && fiatAmount !== undefined) {
                setTokenAmount(convert.convertFromFiat(fiatAmount, tokenSymbol, exchangeRates));
            }
            if (fiatAmount === undefined && tokenAmount !== undefined) {
                setFiatAmount(convert.convertToFiat(tokenAmount, tokenSymbol, exchangeRates));
            }
        },
        tokenBalances,
    });
    const [tokenAmount, setTokenAmount] = React.useState(isInitialAmountValueForToken
        ? (_a = initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.value.toString()) !== null && _a !== void 0 ? _a : ''
        : convert.convertFromFiat((_b = initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.value.toString()) !== null && _b !== void 0 ? _b : '', initialToken.value, exchangeRates));
    const [tokenSymbol, _setTokenSymbol] = React.useState(initialToken.value);
    const [fiatAmount, setFiatAmount] = React.useState(isInitialAmountValueForToken
        ? convert.convertToFiat(tokenAmount !== null && tokenAmount !== void 0 ? tokenAmount : '', tokenSymbol, exchangeRates)
        : (_c = initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.value.toString()) !== null && _c !== void 0 ? _c : '');
    const setTokenSymbol = React.useCallback((symbol) => {
        setHasUserInteracted(true);
        _setTokenSymbol(symbol);
        if (fiatAmount)
            setTokenAmount(convert.convertFromFiat(fiatAmount, symbol, exchangeRates));
    }, [fiatAmount, exchangeRates]);
    // When we eventually allow changing this, add setter as _setFiatSymbol
    // And then create a setFiatSymbol function similar to how we have setTokenSymbol
    const [fiatSymbol] = React.useState('USD');
    const setAmountsByTokenValue = React.useCallback((amount) => {
        setTokenAmount(amount);
        setFiatAmount(convert.convertToFiat(amount, tokenSymbol, exchangeRates));
    }, [tokenSymbol, exchangeRates]);
    const setAmountsByFiatValue = React.useCallback((amount) => {
        setFiatAmount(amount);
        setTokenAmount(convert.convertFromFiat(amount, tokenSymbol, exchangeRates));
    }, [tokenSymbol, exchangeRates]);
    const [showTokenAsPrimary, setShowTokenAsPrimary] = React.useState(false);
    const isMinimumRespected = minimum
        ? respectsMinimum.respectsMinimum({ token: fiatSymbol, value: fiatAmount !== null && fiatAmount !== void 0 ? fiatAmount : '' }, minimum, exchangeRates)
        : true;
    const [primaryData, secondaryData] = showTokenAsPrimary
        ? [
            {
                amount: tokenAmount,
                setAmount: setAmountsByTokenValue,
                symbol: tokenSymbol,
            },
            { amount: fiatAmount, symbol: fiatSymbol },
        ]
        : [
            {
                amount: fiatAmount,
                setAmount: setAmountsByFiatValue,
                symbol: fiatSymbol,
            },
            { amount: tokenAmount, symbol: tokenSymbol },
        ];
    const { secondaryDisplay, grayOutSecondaryDisplay, inputSymbolProp } = useFundingDisplay.useFundingDisplay({
        primaryData,
        secondaryData,
    });
    const quickSuggestionsWithTokenTemp = Array.isArray(quickSuggestions)
        ? { token: 'USD', values: quickSuggestions }
        : quickSuggestions;
    const { quickSuggestionsWithToken, quickSuggestionsParsed } = parseQuickSuggestions.parseQuickSuggestions(quickSuggestions, (value) => respectsMinimum.respectsMinimum({ token: quickSuggestionsWithTokenTemp.token, value: value.toString() }, minimum, exchangeRates));
    const currentToken = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.find(({ symbol }) => symbol === tokenSymbol);
    const fiatBalance = calculateFiatBalance.calculateFiatBalance(currentToken, exchangeRates);
    const [primaryBalance, secondaryBalance] = showTokenAsPrimary
        ? [
            {
                symbol: tokenSymbol,
                value: (_d = currentToken === null || currentToken === void 0 ? void 0 : currentToken.balance) !== null && _d !== void 0 ? _d : 0,
            },
            {
                symbol: fiatSymbol,
                value: fiatBalance,
            },
        ]
        : [
            {
                symbol: fiatSymbol,
                value: fiatBalance,
            },
            {
                symbol: tokenSymbol,
                value: (_e = currentToken === null || currentToken === void 0 ? void 0 : currentToken.balance) !== null && _e !== void 0 ? _e : 0,
            },
        ];
    const showNotEnoughBalance = Boolean(!tokenBalancesLoading &&
        isNonZero.isNonZero(tokenAmount) &&
        tokenAmount !== undefined &&
        (!currentToken || currentToken.balance < parseFloat(tokenAmount)));
    const showMinimumRequired = Boolean(!isMinimumRespected && !showNotEnoughBalance);
    let addressToDisplay = '';
    if (wallet) {
        addressToDisplay = shortenWalletAddress.shortenWalletAddress(wallet.address);
    }
    else if (exchange) {
        addressToDisplay = exchange.charAt(0).toUpperCase() + exchange.slice(1);
    }
    const showQuickSuggestions = quickSuggestionsParsed.length > 0 &&
        !hasUserInteracted &&
        !rulesThatHideQuickSuggestions.includes(initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.rule) &&
        (tokenSymbol === quickSuggestionsWithToken.token ||
            isFiatToken.isFiatToken(quickSuggestionsWithToken.token));
    const disableTokenSelect = rulesThatDisableTokenSelect.includes(initialToken.rule);
    const [showTokenSelect, setShowTokenSelect] = React.useState(false);
    const { handleSelectToken, handleQuickSuggestion, closeTokenSelect, switchPrimaryAndSecondary, } = useFundingHandlers.useFundingHandlers({
        fiatAmount,
        inputEmitter,
        quickSuggestionsToken: quickSuggestionsWithToken.token,
        setAmountsByFiatValue,
        setAmountsByTokenValue,
        setFiatAmount,
        setHasUserInteracted,
        setShowTokenAsPrimary,
        setShowTokenSelect,
        setTokenAmount,
        setTokenSymbol,
        showTokenAsPrimary,
        tokenAmount,
    });
    const handleSubmit = useSubmitWalletFunding.useSubmitWalletFunding();
    const handleExchangeSubmit = useSubmitExchangeFunding.useSubmitExchangeFunding();
    const disableSubmit = !isMinimumRespected || showNotEnoughBalance || !isNonZero.isNonZero(tokenAmount);
    const { backButton, closeButton } = createFundingButtons.createFundingButtons({
        defaultBackAction: () => setDynamicWidgetView('choose-wallet-funding-method'),
        hideBackButton,
        onBack,
        setShowAuthFlow,
        setShowDynamicUserProfile,
    });
    return (jsxRuntime.jsxs("div", { className: 'fund-from-wallet', children: [!disableTokenSelect && (jsxRuntime.jsx(TokenSelectScreen.TokenSelectScreen, { onClose: closeTokenSelect, onSelectToken: handleSelectToken, tokens: tokenBalances !== null && tokenBalances !== void 0 ? tokenBalances : [], currentToken: tokenSymbol, className: classNames.classNames('fund-from-wallet__token-select', {
                    'fund-from-wallet__token-select--open': showTokenSelect,
                }), showTokenAsPrimary: showTokenAsPrimary, exchangeRates: exchangeRates })), jsxRuntime.jsx(ModalHeader.ModalHeader, { leading: backButton, trailing: closeButton, children: jsxRuntime.jsx(Typography.Typography, { variant: 'title', copykey: fundingWithExchange
                        ? 'dyn_fund_from_exchange.title'
                        : 'dyn_wallet_funding.from_wallet.amount_input.title', children: fundingWithExchange
                        ? t('dyn_fund_from_exchange.title')
                        : t('dyn_wallet_funding.from_wallet.amount_input.title') }) }), jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content', children: [jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__amount-container', children: [minimum && (jsxRuntime.jsx(Typography.Typography, { color: 'error-1', className: classNames.classNames('fund-from-wallet__content__amount-container__minimum-error', {
                                    'fund-from-wallet__content__amount-container__minimum-error--visible': showMinimumRequired,
                                }), variant: 'body_normal', weight: 'medium', copykey: 'dyn_wallet_funding.from_wallet.amount_input.minimum_error', children: t('dyn_wallet_funding.from_wallet.amount_input.minimum_error', {
                                    minimum: formatValue.formatValue({
                                        symbol: minimum.token,
                                        value: minimum.value,
                                    }),
                                }) })), primaryData.amount !== undefined && (jsxRuntime.jsx(FormattedInput.FormattedInput, Object.assign({ className: 'fund-from-wallet__content__amount-container__amount', value: (initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.rule) === 'exact'
                                    ? (_f = formatValue.formatValue({
                                        maxDecimals: isFiatToken.isFiatOrStablecoin(primaryData.symbol)
                                            ? 2
                                            : 8,
                                        symbol: undefined,
                                        value: primaryData.amount,
                                        withFixedZeros: isFiatToken.isFiatOrStablecoin(primaryData.symbol),
                                    })) !== null && _f !== void 0 ? _f : primaryData.amount
                                    : primaryData.amount, onChange: primaryData.setAmount, emitter: inputEmitter, onInteraction: () => setHasUserInteracted(true), locked: (initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.rule) === 'exact' }, inputSymbolProp))), primaryData.amount === undefined && (jsxRuntime.jsx(Skeleton.Skeleton, { dataTestId: 'primary-amount-skeleton', container: {
                                    className: 'fund-from-wallet__content__amount-container__skeleton',
                                } })), showQuickSuggestions && (jsxRuntime.jsx("div", { className: 'fund-from-wallet__content__amount-container__quick-suggestions', children: quickSuggestionsParsed.map(({ display, value }) => (jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'secondary', onClick: () => handleQuickSuggestion(value), weight: 'medium', children: display }, value))) })), !showQuickSuggestions && secondaryDisplay && (jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__amount-container__secondary-amount-container', children: [(currentToken === null || currentToken === void 0 ? void 0 : currentToken.logoURI) ? (jsxRuntime.jsx(Image.Image, { dataTestId: 'token-icon', alt: tokenSymbol, src: currentToken.logoURI, className: 'fund-from-wallet__content__token-icon' })) : null, jsxRuntime.jsx(Typography.Typography, { weight: 'medium', className: classNames.classNames('fund-from-wallet__content__amount-container__secondary-amount-container__amount', {
                                            'fund-from-wallet__content__amount-container__secondary-amount-container__amount--grayed-out': grayOutSecondaryDisplay,
                                        }), children: secondaryDisplay }), jsxRuntime.jsx(Icon.Icon, { size: 'small', color: 'text-secondary', className: 'fund-from-wallet__content__amount-container__secondary-amount-container__switch', children: jsxRuntime.jsx(switchToggle.ReactComponent, { "data-testid": 'switch-primary-and-secondary', onClick: switchPrimaryAndSecondary }) })] })), !showQuickSuggestions && !secondaryDisplay && (jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__amount-container__secondary-missing', children: [jsxRuntime.jsx(Typography.Typography, { weight: 'medium', children: formatValue.formatValue({
                                            symbol: secondaryData.symbol,
                                            value: consts.UNAVAILABLE_VALUE,
                                        }) }), jsxRuntime.jsx("div", { ref: setConversionErrorIconRef, children: jsxRuntime.jsx(Icon.Icon, { size: 'medium', color: 'text-tertiary', children: jsxRuntime.jsx(footerInfoIcon.ReactComponent, {}) }) }), jsxRuntime.jsx(Tooltip.Tooltip, { content: t('dyn_wallet_funding.from_wallet.amount_input.pricing_unavailable'), targetRef: conversionErrorIconRef, className: 'fund-from-wallet__content__amount-container__secondary-missing__tooltip' })] })), jsxRuntime.jsx(Typography.Typography, { color: 'error-1', className: classNames.classNames('fund-from-wallet__content__amount-container__balance-error', {
                                    'fund-from-wallet__content__amount-container__balance-error--visible': showNotEnoughBalance,
                                }), variant: 'body_normal', weight: 'medium', copykey: 'dyn_wallet_funding.from_wallet.amount_input.balance_error', children: t('dyn_wallet_funding.from_wallet.amount_input.balance_error') })] }), jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card', children: [jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details', children: [wallet && (jsxRuntime.jsx(walletBook.WalletIcon, { icon: wallet.connector.metadata.icon, walletKey: wallet.connector.key, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' })), provider && (jsxRuntime.jsx(iconic.SocialIcon, { name: provider, variant: iconThemeVariant, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' })), jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details__rows', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'medium', copykey: 'dyn_wallet_funding.from_wallet.amount_input.wallet_detail_from', children: t('dyn_wallet_funding.from_wallet.amount_input.wallet_detail_from') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'secondary', weight: 'medium', children: addressToDisplay })] })] }), tokenBalancesLoading && (jsxRuntime.jsx(Skeleton.Skeleton, { dataTestId: 'balance-skeleton', container: {
                                    className: 'fund-from-wallet__content__wallet-card__balance-skeleton',
                                } })), !tokenBalancesLoading && (jsxRuntime.jsxs("div", { className: classNames.classNames('fund-from-wallet__content__wallet-card__balance', {
                                    'fund-from-wallet__content__wallet-card__balance--disable-select': disableTokenSelect,
                                }), onClick: () => !disableTokenSelect && setShowTokenSelect(true), children: [jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card__balance__rows', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', "data-testid": `primary-balance-amount-${primaryBalance.symbol}`, weight: 'medium', children: formatValue.formatValue({
                                                    maxDecimals: isFiatToken.isFiatOrStablecoin(primaryBalance.symbol)
                                                        ? 2
                                                        : 6,
                                                    symbol: primaryBalance.symbol,
                                                    value: (_g = primaryBalance.value) !== null && _g !== void 0 ? _g : consts.UNAVAILABLE_VALUE,
                                                    withFixedZeros: isFiatToken.isFiatOrStablecoin(primaryBalance.symbol),
                                                }) }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', "data-testid": `secondary-balance-amount-${secondaryBalance.symbol}`, color: 'secondary', weight: 'medium', children: formatValue.formatValue({
                                                    maxDecimals: isFiatToken.isFiatOrStablecoin(secondaryBalance.symbol)
                                                        ? 2
                                                        : 6,
                                                    symbol: secondaryBalance.symbol,
                                                    value: (_h = secondaryBalance.value) !== null && _h !== void 0 ? _h : consts.UNAVAILABLE_VALUE,
                                                    withFixedZeros: isFiatToken.isFiatOrStablecoin(secondaryBalance.symbol),
                                                }) })] }), !disableTokenSelect && (jsxRuntime.jsx(Icon.Icon, { color: 'text-tertiary', size: 'small', className: 'fund-from-wallet__content__wallet-card__balance__icon', children: jsxRuntime.jsx(chevronDown.ReactComponent, { "data-testid": 'token-select-dropdown' }) }))] }))] })] }), jsxRuntime.jsx(TypographyButton.TypographyButton, { dataTestId: 'confirm-button', buttonVariant: 'brand-primary', buttonPadding: 'large', typographyProps: { color: 'white' }, className: 'fund-from-wallet__confirm-button', disabled: disableSubmit, onClick: () => {
                    if (fundingWithExchange && exchange) {
                        const baseConfirmProps = {
                            amount: tokenAmount ? parseFloat(tokenAmount) : undefined,
                            exchange,
                            fiatAmount: fiatAmount ? parseFloat(fiatAmount) : undefined,
                            fiatCurrencySymbol: fiatSymbol,
                            onBack: () => setDynamicWidgetView('receive-wallet-funds', {
                                accounts,
                                amount: initialAmount,
                                destinationAddress,
                                exchange,
                                fundingWithExchange,
                                network,
                                quickSuggestions,
                                token: { rule: 'recommended', value: tokenSymbol },
                                wallet,
                            }),
                            toAddress: destinationAddress !== null && destinationAddress !== void 0 ? destinationAddress : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address,
                            token: currentToken,
                        };
                        const handleConfirmSubmit = () => {
                            var _a;
                            return handleExchangeSubmit({
                                exchange,
                                props: Object.assign(Object.assign({}, baseConfirmProps), { onSubmit: handleConfirmSubmit }),
                                toAddress: (_a = destinationAddress !== null && destinationAddress !== void 0 ? destinationAddress : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address) !== null && _a !== void 0 ? _a : '',
                                tokenAmount,
                                tokenSymbol,
                            });
                        };
                        const confirmProps = Object.assign(Object.assign({}, baseConfirmProps), { onSubmit: handleConfirmSubmit });
                        setDynamicWidgetView('confirm-exchange-transfer', confirmProps);
                    }
                    else if (wallet) {
                        handleSubmit({
                            toWallet: destinationAddress && network
                                ? {
                                    address: destinationAddress,
                                    network: network,
                                }
                                : undefined,
                            tokenAmount,
                            tokenBalances,
                            tokenSymbol,
                            wallet,
                        });
                    }
                }, children: t('dyn_wallet_funding.from_wallet.amount_input.confirm_button') })] }));
};

exports.ReceiveWalletFunds = ReceiveWalletFunds;
