Skip to content

Commit

Permalink
feat: add text tooltips to price change and expando fields (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-toby authored Mar 17, 2023
1 parent 9d4c776 commit f0371e2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/components/Swap/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export function FieldWrapper({
<Row>
<USDC isLoading={isRouteLoading}>
{usdc && `${formatCurrencyAmount(usdc, NumberType.FiatTokenQuantity)}`}
<PriceImpactRow impact={fiatValueChange} />
<PriceImpactRow
impact={fiatValueChange}
tooltipText={t`The estimated difference between the USD values of input and output amounts.`}
/>
</USDC>
{balance && (
<Row gap={0.5}>
Expand Down
7 changes: 4 additions & 3 deletions src/components/Swap/PriceImpactRow.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { Trans } from '@lingui/macro'
import { formatPriceImpact } from '@uniswap/conedison/format'
import Row from 'components/Row'
import Tooltip, { SmallToolTipBody } from 'components/Tooltip'
import Tooltip, { SmallToolTipBody, TooltipText } from 'components/Tooltip'
import { PriceImpact } from 'hooks/usePriceImpact'
import { AlertTriangle } from 'icons'
import { ThemedText } from 'theme'

interface PriceImpactProps {
impact: PriceImpact | undefined | null
tooltipText?: string
reverse?: boolean
}

export function PriceImpactRow({ impact, reverse }: PriceImpactProps) {
export function PriceImpactRow({ impact, reverse, tooltipText }: PriceImpactProps) {
if (!impact) {
return null
}
return (
<Row gap={0.25} flex align="center" flow={reverse ? 'row-reverse' : 'row wrap'}>
<ThemedText.Body2 userSelect={false} color={impact.warning ?? 'hint'}>
({formatPriceImpact(impact?.percent)})
<TooltipText text={`(${formatPriceImpact(impact?.percent)})`}>{tooltipText}</TooltipText>
</ThemedText.Body2>
{impact?.warning && (
<Tooltip icon={AlertTriangle} iconProps={{ color: impact.warning }} data-testid="alert-tooltip">
Expand Down
12 changes: 6 additions & 6 deletions src/components/Swap/Toolbar/ToolbarTradeSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Column from 'components/Column'
import Row from 'components/Row'
import Tooltip from 'components/Tooltip'
import Tooltip, { TooltipText } from 'components/Tooltip'
import { Icon } from 'icons'
import { ReactNode } from 'react'
import styled from 'styled-components/macro'
Expand Down Expand Up @@ -31,7 +31,6 @@ export interface SummaryRowProps {
color?: Color
nameTooltip?: {
content: ReactNode
icon: Icon
}
valueTooltip?: {
content: ReactNode
Expand All @@ -44,10 +43,11 @@ function SummaryRow({ name, value, color, nameTooltip, valueTooltip }: SummaryRo
<Row>
{nameTooltip ? (
<Row gap={0.25}>
<TradeAttributeName color={color}>{name}</TradeAttributeName>
<Tooltip icon={nameTooltip.icon} iconProps={{ color }} placement="auto">
{nameTooltip.content}
</Tooltip>
<TradeAttributeName color={color}>
<TooltipText text={name} placement="top">
<ThemedText.Caption>{nameTooltip.content}</ThemedText.Caption>
</TooltipText>
</TradeAttributeName>
</Row>
) : (
<TradeAttributeName color={color}>{name}</TradeAttributeName>
Expand Down
12 changes: 7 additions & 5 deletions src/components/Swap/Toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import Column from 'components/Column'
import Expando from 'components/Expando'
import { ChainError, useIsAmountPopulated, useSwapInfo } from 'hooks/swap'
import { useIsWrap } from 'hooks/swap/useWrapCallback'
import { AlertTriangle, Info } from 'icons'
import { AlertTriangle } from 'icons'
import { memo, ReactNode, useCallback, useContext, useMemo } from 'react'
import { TradeState } from 'state/routing/types'
import { Field } from 'state/swap'
import styled from 'styled-components/macro'

import Row from '../../Row'
import SwapInputOutputEstimate, { getEstimateMessage } from '../Summary/Estimate'
import { getEstimateMessage } from '../Summary/Estimate'
import SwapActionButton from '../SwapActionButton'
import * as Caption from './Caption'
import { Context as ToolbarContext, Provider as ToolbarContextProvider } from './ToolbarContext'
Expand Down Expand Up @@ -113,15 +113,17 @@ function CaptionRow() {

const tradeSummaryRows: SummaryRowProps[] = useMemo(() => {
const currencySymbol = trade?.outputAmount?.currency.symbol ?? ''
const { descriptor, value } = getEstimateMessage(trade, slippage)
const { descriptor, value, estimateMessage } = getEstimateMessage(trade, slippage)
const rows: SummaryRowProps[] = [
{
name: t`Network fee`,
nameTooltip: { content: t`The fee paid to miners to process your transaction. This must be paid in ETH.` },
value: gasUseEstimateUSD ? `~${formatCurrencyAmount(gasUseEstimateUSD, NumberType.FiatGasPrice)}` : '-',
},
{
color: impact?.warning,
name: t`Price impact`,
nameTooltip: { content: t`The impact your trade has on the market price of this pool.` },
value: impact?.percent ? formatPriceImpact(impact.percent) : '-',
valueTooltip: impact?.warning
? {
Expand All @@ -134,14 +136,14 @@ function CaptionRow() {
// min/max output/input after slippage
name: <div style={{ marginRight: '0.5em' }}>{descriptor}</div>,
value,
nameTooltip: { content: estimateMessage },
},
{
name: t`Expected output`,
value: trade ? `${formatCurrencyAmount(trade?.outputAmount)} ${currencySymbol}` : '-',
nameTooltip: trade
? {
icon: Info,
content: <SwapInputOutputEstimate trade={trade} slippage={slippage} />,
content: t`The amount you expect to receive at the current market price. You may receive less or more if the market price changes while your transaction is pending.`,
}
: undefined,
},
Expand Down

1 comment on commit f0371e2

@vercel
Copy link

@vercel vercel bot commented on f0371e2 Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

widgets – ./

widgets-seven-tau.vercel.app
widgets-git-main-uniswap.vercel.app
widgets-uniswap.vercel.app

Please sign in to comment.