import Slider from '@components/forms/Slider' import Button, { IconButton, LinkButton } from '@components/shared/Button' import { ArrowLeftIcon } from '@heroicons/react/20/solid' import { useTranslation } from 'react-i18next' import { MAX_ACCOUNTS } from 'utils/constants' export type ACCOUNT_SLOTS = { tokenSlots: number serumSlots: number perpSlots: number } export const DEFAULT_SLOTS: ACCOUNT_SLOTS = { tokenSlots: parseInt(MAX_ACCOUNTS.tokenAccounts), serumSlots: parseInt(MAX_ACCOUNTS.spotOpenOrders), perpSlots: parseInt(MAX_ACCOUNTS.perpAccounts), } const CreateAccountAdvancedOptions = ({ slots, setSlots, onClose, }: { slots: ACCOUNT_SLOTS setSlots: (slots: React.SetStateAction | ACCOUNT_SLOTS) => void onClose?: () => void }) => { const { t } = useTranslation(['common', 'settings']) const handleResetDefaults = () => { setSlots(DEFAULT_SLOTS) } const calculateMaxValues = () => { const maxTotalSlots = 28 const maxTokenSlots = Math.floor( (maxTotalSlots - slots.serumSlots - slots.perpSlots * 2) / 2, ) const maxSerumSlots = maxTotalSlots - slots.tokenSlots * 2 - slots.perpSlots * 2 const maxPerpSlots = Math.floor( (maxTotalSlots - slots.tokenSlots * 2 - slots.serumSlots) / 2, ) return { maxTokenSlots, maxSerumSlots, maxPerpSlots, } } const handleSliderChange = (property: keyof ACCOUNT_SLOTS, value: string) => { setSlots((prevSlots: ACCOUNT_SLOTS) => ({ ...prevSlots, [property]: parseInt(value), })) const { maxTokenSlots, maxSerumSlots, maxPerpSlots } = calculateMaxValues() // Ensure each property stays within its maximum value if (property === 'tokenSlots') { setSlots((prevSlots: ACCOUNT_SLOTS) => ({ ...prevSlots, serumSlots: Math.min(prevSlots.serumSlots, maxSerumSlots), perpSlots: Math.min(prevSlots.perpSlots, maxPerpSlots), })) } else if (property === 'serumSlots') { setSlots((prevSlots: ACCOUNT_SLOTS) => ({ ...prevSlots, tokenSlots: Math.min(prevSlots.tokenSlots, maxTokenSlots), perpSlots: Math.min(prevSlots.perpSlots, maxPerpSlots), })) } else if (property === 'perpSlots') { setSlots((prevSlots: ACCOUNT_SLOTS) => ({ ...prevSlots, tokenSlots: Math.min(prevSlots.tokenSlots, maxTokenSlots), serumSlots: Math.min(prevSlots.serumSlots, maxSerumSlots), })) } } const { tokenSlots, serumSlots, perpSlots } = slots return (
{onClose ? ( ) : null}

{t('account:advanced-options')}

{onClose ?
: null}

{t('account:advanced-options-desc')}

{t('settings:account-slots')}

{t('account:reset-defaults')}

{t('tokens')}

{tokenSlots}

handleSliderChange('tokenSlots', value)} step={1} />

{t('spot-markets')}

{serumSlots}

handleSliderChange('serumSlots', value)} step={1} />

{t('perp-markets')}

{perpSlots}

handleSliderChange('perpSlots', value)} step={1} />
) } export default CreateAccountAdvancedOptions