Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: farm ux #1250

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 48 additions & 15 deletions src/components/YieldPools/ProMMFarmGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans, t } from '@lingui/macro'
import { BigNumber } from 'ethers'
import { rgba } from 'polished'
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { Clock, Edit2, Minus, Plus } from 'react-feather'
import { Edit2, Minus, Plus } from 'react-feather'
import { useMedia } from 'react-use'
import { Flex, Text } from 'rebass'
import styled from 'styled-components'
Expand Down Expand Up @@ -295,6 +295,8 @@ const Row = ({

const [showTargetVolInfo, setShowTargetVolInfo] = useState(false)

const amountCanStaked = (position?.amountUsd || 0) - (position?.stakedUsd || 0)

if (!above1000)
return (
<>
Expand Down Expand Up @@ -330,15 +332,15 @@ const Row = ({
{token0?.symbol} - {token1?.symbol}
</Text>

{farm.startTime > currentTimestamp && (
{/* farm.startTime > currentTimestamp && (
<MouseoverTooltip
text={'Starting In ' + getFormattedTimeFromSecond(farm.startTime - currentTimestamp)}
width="fit-content"
placement="top"
>
<Clock size={14} style={{ marginLeft: '6px' }} />
</MouseoverTooltip>
)}
) */}
viet-nv marked this conversation as resolved.
Show resolved Hide resolved
</Flex>

<Flex
Expand Down Expand Up @@ -431,9 +433,20 @@ const Row = ({

<InfoRow>
<Text color={theme.subText}>
<Trans>My Staked</Trans>
<Trans>My Deposit</Trans>
</Text>
<Text>{!!position?.stakedUsd ? formatDollarAmount(position.stakedUsd) : '--'}</Text>

<Flex justifyContent="flex-end" color={!!amountCanStaked ? theme.warning : theme.text}>
{!!position?.amountUsd ? formatDollarAmount(position.amountUsd) : '--'}
{!!amountCanStaked && (
<InfoHelper
color={theme.warning}
text={t`You still have ${formatDollarAmount(
amountCanStaked,
)} liquidity to stake to earn more rewards`}
/>
)}
</Flex>
</InfoRow>

<InfoRow>
Expand Down Expand Up @@ -464,7 +477,7 @@ const Row = ({

<Flex sx={{ gap: '16px' }} marginTop="1.25rem">
<ButtonPrimary
disabled={!isApprovedForAll || tab === 'ended'}
disabled={!isApprovedForAll || tab === 'ended' || !canStake}
style={{ height: '36px', flex: 1 }}
onClick={() => onOpenModal('stake', farm.pid)}
>
Expand Down Expand Up @@ -543,21 +556,41 @@ const Row = ({
)}
</Flex>

<Text textAlign="right">{!!position?.stakedUsd ? formatDollarAmount(position.stakedUsd) : '--'}</Text>
<Flex justifyContent="flex-end" color={!!amountCanStaked ? theme.warning : theme.text}>
{!!position?.amountUsd ? formatDollarAmount(position.amountUsd) : '--'}
{!!amountCanStaked && (
<InfoHelper
color={theme.warning}
text={t`You still have ${formatDollarAmount(amountCanStaked)} liquidity to stake to earn more rewards`}
/>
)}
</Flex>

<Flex flexDirection="column" alignItems="flex-end" sx={{ gap: '8px' }}>
{farm.rewardTokens.map((token, idx) => (
<Reward key={token} token={token} amount={position?.rewardAmounts[idx]} />
))}
</Flex>
<Flex justifyContent="flex-end" sx={{ gap: '4px' }}>
<ActionButton
onClick={() => onOpenModal('stake', farm.pid)}
disabled={!isApprovedForAll || tab === 'ended' || !canStake}
>
<MouseoverTooltip text={!canStake ? t`Farm has not started` : t`Stake`} placement="top" width="fit-content">
<Plus color={isApprovedForAll && tab !== 'ended' ? theme.primary : theme.subText} size={16} />
{!isApprovedForAll || tab === 'ended' || !canStake ? (
<MouseoverTooltip text={t`Farm has not started`} placement="top" width="fit-content">
<ActionButton
style={{
cursor: 'not-allowed',
backgroundColor: theme.buttonGray,
opacity: 0.4,
}}
>
<Plus color={theme.subText} size={16} style={{ minWidth: '16px' }} />
</ActionButton>
</MouseoverTooltip>
</ActionButton>
) : (
<ActionButton onClick={() => onOpenModal('stake', farm.pid)}>
<MouseoverTooltip text={t`Stake`} placement="top" width="fit-content">
<Plus color={theme.primary} size={16} />
</MouseoverTooltip>
</ActionButton>
)}

<ActionButton
disabled={!canUnstake}
Expand Down Expand Up @@ -735,7 +768,7 @@ function ProMMFarmGroup({
<Text fontSize="12px" color={theme.subText}>
<Trans>Deposited Liquidity</Trans>
<InfoHelper
text={t`Dollar value of NFT tokens you've deposited. NFT tokens represent your liquidity position`}
text={t`Total value of the liquidity positions you've deposited. NFT tokens represent your liquidity positions`}
></InfoHelper>
</Text>

Expand Down
2 changes: 1 addition & 1 deletion src/components/YieldPools/ProMMFarms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function ProMMFarms({ active }: { active: boolean }) {

<Flex grid-area="staked_balance" alignItems="center" justifyContent="flex-end">
<ClickableText>
<Trans>My Staked</Trans>
<Trans>My Deposit</Trans>
</ClickableText>
</Flex>

Expand Down
5 changes: 4 additions & 1 deletion src/pages/Pool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ export const FilterRow = styled(Flex)`
${({ theme }) => theme.mediaWidth.upToSmall`
align-items: flex-start;
flex-direction: column-reverse;
>div {
gap: 0;

> div {
margin-top: 12px;
width: 100%
justify-content: space-between
&:nth-child(1){
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Pools/InstructionAndGlobalData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const DetailWrapper = styled.div<{ isOpen?: boolean }>`

const DetailWrapperClassic = styled(DetailWrapper)`
grid-template-columns: 1fr 1fr 1fr;

${({ theme }) => theme.mediaWidth.upToMedium`
grid-template-columns: 1fr;
`}
`
const DetailItem = styled.div`
border-radius: 20px;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Pools/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Currency } from '@kyberswap/ks-sdk-core'
import { Trans, t } from '@lingui/macro'
import React, { useCallback, useMemo, useState } from 'react'
import { useCallback, useMemo, useState } from 'react'
import { Link, RouteComponentProps } from 'react-router-dom'
import { useMedia } from 'react-use'
import { Flex, Text } from 'rebass'
Expand Down
14 changes: 10 additions & 4 deletions src/pages/ProAmmPools/CardItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChainId, Token, WETH } from '@kyberswap/ks-sdk-core'
import { Trans, t } from '@lingui/macro'
import { rgba } from 'polished'
import React, { useState } from 'react'
import { useState } from 'react'
import { ChevronUp, Share2 } from 'react-feather'
import { Link } from 'react-router-dom'
import { Flex, Text } from 'rebass'
Expand All @@ -18,12 +18,13 @@ import { ELASTIC_BASE_FEE_UNIT, PROMM_ANALYTICS_URL } from 'constants/index'
import { nativeOnChain } from 'constants/tokens'
import { VERSION } from 'constants/v2'
import { useActiveWeb3React } from 'hooks'
import { useAllTokens } from 'hooks/Tokens'
import useTheme from 'hooks/useTheme'
import { IconWrapper } from 'pages/Pools/styleds'
import { useProMMFarms } from 'state/farms/promm/hooks'
import { ProMMPoolData } from 'state/prommPools/hooks'
import { ExternalLink } from 'theme'
import { shortenAddress } from 'utils'
import { isAddressString, shortenAddress } from 'utils'
import { formatDollarAmount } from 'utils/numbers'

interface ListItemProps {
Expand Down Expand Up @@ -70,9 +71,14 @@ export default function ProAmmPoolCardItem({ pair, onShared, userPositions, idx
const theme = useTheme()
const [isOpen, setIsOpen] = useState(true)

const allTokens = useAllTokens()
const { data: farms } = useProMMFarms()
const token0 = new Token(chainId as ChainId, pair[0].token0.address, pair[0].token0.decimals, pair[0].token0.symbol)
const token1 = new Token(chainId as ChainId, pair[0].token1.address, pair[0].token1.decimals, pair[0].token1.symbol)
const token0 =
allTokens[isAddressString(pair[0].token0.address)] ||
new Token(chainId as ChainId, pair[0].token0.address, pair[0].token0.decimals, pair[0].token0.symbol)
const token1 =
allTokens[isAddressString(pair[0].token1.address)] ||
new Token(chainId as ChainId, pair[0].token1.address, pair[0].token1.decimals, pair[0].token1.symbol)

const token0Address =
token0.address.toLowerCase() === WETH[chainId as ChainId].address.toLowerCase()
Expand Down
19 changes: 13 additions & 6 deletions src/pages/ProAmmPools/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChainId, Token, WETH } from '@kyberswap/ks-sdk-core'
import { Trans, t } from '@lingui/macro'
import { rgba } from 'polished'
import React, { useState } from 'react'
import { useState } from 'react'
import { BarChart2, ChevronUp, Plus, Share2 } from 'react-feather'
import { Link } from 'react-router-dom'
import { Flex, Text } from 'rebass'
Expand All @@ -17,13 +17,14 @@ import { ELASTIC_BASE_FEE_UNIT, PROMM_ANALYTICS_URL } from 'constants/index'
import { nativeOnChain } from 'constants/tokens'
import { VERSION } from 'constants/v2'
import { useActiveWeb3React } from 'hooks'
import { useAllTokens } from 'hooks/Tokens'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import useTheme from 'hooks/useTheme'
import { ButtonIcon } from 'pages/Pools/styleds'
import { useProMMFarms } from 'state/farms/promm/hooks'
import { ProMMPoolData } from 'state/prommPools/hooks'
import { ExternalLink } from 'theme'
import { shortenAddress } from 'utils'
import { isAddressString, shortenAddress } from 'utils'
import { formatDollarAmount } from 'utils/numbers'

import { ReactComponent as ViewPositionIcon } from '../../assets/svg/view_positions.svg'
Expand Down Expand Up @@ -93,8 +94,14 @@ export default function ProAmmPoolListItem({ pair, idx, onShared, userPositions,
const theme = useTheme()
const [isOpen, setIsOpen] = useState(pair.length > 1 ? idx === 0 : false)

const token0 = new Token(chainId as ChainId, pair[0].token0.address, pair[0].token0.decimals, pair[0].token0.symbol)
const token1 = new Token(chainId as ChainId, pair[0].token1.address, pair[0].token1.decimals, pair[0].token1.symbol)
const allTokens = useAllTokens()

const token0 =
allTokens[isAddressString(pair[0].token0.address)] ||
new Token(chainId as ChainId, pair[0].token0.address, pair[0].token0.decimals, pair[0].token0.symbol)
const token1 =
allTokens[isAddressString(pair[0].token1.address)] ||
new Token(chainId as ChainId, pair[0].token1.address, pair[0].token1.decimals, pair[0].token1.symbol)

const { data: farms } = useProMMFarms()

Expand All @@ -115,7 +122,7 @@ export default function ProAmmPoolListItem({ pair, idx, onShared, userPositions,
const token0Symbol =
pool.token0.address === WETH[chainId as ChainId].address.toLowerCase()
? nativeOnChain(chainId as ChainId).symbol
: pool.token0.symbol
: token0.symbol

const token1Address =
pool.token1.address === WETH[chainId as ChainId].address.toLowerCase()
Expand All @@ -124,7 +131,7 @@ export default function ProAmmPoolListItem({ pair, idx, onShared, userPositions,
const token1Symbol =
pool.token1.address === WETH[chainId as ChainId].address.toLowerCase()
? nativeOnChain(chainId as ChainId).symbol
: pool.token1.symbol
: token1.symbol

const isFarmingPool = Object.values(farms)
.flat()
Expand Down
19 changes: 15 additions & 4 deletions src/state/farms/promm/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export const useProMMFarmTVL = (fairlaunchAddress: string, pid: number) => {
const dataClient = NETWORKS_INFO[chainId || ChainId.MAINNET].elasticClient
const { block24 } = usePoolBlocks()

const { data } = useQuery<Response>(PROMM_JOINED_POSITION(fairlaunchAddress.toLowerCase(), pid, block24), {
const { data, loading } = useQuery<Response>(PROMM_JOINED_POSITION(fairlaunchAddress.toLowerCase(), pid, block24), {
client: dataClient,
fetchPolicy: 'cache-first',
})
Expand Down Expand Up @@ -479,7 +479,16 @@ export const useProMMFarmTVL = (fairlaunchAddress: string, pid: number) => {

const ethPriceUSD = useETHPrice(VERSION.ELASTIC)

return useMemo(() => {
const [farmData, setData] = useState({
tvl: 0,
poolAPY: 0,
farmAPR: 0,
})

useEffect(() => {
if (loading || !Object.values(priceMap).length || (farmData.tvl && farmData.poolAPY && farmData.farmAPR)) {
return
}
let tvl = 0
data?.joinedPositions.forEach(({ position, pool }) => {
const token0 = new Token(chainId as ChainId, pool.token0.id, Number(pool.token0.decimals), pool.token0.symbol)
Expand Down Expand Up @@ -529,6 +538,8 @@ export const useProMMFarmTVL = (fairlaunchAddress: string, pid: number) => {
Number(data?.farmingPool?.pool?.totalValueLockedUSD || 1)
: 0

return { tvl, farmAPR, poolAPY }
}, [chainId, data, ethPriceUSD.currentPrice, priceMap])
setData({ tvl, farmAPR, poolAPY })
}, [chainId, data, ethPriceUSD.currentPrice, priceMap, loading, farmData.poolAPY, farmData.tvl, farmData.farmAPR])

return { ...farmData }
}