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)`
}
`
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)`
border: 1px solid ${({ theme }) => theme.bg2};
background-color: transparent;
......
......@@ -123,9 +123,6 @@ const AccountElement = styled.div<{ active: boolean }>`
:focus {
border: 1px solid blue;
}
/* :hover {
background-color: ${({ theme, active }) => (!active ? theme.bg2 : theme.bg4)};
} */
`
const UNIAmount = styled(AccountElement)`
......
import { JSBI, Pair, Percent } from '@uniswap/sdk'
import { JSBI, Pair, Percent, TokenAmount } from '@uniswap/sdk'
import { darken } from 'polished'
import React, { useState } from 'react'
import { ChevronDown, ChevronUp } from 'react-feather'
......@@ -9,10 +9,10 @@ import { useTotalSupply } from '../../data/TotalSupply'
import { useActiveWeb3React } from '../../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 { unwrappedToken } from '../../utils/wrappedCurrency'
import { ButtonPrimary, ButtonSecondary, ButtonEmpty } from '../Button'
import { ButtonPrimary, ButtonSecondary, ButtonEmpty, ButtonUNIGradient } from '../Button'
import { transparentize } from 'polished'
import { CardNoise } from '../earn/styled'
......@@ -22,8 +22,9 @@ import Card, { GreyCard, LightCard } from '../Card'
import { AutoColumn } from '../Column'
import CurrencyLogo from '../CurrencyLogo'
import DoubleCurrencyLogo from '../DoubleLogo'
import { RowBetween, RowFixed } from '../Row'
import { RowBetween, RowFixed, AutoRow } from '../Row'
import { Dots } from '../swap/styleds'
import { BIG_INT_ZERO } from '../../constants'
export const FixedHeightRow = styled(RowBetween)`
height: 24px;
......@@ -47,6 +48,7 @@ interface PositionCardProps {
pair: Pair
showUnwrapped?: boolean
border?: string
stakedBalance?: TokenAmount // optional balance to indicate that liquidity is deposited in mining pool
}
export function MinimalPositionCard({ pair, showUnwrapped = false, border }: PositionCardProps) {
......@@ -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 currency0 = unwrappedToken(pair.token0)
......@@ -165,9 +167,12 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
const [showMore, setShowMore] = useState(false)
const userPoolBalance = useTokenBalance(account ?? undefined, pair.liquidityToken)
const userDefaultPoolBalance = useTokenBalance(account ?? undefined, 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 =
!!userPoolBalance && !!totalPoolTokens && JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw)
? new Percent(userPoolBalance.raw, totalPoolTokens.raw)
......@@ -192,12 +197,22 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
<CardNoise />
<AutoColumn gap="12px">
<FixedHeightRow>
<RowFixed>
<DoubleCurrencyLogo currency0={currency0} currency1={currency1} margin={true} size={20} />
<AutoRow gap="8px">
<DoubleCurrencyLogo currency0={currency0} currency1={currency1} size={20} />
<Text fontWeight={500} fontSize={20}>
{!currency0 || !currency1 ? <Dots>Loading</Dots> : `${currency0.symbol}/${currency1.symbol}`}
</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">
<ButtonEmpty
......@@ -208,7 +223,6 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
>
{showMore ? (
<>
{' '}
Manage
<ChevronUp size="20" style={{ marginLeft: '10px' }} />
</>
......@@ -226,12 +240,22 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
<AutoColumn gap="8px">
<FixedHeightRow>
<Text fontSize={16} fontWeight={500}>
Your pool tokens:
Your total pool tokens:
</Text>
<Text fontSize={16} fontWeight={500}>
{userPoolBalance ? userPoolBalance.toSignificant(4) : '-'}
</Text>
</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>
<RowFixed>
<Text fontSize={16} fontWeight={500}>
......@@ -273,7 +297,9 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
Your pool share:
</Text>
<Text fontSize={16} fontWeight={500}>
{poolTokenPercentage ? poolTokenPercentage.toFixed(2) + '%' : '-'}
{poolTokenPercentage
? (poolTokenPercentage.toFixed(2) === '0.00' ? '<0.01' : poolTokenPercentage.toFixed(2)) + '%'
: '-'}
</Text>
</FixedHeightRow>
......@@ -285,6 +311,7 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
View accrued fees and analytics<span style={{ fontSize: '11px' }}></span>
</ExternalLink>
</ButtonSecondary>
{userDefaultPoolBalance && JSBI.greaterThan(userDefaultPoolBalance.raw, BIG_INT_ZERO) && (
<RowBetween marginTop="10px">
<ButtonPrimary
padding="8px"
......@@ -305,6 +332,18 @@ export default function FullPositionCard({ pair, border }: PositionCardProps) {
Remove
</ButtonPrimary>
</RowBetween>
)}
{stakedBalance && JSBI.greaterThan(stakedBalance.raw, BIG_INT_ZERO) && (
<ButtonPrimary
padding="8px"
borderRadius="8px"
as={Link}
to={`/uni/${currencyId(currency0)}/${currencyId(currency1)}`}
width="100%"
>
Manage Liquidity in Rewards Pool
</ButtonPrimary>
)}
</AutoColumn>
)}
</AutoColumn>
......
......@@ -29,16 +29,16 @@ const PoolSection = styled.div`
justify-self: center;
`
const DataRow = styled(RowBetween)`
${({ theme }) => theme.mediaWidth.upToSmall`
flex-direction: column;
`};
`
export default function Earn() {
const { chainId } = useActiveWeb3React()
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)
return (
......
import React, { useContext, useMemo } from 'react'
import styled, { ThemeContext } from 'styled-components'
import { Pair } from '@uniswap/sdk'
import { Pair, JSBI } from '@uniswap/sdk'
import { Link } from 'react-router-dom'
import { SwapPoolTabs } from '../../components/NavigationTabs'
......@@ -19,6 +19,8 @@ import { usePairs } from '../../data/Reserves'
import { toV2LiquidityToken, useTrackedTokenPairs } from '../../state/user/hooks'
import { Dots } from '../../components/swap/styleds'
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)`
max-width: 640px;
......@@ -107,11 +109,24 @@ export default function Pool() {
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 (
<>
<PageWrapper>
<SwapPoolTabs active={'pool'} />
<VoteCard>
<CardBGImage />
<CardNoise />
......@@ -170,7 +185,7 @@ export default function Pool() {
<Dots>Loading</Dots>
</TYPE.body>
</EmptyProposals>
) : allV2PairsWithLiquidity?.length > 0 ? (
) : allV2PairsWithLiquidity?.length > 0 || stakingPairs?.length > 0 ? (
<>
<ButtonSecondary>
<RowBetween>
......@@ -180,10 +195,19 @@ export default function Pool() {
<span></span>
</RowBetween>
</ButtonSecondary>
{allV2PairsWithLiquidity.map(v2Pair => (
{v2PairsWithoutStakedAmount.map(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>
......
......@@ -185,3 +185,16 @@ export const HideSmall = styled.span`
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