import type { Route } from '@lifi/sdk' import { Button, Checkbox, FormControlLabel } from '@mui/material' import type { JSX, Ref, RefObject } from 'react' import { useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { BottomSheet } from '../../components/BottomSheet/BottomSheet.js' import type { BottomSheetBase } from '../../components/BottomSheet/types.js' import { FeeBreakdownTooltip } from '../../components/FeeBreakdownTooltip.js' import { IconCircle } from '../../components/IconCircle/IconCircle.js' import { useSetContentHeight } from '../../hooks/useSetContentHeight.js' import { getAccumulatedFeeCostsBreakdown } from '../../utils/fees.js' import { ButtonRow, CenterContainer, ContentContainer, DetailLabel, DetailRow, DetailValue, WarningMessage, WarningTitle, } from './TokenValueBottomSheet.style.js' import { calculateValueLossPercentage } from './utils.js' interface TokenValueBottomSheetProps { route: Route onContinue(): void onCancel?(): void } export const TokenValueBottomSheet = ({ route, onContinue, onCancel, ref, }: TokenValueBottomSheetProps & { ref?: Ref }): JSX.Element => { const handleCancel = () => { ;(ref as RefObject).current?.close() onCancel?.() } return ( ) } const TokenValueBottomSheetContent: React.FC = ({ route, onCancel, onContinue, }) => { const [accepted, setAccepted] = useState(false) const { t } = useTranslation() const ref = useRef(null) useSetContentHeight(ref) const { gasCosts, feeCosts, gasCostUSD, feeCostUSD } = getAccumulatedFeeCostsBreakdown(route) const fromAmountUSD = Number.parseFloat(route.fromAmountUSD) const toAmountUSD = Number.parseFloat(route.toAmountUSD) return ( {t('warning.title.highValueLoss')} {t('warning.message.highValueLoss')} {t('main.sending')} {t('format.currency', { value: route.fromAmountUSD })} {t('main.fees.network')} {!gasCostUSD ? t('main.fees.free') : t('format.currency', { value: gasCostUSD })} {feeCostUSD ? ( {t('main.fees.provider')} {t('format.currency', { value: feeCostUSD })} ) : null} {t('main.receiving')} {t('format.currency', { value: route.toAmountUSD })} {t('main.valueLoss')} {calculateValueLossPercentage( fromAmountUSD, toAmountUSD, gasCostUSD, feeCostUSD )} % setAccepted(checked)} /> } label={t('warning.checkbox.highValueLoss')} sx={{ mt: 1 }} /> ) }