Commit ab99cc61 authored by Noah Zinsmeister's avatar Noah Zinsmeister

add current price

parent 11a4fa23
import React, { useCallback, useMemo, useState } from 'react' import React, { useCallback, useMemo, useState } from 'react'
import { Position } from '@uniswap/v3-sdk' import { Pool, Position } from '@uniswap/v3-sdk'
import { PoolState, usePool } from 'hooks/usePools' import { PoolState, usePool } from 'hooks/usePools'
import { useToken } from 'hooks/Tokens' import { useToken } from 'hooks/Tokens'
import { useV3PositionFromTokenId } from 'hooks/useV3Positions' import { useV3PositionFromTokenId } from 'hooks/useV3Positions'
...@@ -22,7 +22,7 @@ import { currencyId } from 'utils/currencyId' ...@@ -22,7 +22,7 @@ import { currencyId } from 'utils/currencyId'
import { formatTokenAmount } from 'utils/formatTokenAmount' import { formatTokenAmount } from 'utils/formatTokenAmount'
import { useV3PositionFees } from 'hooks/useV3PositionFees' import { useV3PositionFees } from 'hooks/useV3PositionFees'
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { WETH9 } from '@uniswap/sdk-core' import { WETH9, Currency } from '@uniswap/sdk-core'
import { useActiveWeb3React } from 'hooks' import { useActiveWeb3React } from 'hooks'
import { useV3NFTPositionManagerContract } from 'hooks/useContract' import { useV3NFTPositionManagerContract } from 'hooks/useContract'
import { UINT128MAX } from '../RemoveLiquidity/V3' import { UINT128MAX } from '../RemoveLiquidity/V3'
...@@ -94,6 +94,36 @@ export const DarkBadge = styled.div` ...@@ -94,6 +94,36 @@ export const DarkBadge = styled.div`
padding: 4px 6px; padding: 4px 6px;
` `
function CurrentPriceCard({
inverted,
pool,
currencyQuote,
currencyBase,
}: {
inverted?: boolean
pool?: Pool | null
currencyQuote?: Currency
currencyBase?: Currency
}) {
if (!pool || !currencyQuote || !currencyBase) {
return null
}
return (
<DarkGreyCard width="32%">
<AutoColumn gap="sm" justify="flex-start">
<TYPE.main>Current</TYPE.main>
<RowFixed>
<TYPE.label>
{(inverted ? pool.token1Price : pool.token0Price).toSignificant(4)} {currencyQuote?.symbol} / 1{' '}
{currencyBase?.symbol}
</TYPE.label>
</RowFixed>
</AutoColumn>
</DarkGreyCard>
)
}
export function PositionPage({ export function PositionPage({
match: { match: {
params: { tokenId: tokenIdFromUrl }, params: { tokenId: tokenIdFromUrl },
...@@ -134,10 +164,12 @@ export function PositionPage({ ...@@ -134,10 +164,12 @@ export function PositionPage({
const currencyBase = inverted ? currency1 : currency0 const currencyBase = inverted ? currency1 : currency0
// check if price is within range // check if price is within range
const outOfRange: boolean = const inRange: boolean =
pool && typeof tickLower === 'number' && typeof tickUpper === 'number' pool && typeof tickLower === 'number' && typeof tickUpper === 'number'
? pool.tickCurrent < tickLower || pool.tickCurrent > tickUpper ? pool.tickCurrent >= tickLower && pool.tickCurrent < tickUpper
: false : false
const below = pool && typeof tickLower === 'number' ? pool.tickCurrent < tickLower : false
const above = pool && typeof tickUpper === 'number' ? pool.tickCurrent >= tickUpper : false
// fees // fees
const [feeValue0, feeValue1] = useV3PositionFees(pool ?? undefined, positionDetails) const [feeValue0, feeValue1] = useV3PositionFees(pool ?? undefined, positionDetails)
...@@ -277,17 +309,17 @@ export function PositionPage({ ...@@ -277,17 +309,17 @@ export function PositionPage({
</RowBetween> </RowBetween>
<RowBetween> <RowBetween>
<BadgeWrapper> <BadgeWrapper>
{outOfRange ? ( {inRange ? (
<Badge variant={BadgeVariant.DEFAULT}>
<ActiveDot /> &nbsp;
<BadgeText>{t('Active')}</BadgeText>
</Badge>
) : (
<Badge variant={BadgeVariant.WARNING}> <Badge variant={BadgeVariant.WARNING}>
<AlertTriangle width={14} height={14} style={{ marginRight: '4px' }} /> <AlertTriangle width={14} height={14} style={{ marginRight: '4px' }} />
&nbsp; &nbsp;
<BadgeText>{t('Out of range')}</BadgeText> <BadgeText>{t('Out of range')}</BadgeText>
</Badge> </Badge>
) : (
<Badge variant={BadgeVariant.DEFAULT}>
<ActiveDot /> &nbsp;
<BadgeText>{t('Active')}</BadgeText>
</Badge>
)} )}
</BadgeWrapper> </BadgeWrapper>
</RowBetween> </RowBetween>
...@@ -351,8 +383,17 @@ export function PositionPage({ ...@@ -351,8 +383,17 @@ export function PositionPage({
</ButtonText> </ButtonText>
</TYPE.label> </TYPE.label>
{below && (
<CurrentPriceCard
inverted={inverted}
pool={pool}
currencyQuote={currencyQuote}
currencyBase={currencyBase}
/>
)}
<RowBetween> <RowBetween>
<DarkGreyCard width="48%"> <DarkGreyCard width="32%">
<AutoColumn gap="sm" justify="flex-start"> <AutoColumn gap="sm" justify="flex-start">
<TYPE.main>Lower</TYPE.main> <TYPE.main>Lower</TYPE.main>
<RowFixed> <RowFixed>
...@@ -370,7 +411,16 @@ export function PositionPage({ ...@@ -370,7 +411,16 @@ export function PositionPage({
</AutoColumn> </AutoColumn>
</DarkGreyCard> </DarkGreyCard>
<DarkGreyCard width="48%"> {inRange && (
<CurrentPriceCard
inverted={inverted}
pool={pool}
currencyQuote={currencyQuote}
currencyBase={currencyBase}
/>
)}
<DarkGreyCard width="32%">
<AutoColumn gap="sm" justify="flex-start"> <AutoColumn gap="sm" justify="flex-start">
<TYPE.main>Upper</TYPE.main> <TYPE.main>Upper</TYPE.main>
<RowFixed> <RowFixed>
...@@ -387,6 +437,15 @@ export function PositionPage({ ...@@ -387,6 +437,15 @@ export function PositionPage({
</DarkBadge> </DarkBadge>
</AutoColumn> </AutoColumn>
</DarkGreyCard> </DarkGreyCard>
{above && (
<CurrentPriceCard
inverted={inverted}
pool={pool}
currencyQuote={currencyQuote}
currencyBase={currencyBase}
/>
)}
</RowBetween> </RowBetween>
</AutoColumn> </AutoColumn>
</DarkCard> </DarkCard>
......
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