Skip to content

Commit a164dca

Browse files
rawasabiben2x4
andauthored
Revert "Price Impact UI (#259)" (#261)
This reverts commit 168c134. Co-authored-by: ben2x4 <86395884+ben2x4@users.noreply.github.com>
1 parent 168c134 commit a164dca

3 files changed

Lines changed: 48 additions & 93 deletions

File tree

features/liquidity/components/ManagePoolDialog/TokenToTokenRates.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ export const TokenToTokenRates = ({
1717
tokenBSymbol,
1818
})
1919

20-
const {
21-
isShowing,
22-
conversionRate,
23-
conversionRateInDollar,
24-
tokenBSwapValueUSD,
25-
} = useTxRates({
26-
tokenASymbol,
27-
tokenBSymbol,
28-
tokenAAmount,
29-
tokenToTokenPrice: oneTokenToTokenPrice * tokenAAmount,
30-
isLoading,
31-
})
20+
const { isShowing, conversionRate, conversionRateInDollar, dollarValue } =
21+
useTxRates({
22+
tokenASymbol,
23+
tokenBSymbol,
24+
tokenAAmount,
25+
tokenToTokenPrice: oneTokenToTokenPrice * tokenAAmount,
26+
isLoading,
27+
})
3228

3329
return (
3430
<StyledDivForGrid active={isShowing}>
@@ -41,7 +37,7 @@ export const TokenToTokenRates = ({
4137
</Text>
4238
<Text variant="caption" color="disabled">
4339
$
44-
{dollarValueFormatterWithDecimals(tokenBSwapValueUSD * 2, {
40+
{dollarValueFormatterWithDecimals(dollarValue * 2, {
4541
includeCommaSeparation: true,
4642
})}
4743
</Text>

features/swap/components/TransactionTips.tsx

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
ArrowUpIcon,
32
Button,
43
Column,
54
dollarValueFormatterWithDecimals,
@@ -9,7 +8,6 @@ import {
98
Inline,
109
styled,
1110
Text,
12-
Tooltip,
1311
} from 'junoblocks'
1412
import React, { useState } from 'react'
1513
import { useRecoilValue } from 'recoil'
@@ -38,19 +36,14 @@ export const TransactionTips = ({
3836
tokenAmount: tokenA?.amount || 1,
3937
})
4038

41-
const {
42-
isShowing,
43-
conversionRate,
44-
conversionRateInDollar,
45-
tokenASwapValueUSD,
46-
tokenBSwapValueUSD,
47-
} = useTxRates({
48-
tokenASymbol: tokenA?.tokenSymbol,
49-
tokenBSymbol: tokenB?.tokenSymbol,
50-
tokenAAmount: tokenA?.amount || 1,
51-
tokenToTokenPrice,
52-
isLoading: isPriceLoading,
53-
})
39+
const { isShowing, conversionRate, conversionRateInDollar, dollarValue } =
40+
useTxRates({
41+
tokenASymbol: tokenA?.tokenSymbol,
42+
tokenBSymbol: tokenB?.tokenSymbol,
43+
tokenAAmount: tokenA?.amount || 1,
44+
tokenToTokenPrice,
45+
isLoading: isPriceLoading,
46+
})
5447

5548
const switchTokensButton = (
5649
<Button
@@ -79,23 +72,9 @@ export const TransactionTips = ({
7972
</>
8073
)
8174

82-
const priceImpact =
83-
(tokenBSwapValueUSD - tokenASwapValueUSD) / tokenASwapValueUSD
84-
const formattedPriceImpact = Math.abs(Math.round(priceImpact * 10000) / 100)
85-
const errorThreshold = priceImpact < -0.05
86-
87-
const tokenAFormattedSwapValue = dollarValueFormatterWithDecimals(
88-
tokenASwapValueUSD,
89-
{
90-
includeCommaSeparation: true,
91-
}
92-
)
93-
const tokenBFormattedSwapValue = dollarValueFormatterWithDecimals(
94-
tokenBSwapValueUSD,
95-
{
96-
includeCommaSeparation: true,
97-
}
98-
)
75+
const formattedDollarValue = dollarValueFormatterWithDecimals(dollarValue, {
76+
includeCommaSeparation: true,
77+
})
9978

10079
if (size === 'small') {
10180
return (
@@ -114,7 +93,7 @@ export const TransactionTips = ({
11493
{transactionRates}
11594
</Text>
11695
<Text variant="caption" color="disabled" wrap={false}>
117-
Swap estimate: ${tokenBFormattedSwapValue}
96+
Swap estimate: ${formattedDollarValue}
11897
</Text>
11998
</Column>
12099
)}
@@ -133,44 +112,8 @@ export const TransactionTips = ({
133112
</Text>
134113
)}
135114
</StyledDivForRateWrapper>
136-
<Inline justifyContent={'flex-end'} gap={8} css={{ cursor: 'pointer' }}>
137-
{tokenB?.tokenSymbol && (
138-
<Tooltip label="Price impact due to the amount of liquity available in the pool.">
139-
<Inline
140-
css={{
141-
backgroundColor: errorThreshold
142-
? '$backgroundColors$error'
143-
: '$backgroundColors$secondary',
144-
padding: '$2 $4 $2 $2',
145-
borderRadius: 4,
146-
}}
147-
>
148-
<ArrowUpIcon
149-
color={errorThreshold ? 'error' : 'secondary'}
150-
css={{
151-
transform: priceImpact < 0 ? 'rotate(180deg)' : undefined,
152-
}}
153-
size="medium"
154-
/>
155-
<Text
156-
variant="legend"
157-
wrap={false}
158-
css={{
159-
color: errorThreshold
160-
? '$textColors$error'
161-
: '$textColors$secondary',
162-
}}
163-
>
164-
{formattedPriceImpact}%
165-
</Text>
166-
</Inline>
167-
</Tooltip>
168-
)}
169-
<Column gap={4}>
170-
<Text variant="legend">${tokenAFormattedSwapValue}</Text>
171-
<Text variant="legend">${tokenBFormattedSwapValue}</Text>
172-
</Column>
173-
</Inline>
115+
116+
<Text variant="legend">${formattedDollarValue}</Text>
174117
</StyledDivForWrapper>
175118
)
176119
}

features/swap/hooks/useTxRates.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,36 @@ function calculateTokenToTokenConversionRate({
1616
return tokenToTokenPrice / tokenAAmount
1717
}
1818

19+
function calculateTokenToTokenConversionDollarRate({
20+
conversionRate,
21+
tokenADollarPrice,
22+
oneTokenToTokenPrice,
23+
tokenAAmount,
24+
}) {
25+
if (tokenAAmount === 0) {
26+
return tokenADollarPrice
27+
}
28+
29+
return (tokenADollarPrice * conversionRate) / oneTokenToTokenPrice
30+
}
31+
1932
export const useTxRates = ({
2033
tokenASymbol,
2134
tokenBSymbol,
2235
tokenAAmount,
2336
tokenToTokenPrice,
2437
isLoading,
2538
}) => {
26-
const [tokenADollarValue, fetchingTokenDollarPrice] =
39+
const [tokenADollarPrice, fetchingTokenDollarPrice] =
2740
useTokenDollarValue(tokenASymbol)
2841

2942
const [oneTokenToTokenPrice] = usePriceForOneToken({
3043
tokenASymbol: tokenASymbol,
3144
tokenBSymbol: tokenBSymbol,
3245
})
3346

47+
const dollarValue = (tokenADollarPrice || 0) * (tokenAAmount || 0)
48+
3449
const shouldShowRates =
3550
(tokenASymbol &&
3651
tokenBSymbol &&
@@ -51,22 +66,23 @@ export const useTxRates = ({
5166
)
5267
)
5368

54-
const [tokenBDollarValue] = useTokenDollarValue(tokenBSymbol)
5569
const conversionRateInDollar = usePersistance(
5670
isLoading || fetchingTokenDollarPrice || !shouldShowRates
5771
? undefined
58-
: protectAgainstNaN(conversionRate * tokenBDollarValue)
72+
: protectAgainstNaN(
73+
calculateTokenToTokenConversionDollarRate({
74+
tokenAAmount,
75+
conversionRate,
76+
tokenADollarPrice,
77+
oneTokenToTokenPrice,
78+
})
79+
)
5980
)
6081

61-
const tokenASwapValueUSD = (tokenADollarValue || 0) * (tokenAAmount || 0)
62-
const tokenBSwapValueUSD =
63-
(tokenBDollarValue || 0) * (tokenAAmount * conversionRate || 0)
64-
6582
return {
6683
isShowing: Boolean(shouldShowRates),
6784
conversionRate,
6885
conversionRateInDollar,
69-
tokenASwapValueUSD,
70-
tokenBSwapValueUSD,
86+
dollarValue,
7187
}
7288
}

0 commit comments

Comments
 (0)