import React, { useContext, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Typography, Grid, ToggleButton, ToggleButtonGroup, Select, Divider, MenuItem, Box, Tooltip, } from '@mui/material'; import currencyDict from '../../../static/assets/currencies.json'; import { useTheme } from '@mui/system'; import { AutocompletePayments } from '../MakerForm'; import { fiatMethods, swapMethods, PaymentIcon } from '../PaymentMethods'; import { FlagWithProps } from '../Icons'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank'; import SwapCalls from '@mui/icons-material/SwapCalls'; import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; import RobotAvatar from '../RobotAvatar'; interface BookControlProps { width: number; paymentMethod: string[]; setPaymentMethods: (state: string[]) => void; } const BookControl = ({ width, paymentMethod, setPaymentMethods, }: BookControlProps): JSX.Element => { const { fav, setFav } = useContext(AppContext); const { federation } = useContext(FederationContext); const { t, i18n } = useTranslation(); const theme = useTheme(); const [typeZeroText, typeOneText, small, medium, large] = useMemo(() => { const typeZeroText = fav.mode === 'fiat' ? t('Buy') : t('Swap In'); const typeOneText = fav.mode === 'fiat' ? t('Sell') : t('Swap Out'); const small = (typeZeroText.length + typeOneText.length) * 0.7 + (fav.mode === 'fiat' ? 16 : 7.5); const medium = small + 13; const large = medium + (t('and use').length + t('pay with').length) * 0.6 + 5; return [typeZeroText, typeOneText, small, medium, large]; }, [i18n.language, fav.mode]); const handleCurrencyChange = function (e: React.ChangeEvent): void { const currency = Number(e.target.value); setFav({ ...fav, currency, mode: currency === 1000 ? 'swap' : 'fiat' }); }; const handleHostChange = function (e: React.ChangeEvent): void { const coordinator = String(e.target.value); setFav({ ...fav, coordinator }); }; const handleTypeChange = function (mouseEvent: React.MouseEvent, val: number): void { setFav({ ...fav, type: val }); }; const handleModeChange = function (mouseEvent: React.MouseEvent, val: number): void { const mode = fav.mode === 'fiat' ? 'swap' : 'fiat'; const currency = fav.mode === 'fiat' ? 1000 : 0; setFav({ ...fav, mode, currency }); }; return ( {width > large ? ( {t('I want to')} ) : null} {width > small ? ( ) : null} {typeZeroText} {typeOneText} {width > large && fav.mode === 'fiat' ? ( {t('and use')} ) : null} {fav.mode === 'fiat' ? ( ) : null} {width > large ? ( {fav.currency === 1000 ? t(fav.type === 0 ? 'to' : 'from') : t('pay with')} ) : null} {width > medium ? ( ) : null} {width > small && width <= medium ? ( ) : null} {width > large ? ( <> {fav.currency === 1000 ? t(fav.type === 0 ? 'to' : 'from') : t('hosted by')} ) : null} ); }; export default BookControl;