diff --git a/src/components/Button/index.tsx b/src/components/Button/index.tsx
index e9b27266..9f3d5100 100644
--- a/src/components/Button/index.tsx
+++ b/src/components/Button/index.tsx
@@ -344,19 +344,22 @@ const ResponsiveCheck = styled(Check)`
size: 13px;
`
-export function ButtonRadioChecked({ active = false, children, ...rest }: { active?: boolean } & ButtonProps) {
- const theme = useTheme()
-
+export function ButtonRadioChecked({
+ active = false,
+ justifyContent,
+ children,
+ ...rest
+}: { active?: boolean } & ButtonProps) {
if (!active) {
return (
- {children}
+ {children}
)
}
return (
-
+
{children}
{/*
diff --git a/src/components/FeeSelector/index.tsx b/src/components/FeeSelector/index.tsx
index 7ae8156b..d82e421e 100644
--- a/src/components/FeeSelector/index.tsx
+++ b/src/components/FeeSelector/index.tsx
@@ -41,7 +41,7 @@ const FocusedOutlineCard = styled(Card)<{ pulsing: boolean }>`
align-self: center;
`
-const Select = styled.div`
+export const Select = styled.div`
align-items: flex-start;
display: grid;
grid-auto-flow: column;
diff --git a/src/components/LiquidityChartRangeInput/index.tsx b/src/components/LiquidityChartRangeInput/index.tsx
index 3b3f7476..66b98a74 100644
--- a/src/components/LiquidityChartRangeInput/index.tsx
+++ b/src/components/LiquidityChartRangeInput/index.tsx
@@ -16,6 +16,7 @@ import { ThemedText } from 'theme/components'
import { Chart } from './Chart'
import { useDensityChartData } from './hooks'
import { ZoomLevels } from './types'
+import JSBI from 'jsbi'
const ZOOM_LEVELS: Record = {
[FeeAmount.LOWEST]: {
@@ -66,6 +67,7 @@ function InfoBox({ message, icon }: { message?: ReactNode; icon: ReactNode }) {
}
export default function LiquidityChartRangeInput({
+ rangePercentage,
currencyA,
currencyB,
feeAmount,
@@ -77,6 +79,7 @@ export default function LiquidityChartRangeInput({
onRightRangeInput,
interactive,
}: {
+ rangePercentage: number | null
currencyA?: Currency
currencyB?: Currency
feeAmount?: FeeAmount
@@ -134,13 +137,34 @@ export default function LiquidityChartRangeInput({
interactive = interactive && Boolean(formattedData?.length)
const brushDomain: [number, number] | undefined = useMemo(() => {
- const leftPrice = isSorted ? priceLower : priceUpper?.invert()
- const rightPrice = isSorted ? priceUpper : priceLower?.invert()
+ if (priceLower && priceUpper && price) {
+ if (!rangePercentage) {
+ const leftPrice = isSorted ? priceLower : priceUpper?.invert()
+ const rightPrice = isSorted ? priceUpper : priceLower?.invert()
+ return [parseFloat(leftPrice?.toSignificant(6)), parseFloat(rightPrice?.toSignificant(6))]
+ } else {
+ const percentage = JSBI.BigInt(rangePercentage) // 20%
+ const base = JSBI.BigInt(100) // 100 to represent the whole
+ // Calculate the percentage value
+ const percentageValue = JSBI.divide(JSBI.multiply(JSBI.BigInt(Math.floor(price)), percentage), base)
+
+ const leftPriceWithPercentage = JSBI.subtract(JSBI.BigInt(Math.floor(price)), percentageValue)
+ const rightPriceWithPercentage = JSBI.add(JSBI.BigInt(Math.floor(price)), percentageValue)
+
+ // Combine with the base number
+ const leftPriceWithScaledPercentage =
+ Number(leftPriceWithPercentage) - Math.round(Math.random() * 10000) / 10000
+ const rightPriceWithScaledPercentage =
+ Number(rightPriceWithPercentage) + Math.round(Math.random() * 10000) / 10000
+ return [
+ parseFloat(leftPriceWithScaledPercentage.toString()),
+ parseFloat(rightPriceWithScaledPercentage.toString()),
+ ]
+ }
+ }
- return leftPrice && rightPrice
- ? [parseFloat(leftPrice?.toSignificant(6)), parseFloat(rightPrice?.toSignificant(6))]
- : undefined
- }, [isSorted, priceLower, priceUpper])
+ return undefined
+ }, [priceLower, priceUpper, rangePercentage])
const brushLabelValue = useCallback(
(d: 'w' | 'e', x: number) => {
@@ -157,10 +181,10 @@ export default function LiquidityChartRangeInput({
)
const isUninitialized = !currencyA || !currencyB || (formattedData === undefined && !isLoading)
-
+ console.log(formattedData, currencyA, currencyB)
return (
- {isUninitialized ? (
+ {/* {isUninitialized ? (
Your position will appear here.}
icon={}
@@ -177,10 +201,11 @@ export default function LiquidityChartRangeInput({
message={There is no liquidity data.}
icon={}
/>
- ) : (
+ ) : ( */}
+ {price && (
)}
+ {/* )} */}
)
}
diff --git a/src/components/RangeSelector/index.tsx b/src/components/RangeSelector/index.tsx
index 53f41a40..d2c082de 100644
--- a/src/components/RangeSelector/index.tsx
+++ b/src/components/RangeSelector/index.tsx
@@ -2,10 +2,14 @@ import { Trans } from '@lingui/macro'
import { Currency, Price, Token } from '@vnaysn/jediswap-sdk-core'
import StepCounter from 'components/InputStepCounter/InputStepCounter'
import { AutoRow } from 'components/Row'
+import JSBI from 'jsbi'
+import { useMemo } from 'react'
import { Bound } from 'state/mint/v3/actions'
// currencyA is the base token
export default function RangeSelector({
+ price,
+ rangePercentage,
priceLower,
priceUpper,
onLeftRangeInput,
@@ -15,6 +19,8 @@ export default function RangeSelector({
feeAmount,
ticksAtLimit,
}: {
+ price: any
+ rangePercentage: number | null
priceLower?: Price
priceUpper?: Price
onLeftRangeInput: (typedValue: string) => void
@@ -28,13 +34,40 @@ export default function RangeSelector({
const tokenB = (currencyB ?? undefined)?.wrapped
const isSorted = tokenA && tokenB && tokenA.sortsBefore(tokenB)
- const leftPrice = isSorted ? priceLower : priceUpper?.invert()
- const rightPrice = isSorted ? priceUpper : priceLower?.invert()
+ const { leftPrice, rightPrice } = useMemo(() => {
+ if (priceLower && priceUpper) {
+ if (!rangePercentage) {
+ const leftPrice = isSorted ? priceLower : priceUpper?.invert()
+ const rightPrice = isSorted ? priceUpper : priceLower?.invert()
+ return { leftPrice: leftPrice.toSignificant(8), rightPrice: rightPrice.toSignificant(8) }
+ } else {
+ const percentage = JSBI.BigInt(rangePercentage) // 20%
+ const base = JSBI.BigInt(100) // 100 to represent the whole
+ // Calculate the percentage value
+ const percentageValue = JSBI.divide(JSBI.multiply(JSBI.BigInt(parseInt(price)), percentage), base)
+
+ const leftPriceWithPercentage = JSBI.subtract(JSBI.BigInt(parseInt(price)), percentageValue)
+ const rightPriceWithPercentage = JSBI.add(JSBI.BigInt(parseInt(price)), percentageValue)
+
+ // Combine with the base number
+ const leftPriceWithScaledPercentage =
+ Number(leftPriceWithPercentage) - Math.round(Math.random() * 10000) / 10000
+ const rightPriceWithScaledPercentage =
+ Number(rightPriceWithPercentage) + Math.round(Math.random() * 10000) / 10000
+ return {
+ leftPrice: leftPriceWithScaledPercentage.toString(),
+ rightPrice: rightPriceWithScaledPercentage.toString(),
+ }
+ }
+ }
+
+ return { leftPrice: undefined, rightPrice: undefined }
+ }, [priceLower, priceUpper, rangePercentage])
return (
(null)
const [mintCallData, setMintCallData] = useState([])
const {
@@ -156,7 +164,7 @@ function AddLiquidity() {
const invalidPool = false
const { onFieldAInput, onFieldBInput, onLeftRangeInput, onRightRangeInput, onStartPriceInput } =
- useV3MintActionHandlers(noLiquidity)
+ useV3MintActionHandlers(noLiquidity, setRangePercentage)
const { writeAsync, data: txData } = useContractWrite({
calls: mintCallData,
@@ -394,6 +402,7 @@ function AddLiquidity() {
const handleFeePoolSelect = useCallback(
(newFeeAmount: FeeAmount) => {
+ setRangePercentage(null)
onLeftRangeInput('')
onRightRangeInput('')
navigate(`/add/${currencyIdA}/${currencyIdB}/${newFeeAmount}`)
@@ -415,6 +424,7 @@ function AddLiquidity() {
const addIsUnsupported = useIsSwapUnsupported(currencies?.CURRENCY_A, currencies?.CURRENCY_B)
const clearAll = useCallback(() => {
+ setRangePercentage(null)
onFieldAInput('')
onFieldBInput('')
onLeftRangeInput('')
@@ -530,10 +540,9 @@ function AddLiquidity() {
[usdcValueCurrencyB]
)
- // const owner = useSingleCallResult(tokenId ? positionManager : null, 'ownerOf', [tokenId]).result?.[0]
- // const ownsNFT =
- // addressesAreEquivalent(owner, account) || addressesAreEquivalent(existingPositionDetails?.operator, account)
- // const showOwnershipWarning = Boolean(hasExistingPosition && account && !ownsNFT)
+ const handleRange = (p: number) => {
+ setRangePercentage(p)
+ }
return (
<>
@@ -684,19 +693,11 @@ function AddLiquidity() {
)}
- {/* */}
)}
+ {baseCurrency && quoteCurrency && feeAmount && (
+
+
+ {rangePercentages.map((percentage) => (
+ handleRange(percentage)}
+ style={{
+ border: '1px solid #444',
+ borderRadius: '8px',
+ justifyContent: 'center',
+ width: 80,
+ height: 25,
+ }}
+ >
+
+ {percentage}%
+
+
+ ))}
+
+
+ )}
+
+
>
) : (
diff --git a/src/state/mint/v3/hooks.tsx b/src/state/mint/v3/hooks.tsx
index 666bb2b6..f8aaa1b6 100644
--- a/src/state/mint/v3/hooks.tsx
+++ b/src/state/mint/v3/hooks.tsx
@@ -39,7 +39,10 @@ export function useV3MintState(): AppState['mintV3'] {
return useAppSelector((state) => state.mintV3)
}
-export function useV3MintActionHandlers(noLiquidity: boolean | undefined): {
+export function useV3MintActionHandlers(
+ noLiquidity: boolean | undefined,
+ setRangePercentage: any
+): {
onFieldAInput: (typedValue: string) => void
onFieldBInput: (typedValue: string) => void
onLeftRangeInput: (typedValue: string) => void
@@ -66,6 +69,7 @@ export function useV3MintActionHandlers(noLiquidity: boolean | undefined): {
const onLeftRangeInput = useCallback(
(typedValue: string) => {
+ setRangePercentage(null)
dispatch(typeLeftRangeInput({ typedValue }))
const paramMinPrice = searchParams.get('minPrice')
if (!paramMinPrice || (paramMinPrice && paramMinPrice !== typedValue)) {
@@ -78,6 +82,7 @@ export function useV3MintActionHandlers(noLiquidity: boolean | undefined): {
const onRightRangeInput = useCallback(
(typedValue: string) => {
+ setRangePercentage(null)
dispatch(typeRightRangeInput({ typedValue }))
const paramMaxPrice = searchParams.get('maxPrice')
if (!paramMaxPrice || (paramMaxPrice && paramMaxPrice !== typedValue)) {