UNPKG

soso-widget

Version:

LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.

106 lines 8.24 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { ExpandLess, ExpandMore, LocalGasStationRounded, } from '@mui/icons-material'; import { Box, Collapse, Tooltip, Typography } from '@mui/material'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { formatUnits } from 'viem'; import { useWidgetConfig } from '../providers/WidgetProvider/WidgetProvider.js'; import { isRouteDone } from '../stores/routes/utils.js'; import { getAccumulatedFeeCostsBreakdown } from '../utils/fees.js'; import { formatTokenAmount } from '../utils/format.js'; import { getPriceImpact } from '../utils/getPriceImpact.js'; import { Card } from './Card/Card.js'; import { CardIconButton } from './Card/CardIconButton.js'; import { FeeBreakdownTooltip } from './FeeBreakdownTooltip.js'; import { IconTypography } from './IconTypography.js'; import { TokenRate } from './TokenRate/TokenRate.js'; export const TransactionDetails = ({ route, ...props }) => { const { t } = useTranslation(); const { feeConfig } = useWidgetConfig(); const [cardExpanded, setCardExpanded] = useState(false); const toggleCard = () => { setCardExpanded((cardExpanded) => !cardExpanded); }; const { gasCosts, feeCosts, gasCostUSD, feeCostUSD, combinedFeesUSD } = getAccumulatedFeeCostsBreakdown(route); const priceImpact = getPriceImpact({ fromAmount: BigInt(route.fromAmount), toAmount: BigInt(route.toAmount), fromToken: route.fromToken, toToken: route.toToken, }); const feeCollectionStep = route.steps[0].includedSteps.find((includedStep) => includedStep.tool === 'feeCollection'); let feeAmountUSD = 0; if (feeCollectionStep) { const estimatedFromAmount = BigInt(feeCollectionStep.estimate.fromAmount) - BigInt(feeCollectionStep.estimate.toAmount); const feeAmount = formatUnits(estimatedFromAmount, feeCollectionStep.action.fromToken.decimals); feeAmountUSD = Number.parseFloat(feeAmount) * Number.parseFloat(feeCollectionStep.action.fromToken.priceUSD); } const showIntegratorFeeCollectionDetails = feeAmountUSD || Number.isFinite(feeConfig?.fee); return (_jsxs(Card, { selectionColor: "secondary", ...props, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', px: 2, py: 1.75, }, children: [_jsx(Box, { sx: { display: 'flex', flex: 1, alignItems: 'center', justifyContent: 'left', }, children: _jsx(TokenRate, { route: route }) }), _jsx(Collapse, { timeout: 100, in: !cardExpanded, mountOnEnter: true, children: _jsx(FeeBreakdownTooltip, { gasCosts: gasCosts, feeCosts: feeCosts, children: _jsxs(Box, { onClick: toggleCard, // biome-ignore lint/a11y/useSemanticElements: role: "button", sx: { display: 'flex', alignItems: 'center', px: 1, cursor: 'pointer', }, children: [_jsx(IconTypography, { mr: 0.5, fontSize: 16, children: _jsx(LocalGasStationRounded, { fontSize: "inherit" }) }), _jsx(Typography, { "data-value": combinedFeesUSD, sx: { fontSize: 14, color: 'text.primary', fontWeight: '600', lineHeight: 1.429, }, children: t('format.currency', { value: combinedFeesUSD }) })] }) }) }), _jsx(CardIconButton, { onClick: toggleCard, size: "small", children: cardExpanded ? (_jsx(ExpandLess, { fontSize: "inherit" })) : (_jsx(ExpandMore, { fontSize: "inherit" })) })] }), _jsx(Collapse, { timeout: 225, in: cardExpanded, mountOnEnter: true, children: _jsxs(Box, { sx: { px: 2, pb: 2, }, children: [_jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', mb: 0.5, }, children: [_jsx(Typography, { variant: "body2", children: t('main.fees.network') }), _jsx(FeeBreakdownTooltip, { gasCosts: gasCosts, children: _jsx(Typography, { variant: "body2", children: t('format.currency', { value: gasCostUSD, }) }) })] }), feeCosts.length ? (_jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', mb: 0.5, }, children: [_jsx(Typography, { variant: "body2", children: t('main.fees.provider') }), _jsx(FeeBreakdownTooltip, { feeCosts: feeCosts, children: _jsx(Typography, { variant: "body2", children: t('format.currency', { value: feeCostUSD, }) }) })] })) : null, showIntegratorFeeCollectionDetails ? (_jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', mb: 0.5, }, children: [_jsx(Typography, { variant: "body2", children: feeConfig?.name ? t('main.fees.integrator', { tool: feeConfig.name }) : t('main.fees.defaultIntegrator') }), feeConfig?.name ? (_jsx(Tooltip, { title: t('tooltip.feeCollection', { tool: feeConfig.name }), sx: { cursor: 'help' }, children: _jsx(Typography, { variant: "body2", children: t('format.currency', { value: feeAmountUSD, }) }) })) : (_jsx(Typography, { variant: "body2", children: t('format.currency', { value: feeAmountUSD, }) }))] })) : null, _jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', mb: 0.5, }, children: [_jsx(Typography, { variant: "body2", children: t('main.priceImpact') }), _jsx(Tooltip, { title: t('tooltip.priceImpact'), sx: { cursor: 'help' }, children: _jsx(Typography, { variant: "body2", children: t('format.percent', { value: priceImpact }) }) })] }), !isRouteDone(route) ? (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', mb: 0.5, }, children: [_jsx(Typography, { variant: "body2", children: t('main.maxSlippage') }), _jsx(Tooltip, { title: t('tooltip.slippage'), sx: { cursor: 'help' }, children: _jsx(Typography, { variant: "body2", children: t('format.percent', { value: route.steps[0].action.slippage, }) }) })] }), _jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', }, children: [_jsx(Typography, { variant: "body2", children: t('main.minReceived') }), _jsx(Tooltip, { title: t('tooltip.minReceived'), sx: { cursor: 'help' }, children: _jsxs(Typography, { variant: "body2", children: [t('format.number', { value: formatTokenAmount(BigInt(route.toAmountMin), route.toToken.decimals), }), ' ', route.toToken.symbol] }) })] })] })) : null] }) })] })); }; //# sourceMappingURL=TransactionDetails.js.map