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

Fix ticks prices decimals #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions src/components/DensityChart/CurrentPriceLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styled from 'styled-components'
import { AutoColumn } from 'components/Column'
import { RowFixed } from 'components/Row'
import { TYPE } from 'theme'
import { formatAmount } from 'utils/numbers'

const Wrapper = styled.div`
border-radius: 8px;
Expand Down Expand Up @@ -52,12 +53,12 @@ export function CurrentPriceLabel({ data, chartProps, poolData }: CurrentPriceLa
}}
></div>
</RowFixed>
<TYPE.label>{`1 ${poolData.token0.symbol} = ${Number(price0).toLocaleString(undefined, {
minimumSignificantDigits: 1,
})} ${poolData.token1.symbol}`}</TYPE.label>
<TYPE.label>{`1 ${poolData.token1.symbol} = ${Number(price1).toLocaleString(undefined, {
minimumSignificantDigits: 1,
})} ${poolData.token0.symbol}`}</TYPE.label>
<TYPE.label>{`1 ${poolData.token0.symbol} = ${formatAmount(price0, 4)} ${
poolData.token1.symbol
}`}</TYPE.label>
<TYPE.label>{`1 ${poolData.token1.symbol} = ${formatAmount(price1, 4)} ${
poolData.token0.symbol
}`}</TYPE.label>
</AutoColumn>
</Wrapper>
</foreignObject>
Expand Down
14 changes: 2 additions & 12 deletions src/components/DensityChart/CustomToolTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,13 @@ export function CustomToolTip({ chartProps, poolData, currentPrice }: CustomTool
<RowBetween>
<TYPE.label>{poolData?.token0?.symbol} Price: </TYPE.label>
<TYPE.label>
{price0
? Number(price0).toLocaleString(undefined, {
minimumSignificantDigits: 1,
})
: ''}{' '}
{poolData?.token1?.symbol}
{price0 ? formatAmount(price0, 4) : ''} {poolData?.token1?.symbol}
</TYPE.label>
</RowBetween>
<RowBetween>
<TYPE.label>{poolData?.token1?.symbol} Price: </TYPE.label>
<TYPE.label>
{price1
? Number(price1).toLocaleString(undefined, {
minimumSignificantDigits: 1,
})
: ''}{' '}
{poolData?.token0?.symbol}
{price1 ? formatAmount(price1, 4) : ''} {poolData?.token0?.symbol}
</TYPE.label>
</RowBetween>
{currentPrice && price0 && currentPrice > price1 ? (
Expand Down
9 changes: 4 additions & 5 deletions src/data/pools/tickData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { TickMath, tickToPrice } from '@uniswap/v3-sdk'
import { Token } from '@uniswap/sdk-core'
import { ApolloClient, NormalizedCacheObject } from '@apollo/client'

const PRICE_FIXED_DIGITS = 4
const DEFAULT_SURROUNDING_TICKS = 300
const FEE_TIER_TO_TICK_SPACING = (feeTier: string): number => {
switch (feeTier) {
Expand Down Expand Up @@ -231,8 +230,8 @@ export const fetchTicksSurroundingPrice = async (
liquidityActive: JSBI.BigInt(liquidity),
tickIdx: activeTickIdx,
liquidityNet: JSBI.BigInt(0),
price0: tickToPrice(token0, token1, activeTickIdxForPrice).toFixed(PRICE_FIXED_DIGITS),
price1: tickToPrice(token1, token0, activeTickIdxForPrice).toFixed(PRICE_FIXED_DIGITS),
price0: tickToPrice(token0, token1, activeTickIdxForPrice).toFixed(token1.decimals),
price1: tickToPrice(token1, token0, activeTickIdxForPrice).toFixed(token0.decimals),
liquidityGross: JSBI.BigInt(0),
}

Expand Down Expand Up @@ -278,8 +277,8 @@ export const fetchTicksSurroundingPrice = async (
liquidityActive: previousTickProcessed.liquidityActive,
tickIdx: currentTickIdx,
liquidityNet: JSBI.BigInt(0),
price0: tickToPrice(token0, token1, currentTickIdx).toFixed(PRICE_FIXED_DIGITS),
price1: tickToPrice(token1, token0, currentTickIdx).toFixed(PRICE_FIXED_DIGITS),
price0: tickToPrice(token0, token1, currentTickIdx).toFixed(token1.decimals),
price1: tickToPrice(token1, token0, currentTickIdx).toFixed(token0.decimals),
liquidityGross: JSBI.BigInt(0),
}

Expand Down