Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit b8998ef

Browse files
authored
revert: "fix: remove USD value impact" (#525)
* Revert "fix: remove USD value impact (#457)" This reverts commit d51888a. * fix: use USD value change in output field * feat: improvements to slippage * fix: add testg * fix: string consistency * fix: use correct formatting * fix: rename prop
1 parent dd65824 commit b8998ef

14 files changed

+125
-119
lines changed

src/components/Swap/Input.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ interface FieldWrapperProps {
8585
field: Field
8686
maxAmount?: string
8787
approved?: boolean
88-
impact?: PriceImpact
88+
fiatValueChange?: PriceImpact
8989
subheader: string
9090
}
9191

9292
export function FieldWrapper({
9393
field,
9494
maxAmount,
9595
approved,
96-
impact,
96+
fiatValueChange,
9797
className,
9898
subheader,
9999
}: FieldWrapperProps & { className?: string }) {
@@ -164,7 +164,7 @@ export function FieldWrapper({
164164
<Row>
165165
<USDC isLoading={isRouteLoading}>
166166
{usdc && `${formatCurrencyAmount(usdc, NumberType.FiatTokenQuantity)}`}
167-
<PriceImpactRow impact={impact} />
167+
<PriceImpactRow impact={fiatValueChange} />
168168
</USDC>
169169
{balance && (
170170
<Row gap={0.5}>

src/components/Swap/Output.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ const OutputWrapper = styled(FieldWrapper)<{ hasColor?: boolean | null; isWide:
2828
`
2929

3030
export default function Output() {
31-
const { impact } = useSwapInfo()
32-
31+
const { fiatValueChange } = useSwapInfo()
3332
const [currency] = useSwapCurrency(Field.OUTPUT)
3433
const overrideColor = useAtomValue(colorAtom)
3534
const dynamicColor = useCurrencyColor(currency)
@@ -43,7 +42,7 @@ export default function Output() {
4342
<OutputWrapper
4443
isWide={isWideWidget}
4544
field={Field.OUTPUT}
46-
impact={impact}
45+
fiatValueChange={fiatValueChange}
4746
hasColor={hasColor}
4847
subheader={t`You receive`}
4948
/>

src/components/Swap/Settings/MaxSlippageSelect.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Trans } from '@lingui/macro'
22
import Expando, { IconPrefix } from 'components/Expando'
33
import Popover from 'components/Popover'
44
import { useTooltip } from 'components/Tooltip'
5+
import { useSwapInfo } from 'hooks/swap'
56
import { getSlippageWarning, toPercent } from 'hooks/useSlippage'
67
import { Expando as ExpandoIcon } from 'icons'
78
import { AlertTriangle, Check, Icon, LargeIcon, XOctagon } from 'icons'
@@ -144,6 +145,8 @@ export default function MaxSlippageSelect() {
144145
[setSlippage]
145146
)
146147

148+
const { slippage: allowedSlippage } = useSwapInfo()
149+
147150
const [open, setOpen] = useState(false)
148151
return (
149152
<Column gap={0.75}>
@@ -190,7 +193,7 @@ export default function MaxSlippageSelect() {
190193
size={Math.max(maxSlippageInput.length, 4)}
191194
value={maxSlippageInput}
192195
onChange={(input) => processInput(input)}
193-
placeholder={'0.10'}
196+
placeholder={allowedSlippage.allowed.toFixed(2)}
194197
ref={input}
195198
data-testid="input-slippage"
196199
maxLength={10}

src/components/Swap/Summary/Details.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default function Details({ trade, slippage, gasUseEstimateUSD, inputUSDC,
156156
details.push([t`Price impact`, impact?.percent ? impact?.toString() : '-', impact.warning])
157157
}
158158

159-
const { estimateMessage, descriptor, value } = getEstimateMessage(trade, slippage, impact)
159+
const { estimateMessage, descriptor, value } = getEstimateMessage(trade, slippage)
160160
details.push([descriptor, value])
161161

162162
return { details, estimateMessage }

src/components/Swap/Summary/Estimate.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { t, Trans } from '@lingui/macro'
22
import { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
3-
import { PriceImpact } from 'hooks/usePriceImpact'
4-
import { Slippage } from 'hooks/useSlippage'
3+
import { formatSlippage, Slippage } from 'hooks/useSlippage'
54
import { ReactNode, useMemo } from 'react'
65
import { InterfaceTrade } from 'state/routing/types'
76
import styled from 'styled-components/macro'
@@ -20,22 +19,25 @@ interface EstimateProps {
2019
}
2120

2221
export default function SwapInputOutputEstimate({ trade, slippage }: EstimateProps) {
23-
const { estimateMessage } = useMemo(
24-
() => getEstimateMessage(trade, slippage, undefined /* priceImpact */),
25-
[slippage, trade]
26-
)
22+
const { estimateMessage } = useMemo(() => getEstimateMessage(trade, slippage), [slippage, trade])
2723
return <StyledEstimate color="secondary">{estimateMessage}</StyledEstimate>
2824
}
2925

3026
export function getEstimateMessage(
31-
trade: InterfaceTrade,
32-
slippage: Slippage,
33-
priceImpact: PriceImpact | undefined
27+
trade: InterfaceTrade | undefined,
28+
slippage: Slippage
3429
): {
3530
estimateMessage: string
3631
descriptor: ReactNode
3732
value: string
3833
} {
34+
if (!trade) {
35+
return {
36+
estimateMessage: '',
37+
descriptor: '',
38+
value: '-',
39+
}
40+
}
3941
const { inputAmount, outputAmount } = trade
4042
const inputCurrency = inputAmount.currency
4143
const outputCurrency = outputAmount.currency
@@ -49,10 +51,10 @@ export function getEstimateMessage(
4951
descriptor: (
5052
<ThemedText.Body2>
5153
<Trans>Minimum output after slippage</Trans>
52-
{priceImpact && (
54+
{slippage && (
5355
<ThemedText.Body2 $inline color={slippage?.warning ?? 'secondary'}>
5456
{' '}
55-
({priceImpact?.toString()})
57+
({formatSlippage(slippage)})
5658
</ThemedText.Body2>
5759
)}
5860
</ThemedText.Body2>
@@ -68,10 +70,10 @@ export function getEstimateMessage(
6870
descriptor: (
6971
<ThemedText.Body2>
7072
<Trans>Maximum input after slippage</Trans>
71-
{priceImpact && (
73+
{slippage && (
7274
<ThemedText.Body2 $inline color={slippage?.warning ?? 'secondary'}>
7375
{' '}
74-
({priceImpact?.toString()})
76+
({formatSlippage(slippage)})
7577
</ThemedText.Body2>
7678
)}
7779
</ThemedText.Body2>

src/components/Swap/TokenInput.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ const TokenInputRow = styled(Row)`
1818

1919
const ValueInput = styled(DecimalInput)`
2020
color: ${({ theme }) => theme.primary};
21-
height: 1.5rem;
22-
margin: -0.25rem 0;
2321
24-
${loadingTransitionCss};
22+
${loadingTransitionCss}
2523
`
2624

2725
const TokenInputColumn = styled(Column)`

src/components/Swap/Toolbar/index.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import { memo, ReactNode, useCallback, useContext, useMemo } from 'react'
1010
import { TradeState } from 'state/routing/types'
1111
import { Field } from 'state/swap'
1212
import styled from 'styled-components/macro'
13-
import { ThemedText } from 'theme'
1413

1514
import Row from '../../Row'
16-
import SwapInputOutputEstimate from '../Summary/Estimate'
15+
import SwapInputOutputEstimate, { getEstimateMessage } from '../Summary/Estimate'
1716
import SwapActionButton from '../SwapActionButton'
1817
import * as Caption from './Caption'
1918
import { Context as ToolbarContext, Provider as ToolbarContextProvider } from './ToolbarContext'
@@ -111,6 +110,7 @@ function CaptionRow() {
111110

112111
const tradeSummaryRows: SummaryRowProps[] = useMemo(() => {
113112
const currencySymbol = trade?.outputAmount?.currency.symbol ?? ''
113+
const { descriptor, value } = getEstimateMessage(trade, slippage)
114114
const rows: SummaryRowProps[] = [
115115
{
116116
name: t`Network fee`,
@@ -128,16 +128,9 @@ function CaptionRow() {
128128
: undefined,
129129
},
130130
{
131-
name: (
132-
<ThemedText.Body2 marginRight="0.25rem">
133-
<Trans>Minimum output after slippage </Trans>
134-
<ThemedText.Body2 $inline color={impact?.warning ?? 'secondary'}>
135-
{' '}
136-
({impact?.toString()})
137-
</ThemedText.Body2>
138-
</ThemedText.Body2>
139-
),
140-
value: trade ? `${formatCurrencyAmount(trade?.minimumAmountOut(slippage.allowed))} ${currencySymbol}` : '-',
131+
// min/max output/input after slippage
132+
name: <div style={{ marginRight: '0.25em' }}>{descriptor}</div>,
133+
value,
141134
},
142135
{
143136
name: t`Expected output`,

src/components/Swap/index.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ export default function Swap(props: SwapProps) {
4848

4949
return (
5050
<>
51-
<Header title={<Trans>Swap</Trans>}>
52-
<Wallet disabled={props.hideConnectionUI} />
53-
<Settings />
54-
</Header>
55-
<div ref={setWrapper}>
56-
<PopoverBoundaryProvider value={wrapper}>
57-
<SwapInfoProvider>
51+
<SwapInfoProvider>
52+
<Header title={<Trans>Swap</Trans>}>
53+
<Wallet disabled={props.hideConnectionUI} />
54+
<Settings />
55+
</Header>
56+
<div ref={setWrapper}>
57+
<PopoverBoundaryProvider value={wrapper}>
5858
<Input />
5959
<ReverseButton />
6060
<Output />
6161
<Toolbar />
6262
{useBrandedFooter() && <BrandedFooter />}
63-
</SwapInfoProvider>
64-
</PopoverBoundaryProvider>
65-
</div>
63+
</PopoverBoundaryProvider>
64+
</div>
65+
</SwapInfoProvider>
6666
{displayTx && (
6767
<Dialog color="dialog">
6868
<StatusDialog tx={displayTx} onClose={() => setDisplayTxHash()} />

src/hooks/swap/useSwapInfo.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useRouterTrade } from 'hooks/routing/useRouterTrade'
66
import { useCurrencyBalances } from 'hooks/useCurrencyBalance'
77
import useOnSupportedNetwork from 'hooks/useOnSupportedNetwork'
88
import usePermit2Allowance, { Allowance, AllowanceState } from 'hooks/usePermit2Allowance'
9-
import { PriceImpact, usePriceImpact } from 'hooks/usePriceImpact'
9+
import { PriceImpact, useFiatValueChange, usePriceImpact } from 'hooks/usePriceImpact'
1010
import useSlippage, { DEFAULT_SLIPPAGE, Slippage } from 'hooks/useSlippage'
1111
import { usePermit2 as usePermit2Enabled } from 'hooks/useSyncFlags'
1212
import useUSDCPrice, { useUSDCValue } from 'hooks/useUSDCPrice'
@@ -50,6 +50,7 @@ interface SwapInfo {
5050
allowance: Allowance
5151
slippage: Slippage
5252
impact?: PriceImpact
53+
fiatValueChange?: PriceImpact
5354
}
5455

5556
/** Returns the best computed swap (trade/wrap). */
@@ -105,6 +106,7 @@ function useComputeSwapInfo(): SwapInfo {
105106
// Wait until the trade is valid to avoid displaying incorrect intermediate values.
106107
const slippage = useSlippage(trade)
107108
const impact = usePriceImpact(trade.trade)
109+
const fiatValueChange = useFiatValueChange(trade.trade)
108110

109111
const permit2Enabled = usePermit2Enabled()
110112
const maximumAmountIn = useMemo(() => {
@@ -137,6 +139,7 @@ function useComputeSwapInfo(): SwapInfo {
137139
allowance,
138140
slippage,
139141
impact,
142+
fiatValueChange,
140143
}
141144
}, [
142145
allowance,
@@ -148,6 +151,7 @@ function useComputeSwapInfo(): SwapInfo {
148151
currencyIn,
149152
currencyOut,
150153
error,
154+
fiatValueChange,
151155
impact,
152156
slippage,
153157
trade,

src/hooks/useAllCurrencyCombinations.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/hooks/usePriceImpact.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { Percent } from '@uniswap/sdk-core'
22
import { useMemo } from 'react'
33
import { InterfaceTrade } from 'state/routing/types'
4+
import { computeFiatValuePriceImpact } from 'utils/computeFiatValuePriceImpact'
45
import { computeRealizedPriceImpact, getPriceImpactWarning } from 'utils/prices'
56

7+
import { useUSDCValue } from './useUSDCPrice'
8+
69
export interface PriceImpact {
710
percent: Percent
811
warning?: 'warning' | 'error'
@@ -22,6 +25,21 @@ export function usePriceImpact(trade?: InterfaceTrade): PriceImpact | undefined
2225
}, [trade])
2326
}
2427

28+
export function useFiatValueChange(trade?: InterfaceTrade) {
29+
const [inputUSDCValue, outputUSDCValue] = [useUSDCValue(trade?.inputAmount), useUSDCValue(trade?.outputAmount)]
30+
return useMemo(() => {
31+
const fiatPriceImpact = computeFiatValuePriceImpact(inputUSDCValue, outputUSDCValue)
32+
if (!fiatPriceImpact) {
33+
return undefined
34+
}
35+
return {
36+
percent: fiatPriceImpact,
37+
warning: getPriceImpactWarning(fiatPriceImpact),
38+
toString: () => toHumanReadablePercent(fiatPriceImpact),
39+
}
40+
}, [inputUSDCValue, outputUSDCValue])
41+
}
42+
2543
export function toHumanReadablePercent(priceImpact: Percent): string {
2644
const sign = priceImpact.lessThan(0) ? '+' : ''
2745
const exactFloat = (Number(priceImpact.numerator) / Number(priceImpact.denominator)) * 100

0 commit comments

Comments
 (0)