import Button, { IconButton } from '@components/shared/Button' import { Dialog, Transition } from '@headlessui/react' import { TrashIcon, XMarkIcon } from '@heroicons/react/20/solid' import { Fragment, useCallback, useState } from 'react' import { useTranslation } from 'next-i18next' import { ttCommons, ttCommonsExpanded, ttCommonsMono } from 'utils/fonts' import useLocalStorageState from 'hooks/useLocalStorageState' import { HotKey } from '@components/settings/HotKeysSettings' import { HOT_KEYS_KEY } from 'utils/constants' import { PerpMarket } from '@blockworks-foundation/mango-v4' import mangoStore from '@store/mangoStore' import HotKeyModal from '@components/modals/HotKeyModal' import InlineNotification from '@components/shared/InlineNotification' import KeyboardIcon from '@components/icons/KeyboardIcon' const BADGE_CLASSNAMES = 'mt-2 rounded border border-th-fgd-4 px-1 py-0.5 text-xs text-th-fgd-4' const HotKeysDrawer = ({ isOpen, onClose, }: { isOpen: boolean onClose: () => void }) => { const { t } = useTranslation(['common', 'settings', 'trade']) const [hotKeys, setHotKeys] = useLocalStorageState(HOT_KEYS_KEY, []) const [showHotKeyModal, setShowHotKeyModal] = useState(false) const handleDeleteKey = useCallback( (key: string) => { const newKeys = hotKeys.filter((hk: HotKey) => hk.keySequence !== key) setHotKeys([...newKeys]) }, [hotKeys, setHotKeys], ) return ( <>

{t('settings:hot-keys')}

{t('settings:hot-keys-desc')}

{hotKeys.length === 20 ? (
) : null} {hotKeys.length ? (
{hotKeys.map((hk: HotKey) => { const { custom, keySequence, name, orderSide, orderPrice, orderSize, orderSizeType, orderType, ioc, margin, reduceOnly, postOnly, } = hk const options = { margin: margin, IOC: ioc, post: postOnly, reduce: reduceOnly, } const size = orderSizeType === 'percentage' ? t('settings:percentage-of-max', { size: orderSize }) : `$${orderSize}` const price = orderPrice ? `${orderPrice}% ${ orderSide === 'buy' ? t('settings:below') : t('settings:above') } oracle` : t('trade:market') const selectedMarket = mangoStore.getState().selectedMarket.current return (

{name}

{keySequence}

{!custom ? (

{`${t(orderSide)} ${t( `trade:${orderType}`, )}, ${size} at ${price}`}

) : null} {!custom ? (
{!options.margin && selectedMarket instanceof PerpMarket ? (
{t('trade:margin')}
) : null} {Object.entries(options).map((e, i) => { return e[1] ? (
{t(`trade:${e[0]}`)}
) : null })}
) : null}
handleDeleteKey(keySequence)} size="small" >
) })}
) : (

{t('settings:no-hot-keys')}

)}
{showHotKeyModal ? ( setShowHotKeyModal(false)} /> ) : null} ) } export default HotKeysDrawer