Skip to content

Commit

Permalink
feat: add recommended tag tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Apr 28, 2023
1 parent 6fd0c06 commit 6021bb3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 34 deletions.
97 changes: 65 additions & 32 deletions packages/widget/src/components/SwapRouteCard/SwapRouteCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import type { TokenAmount } from '@lifi/sdk';
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import VerifiedUserIcon from '@mui/icons-material/VerifiedUser';
import type { TooltipProps } from '@mui/material';
import { Box, Collapse, Tooltip, Typography } from '@mui/material';
import type { MouseEventHandler } from 'react';
import { useState } from 'react';
import { Fragment, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useWidgetConfig } from '../../providers';
import type { CardProps } from '../Card';
Expand Down Expand Up @@ -32,36 +33,15 @@ export const SwapRouteCard: React.FC<
? { ...route.fromToken, amount: route.fromAmount }
: { ...route.toToken, amount: route.toAmount };

const RecommendedTagTooltip =
route.tags?.[0] === 'RECOMMENDED' ? RecommendedTooltip : Fragment;

const cardContent = (
<Box flex={1}>
{widgetVariant !== 'refuel' && (insurable || route.tags?.length) ? (
<Box display="flex" alignItems="center" mb={2}>
{insurable ? (
<Tooltip
title={
<Box component="span">
<Typography fontSize={12}>
{t('swap.insurance.insure')}
</Typography>
<Box
sx={{
listStyleType: 'disc',
pl: 2,
}}
>
<Typography fontSize={12} display="list-item">
{t('swap.insurance.bridgeExploits')}
</Typography>
<Typography fontSize={12} display="list-item">
{t('swap.insurance.slippageError')}
</Typography>
</Box>
</Box>
}
placement="top"
enterDelay={400}
arrow
>
<InsuranceTooltip>
<CardLabel
type={
route.tags?.length && !cardExpanded
Expand All @@ -76,14 +56,16 @@ export const SwapRouteCard: React.FC<
</CardLabelTypography>
) : null}
</CardLabel>
</Tooltip>
</InsuranceTooltip>
) : null}
{route.tags?.length ? (
<CardLabel type={active ? 'active' : undefined}>
<CardLabelTypography>
{t(`swap.tags.${route.tags[0].toLowerCase()}` as any)}
</CardLabelTypography>
</CardLabel>
<RecommendedTagTooltip>
<CardLabel type={active ? 'active' : undefined}>
<CardLabelTypography>
{t(`swap.tags.${route.tags[0].toLowerCase()}` as any)}
</CardLabelTypography>
</CardLabel>
</RecommendedTagTooltip>
) : null}
</Box>
) : null}
Expand Down Expand Up @@ -120,3 +102,54 @@ export const SwapRouteCard: React.FC<
</Card>
);
};

const InsuranceTooltip: React.FC<Pick<TooltipProps, 'children'>> = ({
children,
}) => {
const { t } = useTranslation();
return (
<Tooltip
title={
<Box component="span">
<Typography fontSize={12} fontWeight="500">
{t('swap.insurance.insure')}
</Typography>
<Box
sx={{
listStyleType: 'disc',
pl: 2,
}}
>
<Typography fontSize={12} fontWeight="500" display="list-item">
{t('swap.insurance.bridgeExploits')}
</Typography>
<Typography fontSize={12} fontWeight="500" display="list-item">
{t('swap.insurance.slippageError')}
</Typography>
</Box>
</Box>
}
placement="top"
enterDelay={400}
arrow
>
{children}
</Tooltip>
);
};

const RecommendedTooltip: React.FC<Pick<TooltipProps, 'children'>> = ({
children,
}) => {
const { t } = useTranslation();
return (
<Tooltip
title={t('tooltip.recommended')}
placement="top"
enterDelay={400}
arrow
>
{children}
</Tooltip>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export const SwapRouteCardEssentials: React.FC<
<Box component="span">
{t(`tooltip.estimatedNetworkFee`)}
{gasCosts.map((gas, index) => (
<Typography fontSize={12} key={`${gas.token.address}${index}`}>
<Typography
fontSize={12}
fontWeight="500"
key={`${gas.token.address}${index}`}
>
{gas.amount?.toFixed(9)} {gas.token.symbol} (
{t(`format.currency`, { value: gas.amountUSD })})
</Typography>
Expand Down Expand Up @@ -57,7 +61,11 @@ export const SwapRouteCardEssentials: React.FC<
<Box component="span">
{t(`tooltip.additionalProviderFee`)}
{feeCosts.map((fee, index) => (
<Typography fontSize={12} key={`${fee.token.address}${index}`}>
<Typography
fontSize={12}
fontWeight="500"
key={`${fee.token.address}${index}`}
>
{fee.amount?.toFixed(9)} {fee.token.symbol} (
{t(`format.currency`, { value: fee.amountUSD })})
</Typography>
Expand Down
1 change: 1 addition & 0 deletions packages/widget/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
},
"numberOfSteps": "A number of swap steps. Each step can contain 1-2 transactions that require a signature.",
"progressToNextUpdate": "Displayed data will auto-refresh after {{value}} seconds. Click here to update manually.",
"recommended": "A cheap route that balances complexity and ease of use.",
"settingsModified": "Settings (modified)"
},
"wallet": {
Expand Down

0 comments on commit 6021bb3

Please sign in to comment.