import type { Route } from '@lifi/sdk'; import WarningRoundedIcon from '@mui/icons-material/WarningRounded'; import { Box, Button, Typography } from '@mui/material'; import type { MutableRefObject } from 'react'; import { forwardRef, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import type { BottomSheetBase } from '../../components/BottomSheet'; import { BottomSheet } from '../../components/BottomSheet'; import { useSetContentHeight } from '../../hooks'; import { CenterContainer, IconCircle } from './StatusBottomSheet.style'; import { calcValueLoss } from './utils'; interface TokenValueBottomSheetProps { route: Route; onContinue(): void; onCancel?(): void; } export const TokenValueBottomSheet = forwardRef< BottomSheetBase, TokenValueBottomSheetProps >(({ route, onContinue, onCancel }, ref) => { const handleCancel = () => { (ref as MutableRefObject).current?.close(); onCancel?.(); }; return ( ); }); const TokenValueBottomSheetContent: React.FC = ({ route, onCancel, onContinue, }) => { const { t } = useTranslation(); const ref = useRef(); useSetContentHeight(ref); return ( {t('warning.title.highValueLoss')} {t('warning.message.highValueLoss')} {t('main.sending')} {t('format.currency', { value: route.fromAmountUSD })} {t('main.gasCost')} {t('format.currency', { value: route.gasCostUSD })} {t('main.receiving')} {t('format.currency', { value: route.toAmountUSD })} {t('main.valueLoss')} {calcValueLoss(route)} ); }; export const getTokenValueLossThreshold = (route?: Route) => { if (!route) { return false; } const fromAmountUSD = Number(route.fromAmountUSD || 0); const toAmountUSD = Number(route.toAmountUSD || 0); const gasCostUSD = Number(route.gasCostUSD || 0); if (!fromAmountUSD && !toAmountUSD) { return false; } return toAmountUSD / (fromAmountUSD + gasCostUSD) < 0.9; };