Skip to content

Commit

Permalink
fix: logic to revert the default price
Browse files Browse the repository at this point in the history
  • Loading branch information
tienkane committed Feb 27, 2025
1 parent c15ce99 commit a9058df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@kyberswap/ks-sdk-classic": "^1.0.3",
"@kyberswap/ks-sdk-core": "1.1.9",
"@kyberswap/ks-sdk-elastic": "^1.1.2",
"kane4-liquidity-widgets": "1.1.33",
"kane4-liquidity-widgets": "1.1.34",
"kane4-zap-migration-widgets": "1.0.8",
"kane4-liquidity-chart": "1.0.43",
"@kyberswap/oauth2": "1.0.2",
Expand Down
13 changes: 10 additions & 3 deletions src/pages/Earns/PositionDetail/RightSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { usePoolDetailQuery } from 'services/poolService'

import { Swap as SwapIcon } from 'components/Icons'
import { NativeCurrencies } from 'constants/tokens'
import { useStableCoins } from 'hooks/Tokens'
import useTheme from 'hooks/useTheme'
import { formatDisplayNumber, toString } from 'utils/numbers'

Expand All @@ -16,6 +17,7 @@ import { MAX_TICK, MIN_TICK, nearestUsableTick, priceToClosestTick } from './uni

const RightSection = ({ position }: { position: ParsedPosition }) => {
const theme = useTheme()
const { stableCoins } = useStableCoins(position.chainId)
const { data: pool } = usePoolDetailQuery({ chainId: position.chainId, ids: position.poolAddress })
const [revert, setRevert] = useState(false)
const [defaultRevertChecked, setDefaultRevertChecked] = useState(false)
Expand Down Expand Up @@ -55,13 +57,18 @@ const RightSection = ({ position }: { position: ParsedPosition }) => {
}, [pool, position, revert])

useEffect(() => {
if (!pool || !position.chainId || !pool.tokens?.[0] || defaultRevertChecked) return
if (!pool || !position.chainId || !pool.tokens?.[0] || defaultRevertChecked || !stableCoins.length) return
setDefaultRevertChecked(true)
const isToken0Native =
pool.tokens[0].address.toLowerCase() ===
NativeCurrencies[position.chainId as ChainId].wrapped.address.toLowerCase()
if (isToken0Native) setRevert(true)
}, [defaultRevertChecked, pool, position.chainId])
const isToken1Native =
pool.tokens[1].address.toLowerCase() ===
NativeCurrencies[position.chainId as ChainId].wrapped.address.toLowerCase()
const isToken0Stable = stableCoins.some(coin => coin.address === pool.tokens[0].address)
const isToken1Stable = stableCoins.some(coin => coin.address === pool.tokens[1].address)
if ((isToken0Native && !isToken1Stable) || (isToken1Native && isToken0Stable)) setRevert(true)
}, [defaultRevertChecked, pool, position.chainId, stableCoins])

return (
<InfoRightColumn>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14090,10 +14090,10 @@ [email protected]:
d3 "^7.9.0"
lodash.partition "^4.6.0"

[email protected].33:
version "1.1.33"
resolved "https://registry.yarnpkg.com/kane4-liquidity-widgets/-/kane4-liquidity-widgets-1.1.33.tgz#64b0601940ff481927f079d276e8d38ad0b2a6ff"
integrity sha512-Hh0T1zWXqtYNOEt5vTgMGesz1ZF76t2/cJBJhimOuI03D5k3NWdbbPm1y2ZThjY39rjoLNFkPC3QliI5Zj5Xjg==
[email protected].34:
version "1.1.34"
resolved "https://registry.yarnpkg.com/kane4-liquidity-widgets/-/kane4-liquidity-widgets-1.1.34.tgz#1afeab8cfae44b2f9250dfb5275b8b189608aea4"
integrity sha512-a0c4aKcpqmMo14/TdogGkxpC8JssKaqAICY7SGvPHXVq9f8qoMniTQem3M1PmxGc08PVfXu/qERsxsCt3wM8cQ==
dependencies:
"@popperjs/core" "^2.11.8"
"@radix-ui/react-accordion" "^1.2.1"
Expand Down

0 comments on commit a9058df

Please sign in to comment.