import { Sheet } from '@/internal/components/Sheet'; import { zIndex } from '@/styles/constants'; import { border, cn, text } from '@/styles/theme'; import { useCallback, useMemo } from 'react'; import { WALLET_ADVANCED_DEFAULT_SWAPPABLE_TOKENS } from '../constants'; import { WalletAdvancedQrReceive } from './WalletAdvancedQrReceive'; import { WalletAdvancedSwap } from './WalletAdvancedSwap'; import { useWalletContext } from './WalletProvider'; import { Send } from './wallet-advanced-send/components/Send'; import { RequestContext } from '@/core/network/constants'; import { usePortfolio } from '@/wallet/hooks/usePortfolio'; import { useAccount } from 'wagmi'; import { WalletAdvancedQrReceiveProps, WalletAdvancedSwapProps, } from '../types'; import { Token } from '@/token'; export type WalletDropdownContentProps = { children?: React.ReactNode; swappableTokens?: Token[]; classNames?: { container?: string; qr?: WalletAdvancedQrReceiveProps['classNames']; swap?: WalletAdvancedSwapProps['classNames']; }; }; export function WalletDropdownContent({ children, swappableTokens, classNames, }: WalletDropdownContentProps) { const { isSubComponentOpen, setIsSubComponentOpen, isSubComponentClosing, setIsSubComponentClosing, breakpoint, activeFeature, animations, } = useWalletContext(); const { address } = useAccount(); const { data: portfolioData } = usePortfolio( { address, enabled: Boolean(activeFeature) }, RequestContext.Wallet, ); const tokenBalances = portfolioData?.tokenBalances; const handleBottomSheetClose = useCallback(() => { setIsSubComponentOpen(false); }, [setIsSubComponentOpen]); const handleAnimationEnd = useCallback(() => { if (isSubComponentClosing) { setIsSubComponentOpen(false); setIsSubComponentClosing(false); } }, [isSubComponentClosing, setIsSubComponentOpen, setIsSubComponentClosing]); const content = useMemo(() => { if (activeFeature === 'send') { return ( ); } if (activeFeature === 'qr') { return ( ); } if (activeFeature === 'swap') { return ( Swap } to={swappableTokens ?? WALLET_ADVANCED_DEFAULT_SWAPPABLE_TOKENS} from={ tokenBalances?.map((token) => ({ address: token.address, chainId: token.chainId, symbol: token.symbol, decimals: token.decimals, image: token.image, name: token.name, })) ?? [] } classNames={classNames?.swap} /> ); } return {children}; }, [activeFeature, swappableTokens, tokenBalances, children, classNames]); if (breakpoint === 'sm') { return (
{content}
); } if (!isSubComponentOpen && !isSubComponentClosing) { return null; } return (
{content}
); } function ContentWrapper({ children, className, }: { children: React.ReactNode; className?: string; }) { return (
{children}
); }