import KeyboardIcon from '@components/icons/KeyboardIcon' import HotKeyModal, { HOTKEY_TEMPLATES } from '@components/modals/HotKeyModal' import Button, { IconButton } from '@components/shared/Button' import InlineNotification from '@components/shared/InlineNotification' import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements' import { TrashIcon } from '@heroicons/react/20/solid' import useLocalStorageState from 'hooks/useLocalStorageState' import { useTranslation } from 'next-i18next' import { useState } from 'react' import { HOT_KEYS_KEY } from 'utils/constants' export type HotKey = { custom?: HOTKEY_TEMPLATES name?: string ioc: boolean keySequence: string margin: boolean orderSide: 'buy' | 'sell' orderSizeType: 'percentage' | 'notional' orderSize: string orderType: 'limit' | 'market' orderPrice: string postOnly: boolean reduceOnly: boolean } const HotKeysSettings = () => { const { t } = useTranslation(['common', 'settings', 'trade']) const [hotKeys, setHotKeys] = useLocalStorageState(HOT_KEYS_KEY, []) const [showHotKeyModal, setShowHotKeyModal] = useState(false) const handleDeleteKey = (key: string) => { const newKeys = hotKeys.filter((hk: HotKey) => hk.keySequence !== key) setHotKeys([...newKeys]) } return ( <>

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

{hotKeys.length ? ( ) : null}
{hotKeys.length === 20 ? (
) : null} {hotKeys.length ? ( {hotKeys.map((hk: HotKey) => { const { custom, name, keySequence, orderSide, orderPrice, orderSize, orderSizeType, orderType, ioc, margin, reduceOnly, postOnly, } = hk const size = orderSize ? 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 options = { margin: margin, IOC: ioc, post: postOnly, reduce: reduceOnly, } return ( ) })}
{t('settings:nickname')} {t('settings:key-sequence')} {t('trade:order-type')} {t('trade:side')} {t('trade:size')} {t('price')} {t('settings:options')}
{name || '–'} {keySequence} {orderType ? t(`trade:${orderType}`) : '–'} {orderSide ? t(orderSide) : '–'} {size} {price} {!custom ? (
{Object.entries(options).map((e) => { return e[1] ? (
{t(`trade:${e[0]}`)}
) : null })}
) : null}
handleDeleteKey(keySequence)} size="small" >
) : (

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

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