Commit b39aeeb8 authored by Noah Zinsmeister's avatar Noah Zinsmeister

fix for inactive positions

parent 660c3552
...@@ -33,15 +33,27 @@ export const DarkBadge = styled.div` ...@@ -33,15 +33,27 @@ export const DarkBadge = styled.div`
padding: 4px 6px; padding: 4px 6px;
` `
export default function RangeBadge({ inRange }: { inRange?: boolean }) { export default function RangeBadge({
removed,
inRange,
}: {
removed: boolean | undefined
inRange: boolean | undefined
}) {
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
<BadgeWrapper> <BadgeWrapper>
{inRange ? ( {removed ? (
<MouseoverTooltip <MouseoverTooltip text={`Your position has 0 liquidity, and is not earning fees.`}>
text={`The price of this pair is within your selected range. Your positions is earning fees.`} <Badge variant={BadgeVariant.WARNING_OUTLINE}>
> <AlertCircle width={14} height={14} />
&nbsp;
<BadgeText>{t('Inactive')}</BadgeText>
</Badge>
</MouseoverTooltip>
) : inRange ? (
<MouseoverTooltip text={`The price of this pool is within your selected range. Your position is earning fees.`}>
<Badge variant={BadgeVariant.DEFAULT}> <Badge variant={BadgeVariant.DEFAULT}>
<ActiveDot /> &nbsp; <ActiveDot /> &nbsp;
<BadgeText>{t('In range')}</BadgeText> <BadgeText>{t('In range')}</BadgeText>
...@@ -49,7 +61,7 @@ export default function RangeBadge({ inRange }: { inRange?: boolean }) { ...@@ -49,7 +61,7 @@ export default function RangeBadge({ inRange }: { inRange?: boolean }) {
</MouseoverTooltip> </MouseoverTooltip>
) : ( ) : (
<MouseoverTooltip <MouseoverTooltip
text={`The price of this pair is outside of your selected range. Your positions is not earning fees.`} text={`The price of this pool is outside of your selected range. Your position is not earning fees.`}
> >
<Badge variant={BadgeVariant.WARNING}> <Badge variant={BadgeVariant.WARNING}>
<AlertCircle width={14} height={14} /> <AlertCircle width={14} height={14} />
......
import React, { useMemo, useState } from 'react' import React, { useMemo, useState } from 'react'
import { Position } from '@uniswap/v3-sdk' import { Position } from '@uniswap/v3-sdk'
import Badge, { BadgeVariant } from 'components/Badge' import Badge from 'components/Badge'
import DoubleCurrencyLogo from 'components/DoubleLogo' import DoubleCurrencyLogo from 'components/DoubleLogo'
import { usePool } from 'hooks/usePools' import { usePool } from 'hooks/usePools'
import { useToken } from 'hooks/Tokens' import { useToken } from 'hooks/Tokens'
import { AlertCircle } from 'react-feather'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import styled from 'styled-components' import styled from 'styled-components'
import { HideSmall, MEDIA_WIDTHS, SmallOnly } from 'theme' import { HideSmall, MEDIA_WIDTHS, SmallOnly } from 'theme'
...@@ -15,16 +13,9 @@ import { formatPrice } from 'utils/formatTokenAmount' ...@@ -15,16 +13,9 @@ import { formatPrice } from 'utils/formatTokenAmount'
import Loader from 'components/Loader' import Loader from 'components/Loader'
import { unwrappedToken } from 'utils/wrappedCurrency' import { unwrappedToken } from 'utils/wrappedCurrency'
import { DAI, USDC, USDT, WBTC } from '../../constants' import { DAI, USDC, USDT, WBTC } from '../../constants'
import { MouseoverTooltip } from '../Tooltip' import RangeBadge from 'components/Badge/RangeBadge'
import { RowFixed } from 'components/Row' import { RowFixed } from 'components/Row'
const ActiveDot = styled.span`
background-color: ${({ theme }) => theme.success};
border-radius: 50%;
height: 8px;
width: 8px;
margin-right: 4px;
`
const Row = styled(Link)` const Row = styled(Link)`
align-items: center; align-items: center;
border-radius: 20px; border-radius: 20px;
...@@ -65,9 +56,7 @@ const BadgeText = styled.div` ...@@ -65,9 +56,7 @@ const BadgeText = styled.div`
font-size: 12px; font-size: 12px;
`}; `};
` `
const BadgeWrapper = styled.div`
font-size: 14px;
`
const DataLineItem = styled.div` const DataLineItem = styled.div`
font-size: 14px; font-size: 14px;
` `
...@@ -185,8 +174,6 @@ export function getPriceOrderingFromPositionForUI( ...@@ -185,8 +174,6 @@ export function getPriceOrderingFromPositionForUI(
} }
export default function PositionListItem({ positionDetails }: PositionListItemProps) { export default function PositionListItem({ positionDetails }: PositionListItemProps) {
const { t } = useTranslation()
const { const {
token0: token0Address, token0: token0Address,
token1: token1Address, token1: token1Address,
...@@ -228,11 +215,7 @@ export default function PositionListItem({ positionDetails }: PositionListItemPr ...@@ -228,11 +215,7 @@ export default function PositionListItem({ positionDetails }: PositionListItemPr
;[priceLower, priceUpper, base, quote] = [priceUpper?.invert(), priceLower?.invert(), quote, base] ;[priceLower, priceUpper, base, quote] = [priceUpper?.invert(), priceLower?.invert(), quote, base]
} }
const quotePrice = useMemo(() => { const removed = liquidity?.eq(0)
return manuallyInverted
? position?.pool.priceOf(position?.pool.token0)
: position?.pool.priceOf(position?.pool.token1)
}, [manuallyInverted, position?.pool])
return ( return (
<Row to={positionSummaryLink}> <Row to={positionSummaryLink}>
...@@ -247,36 +230,7 @@ export default function PositionListItem({ positionDetails }: PositionListItemPr ...@@ -247,36 +230,7 @@ export default function PositionListItem({ positionDetails }: PositionListItemPr
<BadgeText>{new Percent(feeAmount, 1_000_000).toSignificant()}%</BadgeText> <BadgeText>{new Percent(feeAmount, 1_000_000).toSignificant()}%</BadgeText>
</Badge> </Badge>
</PrimaryPositionIdData> </PrimaryPositionIdData>
<BadgeWrapper> <RangeBadge removed={removed} inRange={!outOfRange} />
{outOfRange ? (
<MouseoverTooltip
text={`The price of this pair is outside of your selected range. Your positions is not earning fees. Current price: ${quotePrice?.toSignificant(
6
)} ${manuallyInverted ? currencyQuote?.symbol : currencyBase?.symbol} / ${
manuallyInverted ? currencyBase?.symbol : currencyQuote?.symbol
}`}
>
<Badge variant={BadgeVariant.WARNING}>
<AlertCircle width={14} height={14} style={{ marginRight: '' }} />
&nbsp;
<BadgeText>{t('Out of range')}</BadgeText>
</Badge>
</MouseoverTooltip>
) : (
<MouseoverTooltip
text={`The price of this pair is within your selected range. Your positions is earning fees. Current price: ${quotePrice?.toSignificant(
6
)} ${manuallyInverted ? currencyQuote?.symbol : currencyBase?.symbol} / ${
manuallyInverted ? currencyBase?.symbol : currencyQuote?.symbol
}`}
>
<Badge variant={BadgeVariant.DEFAULT}>
<ActiveDot /> &nbsp;
<BadgeText>{t('In range')}</BadgeText>
</Badge>
</MouseoverTooltip>
)}
</BadgeWrapper>
</RowFixed> </RowFixed>
{priceLower && priceUpper ? ( {priceLower && priceUpper ? (
......
...@@ -13,6 +13,7 @@ import RateToggle from 'components/RateToggle' ...@@ -13,6 +13,7 @@ import RateToggle from 'components/RateToggle'
import DoubleCurrencyLogo from 'components/DoubleLogo' import DoubleCurrencyLogo from 'components/DoubleLogo'
import RangeBadge from 'components/Badge/RangeBadge' import RangeBadge from 'components/Badge/RangeBadge'
import { ThemeContext } from 'styled-components' import { ThemeContext } from 'styled-components'
import { JSBI } from '@uniswap/v2-sdk'
export const PositionPreview = ({ export const PositionPreview = ({
position, position,
...@@ -55,6 +56,8 @@ export const PositionPreview = ({ ...@@ -55,6 +56,8 @@ export const PositionPreview = ({
setBaseCurrency(quoteCurrency) setBaseCurrency(quoteCurrency)
}, [quoteCurrency]) }, [quoteCurrency])
const removed = position?.liquidity && JSBI.equal(position?.liquidity, JSBI.BigInt(0))
return ( return (
<AutoColumn gap="md" style={{ marginTop: '0.5rem' }}> <AutoColumn gap="md" style={{ marginTop: '0.5rem' }}>
<RowBetween style={{ marginBottom: '0.5rem' }}> <RowBetween style={{ marginBottom: '0.5rem' }}>
...@@ -69,7 +72,7 @@ export const PositionPreview = ({ ...@@ -69,7 +72,7 @@ export const PositionPreview = ({
{currency0?.symbol} / {currency1?.symbol} {currency0?.symbol} / {currency1?.symbol}
</TYPE.label> </TYPE.label>
</RowFixed> </RowFixed>
<RangeBadge inRange={inRange} /> <RangeBadge removed={removed} inRange={inRange} />
</RowBetween> </RowBetween>
<LightCard> <LightCard>
......
import styled from 'styled-components' import styled from 'styled-components'
import { AutoColumn } from 'components/Column' import { AutoColumn } from 'components/Column'
import CurrencyInputPanel from 'components/CurrencyInputPanel' import CurrencyInputPanel from 'components/CurrencyInputPanel'
import Card, { DarkGreyCard } from 'components/Card' import { DarkGreyCard } from 'components/Card'
import Input from 'components/NumericalInput' import Input from 'components/NumericalInput'
export const Wrapper = styled.div` export const Wrapper = styled.div`
...@@ -24,16 +24,6 @@ export const ScrollablePage = styled.div` ...@@ -24,16 +24,6 @@ export const ScrollablePage = styled.div`
flex-direction: row; flex-direction: row;
` `
export const RangeBadge = styled(Card)<{ inRange?: boolean }>`
width: fit-content;
font-size: 14px;
font-weight: 500;
border-radius: 8px;
padding: 4px 6px;
color: ${({ theme }) => theme.black};
background-color: ${({ inRange, theme }) => (inRange ? theme.green1 : theme.yellow2)};
`
export const FixedPreview = styled.div` export const FixedPreview = styled.div`
position: relative; position: relative;
padding: 16px; padding: 16px;
...@@ -49,8 +39,8 @@ export const FixedPreview = styled.div` ...@@ -49,8 +39,8 @@ export const FixedPreview = styled.div`
` `
export const DynamicSection = styled(AutoColumn)<{ disabled?: boolean }>` export const DynamicSection = styled(AutoColumn)<{ disabled?: boolean }>`
opacity: ${({ disabled }) => (disabled ? '0.3' : '1')} opacity: ${({ disabled }) => (disabled ? '0.3' : '1')};
pointer-events: ${({ disabled }) => (disabled ? 'none' : 'initial')} pointer-events: ${({ disabled }) => (disabled ? 'none' : 'initial')};
` `
export const CurrencyDropdown = styled(CurrencyInputPanel)` export const CurrencyDropdown = styled(CurrencyInputPanel)`
......
...@@ -194,6 +194,8 @@ export function PositionPage({ ...@@ -194,6 +194,8 @@ export function PositionPage({
const { token0: token0Address, token1: token1Address, fee: feeAmount, liquidity, tickLower, tickUpper, tokenId } = const { token0: token0Address, token1: token1Address, fee: feeAmount, liquidity, tickLower, tickUpper, tokenId } =
positionDetails || {} positionDetails || {}
const removed = liquidity?.eq(0)
const token0 = useToken(token0Address) const token0 = useToken(token0Address)
const token1 = useToken(token1Address) const token1 = useToken(token1Address)
...@@ -236,9 +238,6 @@ export function PositionPage({ ...@@ -236,9 +238,6 @@ export function PositionPage({
: undefined : undefined
}, [inverted, pool, priceLower, priceUpper]) }, [inverted, pool, priceLower, priceUpper])
// really can't figure out why i have to do this, getting conditional hook call errors otherwise
const WORKAROUND = typeof ratio === 'number' ? (inverted ? 100 - ratio : ratio) : undefined
// fees // fees
const [feeValue0, feeValue1] = useV3PositionFees(pool ?? undefined, positionDetails) const [feeValue0, feeValue1] = useV3PositionFees(pool ?? undefined, positionDetails)
...@@ -408,7 +407,7 @@ export function PositionPage({ ...@@ -408,7 +407,7 @@ export function PositionPage({
<Badge style={{ marginRight: '8px' }}> <Badge style={{ marginRight: '8px' }}>
<BadgeText>{new Percent(feeAmount, 1_000_000).toSignificant()}%</BadgeText> <BadgeText>{new Percent(feeAmount, 1_000_000).toSignificant()}%</BadgeText>
</Badge> </Badge>
<RangeBadge inRange={inRange} /> <RangeBadge removed={removed} inRange={inRange} />
</RowFixed> </RowFixed>
{ownsNFT && ( {ownsNFT && (
<RowFixed> <RowFixed>
...@@ -424,7 +423,7 @@ export function PositionPage({ ...@@ -424,7 +423,7 @@ export function PositionPage({
{t('Add Liquidity')} {t('Add Liquidity')}
</ButtonGray> </ButtonGray>
) : null} ) : null}
{tokenId && ( {tokenId && !removed ? (
<ResponsiveButtonPrimary <ResponsiveButtonPrimary
as={Link} as={Link}
to={`/remove/${tokenId}`} to={`/remove/${tokenId}`}
...@@ -434,7 +433,7 @@ export function PositionPage({ ...@@ -434,7 +433,7 @@ export function PositionPage({
> >
{t('Remove Liquidity')} {t('Remove Liquidity')}
</ResponsiveButtonPrimary> </ResponsiveButtonPrimary>
)} ) : null}
</RowFixed> </RowFixed>
)} )}
</ResponsiveRow> </ResponsiveRow>
...@@ -498,13 +497,13 @@ export function PositionPage({ ...@@ -498,13 +497,13 @@ export function PositionPage({
<TYPE.main> <TYPE.main>
{inverted ? position?.amount0.toSignificant(4) : position?.amount1.toSignificant(4)} {inverted ? position?.amount0.toSignificant(4) : position?.amount1.toSignificant(4)}
</TYPE.main> </TYPE.main>
{typeof ratio === 'number' && ( {typeof ratio === 'number' && !removed ? (
<DarkGreyCard padding="4px 6px" style={{ width: 'fit-content', marginLeft: '8px' }}> <DarkGreyCard padding="4px 6px" style={{ width: 'fit-content', marginLeft: '8px' }}>
<TYPE.main color={theme.text2} fontSize={11}> <TYPE.main color={theme.text2} fontSize={11}>
{inverted ? ratio : 100 - ratio}% {inverted ? ratio : 100 - ratio}%
</TYPE.main> </TYPE.main>
</DarkGreyCard> </DarkGreyCard>
)} ) : null}
</RowFixed> </RowFixed>
</RowBetween> </RowBetween>
<RowBetween> <RowBetween>
...@@ -516,13 +515,13 @@ export function PositionPage({ ...@@ -516,13 +515,13 @@ export function PositionPage({
<TYPE.main> <TYPE.main>
{inverted ? position?.amount1.toSignificant(4) : position?.amount0.toSignificant(4)} {inverted ? position?.amount1.toSignificant(4) : position?.amount0.toSignificant(4)}
</TYPE.main> </TYPE.main>
{typeof ratio === 'number' && ( {typeof ratio === 'number' && !removed ? (
<DarkGreyCard padding="4px 6px" style={{ width: 'fit-content', marginLeft: '8px' }}> <DarkGreyCard padding="4px 6px" style={{ width: 'fit-content', marginLeft: '8px' }}>
<TYPE.main color={theme.text2} fontSize={11}> <TYPE.main color={theme.text2} fontSize={11}>
{WORKAROUND}% {inverted ? 100 - ratio : ratio}%
</TYPE.main> </TYPE.main>
</DarkGreyCard> </DarkGreyCard>
)} ) : null}
</RowFixed> </RowFixed>
</RowBetween> </RowBetween>
</AutoColumn> </AutoColumn>
...@@ -621,7 +620,7 @@ export function PositionPage({ ...@@ -621,7 +620,7 @@ export function PositionPage({
</Label> </Label>
<HideExtraSmall> <HideExtraSmall>
<> <>
<RangeBadge inRange={inRange} /> <RangeBadge removed={removed} inRange={inRange} />
<span style={{ width: '8px' }} /> <span style={{ width: '8px' }} />
</> </>
</HideExtraSmall> </HideExtraSmall>
......
...@@ -28,12 +28,12 @@ import Loader from 'components/Loader' ...@@ -28,12 +28,12 @@ import Loader from 'components/Loader'
import { useToken } from 'hooks/Tokens' import { useToken } from 'hooks/Tokens'
import { unwrappedToken } from 'utils/wrappedCurrency' import { unwrappedToken } from 'utils/wrappedCurrency'
import DoubleCurrencyLogo from 'components/DoubleLogo' import DoubleCurrencyLogo from 'components/DoubleLogo'
import { RangeBadge } from 'pages/AddLiquidity/styled'
import { Break } from 'components/earn/styled' import { Break } from 'components/earn/styled'
import { NonfungiblePositionManager } from '@uniswap/v3-sdk' import { NonfungiblePositionManager } from '@uniswap/v3-sdk'
import { calculateGasMargin } from 'utils' import { calculateGasMargin } from 'utils'
import useTheme from 'hooks/useTheme' import useTheme from 'hooks/useTheme'
import { AddRemoveTabs } from 'components/NavigationTabs' import { AddRemoveTabs } from 'components/NavigationTabs'
import RangeBadge from 'components/Badge/RangeBadge'
export const UINT128MAX = BigNumber.from(2).pow(128).sub(1) export const UINT128MAX = BigNumber.from(2).pow(128).sub(1)
...@@ -83,6 +83,8 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { ...@@ -83,6 +83,8 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
} = useDerivedV3BurnInfo(position) } = useDerivedV3BurnInfo(position)
const { onPercentSelect } = useBurnV3ActionHandlers() const { onPercentSelect } = useBurnV3ActionHandlers()
const removed = position?.liquidity?.eq(0)
// boilerplate for the slider // boilerplate for the slider
const [percentForSlider, onPercentSelectForSlider] = useDebouncedChangeHandler(percent, onPercentSelect) const [percentForSlider, onPercentSelectForSlider] = useDebouncedChangeHandler(percent, onPercentSelect)
...@@ -281,7 +283,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { ...@@ -281,7 +283,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
<DoubleCurrencyLogo currency0={currency1} currency1={currency0} size={20} margin={true} /> <DoubleCurrencyLogo currency0={currency1} currency1={currency0} size={20} margin={true} />
<TYPE.label ml="10px" fontSize="20px">{`${currency0?.symbol}/${currency1?.symbol}`}</TYPE.label> <TYPE.label ml="10px" fontSize="20px">{`${currency0?.symbol}/${currency1?.symbol}`}</TYPE.label>
</RowFixed> </RowFixed>
<RangeBadge inRange={!outOfRange}>{outOfRange ? 'Out of range' : 'In Range'}</RangeBadge> <RangeBadge removed={removed} inRange={!outOfRange} />
</RowBetween> </RowBetween>
<LightCard> <LightCard>
<AutoColumn gap="md"> <AutoColumn gap="md">
...@@ -363,10 +365,10 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { ...@@ -363,10 +365,10 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
<AutoColumn gap="12px" style={{ flex: '1' }}> <AutoColumn gap="12px" style={{ flex: '1' }}>
<ButtonConfirmed <ButtonConfirmed
confirmed={false} confirmed={false}
disabled={percent === 0 || !liquidityValue0} disabled={removed || percent === 0 || !liquidityValue0}
onClick={() => setShowConfirm(true)} onClick={() => setShowConfirm(true)}
> >
{error ?? 'Remove'} {removed ? 'Inactive' : error ?? 'Remove'}
</ButtonConfirmed> </ButtonConfirmed>
</AutoColumn> </AutoColumn>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment