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