import { JSBI, Pair, Percent } from 'moonbeamswap' import { darken } from 'polished' import React, { useState } from 'react' import { ChevronDown, ChevronUp } from 'react-feather' import { Link } from 'react-router-dom' import { Text } from 'rebass' import styled from 'styled-components' import { useTotalSupply } from '../../data/TotalSupply' import { useActiveWeb3React } from '../../hooks' import { useTokenBalance } from '../../state/wallet/hooks' import { ExternalLink } from '../../theme' import { currencyId } from '../../utils/currencyId' import { unwrappedToken } from '../../utils/wrappedCurrency' import { ButtonSecondary } from '../Button' import Card, { GreyCard } from '../Card' import { AutoColumn } from '../Column' import CurrencyLogo from '../CurrencyLogo' import DoubleCurrencyLogo from '../DoubleLogo' import { AutoRow, RowBetween, RowFixed } from '../Row' import { Dots } from '../swap/styleds' export const FixedHeightRow = styled(RowBetween)` height: 24px; ` export const HoverCard = styled(Card)` border: 1px solid ${({ theme }) => theme.bg2}; :hover { border: 1px solid ${({ theme }) => darken(0.06, theme.bg2)}; } ` interface PositionCardProps { pair: Pair showUnwrapped?: boolean border?: string } export function MinimalPositionCard({ pair, showUnwrapped = false, border }: PositionCardProps) { const { account } = useActiveWeb3React() const currency0 = showUnwrapped ? pair.token0 : unwrappedToken(pair.token0) const currency1 = showUnwrapped ? pair.token1 : unwrappedToken(pair.token1) const [showMore, setShowMore] = useState(false) const userPoolBalance = useTokenBalance(account ?? undefined, pair.liquidityToken) const totalPoolTokens = useTotalSupply(pair.liquidityToken) const [token0Deposited, token1Deposited] = !!pair && !!totalPoolTokens && !!userPoolBalance && // this condition is a short-circuit in the case where useTokenBalance updates sooner than useTotalSupply JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw) ? [ pair.getLiquidityValue(pair.token0, totalPoolTokens, userPoolBalance, false), pair.getLiquidityValue(pair.token1, totalPoolTokens, userPoolBalance, false) ] : [undefined, undefined] return ( <> {userPoolBalance && ( Your position setShowMore(!showMore)}> {currency0.symbol}/{currency1.symbol} {userPoolBalance ? userPoolBalance.toSignificant(4) : '-'} {currency0.symbol}: {token0Deposited ? ( {token0Deposited?.toSignificant(6)} ) : ( '-' )} {currency1.symbol}: {token1Deposited ? ( {token1Deposited?.toSignificant(6)} ) : ( '-' )} )} ) } export default function FullPositionCard({ pair, border }: PositionCardProps) { const { account } = useActiveWeb3React() const currency0 = unwrappedToken(pair.token0) const currency1 = unwrappedToken(pair.token1) const [showMore, setShowMore] = useState(false) const userPoolBalance = useTokenBalance(account ?? undefined, pair.liquidityToken) const totalPoolTokens = useTotalSupply(pair.liquidityToken) const poolTokenPercentage = !!userPoolBalance && !!totalPoolTokens && JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw) ? new Percent(userPoolBalance.raw, totalPoolTokens.raw) : undefined const [token0Deposited, token1Deposited] = !!pair && !!totalPoolTokens && !!userPoolBalance && // this condition is a short-circuit in the case where useTokenBalance updates sooner than useTotalSupply JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw) ? [ pair.getLiquidityValue(pair.token0, totalPoolTokens, userPoolBalance, false), pair.getLiquidityValue(pair.token1, totalPoolTokens, userPoolBalance, false) ] : [undefined, undefined] return ( setShowMore(!showMore)} style={{ cursor: 'pointer' }}> {!currency0 || !currency1 ? Loading : `${currency0.symbol}/${currency1.symbol}`} {showMore ? ( ) : ( )} {showMore && ( Pooled {currency0.symbol}: {token0Deposited ? ( {token0Deposited?.toSignificant(6)} ) : ( '-' )} Pooled {currency1.symbol}: {token1Deposited ? ( {token1Deposited?.toSignificant(6)} ) : ( '-' )} Your pool tokens: {userPoolBalance ? userPoolBalance.toSignificant(4) : '-'} Your pool share: {poolTokenPercentage ? poolTokenPercentage.toFixed(2) + '%' : '-'} View pool information (comming soon) ↗ Add Remove )} ) }