From 6021bb38aa17f9bc31a4631221eddd038c132cb8 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Fri, 28 Apr 2023 16:44:01 +0700 Subject: [PATCH] feat: add recommended tag tooltip --- .../SwapRouteCard/SwapRouteCard.tsx | 97 +++++++++++++------ .../SwapRouteCard/SwapRouteCardEssentials.tsx | 12 ++- packages/widget/src/i18n/en.json | 1 + 3 files changed, 76 insertions(+), 34 deletions(-) diff --git a/packages/widget/src/components/SwapRouteCard/SwapRouteCard.tsx b/packages/widget/src/components/SwapRouteCard/SwapRouteCard.tsx index 8dc97d3be..46f0b6b35 100644 --- a/packages/widget/src/components/SwapRouteCard/SwapRouteCard.tsx +++ b/packages/widget/src/components/SwapRouteCard/SwapRouteCard.tsx @@ -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'; @@ -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 = ( {widgetVariant !== 'refuel' && (insurable || route.tags?.length) ? ( {insurable ? ( - - - {t('swap.insurance.insure')} - - - - {t('swap.insurance.bridgeExploits')} - - - {t('swap.insurance.slippageError')} - - - - } - placement="top" - enterDelay={400} - arrow - > + ) : null} - + ) : null} {route.tags?.length ? ( - - - {t(`swap.tags.${route.tags[0].toLowerCase()}` as any)} - - + + + + {t(`swap.tags.${route.tags[0].toLowerCase()}` as any)} + + + ) : null} ) : null} @@ -120,3 +102,54 @@ export const SwapRouteCard: React.FC< ); }; + +const InsuranceTooltip: React.FC> = ({ + children, +}) => { + const { t } = useTranslation(); + return ( + + + {t('swap.insurance.insure')} + + + + {t('swap.insurance.bridgeExploits')} + + + {t('swap.insurance.slippageError')} + + + + } + placement="top" + enterDelay={400} + arrow + > + {children} + + ); +}; + +const RecommendedTooltip: React.FC> = ({ + children, +}) => { + const { t } = useTranslation(); + return ( + + {children} + + ); +}; diff --git a/packages/widget/src/components/SwapRouteCard/SwapRouteCardEssentials.tsx b/packages/widget/src/components/SwapRouteCard/SwapRouteCardEssentials.tsx index 131c7c470..1f3e7d720 100644 --- a/packages/widget/src/components/SwapRouteCard/SwapRouteCardEssentials.tsx +++ b/packages/widget/src/components/SwapRouteCard/SwapRouteCardEssentials.tsx @@ -27,7 +27,11 @@ export const SwapRouteCardEssentials: React.FC< {t(`tooltip.estimatedNetworkFee`)} {gasCosts.map((gas, index) => ( - + {gas.amount?.toFixed(9)} {gas.token.symbol} ( {t(`format.currency`, { value: gas.amountUSD })}) @@ -57,7 +61,11 @@ export const SwapRouteCardEssentials: React.FC< {t(`tooltip.additionalProviderFee`)} {feeCosts.map((fee, index) => ( - + {fee.amount?.toFixed(9)} {fee.token.symbol} ( {t(`format.currency`, { value: fee.amountUSD })}) diff --git a/packages/widget/src/i18n/en.json b/packages/widget/src/i18n/en.json index 1ede01282..39d01bb2a 100644 --- a/packages/widget/src/i18n/en.json +++ b/packages/widget/src/i18n/en.json @@ -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": {