import type { Route } from '@lifi/sdk' import WarningRounded from '@mui/icons-material/WarningRounded' import { Box, Button, Typography } from '@mui/material' import type { RefObject } from 'react' import { forwardRef, useRef } 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 { useSetContentHeight } from '../../hooks/useSetContentHeight.js' import { getAccumulatedFeeCostsBreakdown } from '../../utils/fees.js' import { CenterContainer, IconCircle } from './StatusBottomSheet.style.js' import { calculateValueLossPercentage } from './utils.js' interface TokenValueBottomSheetProps { route: Route onContinue(): void onCancel?(): void } export const TokenValueBottomSheet = forwardRef< BottomSheetBase, TokenValueBottomSheetProps >(({ route, onContinue, onCancel }, ref) => { const handleCancel = () => { ;(ref as RefObject).current?.close() onCancel?.() } return ( ) }) const TokenValueBottomSheetContent: React.FC = ({ route, onCancel, onContinue, }) => { 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 )} % ) }