'use client'
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { SocialIcon } from '@dynamic-labs/iconic';
import { WalletIcon } from '@dynamic-labs/wallet-book';
import { classNames } from '../../../../utils/functions/classNames/classNames.js';
import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
import { ReactComponent as SvgChevronDown } from '../../../../shared/assets/chevron-down.js';
import { ReactComponent as SvgFooterInfoIcon } from '../../../../shared/assets/footer-info-icon.js';
import { ReactComponent as SvgSwitchToggle } from '../../../../shared/assets/switch-toggle.js';
import '../../../../context/ViewContext/ViewContext.js';
import '../../../../../../_virtual/_tslib.js';
import '@dynamic-labs/wallet-connector-core';
import '../../../../shared/logger.js';
import '@dynamic-labs/utils';
import '../../../../utils/constants/colors.js';
import '../../../../utils/constants/values.js';
import '@dynamic-labs/sdk-api-core';
import '../../../../shared/consts/index.js';
import '../../../../components/Alert/Alert.js';
import '../../../../events/dynamicEvents.js';
import '../../../../context/DynamicContext/DynamicContext.js';
import '../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.js';
import '../../../../store/state/authMode/authMode.js';
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
import '../../../../context/CaptchaContext/CaptchaContext.js';
import '../../../../context/ErrorContext/ErrorContext.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../../../store/state/nonce/nonce.js';
import '@dynamic-labs-sdk/client/core';
import '../../../../client/client.js';
import '@dynamic-labs-sdk/client';
import '../../../../config/ApiEndpoint.js';
import '@dynamic-labs/locale';
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 '../../../../context/VerificationContext/VerificationContext.js';
import 'react-dom';
import '../../../../utils/functions/compareChains/compareChains.js';
import '../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
import { useIconThemeVariant } from '../../../../utils/hooks/useIconThemeVariant/useIconThemeVariant.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 '../../../../views/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 { Typography } from '../../../../components/Typography/Typography.js';
import '../../../../context/FooterAnimationContext/index.js';
import '../../../../components/ShadowDOM/ShadowDOM.js';
import '../../../../components/Transition/ZoomTransition/ZoomTransition.js';
import '../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
import '../../../../components/Transition/OpacityTransition/OpacityTransition.js';
import '../../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js';
import { Skeleton } from '../../../../components/Skeleton/Skeleton.js';
import { Tooltip } from '../../../../components/Tooltip/Tooltip.js';
import '../../../../context/WalletGroupContext/WalletGroupContext.js';
import '../../components/DynamicWidgetHeader/DynamicWidgetHeader.js';
import 'react-focus-lock';
import '../../../../context/ThemeContext/ThemeContext.js';
import { Icon } from '../../../../components/Icon/Icon.js';
import { shortenWalletAddress } from '../../../../shared/utils/functions/shortenWalletAddress/shortenWalletAddress.js';
import { useWidgetContext } from '../../context/DynamicWidgetContext.js';
import '../../../../components/IconButton/IconButton.js';
import { ModalHeader } from '../../../../components/ModalHeader/ModalHeader.js';
import { TypographyButton } from '../../../../components/TypographyButton/TypographyButton.js';
import '../../../../components/MenuList/Dropdown/Dropdown.js';
import { Image } from '../../../../components/Image/Image.js';
import 'formik';
import '../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
import '../../../../store/state/sendBalances.js';
import '../../../../components/Input/Input.js';
import '../../../../components/OverlayCard/OverlayCard.js';
import '../../../../views/TransactionConfirmationView/TransactionConfirmationView.js';
import '../../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
import '../../../../context/PasskeyContext/PasskeyContext.js';
import '../../components/PasskeyCard/PasskeyCard.js';
import '../CryptoComOnramp/CryptoComOnramp.js';
import '../../../../context/OnrampContext/OnrampContext.js';
import '../../../../../index.js';
import { convertExchangeKeytoProviderEnum } from '../../helpers/convertExchangeKeyAndProviderEnum.js';
import 'qrcode';
import '../../../../context/IpConfigurationContext/IpConfigurationContext.js';
import '../../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
import '../../../DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
import '@hcaptcha/react-hcaptcha';
import '../../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.js';
import '../../../../context/ErrorContext/hooks/useErrorText/useErrorText.js';
import '../../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.js';
import '../../../../store/state/connectorsInitializing/connectorsInitializing.js';
import '../../../../store/state/tokenBalances.js';
import '../../../../store/state/multichainBalances.js';
import '../../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
import { useSubmitExchangeFunding } from '../../../../utils/hooks/useSubmitExchangeFunding/useSubmitExchangeFunding.js';
import '../../../../components/InlineWidget/InlineWidget.js';
import '../../../../components/IsBrowser/IsBrowser.js';
import '../../../../components/Popper/Popper/Popper.js';
import '../../../../components/Popper/PopperContext/PopperContext.js';
import { FormattedInput } from './FormattedInput/FormattedInput.js';
import { createFormattedInputEmitter } from './FormattedInput/formattedInputEmitter.js';
import { TokenSelectScreen } from './TokenSelectScreen/TokenSelectScreen.js';
import { UNAVAILABLE_VALUE } from './consts.js';
import { calculateFiatBalance } from './utils/calculateFiatBalance/calculateFiatBalance.js';
import { convertFromFiat, convertToFiat } from './utils/convert/convert.js';
import { formatValue } from './utils/formatValue/formatValue.js';
import { isFiatToken, isFiatOrStablecoin } from './utils/isFiatToken/isFiatToken.js';
import { isNonZero } from './utils/isNonZero/isNonZero.js';
import { respectsMinimum } from './utils/respectsMinimum/respectsMinimum.js';
import { useExchangeRatesForFunding } from './utils/useExchangeRatesForFunding/useExchangeRatesForFunding.js';
import { useExchangeTokensForFunding } from './utils/useExchangeTokensForFunding/useExchangeTokensForFunding.js';
import { useSubmitWalletFunding } from './utils/useSubmitWalletFunding/useSubmitWalletFunding.js';
import { useTokensForFunding } from './utils/useTokensForFunding/useTokensForFunding.js';
import { createFundingButtons } from './utils/createFundingButtons/createFundingButtons.js';
import { parseQuickSuggestions } from './utils/parseQuickSuggestions/parseQuickSuggestions.js';
import { useFundingHandlers } from './utils/useFundingHandlers/useFundingHandlers.js';
import { useFundingDisplay } from './utils/useFundingDisplay/useFundingDisplay.js';

const defaultQuickSuggestions = {
    token: 'USD',
    values: [25, 100, 500],
};
const rulesThatHideQuickSuggestions = ['exact', 'minimum'];
const rulesThatDisableTokenSelect = ['exact', 'exact-with-amount'];
const inputEmitter = 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 } = useTranslation();
    const [hasUserInteracted, setHasUserInteracted] = useState(false);
    const [conversionErrorIconRef, setConversionErrorIconRef] = useState(null);
    const { primaryWallet, setShowAuthFlow, setShowDynamicUserProfile } = useInternalDynamicContext();
    const iconThemeVariant = useIconThemeVariant();
    const provider = exchange
        ? convertExchangeKeytoProviderEnum(exchange)
        : undefined;
    const { setDynamicWidgetView } = useWidgetContext();
    const { isLoading: tokenBalancesLoadingWallet, tokens: tokenBalancesWallet } = useTokensForFunding({
        wallet: wallet,
    });
    const { tokens: tokenBalancesExchange } = useExchangeTokensForFunding({
        accounts: accounts !== null && accounts !== void 0 ? accounts : [],
    });
    const tokenBalances = fundingWithExchange
        ? tokenBalancesExchange
        : tokenBalancesWallet;
    const tokenBalancesLoading = fundingWithExchange
        ? false
        : tokenBalancesLoadingWallet;
    const exchangeRates = useExchangeRatesForFunding({
        // Initialize amounts after exchange rates are fetched
        onFetch: (exchangeRates) => {
            if (tokenAmount === undefined && fiatAmount !== undefined) {
                setTokenAmount(convertFromFiat(fiatAmount, tokenSymbol, exchangeRates));
            }
            if (fiatAmount === undefined && tokenAmount !== undefined) {
                setFiatAmount(convertToFiat(tokenAmount, tokenSymbol, exchangeRates));
            }
        },
        tokenBalances,
    });
    const [tokenAmount, setTokenAmount] = useState(isInitialAmountValueForToken
        ? (_a = initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.value.toString()) !== null && _a !== void 0 ? _a : ''
        : convertFromFiat((_b = initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.value.toString()) !== null && _b !== void 0 ? _b : '', initialToken.value, exchangeRates));
    const [tokenSymbol, _setTokenSymbol] = useState(initialToken.value);
    const [fiatAmount, setFiatAmount] = useState(isInitialAmountValueForToken
        ? 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 = useCallback((symbol) => {
        setHasUserInteracted(true);
        _setTokenSymbol(symbol);
        if (fiatAmount)
            setTokenAmount(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] = useState('USD');
    const setAmountsByTokenValue = useCallback((amount) => {
        setTokenAmount(amount);
        setFiatAmount(convertToFiat(amount, tokenSymbol, exchangeRates));
    }, [tokenSymbol, exchangeRates]);
    const setAmountsByFiatValue = useCallback((amount) => {
        setFiatAmount(amount);
        setTokenAmount(convertFromFiat(amount, tokenSymbol, exchangeRates));
    }, [tokenSymbol, exchangeRates]);
    const [showTokenAsPrimary, setShowTokenAsPrimary] = useState(false);
    const isMinimumRespected = minimum
        ? 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({
        primaryData,
        secondaryData,
    });
    const quickSuggestionsWithTokenTemp = Array.isArray(quickSuggestions)
        ? { token: 'USD', values: quickSuggestions }
        : quickSuggestions;
    const { quickSuggestionsWithToken, quickSuggestionsParsed } = parseQuickSuggestions(quickSuggestions, (value) => 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(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(tokenAmount) &&
        tokenAmount !== undefined &&
        (!currentToken || currentToken.balance < parseFloat(tokenAmount)));
    const showMinimumRequired = Boolean(!isMinimumRespected && !showNotEnoughBalance);
    let addressToDisplay = '';
    if (wallet) {
        addressToDisplay = 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(quickSuggestionsWithToken.token));
    const disableTokenSelect = rulesThatDisableTokenSelect.includes(initialToken.rule);
    const [showTokenSelect, setShowTokenSelect] = useState(false);
    const { handleSelectToken, handleQuickSuggestion, closeTokenSelect, switchPrimaryAndSecondary, } = useFundingHandlers({
        fiatAmount,
        inputEmitter,
        quickSuggestionsToken: quickSuggestionsWithToken.token,
        setAmountsByFiatValue,
        setAmountsByTokenValue,
        setFiatAmount,
        setHasUserInteracted,
        setShowTokenAsPrimary,
        setShowTokenSelect,
        setTokenAmount,
        setTokenSymbol,
        showTokenAsPrimary,
        tokenAmount,
    });
    const handleSubmit = useSubmitWalletFunding();
    const handleExchangeSubmit = useSubmitExchangeFunding();
    const disableSubmit = !isMinimumRespected || showNotEnoughBalance || !isNonZero(tokenAmount);
    const { backButton, closeButton } = createFundingButtons({
        defaultBackAction: () => setDynamicWidgetView('choose-wallet-funding-method'),
        hideBackButton,
        onBack,
        setShowAuthFlow,
        setShowDynamicUserProfile,
    });
    return (jsxs("div", { className: 'fund-from-wallet', children: [!disableTokenSelect && (jsx(TokenSelectScreen, { onClose: closeTokenSelect, onSelectToken: handleSelectToken, tokens: tokenBalances !== null && tokenBalances !== void 0 ? tokenBalances : [], currentToken: tokenSymbol, className: classNames('fund-from-wallet__token-select', {
                    'fund-from-wallet__token-select--open': showTokenSelect,
                }), showTokenAsPrimary: showTokenAsPrimary, exchangeRates: exchangeRates })), jsx(ModalHeader, { leading: backButton, trailing: closeButton, children: jsx(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') }) }), jsxs("div", { className: 'fund-from-wallet__content', children: [jsxs("div", { className: 'fund-from-wallet__content__amount-container', children: [minimum && (jsx(Typography, { color: 'error-1', className: 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({
                                        symbol: minimum.token,
                                        value: minimum.value,
                                    }),
                                }) })), primaryData.amount !== undefined && (jsx(FormattedInput, Object.assign({ className: 'fund-from-wallet__content__amount-container__amount', value: (initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.rule) === 'exact'
                                    ? (_f = formatValue({
                                        maxDecimals: isFiatOrStablecoin(primaryData.symbol)
                                            ? 2
                                            : 8,
                                        symbol: undefined,
                                        value: primaryData.amount,
                                        withFixedZeros: 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 && (jsx(Skeleton, { dataTestId: 'primary-amount-skeleton', container: {
                                    className: 'fund-from-wallet__content__amount-container__skeleton',
                                } })), showQuickSuggestions && (jsx("div", { className: 'fund-from-wallet__content__amount-container__quick-suggestions', children: quickSuggestionsParsed.map(({ display, value }) => (jsx(Typography, { variant: 'body_small', color: 'secondary', onClick: () => handleQuickSuggestion(value), weight: 'medium', children: display }, value))) })), !showQuickSuggestions && secondaryDisplay && (jsxs("div", { className: 'fund-from-wallet__content__amount-container__secondary-amount-container', children: [(currentToken === null || currentToken === void 0 ? void 0 : currentToken.logoURI) ? (jsx(Image, { dataTestId: 'token-icon', alt: tokenSymbol, src: currentToken.logoURI, className: 'fund-from-wallet__content__token-icon' })) : null, jsx(Typography, { weight: 'medium', className: 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 }), jsx(Icon, { size: 'small', color: 'text-secondary', className: 'fund-from-wallet__content__amount-container__secondary-amount-container__switch', children: jsx(SvgSwitchToggle, { "data-testid": 'switch-primary-and-secondary', onClick: switchPrimaryAndSecondary }) })] })), !showQuickSuggestions && !secondaryDisplay && (jsxs("div", { className: 'fund-from-wallet__content__amount-container__secondary-missing', children: [jsx(Typography, { weight: 'medium', children: formatValue({
                                            symbol: secondaryData.symbol,
                                            value: UNAVAILABLE_VALUE,
                                        }) }), jsx("div", { ref: setConversionErrorIconRef, children: jsx(Icon, { size: 'medium', color: 'text-tertiary', children: jsx(SvgFooterInfoIcon, {}) }) }), jsx(Tooltip, { content: t('dyn_wallet_funding.from_wallet.amount_input.pricing_unavailable'), targetRef: conversionErrorIconRef, className: 'fund-from-wallet__content__amount-container__secondary-missing__tooltip' })] })), jsx(Typography, { color: 'error-1', className: 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') })] }), jsxs("div", { className: 'fund-from-wallet__content__wallet-card', children: [jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details', children: [wallet && (jsx(WalletIcon, { icon: wallet.connector.metadata.icon, walletKey: wallet.connector.key, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' })), provider && (jsx(SocialIcon, { name: provider, variant: iconThemeVariant, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' })), jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details__rows', children: [jsx(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') }), jsx(Typography, { variant: 'body_small', color: 'secondary', weight: 'medium', children: addressToDisplay })] })] }), tokenBalancesLoading && (jsx(Skeleton, { dataTestId: 'balance-skeleton', container: {
                                    className: 'fund-from-wallet__content__wallet-card__balance-skeleton',
                                } })), !tokenBalancesLoading && (jsxs("div", { className: classNames('fund-from-wallet__content__wallet-card__balance', {
                                    'fund-from-wallet__content__wallet-card__balance--disable-select': disableTokenSelect,
                                }), onClick: () => !disableTokenSelect && setShowTokenSelect(true), children: [jsxs("div", { className: 'fund-from-wallet__content__wallet-card__balance__rows', children: [jsx(Typography, { variant: 'body_small', "data-testid": `primary-balance-amount-${primaryBalance.symbol}`, weight: 'medium', children: formatValue({
                                                    maxDecimals: isFiatOrStablecoin(primaryBalance.symbol)
                                                        ? 2
                                                        : 6,
                                                    symbol: primaryBalance.symbol,
                                                    value: (_g = primaryBalance.value) !== null && _g !== void 0 ? _g : UNAVAILABLE_VALUE,
                                                    withFixedZeros: isFiatOrStablecoin(primaryBalance.symbol),
                                                }) }), jsx(Typography, { variant: 'body_small', "data-testid": `secondary-balance-amount-${secondaryBalance.symbol}`, color: 'secondary', weight: 'medium', children: formatValue({
                                                    maxDecimals: isFiatOrStablecoin(secondaryBalance.symbol)
                                                        ? 2
                                                        : 6,
                                                    symbol: secondaryBalance.symbol,
                                                    value: (_h = secondaryBalance.value) !== null && _h !== void 0 ? _h : UNAVAILABLE_VALUE,
                                                    withFixedZeros: isFiatOrStablecoin(secondaryBalance.symbol),
                                                }) })] }), !disableTokenSelect && (jsx(Icon, { color: 'text-tertiary', size: 'small', className: 'fund-from-wallet__content__wallet-card__balance__icon', children: jsx(SvgChevronDown, { "data-testid": 'token-select-dropdown' }) }))] }))] })] }), jsx(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') })] }));
};

export { ReceiveWalletFunds };
