Commit c9ee1b3b authored by Ian Lapham's avatar Ian Lapham Committed by GitHub

Fix(pool page): show deposited liquidity on pool page (#1195)

* Show staked liquidity on pool page

* update button, cleanup

* Show combined balance for staking cards

* hide buttons on position card if no balance
parent eb4c305e
...@@ -159,6 +159,26 @@ export const ButtonPink = styled(Base)` ...@@ -159,6 +159,26 @@ export const ButtonPink = styled(Base)`
} }
` `
export const ButtonUNIGradient = styled(ButtonPrimary)`
color: white;
padding: 4px 8px;
height: 36px;
font-weight: 500;
background-color: ${({ theme }) => theme.bg3};
background: radial-gradient(174.47% 188.91% at 1.84% 0%, #ff007a 0%, #2172e5 100%), #edeef2;
width: fit-content;
position: relative;
cursor: pointer;
border: none;
white-space: no-wrap;
:hover {
opacity: 0.8;
}
:active {
opacity: 0.9;
}
`
export const ButtonOutlined = styled(Base)` export const ButtonOutlined = styled(Base)`
border: 1px solid ${({ theme }) => theme.bg2}; border: 1px solid ${({ theme }) => theme.bg2};
background-color: transparent; background-color: transparent;
......
...@@ -123,9 +123,6 @@ const AccountElement = styled.div<{ active: boolean }>` ...@@ -123,9 +123,6 @@ const AccountElement = styled.div<{ active: boolean }>`
:focus { :focus {
border: 1px solid blue; border: 1px solid blue;
} }
/* :hover {
background-color: ${({ theme, active }) => (!active ? theme.bg2 : theme.bg4)};
} */
` `
const UNIAmount = styled(AccountElement)` const UNIAmount = styled(AccountElement)`
......
import { JSBI, Pair, Percent } from '@uniswap/sdk' import { JSBI, Pair, Percent, TokenAmount } from '@uniswap/sdk'
import { darken } from 'polished' import { darken } from 'polished'
import React, { useState } from 'react' import React, { useState } from 'react'
import { ChevronDown, ChevronUp } from 'react-feather' import { ChevronDown, ChevronUp } from 'react-feather'
...@@ -9,10 +9,10 @@ import { useTotalSupply } from '../../data/TotalSupply' ...@@ -9,10 +9,10 @@ import { useTotalSupply } from '../../data/TotalSupply'
import { useActiveWeb3React } from '../../hooks' import { useActiveWeb3React } from '../../hooks'
import { useTokenBalance } from '../../state/wallet/hooks' import { useTokenBalance } from '../../state/wallet/hooks'
import { ExternalLink, TYPE } from '../../theme' import { ExternalLink, TYPE, HideExtraSmall, ExtraSmallOnly } from '../../theme'
import { currencyId } from '../../utils/currencyId' import { currencyId } from '../../utils/currencyId'
import { unwrappedToken } from '../../utils/wrappedCurrency' import { unwrappedToken } from '../../utils/wrappedCurrency'
import { ButtonPrimary, ButtonSecondary, ButtonEmpty } from '../Button' import { ButtonPrimary, ButtonSecondary, ButtonEmpty, ButtonUNIGradient } from '../Button'
import { transparentize } from 'polished' import { transparentize } from 'polished'
import { CardNoise } from '../earn/styled' import { CardNoise } from '../earn/styled'
...@@ -22,8 +22,9 @@ import Card, { GreyCard, LightCard } from '../Card' ...@@ -22,8 +22,9 @@ import Card, { GreyCard, LightCard } from '../Card'
import { AutoColumn } from '../Column' import { AutoColumn } from '../Column'
import CurrencyLogo from '../CurrencyLogo' import CurrencyLogo from '../CurrencyLogo'
import DoubleCurrencyLogo from '../DoubleLogo' import DoubleCurrencyLogo from '../DoubleLogo'
import { RowBetween, RowFixed } from '../Row' import { RowBetween, RowFixed, AutoRow } from '../Row'
import { Dots } from '../swap/styleds' import { Dots } from '../swap/styleds'
import { BIG_INT_ZERO } from '../../constants'
export const FixedHeightRow = styled(RowBetween)` export const FixedHeightRow = styled(RowBetween)`
height: 24px; height: 24px;
...@@ -47,6 +48,7 @@ interface PositionCardProps { ...@@ -47,6 +48,7 @@ interface PositionCardProps {
pair: Pair pair: Pair
showUnwrapped?: boolean showUnwrapped?: boolean
border?: string border?: string
stakedBalance?: TokenAmount // optional balance to indicate that liquidity is deposited in mining pool
} }
export function MinimalPositionCard({ pair, showUnwrapped = false, border }: PositionCardProps) { export function MinimalPositionCard({ pair, showUnwrapped = false, border }: PositionCardProps) {
...@@ -157,7 +159,7 @@ export function MinimalPositionCard({ pair, showUnwrapped = false, border }: Pos ...@@ -157,7 +159,7 @@ export function MinimalPositionCard({ pair, showUnwrapped = false, border }: Pos
) )
} }
export default function FullPositionCard({ pair, border }: PositionCardProps) { export default function FullPositionCard({ pair, border, stakedBalance }: PositionCardProps) {
const { account } = useActiveWeb3React() const { account } = useActiveWeb3React()
const currency0 = unwrappedToken(pair.token0) const currency0 = unwrappedToken(pair.token0)
...@@ -165,9 +167,12 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) { ...@@ -165,9 +167,12 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
const [showMore, setShowMore] = useState(false) const [showMore, setShowMore] = useState(false)
const userPoolBalance = useTokenBalance(account ?? undefined, pair.liquidityToken) const userDefaultPoolBalance = useTokenBalance(account ?? undefined, pair.liquidityToken)
const totalPoolTokens = useTotalSupply(pair.liquidityToken) const totalPoolTokens = useTotalSupply(pair.liquidityToken)
// if staked balance balance provided, add to standard liquidity amount
const userPoolBalance = stakedBalance ? userDefaultPoolBalance?.add(stakedBalance) : userDefaultPoolBalance
const poolTokenPercentage = const poolTokenPercentage =
!!userPoolBalance && !!totalPoolTokens && JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw) !!userPoolBalance && !!totalPoolTokens && JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw)
? new Percent(userPoolBalance.raw, totalPoolTokens.raw) ? new Percent(userPoolBalance.raw, totalPoolTokens.raw)
...@@ -192,12 +197,22 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) { ...@@ -192,12 +197,22 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
<CardNoise /> <CardNoise />
<AutoColumn gap="12px"> <AutoColumn gap="12px">
<FixedHeightRow> <FixedHeightRow>
<RowFixed> <AutoRow gap="8px">
<DoubleCurrencyLogo currency0={currency0} currency1={currency1} margin={true} size={20} /> <DoubleCurrencyLogo currency0={currency0} currency1={currency1} size={20} />
<Text fontWeight={500} fontSize={20}> <Text fontWeight={500} fontSize={20}>
{!currency0 || !currency1 ? <Dots>Loading</Dots> : `${currency0.symbol}/${currency1.symbol}`} {!currency0 || !currency1 ? <Dots>Loading</Dots> : `${currency0.symbol}/${currency1.symbol}`}
</Text> </Text>
</RowFixed> {!!stakedBalance && (
<ButtonUNIGradient as={Link} to={`/uni/${currencyId(currency0)}/${currencyId(currency1)}`}>
<HideExtraSmall>Earning UNI</HideExtraSmall>
<ExtraSmallOnly>
<span role="img" aria-label="bolt">
</span>
</ExtraSmallOnly>
</ButtonUNIGradient>
)}
</AutoRow>
<RowFixed gap="8px"> <RowFixed gap="8px">
<ButtonEmpty <ButtonEmpty
...@@ -208,7 +223,6 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) { ...@@ -208,7 +223,6 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
> >
{showMore ? ( {showMore ? (
<> <>
{' '}
Manage Manage
<ChevronUp size="20" style={{ marginLeft: '10px' }} /> <ChevronUp size="20" style={{ marginLeft: '10px' }} />
</> </>
...@@ -226,12 +240,22 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) { ...@@ -226,12 +240,22 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
<AutoColumn gap="8px"> <AutoColumn gap="8px">
<FixedHeightRow> <FixedHeightRow>
<Text fontSize={16} fontWeight={500}> <Text fontSize={16} fontWeight={500}>
Your pool tokens: Your total pool tokens:
</Text> </Text>
<Text fontSize={16} fontWeight={500}> <Text fontSize={16} fontWeight={500}>
{userPoolBalance ? userPoolBalance.toSignificant(4) : '-'} {userPoolBalance ? userPoolBalance.toSignificant(4) : '-'}
</Text> </Text>
</FixedHeightRow> </FixedHeightRow>
{stakedBalance && (
<FixedHeightRow>
<Text fontSize={16} fontWeight={500}>
Pool tokens in rewards pool:
</Text>
<Text fontSize={16} fontWeight={500}>
{stakedBalance.toSignificant(4)}
</Text>
</FixedHeightRow>
)}
<FixedHeightRow> <FixedHeightRow>
<RowFixed> <RowFixed>
<Text fontSize={16} fontWeight={500}> <Text fontSize={16} fontWeight={500}>
...@@ -273,7 +297,9 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) { ...@@ -273,7 +297,9 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
Your pool share: Your pool share:
</Text> </Text>
<Text fontSize={16} fontWeight={500}> <Text fontSize={16} fontWeight={500}>
{poolTokenPercentage ? poolTokenPercentage.toFixed(2) + '%' : '-'} {poolTokenPercentage
? (poolTokenPercentage.toFixed(2) === '0.00' ? '<0.01' : poolTokenPercentage.toFixed(2)) + '%'
: '-'}
</Text> </Text>
</FixedHeightRow> </FixedHeightRow>
...@@ -285,26 +311,39 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) { ...@@ -285,26 +311,39 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
View accrued fees and analytics<span style={{ fontSize: '11px' }}></span> View accrued fees and analytics<span style={{ fontSize: '11px' }}></span>
</ExternalLink> </ExternalLink>
</ButtonSecondary> </ButtonSecondary>
<RowBetween marginTop="10px"> {userDefaultPoolBalance && JSBI.greaterThan(userDefaultPoolBalance.raw, BIG_INT_ZERO) && (
<ButtonPrimary <RowBetween marginTop="10px">
padding="8px" <ButtonPrimary
borderRadius="8px" padding="8px"
as={Link} borderRadius="8px"
to={`/add/${currencyId(currency0)}/${currencyId(currency1)}`} as={Link}
width="48%" to={`/add/${currencyId(currency0)}/${currencyId(currency1)}`}
> width="48%"
Add >
</ButtonPrimary> Add
</ButtonPrimary>
<ButtonPrimary
padding="8px"
borderRadius="8px"
as={Link}
width="48%"
to={`/remove/${currencyId(currency0)}/${currencyId(currency1)}`}
>
Remove
</ButtonPrimary>
</RowBetween>
)}
{stakedBalance && JSBI.greaterThan(stakedBalance.raw, BIG_INT_ZERO) && (
<ButtonPrimary <ButtonPrimary
padding="8px" padding="8px"
borderRadius="8px" borderRadius="8px"
as={Link} as={Link}
width="48%" to={`/uni/${currencyId(currency0)}/${currencyId(currency1)}`}
to={`/remove/${currencyId(currency0)}/${currencyId(currency1)}`} width="100%"
> >
Remove Manage Liquidity in Rewards Pool
</ButtonPrimary> </ButtonPrimary>
</RowBetween> )}
</AutoColumn> </AutoColumn>
)} )}
</AutoColumn> </AutoColumn>
......
...@@ -29,16 +29,16 @@ const PoolSection = styled.div` ...@@ -29,16 +29,16 @@ const PoolSection = styled.div`
justify-self: center; justify-self: center;
` `
const DataRow = styled(RowBetween)`
${({ theme }) => theme.mediaWidth.upToSmall`
flex-direction: column;
`};
`
export default function Earn() { export default function Earn() {
const { chainId } = useActiveWeb3React() const { chainId } = useActiveWeb3React()
const stakingInfos = useStakingInfo() const stakingInfos = useStakingInfo()
const DataRow = styled(RowBetween)`
${({ theme }) => theme.mediaWidth.upToSmall`
flex-direction: column;
`};
`
const stakingRewardsExist = Boolean(typeof chainId === 'number' && (STAKING_REWARDS_INFO[chainId]?.length ?? 0) > 0) const stakingRewardsExist = Boolean(typeof chainId === 'number' && (STAKING_REWARDS_INFO[chainId]?.length ?? 0) > 0)
return ( return (
......
import React, { useContext, useMemo } from 'react' import React, { useContext, useMemo } from 'react'
import styled, { ThemeContext } from 'styled-components' import styled, { ThemeContext } from 'styled-components'
import { Pair } from '@uniswap/sdk' import { Pair, JSBI } from '@uniswap/sdk'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { SwapPoolTabs } from '../../components/NavigationTabs' import { SwapPoolTabs } from '../../components/NavigationTabs'
...@@ -19,6 +19,8 @@ import { usePairs } from '../../data/Reserves' ...@@ -19,6 +19,8 @@ import { usePairs } from '../../data/Reserves'
import { toV2LiquidityToken, useTrackedTokenPairs } from '../../state/user/hooks' import { toV2LiquidityToken, useTrackedTokenPairs } from '../../state/user/hooks'
import { Dots } from '../../components/swap/styleds' import { Dots } from '../../components/swap/styleds'
import { CardSection, DataCard, CardNoise, CardBGImage } from '../../components/earn/styled' import { CardSection, DataCard, CardNoise, CardBGImage } from '../../components/earn/styled'
import { useStakingInfo } from '../../state/stake/hooks'
import { BIG_INT_ZERO } from '../../constants'
const PageWrapper = styled(AutoColumn)` const PageWrapper = styled(AutoColumn)`
max-width: 640px; max-width: 640px;
...@@ -107,11 +109,24 @@ export default function Pool() { ...@@ -107,11 +109,24 @@ export default function Pool() {
const hasV1Liquidity = useUserHasLiquidityInAllTokens() const hasV1Liquidity = useUserHasLiquidityInAllTokens()
// show liquidity even if its deposited in rewards contract
const stakingInfo = useStakingInfo()
const stakingInfosWithBalance = stakingInfo?.filter(pool => JSBI.greaterThan(pool.stakedAmount.raw, BIG_INT_ZERO))
const stakingPairs = usePairs(stakingInfosWithBalance?.map(stakingInfo => stakingInfo.tokens))
// remove any pairs that also are included in pairs with stake in mining pool
const v2PairsWithoutStakedAmount = allV2PairsWithLiquidity.filter(v2Pair => {
return (
stakingPairs
?.map(stakingPair => stakingPair[1])
.filter(stakingPair => stakingPair?.liquidityToken.address === v2Pair.liquidityToken.address).length === 0
)
})
return ( return (
<> <>
<PageWrapper> <PageWrapper>
<SwapPoolTabs active={'pool'} /> <SwapPoolTabs active={'pool'} />
<VoteCard> <VoteCard>
<CardBGImage /> <CardBGImage />
<CardNoise /> <CardNoise />
...@@ -170,7 +185,7 @@ export default function Pool() { ...@@ -170,7 +185,7 @@ export default function Pool() {
<Dots>Loading</Dots> <Dots>Loading</Dots>
</TYPE.body> </TYPE.body>
</EmptyProposals> </EmptyProposals>
) : allV2PairsWithLiquidity?.length > 0 ? ( ) : allV2PairsWithLiquidity?.length > 0 || stakingPairs?.length > 0 ? (
<> <>
<ButtonSecondary> <ButtonSecondary>
<RowBetween> <RowBetween>
...@@ -180,10 +195,19 @@ export default function Pool() { ...@@ -180,10 +195,19 @@ export default function Pool() {
<span></span> <span></span>
</RowBetween> </RowBetween>
</ButtonSecondary> </ButtonSecondary>
{v2PairsWithoutStakedAmount.map(v2Pair => (
{allV2PairsWithLiquidity.map(v2Pair => (
<FullPositionCard key={v2Pair.liquidityToken.address} pair={v2Pair} /> <FullPositionCard key={v2Pair.liquidityToken.address} pair={v2Pair} />
))} ))}
{stakingPairs.map(
(stakingPair, i) =>
stakingPair[1] && ( // skip pairs that arent loaded
<FullPositionCard
key={stakingInfosWithBalance[i].stakingRewardAddress}
pair={stakingPair[1]}
stakedBalance={stakingInfosWithBalance[i].stakedAmount}
/>
)
)}
</> </>
) : ( ) : (
<EmptyProposals> <EmptyProposals>
......
...@@ -185,3 +185,16 @@ export const HideSmall = styled.span` ...@@ -185,3 +185,16 @@ export const HideSmall = styled.span`
display: none; display: none;
`}; `};
` `
export const HideExtraSmall = styled.span`
${({ theme }) => theme.mediaWidth.upToExtraSmall`
display: none;
`};
`
export const ExtraSmallOnly = styled.span`
display: none;
${({ theme }) => theme.mediaWidth.upToExtraSmall`
display: block;
`};
`
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