Commit 7fd40051 authored by Ian Lapham's avatar Ian Lapham Committed by GitHub

Fix(UNI page): hide inactive pools (#1213)

* Hide rewards

* remove config changes

* move active detection to hook, small changes

* replace string math
parent 48eab0d0
......@@ -14,6 +14,7 @@ import { unwrappedToken } from '../../utils/wrappedCurrency'
import { useTotalSupply } from '../../data/TotalSupply'
import { usePair } from '../../data/Reserves'
import useUSDCPrice from '../../utils/useUSDCPrice'
import { BIG_INT_SECONDS_IN_WEEK } from '../../constants'
const StatContainer = styled.div`
display: flex;
......@@ -56,11 +57,6 @@ const TopSection = styled.div`
`};
`
// const APR = styled.div`
// display: flex;
// justify-content: flex-end;
// `
const BottomSection = styled.div<{ showBackground: boolean }>`
padding: 12px 16px;
opacity: ${({ showBackground }) => (showBackground ? '1' : '0.4')};
......@@ -139,9 +135,15 @@ export default function PoolCard({ stakingInfo }: { stakingInfo: StakingInfo })
</RowBetween>
<RowBetween>
<TYPE.white> Pool rate </TYPE.white>
<TYPE.white>{`${stakingInfo.totalRewardRate
?.multiply(`${60 * 60 * 24 * 7}`)
?.toFixed(0, { groupSeparator: ',' })} UNI / week`}</TYPE.white>
<TYPE.white>
{stakingInfo
? stakingInfo.active
? `${stakingInfo.totalRewardRate
?.multiply(BIG_INT_SECONDS_IN_WEEK)
?.toFixed(0, { groupSeparator: ',' })} UNI / week`
: '0 UNI / week'
: '-'}
</TYPE.white>
</RowBetween>
</StatContainer>
......@@ -157,9 +159,13 @@ export default function PoolCard({ stakingInfo }: { stakingInfo: StakingInfo })
<span role="img" aria-label="wizard-icon" style={{ marginRight: '0.5rem' }}>
</span>
{`${stakingInfo.rewardRate
?.multiply(`${60 * 60 * 24 * 7}`)
?.toSignificant(4, { groupSeparator: ',' })} UNI / week`}
{stakingInfo
? stakingInfo.active
? `${stakingInfo.rewardRate
?.multiply(BIG_INT_SECONDS_IN_WEEK)
?.toSignificant(4, { groupSeparator: ',' })} UNI / week`
: '0 UNI / week'
: '-'}
</TYPE.black>
</BottomSection>
</>
......
......@@ -179,6 +179,9 @@ export const INITIAL_ALLOWED_SLIPPAGE = 50
// 20 minutes, denominated in seconds
export const DEFAULT_DEADLINE_FROM_NOW = 60 * 20
// used for rewards deadlines
export const BIG_INT_SECONDS_IN_WEEK = JSBI.BigInt(60 * 60 * 24 * 7)
export const BIG_INT_ZERO = JSBI.BigInt(0)
// one basis point
......
......@@ -28,7 +28,7 @@ import { useTotalSupply } from '../../data/TotalSupply'
import { usePair } from '../../data/Reserves'
import usePrevious from '../../hooks/usePrevious'
import useUSDCPrice from '../../utils/useUSDCPrice'
import { BIG_INT_ZERO } from '../../constants'
import { BIG_INT_ZERO, BIG_INT_SECONDS_IN_WEEK } from '../../constants'
const PageWrapper = styled(AutoColumn)`
max-width: 640px;
......@@ -177,9 +177,11 @@ export default function Manage({
<AutoColumn gap="sm">
<TYPE.body style={{ margin: 0 }}>Pool Rate</TYPE.body>
<TYPE.body fontSize={24} fontWeight={500}>
{stakingInfo?.totalRewardRate
?.multiply((60 * 60 * 24 * 7).toString())
?.toFixed(0, { groupSeparator: ',' }) ?? '-'}
{stakingInfo?.active
? stakingInfo?.totalRewardRate
?.multiply(BIG_INT_SECONDS_IN_WEEK)
?.toFixed(0, { groupSeparator: ',' }) ?? '-'
: '0'}
{' UNI / week'}
</TYPE.body>
</AutoColumn>
......@@ -293,9 +295,11 @@ export default function Manage({
<span role="img" aria-label="wizard-icon" style={{ marginRight: '8px ' }}>
</span>
{stakingInfo?.rewardRate
?.multiply((60 * 60 * 24 * 7).toString())
?.toSignificant(4, { groupSeparator: ',' }) ?? '-'}
{stakingInfo?.active
? stakingInfo?.rewardRate
?.multiply(BIG_INT_SECONDS_IN_WEEK)
?.toSignificant(4, { groupSeparator: ',' }) ?? '-'
: '0'}
{' UNI / week'}
</TYPE.black>
</RowBetween>
......@@ -311,9 +315,11 @@ export default function Manage({
{!showAddLiquidityButton && (
<DataRow style={{ marginBottom: '1rem' }}>
<ButtonPrimary padding="8px" borderRadius="8px" width="160px" onClick={handleDepositClick}>
{stakingInfo?.stakedAmount?.greaterThan(JSBI.BigInt(0)) ? 'Deposit' : 'Deposit UNI-V2 LP Tokens'}
</ButtonPrimary>
{stakingInfo && stakingInfo.active && (
<ButtonPrimary padding="8px" borderRadius="8px" width="160px" onClick={handleDepositClick}>
{stakingInfo?.stakedAmount?.greaterThan(JSBI.BigInt(0)) ? 'Deposit' : 'Deposit UNI-V2 LP Tokens'}
</ButtonPrimary>
)}
{stakingInfo?.stakedAmount?.greaterThan(JSBI.BigInt(0)) && (
<>
......@@ -329,7 +335,7 @@ export default function Manage({
)}
</DataRow>
)}
{!userLiquidityUnstaked ? null : userLiquidityUnstaked.equalTo('0') ? null : (
{!userLiquidityUnstaked ? null : userLiquidityUnstaked.equalTo('0') ? null : !stakingInfo?.active ? null : (
<TYPE.main>{userLiquidityUnstaked.toSignificant(6)} UNI-V2 LP tokens available</TYPE.main>
)}
</PositionInfo>
......
......@@ -9,6 +9,9 @@ import { CardSection, DataCard, CardNoise, CardBGImage } from '../../components/
import { Countdown } from './Countdown'
import Loader from '../../components/Loader'
import { useActiveWeb3React } from '../../hooks'
import { JSBI } from '@uniswap/sdk'
import { BIG_INT_ZERO } from '../../constants'
import { OutlineCard } from '../../components/Card'
const PageWrapper = styled(AutoColumn)`
max-width: 640px;
......@@ -37,8 +40,17 @@ flex-direction: column;
export default function Earn() {
const { chainId } = useActiveWeb3React()
// staking info for connected account
const stakingInfos = useStakingInfo()
/**
* only show staking cards with balance
* @todo only account for this if rewards are inactive
*/
const stakingInfosWithBalance = stakingInfos?.filter(s => JSBI.greaterThan(s.stakedAmount.raw, BIG_INT_ZERO))
// toggle copy if rewards are inactive
const stakingRewardsExist = Boolean(typeof chainId === 'number' && (STAKING_REWARDS_INFO[chainId]?.length ?? 0) > 0)
return (
......@@ -81,9 +93,11 @@ export default function Earn() {
{stakingRewardsExist && stakingInfos?.length === 0 ? (
<Loader style={{ margin: 'auto' }} />
) : !stakingRewardsExist ? (
'No active rewards'
<OutlineCard>No active pools</OutlineCard>
) : stakingInfos?.length !== 0 && stakingInfosWithBalance.length === 0 ? (
<OutlineCard>No active pools</OutlineCard>
) : (
stakingInfos?.map(stakingInfo => {
stakingInfosWithBalance?.map(stakingInfo => {
// need to sort by added liquidity here
return <PoolCard key={stakingInfo.stakingRewardAddress} stakingInfo={stakingInfo} />
})
......
......@@ -5,6 +5,7 @@ import { STAKING_REWARDS_INTERFACE } from '../../constants/abis/staking-rewards'
import { useActiveWeb3React } from '../../hooks'
import { NEVER_RELOAD, useMultipleContractSingleData } from '../multicall/hooks'
import { tryParseAmount } from '../swap/hooks'
import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp'
export const STAKING_GENESIS = 1600387200
......@@ -55,6 +56,8 @@ export interface StakingInfo {
rewardRate: TokenAmount
// when the period ends
periodFinish: Date | undefined
// if pool is active
active: boolean
// calculates a hypothetical amount of token distributed to the active account per second.
getHypotheticalRewardRate: (
stakedAmount: TokenAmount,
......@@ -67,6 +70,9 @@ export interface StakingInfo {
export function useStakingInfo(pairToFilterBy?: Pair | null): StakingInfo[] {
const { chainId, account } = useActiveWeb3React()
// detect if staking is ended
const currentBlockTimestamp = useCurrentBlockTimestamp()
const info = useMemo(
() =>
chainId
......@@ -170,7 +176,12 @@ export function useStakingInfo(pairToFilterBy?: Pair | null): StakingInfo[] {
const individualRewardRate = getHypotheticalRewardRate(stakedAmount, totalStakedAmount, totalRewardRate)
const periodFinishMs = periodFinishState.result?.[0]?.mul(1000)?.toNumber()
const periodFinishSeconds = periodFinishState.result?.[0]?.toNumber()
const periodFinishMs = periodFinishSeconds * 1000
// compare period end timestamp vs current block timestamp (in seconds)
const active =
periodFinishSeconds && currentBlockTimestamp ? periodFinishSeconds > currentBlockTimestamp.toNumber() : true
memo.push({
stakingRewardAddress: rewardsAddress,
......@@ -181,12 +192,24 @@ export function useStakingInfo(pairToFilterBy?: Pair | null): StakingInfo[] {
totalRewardRate: totalRewardRate,
stakedAmount: stakedAmount,
totalStakedAmount: totalStakedAmount,
getHypotheticalRewardRate
getHypotheticalRewardRate,
active
})
}
return memo
}, [])
}, [balances, chainId, earnedAmounts, info, periodFinishes, rewardRates, rewardsAddresses, totalSupplies, uni])
}, [
balances,
chainId,
currentBlockTimestamp,
earnedAmounts,
info,
periodFinishes,
rewardRates,
rewardsAddresses,
totalSupplies,
uni
])
}
export function useTotalUniEarned(): TokenAmount | undefined {
......
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