Commit da33ec9d authored by Ian Lapham's avatar Ian Lapham Committed by GitHub

use token0 as base in all calculations (#51)

* use token0 as base in all calculations

* refactor

* fix price order

* fix existing position ticks

* remove empty space
Co-authored-by: default avatarNoah Zinsmeister <noahwz@gmail.com>
parent 60536862
...@@ -2,7 +2,7 @@ import React, { useState, useCallback, useEffect } from 'react' ...@@ -2,7 +2,7 @@ import React, { useState, useCallback, useEffect } from 'react'
import { OutlineCard } from 'components/Card' import { OutlineCard } from 'components/Card'
import { RowBetween } from 'components/Row' import { RowBetween } from 'components/Row'
import { Input as NumericalInput } from '../NumericalInput' import { Input as NumericalInput } from '../NumericalInput'
import styled, { keyframes, css } from 'styled-components' import styled, { keyframes } from 'styled-components'
import { TYPE } from 'theme' import { TYPE } from 'theme'
import { AutoColumn } from 'components/Column' import { AutoColumn } from 'components/Column'
import { ButtonSecondary } from 'components/Button' import { ButtonSecondary } from 'components/Button'
...@@ -34,11 +34,7 @@ const FocusedOutlineCard = styled(OutlineCard)<{ active?: boolean; pulsing?: boo ...@@ -34,11 +34,7 @@ const FocusedOutlineCard = styled(OutlineCard)<{ active?: boolean; pulsing?: boo
border-color: ${({ active, theme }) => active && theme.blue1}; border-color: ${({ active, theme }) => active && theme.blue1};
padding: 12px; padding: 12px;
${({ pulsing, theme }) => animation: ${({ pulsing, theme }) => pulsing && pulse(theme.blue1)} 0.8s linear;
pulsing &&
css`
animation: ${pulse(theme.blue1)} 0.8s linear;
`}
` `
const StyledInput = styled(NumericalInput)<{ usePercent?: boolean }>` const StyledInput = styled(NumericalInput)<{ usePercent?: boolean }>`
...@@ -54,8 +50,8 @@ const ContentWrapper = styled(RowBetween)` ...@@ -54,8 +50,8 @@ const ContentWrapper = styled(RowBetween)`
interface StepCounterProps { interface StepCounterProps {
value: string value: string
onUserInput: (value: string) => void onUserInput: (value: string) => void
getDecrementValue?: () => string decrement: () => string
getIncrementValue?: () => string increment: () => string
feeAmount?: FeeAmount feeAmount?: FeeAmount
label?: string label?: string
width?: string width?: string
...@@ -64,13 +60,13 @@ interface StepCounterProps { ...@@ -64,13 +60,13 @@ interface StepCounterProps {
const StepCounter = ({ const StepCounter = ({
value, value,
onUserInput, decrement,
getDecrementValue, increment,
getIncrementValue,
feeAmount, feeAmount,
label, label,
width, width,
locked, locked,
onUserInput,
}: StepCounterProps) => { }: StepCounterProps) => {
// for focus state, styled components doesnt let you select input parent container // for focus state, styled components doesnt let you select input parent container
const [active, setActive] = useState(false) const [active, setActive] = useState(false)
...@@ -83,7 +79,7 @@ const StepCounter = ({ ...@@ -83,7 +79,7 @@ const StepCounter = ({
const [pulsing, setPulsing] = useState<boolean>(false) const [pulsing, setPulsing] = useState<boolean>(false)
// format fee amount // format fee amount
const feeAmountFormatted = feeAmount ? formattedFeeAmount(feeAmount) : '' const feeAmountFormatted = feeAmount ? formattedFeeAmount(feeAmount * 2) : ''
const handleOnFocus = () => { const handleOnFocus = () => {
setUseLocalValue(true) setUseLocalValue(true)
...@@ -92,18 +88,14 @@ const StepCounter = ({ ...@@ -92,18 +88,14 @@ const StepCounter = ({
// for button clicks // for button clicks
const handleDecrement = useCallback(() => { const handleDecrement = useCallback(() => {
if (getDecrementValue) { setLocalValue(decrement())
setLocalValue(getDecrementValue()) onUserInput(decrement())
onUserInput(getDecrementValue()) }, [decrement, onUserInput])
}
}, [getDecrementValue, onUserInput])
const handleIncrement = useCallback(() => { const handleIncrement = useCallback(() => {
if (getIncrementValue) { setLocalValue(increment())
setLocalValue(getIncrementValue()) onUserInput(increment())
onUserInput(getIncrementValue()) }, [increment, onUserInput])
}
}, [getIncrementValue, onUserInput])
const handleOnBlur = useCallback(() => { const handleOnBlur = useCallback(() => {
setUseLocalValue(false) setUseLocalValue(false)
...@@ -138,7 +130,7 @@ const StepCounter = ({ ...@@ -138,7 +130,7 @@ const StepCounter = ({
/> />
</ContentWrapper> </ContentWrapper>
{label && <TYPE.label fontSize="12px">{label}</TYPE.label>} {label && <TYPE.label fontSize="12px">{label}</TYPE.label>}
{getDecrementValue && getIncrementValue && !locked ? ( {!locked ? (
<RowBetween> <RowBetween>
<SmallButton onClick={handleDecrement}> <SmallButton onClick={handleDecrement}>
<TYPE.main fontSize="12px">-{feeAmountFormatted}%</TYPE.main> <TYPE.main fontSize="12px">-{feeAmountFormatted}%</TYPE.main>
......
...@@ -159,10 +159,10 @@ export default function PositionListItem({ positionDetails }: PositionListItemPr ...@@ -159,10 +159,10 @@ export default function PositionListItem({ positionDetails }: PositionListItemPr
const formattedAmount1 = formatTokenAmount(amount1, 4) const formattedAmount1 = formatTokenAmount(amount1, 4)
// prices // prices
const price0Lower = position ? position.token0PriceLower : undefined const price0Lower = position?.token0PriceLower
const price0Upper = position ? position.token0PriceUpper : undefined const price0Upper = position?.token0PriceUpper
const price1Lower = price0Upper ? price0Upper.invert() : undefined const price1Lower = price0Lower?.invert()
const price1Upper = price0Lower ? price0Lower.invert() : undefined const price1Upper = price0Upper?.invert()
// fees // fees
const [feeValue0, feeValue1] = useV3PositionFees(pool ?? undefined, positionDetails) const [feeValue0, feeValue1] = useV3PositionFees(pool ?? undefined, positionDetails)
...@@ -205,13 +205,13 @@ export default function PositionListItem({ positionDetails }: PositionListItemPr ...@@ -205,13 +205,13 @@ export default function PositionListItem({ positionDetails }: PositionListItemPr
<> <>
<DataLineItem> <DataLineItem>
{formatPrice(price0Lower, 4)} <DoubleArrow></DoubleArrow> {formatPrice(price0Upper, 4)}{' '} {formatPrice(price0Lower, 4)} <DoubleArrow></DoubleArrow> {formatPrice(price0Upper, 4)}{' '}
{currency0?.symbol}&nbsp;/&nbsp; {currency1?.symbol}&nbsp;/&nbsp;
{currency1?.symbol} {currency0?.symbol}
</DataLineItem> </DataLineItem>
<DataLineItem> <DataLineItem>
{formatPrice(price1Lower, 4)} <DoubleArrow></DoubleArrow> {formatPrice(price1Upper, 4)}{' '} {formatPrice(price1Lower, 4)} <DoubleArrow></DoubleArrow> {formatPrice(price1Upper, 4)}{' '}
{currency1?.symbol}&nbsp;/&nbsp; {currency0?.symbol}&nbsp;/&nbsp;
{currency0?.symbol} {currency1?.symbol}
</DataLineItem> </DataLineItem>
</> </>
) : ( ) : (
......
import React from 'react'
import { Currency, Price } from '@uniswap/sdk-core' import { Currency, Price } from '@uniswap/sdk-core'
import StepCounter from 'components/InputStepCounter/InputStepCounter' import StepCounter from 'components/InputStepCounter/InputStepCounter'
import { RowBetween } from 'components/Row' import { RowBetween } from 'components/Row'
import React from 'react' import { useActiveWeb3React } from 'hooks'
import { wrappedCurrency } from 'utils/wrappedCurrency'
// currencyA is the base token // currencyA is the base token
export default function RangeSelector({ export default function RangeSelector({
priceLower, priceLower,
priceUpper, priceUpper,
onUpperRangeInput, onLeftRangeInput,
onLowerRangeInput, onRightRangeInput,
getLowerDecrement, getDecrementLower,
getLowerIncrement, getIncrementLower,
getUpperDecrement, getDecrementUpper,
getUpperIncrement, getIncrementUpper,
currencyA, currencyA,
currencyB, currencyB,
feeAmount, feeAmount,
fixedValueLower,
fixedValueUpper,
}: { }: {
priceLower?: Price priceLower?: Price
priceUpper?: Price priceUpper?: Price
getLowerIncrement?: () => string getDecrementLower: () => string
getLowerDecrement?: () => string getIncrementLower: () => string
getUpperIncrement?: () => string getDecrementUpper: () => string
getUpperDecrement?: () => string getIncrementUpper: () => string
onLowerRangeInput: (typedValue: string) => void onLeftRangeInput: (typedValue: string) => void
onUpperRangeInput: (typedValue: string) => void onRightRangeInput: (typedValue: string) => void
currencyA?: Currency | null currencyA?: Currency | null
currencyB?: Currency | null currencyB?: Currency | null
feeAmount?: number feeAmount?: number
fixedValueLower?: string
fixedValueUpper?: string
}) { }) {
const { chainId } = useActiveWeb3React()
const tokenA = wrappedCurrency(currencyA ?? undefined, chainId)
const tokenB = wrappedCurrency(currencyB ?? undefined, chainId)
const isSorted = tokenA && tokenB && tokenA.sortsBefore(tokenB)
const leftPrice = isSorted ? priceLower : priceUpper?.invert()
const rightPrice = isSorted ? priceUpper : priceLower?.invert()
return ( return (
<RowBetween> <RowBetween>
<StepCounter <StepCounter
value={fixedValueLower ?? priceLower?.toSignificant(5) ?? ''} value={leftPrice?.toSignificant(5) ?? ''}
onUserInput={onLowerRangeInput} onUserInput={onLeftRangeInput}
width="48%" width="48%"
getIncrementValue={getLowerIncrement} decrement={isSorted ? getDecrementLower : getIncrementUpper}
getDecrementValue={getLowerDecrement} increment={isSorted ? getIncrementLower : getDecrementUpper}
feeAmount={feeAmount} feeAmount={feeAmount}
label={ label={leftPrice ? `${leftPrice.toSignificant(5)} ${currencyB?.symbol}/${currencyA?.symbol}` : '-'}
priceLower && currencyA && currencyB
? `${priceLower.toSignificant(4)} ${currencyB.symbol} / 1 ${currencyA.symbol}`
: '-'
}
locked={!!fixedValueLower}
/> />
<StepCounter <StepCounter
value={fixedValueUpper ?? priceUpper?.toSignificant(5) ?? ''} value={rightPrice?.toSignificant(5) ?? ''}
onUserInput={onUpperRangeInput} onUserInput={onRightRangeInput}
width="48%" width="48%"
getDecrementValue={getUpperDecrement} decrement={isSorted ? getDecrementUpper : getIncrementLower}
getIncrementValue={getUpperIncrement} increment={isSorted ? getIncrementUpper : getDecrementLower}
feeAmount={feeAmount} feeAmount={feeAmount}
label={ label={rightPrice ? `${rightPrice.toSignificant(5)} ${currencyB?.symbol}/${currencyA?.symbol}` : '-'}
priceUpper && currencyA && currencyB
? `${priceUpper.toSignificant(4)} ${currencyB?.symbol} / 1 ${currencyA?.symbol}`
: '-'
}
locked={!!fixedValueUpper}
/> />
</RowBetween> </RowBetween>
) )
......
This diff is collapsed.
...@@ -29,10 +29,10 @@ import { useUserSlippageTolerance } from 'state/user/hooks' ...@@ -29,10 +29,10 @@ import { useUserSlippageTolerance } from 'state/user/hooks'
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
import { TransactionResponse } from '@ethersproject/providers' import { TransactionResponse } from '@ethersproject/providers'
import { useIsTransactionPending, useTransactionAdder } from 'state/transactions/hooks' import { useIsTransactionPending, useTransactionAdder } from 'state/transactions/hooks'
import { useDerivedMintInfo, useMintActionHandlers } from 'state/mint/hooks' import { useDerivedMintInfo, useMintActionHandlers, useRangeHopCallbacks } from 'state/mint/hooks'
import { Bound } from 'state/mint/actions' import { Bound } from 'state/mint/actions'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { ChevronDown } from 'react-feather' import { AlertTriangle, ChevronDown } from 'react-feather'
import FeeSelector from 'components/FeeSelector' import FeeSelector from 'components/FeeSelector'
import RangeSelector from 'components/RangeSelector' import RangeSelector from 'components/RangeSelector'
import RateToggle from 'components/RateToggle' import RateToggle from 'components/RateToggle'
...@@ -42,6 +42,7 @@ import { splitSignature } from '@ethersproject/bytes' ...@@ -42,6 +42,7 @@ import { splitSignature } from '@ethersproject/bytes'
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp' import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp'
import { formatTokenAmount } from 'utils/formatTokenAmount' import { formatTokenAmount } from 'utils/formatTokenAmount'
import useTheme from 'hooks/useTheme'
const ZERO = JSBI.BigInt(0) const ZERO = JSBI.BigInt(0)
...@@ -104,6 +105,7 @@ function V2PairMigration({ ...@@ -104,6 +105,7 @@ function V2PairMigration({
}) { }) {
const { t } = useTranslation() const { t } = useTranslation()
const { chainId, account, library } = useActiveWeb3React() const { chainId, account, library } = useActiveWeb3React()
const theme = useTheme()
const deadline = useTransactionDeadline() // custom from users settings const deadline = useTransactionDeadline() // custom from users settings
const blockTimestamp = useCurrentBlockTimestamp() const blockTimestamp = useCurrentBlockTimestamp()
...@@ -141,31 +143,39 @@ function V2PairMigration({ ...@@ -141,31 +143,39 @@ function V2PairMigration({
const largePriceDifference = priceDifferenceFraction && !priceDifferenceFraction?.lessThan(JSBI.BigInt(4)) const largePriceDifference = priceDifferenceFraction && !priceDifferenceFraction?.lessThan(JSBI.BigInt(4))
const [invertPrice, setInvertPrice] = useState(false)
// the following is a small hack to get access to price range data/input handlers // the following is a small hack to get access to price range data/input handlers
const { ticks, pricesAtTicks } = useDerivedMintInfo( const [baseToken, setBaseToken] = useState(token0)
invertPrice ? token1 : token0, const { ticks, pricesAtTicks, invertPrice, invalidRange, outOfRange } = useDerivedMintInfo(
invertPrice ? token0 : token1, token0,
feeAmount token1,
feeAmount,
baseToken
) )
// get value and prices at ticks // get value and prices at ticks
const { [Bound.LOWER]: tickLower, [Bound.UPPER]: tickUpper } = ticks const { [Bound.LOWER]: tickLower, [Bound.UPPER]: tickUpper } = ticks
const { [Bound.LOWER]: priceLower, [Bound.UPPER]: priceUpper } = pricesAtTicks const { [Bound.LOWER]: priceLower, [Bound.UPPER]: priceUpper } = pricesAtTicks
const { onLowerRangeInput, onUpperRangeInput } = useMintActionHandlers(noLiquidity) const { getDecrementLower, getIncrementLower, getDecrementUpper, getIncrementUpper } = useRangeHopCallbacks(
baseToken,
baseToken.equals(token0) ? token1 : token0,
feeAmount,
tickLower,
tickUpper
)
const { onLeftRangeInput, onRightRangeInput } = useMintActionHandlers(noLiquidity)
// the v3 tick is either the pool's tickCurrent, or the tick closest to the v2 spot price // the v3 tick is either the pool's tickCurrent, or the tick closest to the v2 spot price
const tick = pool?.tickCurrent ?? priceToClosestTick(v2SpotPrice) const tick = pool?.tickCurrent ?? priceToClosestTick(v2SpotPrice)
// the price is either the current v3 price, or the price at the tick // the price is either the current v3 price, or the price at the tick
const sqrtPrice = pool?.sqrtRatioX96 ?? TickMath.getSqrtRatioAtTick(tick) const sqrtPrice = pool?.sqrtRatioX96 ?? TickMath.getSqrtRatioAtTick(tick)
const position = const position =
typeof tickLower === 'number' && typeof tickUpper === 'number' typeof tickLower === 'number' && typeof tickUpper === 'number' && !invalidRange
? Position.fromAmounts({ ? Position.fromAmounts({
pool: pool ?? new Pool(token0, token1, feeAmount, sqrtPrice, 0, tick, []), pool: pool ?? new Pool(token0, token1, feeAmount, sqrtPrice, 0, tick, []),
tickLower: invertPrice ? tickUpper : tickLower, tickLower,
tickUpper: invertPrice ? tickLower : tickUpper, tickUpper,
amount0: token0Value.raw, amount0: token0Value.raw,
amount1: token1Value.raw, amount1: token1Value.raw,
}) })
...@@ -340,8 +350,8 @@ function V2PairMigration({ ...@@ -340,8 +350,8 @@ function V2PairMigration({
token0: token0.address, token0: token0.address,
token1: token1.address, token1: token1.address,
fee: feeAmount, fee: feeAmount,
tickLower: invertPrice ? tickUpper : tickLower, tickLower,
tickUpper: invertPrice ? tickLower : tickUpper, tickUpper,
amount0Min: `0x${v3Amount0Min.raw.toString(16)}`, amount0Min: `0x${v3Amount0Min.raw.toString(16)}`,
amount1Min: `0x${v3Amount1Min.raw.toString(16)}`, amount1Min: `0x${v3Amount1Min.raw.toString(16)}`,
recipient: account, recipient: account,
...@@ -379,7 +389,6 @@ function V2PairMigration({ ...@@ -379,7 +389,6 @@ function V2PairMigration({
token1, token1,
feeAmount, feeAmount,
pairBalance, pairBalance,
invertPrice,
tickLower, tickLower,
tickUpper, tickUpper,
sqrtPrice, sqrtPrice,
...@@ -475,9 +484,9 @@ function V2PairMigration({ ...@@ -475,9 +484,9 @@ function V2PairMigration({
currencyA={invertPrice ? token1 : token0} currencyA={invertPrice ? token1 : token0}
currencyB={invertPrice ? token0 : token1} currencyB={invertPrice ? token0 : token1}
handleRateToggle={() => { handleRateToggle={() => {
onLowerRangeInput('') onLeftRangeInput('')
onUpperRangeInput('') onRightRangeInput('')
setInvertPrice((invertPrice) => !invertPrice) setBaseToken((base) => (base.equals(token0) ? token1 : token0))
}} }}
/> />
</RowBetween> </RowBetween>
...@@ -485,12 +494,39 @@ function V2PairMigration({ ...@@ -485,12 +494,39 @@ function V2PairMigration({
<RangeSelector <RangeSelector
priceLower={priceLower} priceLower={priceLower}
priceUpper={priceUpper} priceUpper={priceUpper}
onLowerRangeInput={onLowerRangeInput} getDecrementLower={getDecrementLower}
onUpperRangeInput={onUpperRangeInput} getIncrementLower={getIncrementLower}
getDecrementUpper={getDecrementUpper}
getIncrementUpper={getIncrementUpper}
onLeftRangeInput={onLeftRangeInput}
onRightRangeInput={onRightRangeInput}
currencyA={invertPrice ? token1 : token0} currencyA={invertPrice ? token1 : token0}
currencyB={invertPrice ? token0 : token1} currencyB={invertPrice ? token0 : token1}
feeAmount={feeAmount}
/> />
{outOfRange ? (
<YellowCard padding="8px 12px" borderRadius="12px">
<RowBetween>
<AlertTriangle stroke={theme.yellow3} size="16px" />
<TYPE.yellow ml="12px" fontSize="12px">
{t('inactiveRangeWarning')}
</TYPE.yellow>
</RowBetween>
</YellowCard>
) : null}
{invalidRange ? (
<YellowCard padding="8px 12px" borderRadius="12px">
<RowBetween>
<AlertTriangle stroke={theme.yellow3} size="16px" />
<TYPE.yellow ml="12px" fontSize="12px">
{t('invalidRangeWarning')}
</TYPE.yellow>
</RowBetween>
</YellowCard>
) : null}
<LightCard> <LightCard>
{v3Amount0Min && v3Amount1Min ? ( {v3Amount0Min && v3Amount1Min ? (
<LiquidityInfo token0Amount={v3Amount0Min} token1Amount={v3Amount1Min} /> <LiquidityInfo token0Amount={v3Amount0Min} token1Amount={v3Amount1Min} />
...@@ -506,6 +542,7 @@ function V2PairMigration({ ...@@ -506,6 +542,7 @@ function V2PairMigration({
signatureData !== null || signatureData !== null ||
!v3Amount0Min || !v3Amount0Min ||
!v3Amount1Min || !v3Amount1Min ||
invalidRange ||
confirmingMigration confirmingMigration
} }
onClick={approve} onClick={approve}
...@@ -526,6 +563,7 @@ function V2PairMigration({ ...@@ -526,6 +563,7 @@ function V2PairMigration({
disabled={ disabled={
!v3Amount0Min || !v3Amount0Min ||
!v3Amount1Min || !v3Amount1Min ||
invalidRange ||
(approval !== ApprovalState.APPROVED && signatureData === null) || (approval !== ApprovalState.APPROVED && signatureData === null) ||
confirmingMigration || confirmingMigration ||
isMigrationPending || isMigrationPending ||
......
...@@ -122,10 +122,10 @@ export function PositionPage({ ...@@ -122,10 +122,10 @@ export function PositionPage({
return undefined return undefined
}, [liquidity, pool, tickLower, tickUpper]) }, [liquidity, pool, tickLower, tickUpper])
const price0Lower = position ? position.token0PriceLower : undefined const price0Lower = position?.token0PriceLower
const price0Upper = position ? position.token0PriceUpper : undefined const price0Upper = position?.token0PriceUpper
const price1Lower = price0Upper ? price0Upper.invert() : undefined const price1Lower = price0Lower?.invert()
const price1Upper = price0Lower ? price0Lower.invert() : undefined const price1Upper = price0Upper?.invert()
// check if price is within range // check if price is within range
const outOfRange: boolean = const outOfRange: boolean =
...@@ -322,13 +322,13 @@ export function PositionPage({ ...@@ -322,13 +322,13 @@ export function PositionPage({
<RowFixed> <RowFixed>
<TYPE.label>{price0Lower?.toSignificant(4)}</TYPE.label> <TYPE.label>{price0Lower?.toSignificant(4)}</TYPE.label>
<TYPE.label ml="10px"> <TYPE.label ml="10px">
{currency0?.symbol} / {currency1?.symbol} {currency1?.symbol} / {currency0?.symbol}
</TYPE.label> </TYPE.label>
</RowFixed> </RowFixed>
<RowFixed> <RowFixed>
<TYPE.label>{price1Lower?.toSignificant(4)}</TYPE.label> <TYPE.label>{price1Lower?.toSignificant(4)}</TYPE.label>
<TYPE.label ml="10px"> <TYPE.label ml="10px">
{currency1?.symbol} / {currency0?.symbol} {currency0?.symbol} / {currency1?.symbol}
</TYPE.label> </TYPE.label>
</RowFixed> </RowFixed>
<DarkBadge> <DarkBadge>
...@@ -342,17 +342,17 @@ export function PositionPage({ ...@@ -342,17 +342,17 @@ export function PositionPage({
</DarkGreyCard> </DarkGreyCard>
<DarkGreyCard width="49%"> <DarkGreyCard width="49%">
<AutoColumn gap="sm" justify="flex-start"> <AutoColumn gap="sm" justify="flex-start">
<TYPE.main>Lower Limit</TYPE.main> <TYPE.main>Upper Limit</TYPE.main>
<RowFixed> <RowFixed>
<TYPE.label>{price0Upper?.toSignificant(4)}</TYPE.label> <TYPE.label>{price0Upper?.toSignificant(4)}</TYPE.label>
<TYPE.label ml="10px"> <TYPE.label ml="10px">
{currency0?.symbol} / {currency1?.symbol} {currency1?.symbol} / {currency0?.symbol}
</TYPE.label> </TYPE.label>
</RowFixed> </RowFixed>
<RowFixed> <RowFixed>
<TYPE.label>{price1Upper?.toSignificant(4)}</TYPE.label> <TYPE.label>{price1Upper?.toSignificant(4)}</TYPE.label>
<TYPE.label ml="10px"> <TYPE.label ml="10px">
{currency1?.symbol} / {currency0?.symbol} {currency0?.symbol} / {currency1?.symbol}
</TYPE.label> </TYPE.label>
</RowFixed> </RowFixed>
<DarkBadge> <DarkBadge>
......
...@@ -17,7 +17,7 @@ export enum RangeType { ...@@ -17,7 +17,7 @@ export enum RangeType {
} }
export const typeInput = createAction<{ field: Field; typedValue: string; noLiquidity: boolean }>('mint/typeInputMint') export const typeInput = createAction<{ field: Field; typedValue: string; noLiquidity: boolean }>('mint/typeInputMint')
export const typeLowerRangeInput = createAction<{ typedValue: string }>('mint/typeLowerRangeInput')
export const typeUpperRangeInput = createAction<{ typedValue: string }>('mint/typeUpperRangeInput')
export const typeStartPriceInput = createAction<{ typedValue: string }>('mint/typeStartPriceInput') export const typeStartPriceInput = createAction<{ typedValue: string }>('mint/typeStartPriceInput')
export const typeLeftRangeInput = createAction<{ typedValue: string }>('mint/typeLeftRangeInput')
export const typeRightRangeInput = createAction<{ typedValue: string }>('mint/typeRightRangeInput')
export const resetMintState = createAction<void>('mint/resetMintState') export const resetMintState = createAction<void>('mint/resetMintState')
This diff is collapsed.
...@@ -3,9 +3,9 @@ import { ...@@ -3,9 +3,9 @@ import {
Field, Field,
resetMintState, resetMintState,
typeInput, typeInput,
typeLowerRangeInput,
typeUpperRangeInput,
typeStartPriceInput, typeStartPriceInput,
typeLeftRangeInput,
typeRightRangeInput,
} from './actions' } from './actions'
export interface MintState { export interface MintState {
...@@ -13,8 +13,8 @@ export interface MintState { ...@@ -13,8 +13,8 @@ export interface MintState {
readonly typedValue: string readonly typedValue: string
readonly otherTypedValue: string // for the case when there's no liquidity readonly otherTypedValue: string // for the case when there's no liquidity
readonly startPriceTypedValue: string // for the case when there's no liquidity readonly startPriceTypedValue: string // for the case when there's no liquidity
readonly lowerRangeTypedValue: string readonly leftRangeTypedValue: string
readonly upperRangeTypedValue: string readonly rightRangeTypedValue: string
} }
export const initialState: MintState = { export const initialState: MintState = {
...@@ -22,29 +22,29 @@ export const initialState: MintState = { ...@@ -22,29 +22,29 @@ export const initialState: MintState = {
typedValue: '', typedValue: '',
otherTypedValue: '', otherTypedValue: '',
startPriceTypedValue: '', startPriceTypedValue: '',
lowerRangeTypedValue: '', leftRangeTypedValue: '',
upperRangeTypedValue: '', rightRangeTypedValue: '',
} }
export default createReducer<MintState>(initialState, (builder) => export default createReducer<MintState>(initialState, (builder) =>
builder builder
.addCase(resetMintState, () => initialState) .addCase(resetMintState, () => initialState)
.addCase(typeLowerRangeInput, (state, { payload: { typedValue } }) => { .addCase(typeStartPriceInput, (state, { payload: { typedValue } }) => {
return { return {
...state, ...state,
lowerRangeTypedValue: typedValue, startPriceTypedValue: typedValue,
} }
}) })
.addCase(typeUpperRangeInput, (state, { payload: { typedValue } }) => { .addCase(typeLeftRangeInput, (state, { payload: { typedValue } }) => {
return { return {
...state, ...state,
upperRangeTypedValue: typedValue, leftRangeTypedValue: typedValue,
} }
}) })
.addCase(typeStartPriceInput, (state, { payload: { typedValue } }) => { .addCase(typeRightRangeInput, (state, { payload: { typedValue } }) => {
return { return {
...state, ...state,
startPriceTypedValue: typedValue, rightRangeTypedValue: typedValue,
} }
}) })
.addCase(typeInput, (state, { payload: { field, typedValue, noLiquidity } }) => { .addCase(typeInput, (state, { payload: { field, typedValue, noLiquidity } }) => {
......
...@@ -18,9 +18,10 @@ export function tryParseTick( ...@@ -18,9 +18,10 @@ export function tryParseTick(
if (!amount || !amountOne) return undefined if (!amount || !amountOne) return undefined
// parse the typed value into a price, token0 should always be base currency based on url // parse the typed value into a price
const price = new Price(baseToken, quoteToken, amountOne.raw, amount.raw) const price = new Price(baseToken, quoteToken, amountOne.raw, amount.raw)
// this function is agnostic to the base, will always return the correct tick
const tick = priceToClosestTick(price) const tick = priceToClosestTick(price)
return nearestUsableTick(tick, TICK_SPACINGS[feeAmount]) return nearestUsableTick(tick, TICK_SPACINGS[feeAmount])
......
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