Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vkulinich-cl committed Dec 23, 2024
1 parent d3ad499 commit 539ecf8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/api/xyk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useAllXykPools = () => {
})
}

export const useXYKPools = () => {
export const useXYKSDKPools = () => {
return useQuery<PoolBase[]>(QUERY_KEYS.xykPools, {
enabled: false,
staleTime: Infinity,
Expand Down
14 changes: 13 additions & 1 deletion src/components/Layout/Header/DegenMode/DegenMode.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "sections/wallet/addToken/AddToken.utils"
import { useSettingsStore } from "state/store"
import { useAssets } from "providers/assets"
import { useQueryClient } from "@tanstack/react-query"
import { QUERY_KEYS } from "utils/queryKeys"

export const useDegenModeSubscription = () => {
const { external, externalInvalid } = useAssets()
Expand All @@ -16,6 +18,7 @@ export const useDegenModeSubscription = () => {
const { getDataEnv } = useProviderRpcUrlStore()
const refetchProvider = useRefetchProviderData()
const { isLoaded, poolService } = useRpcProvider()
const queryClient = useQueryClient()

const hasInitializedDegenMode = useRef(false)

Expand Down Expand Up @@ -67,8 +70,17 @@ export const useDegenModeSubscription = () => {
poolService.syncRegistry(data)
hasInitializedDegenMode.current = true
refetchProvider()
queryClient.invalidateQueries(QUERY_KEYS.pools)
}
}, [degenMode, data, getDataEnv, isSuccess, refetchProvider, poolService])
}, [
degenMode,
data,
getDataEnv,
isSuccess,
refetchProvider,
poolService,
queryClient,
])

// Subscribe to degenMode change to update ExternalAssetCursor
useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/sections/pools/PoolsPage.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export const useXYKPools = () => {
const tvlDisplay =
shareTokenIssuance?.totalShare
?.shiftedBy(-shareToken.decimals)
?.multipliedBy(shareTokenSpotPrice?.spotPrice ?? 1) ?? BN_0
?.multipliedBy(shareTokenSpotPrice?.spotPrice ?? BN_NAN) ?? BN_NAN

const volume = volumes?.find(
(volume) => volume.poolAddress === poolAddress,
Expand Down Expand Up @@ -372,6 +372,9 @@ export const useXYKPools = () => {
if (a.isInvalid) return 1
if (b.isInvalid) return -1

if (a.tvlDisplay.isNaN()) return 1
if (b.tvlDisplay.isNaN()) return -1

return b.tvlDisplay.minus(a.tvlDisplay).toNumber()
})
}, [
Expand Down
4 changes: 2 additions & 2 deletions src/sections/pools/farms/position/FarmingPosition.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useDisplayShareTokenPrice } from "utils/displayAsset"
import { TShareToken, useAssets } from "providers/assets"
import { scaleHuman } from "utils/balance"
import { useTotalIssuances } from "api/totalIssuance"
import { useXYKPools } from "api/xyk"
import { useXYKSDKPools } from "api/xyk"

type TokenAmount = {
id: string
Expand Down Expand Up @@ -89,7 +89,7 @@ export const useAllXYKDeposits = (address?: string) => {

const issuances = useTotalIssuances()
const shareTokeSpotPrices = useDisplayShareTokenPrice(uniqAssetIds)
const { data: xykPools, isLoading: isXykPoolsLoading } = useXYKPools()
const { data: xykPools, isLoading: isXykPoolsLoading } = useXYKSDKPools()

const isLoading =
isXykPoolsLoading ||
Expand Down
4 changes: 2 additions & 2 deletions src/sections/pools/modals/CreateXYKPool/CreateXYKPool.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useXYKPools } from "api/xyk"
import { useXYKSDKPools } from "api/xyk"
import { useMemo, useState } from "react"
import { AssetsModalContent } from "sections/assets/AssetsModal"
import { CreateXYKPoolForm } from "./CreateXYKPoolForm"
Expand Down Expand Up @@ -44,7 +44,7 @@ export const CreateXYKPool = ({
onAssetSelectClose,
children,
}: CreateXYKPoolProps) => {
const { data: xykPools } = useXYKPools()
const { data: xykPools } = useXYKSDKPools()

const allowedAssets = useAllowedXYKPoolAssets()
const allowedAssetIds = allowedAssets.map(({ id }) => id)
Expand Down
4 changes: 2 additions & 2 deletions src/sections/pools/pool/details/PoolDetails.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMemo } from "react"
import { useDisplayPrices } from "utils/displayAsset"
import { TShareToken, useAssets } from "providers/assets"
import BN from "bignumber.js"
import { BN_NAN } from "utils/constants"

export const useXYKPoolTradeVolumes = (shareTokens: TShareToken[]) => {
const { getAssetWithFallback } = useAssets()
Expand All @@ -11,7 +12,6 @@ export const useXYKPoolTradeVolumes = (shareTokens: TShareToken[]) => {
useXYKSquidVolumes(shareTokens.map((shareToken) => shareToken.poolAddress))

const allAssetsInPools = [...new Set(volumes.map((volume) => volume.assetId))]

const spotPrices = useDisplayPrices(allAssetsInPools)
const isLoading = spotPrices.isInitialLoading || isVolumesLoading

Expand All @@ -26,7 +26,7 @@ export const useXYKPoolTradeVolumes = (shareTokens: TShareToken[]) => {

const volume = BN(value.volume)
.shiftedBy(-assetMeta.decimals)
.multipliedBy(spotPrice ?? 1)
.multipliedBy(spotPrice ?? BN_NAN)
.toFixed(3)

return { volume, poolAddress: value.poolId, assetMeta }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useAccountAssets } from "api/deposits"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { useTotalIssuances } from "api/totalIssuance"
import BigNumber from "bignumber.js"
import { useXYKPools } from "api/xyk"
import { useXYKSDKPools } from "api/xyk"

export const useOmnipoolPositionsData = ({
search,
Expand Down Expand Up @@ -66,7 +66,7 @@ export const useXykPositionsData = ({ search }: { search?: string } = {}) => {

const shareTokensId = accountShareTokens.map((pool) => pool.asset.id)

const { data: xykPools, isLoading: isXykPoolsLoading } = useXYKPools()
const { data: xykPools, isLoading: isXykPoolsLoading } = useXYKSDKPools()
const { data: totalIssuances, isLoading: isIssuancesLoading } =
useTotalIssuances()
const spotPrices = useDisplayShareTokenPrice(shareTokensId)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/displayAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { QUERY_KEYS } from "./queryKeys"
import { isNotNil } from "./helpers"
import { TShareToken, useAssets } from "providers/assets"
import { useTotalIssuances } from "api/totalIssuance"
import { useXYKPools } from "api/xyk"
import { useXYKSDKPools } from "api/xyk"

type Props = { id: string; amount: BigNumber }

Expand Down Expand Up @@ -61,7 +61,7 @@ export const useDisplayShareTokenPrice = (ids: string[]) => {
const { getShareTokens, getAssetWithFallback } = useAssets()
const pools = getShareTokens(ids) as TShareToken[]

const { data: xykPools = [], isLoading: isPoolsLoading } = useXYKPools()
const { data: xykPools = [], isLoading: isPoolsLoading } = useXYKSDKPools()
const { data: issuances, isLoading: isIssuanceLoading } = useTotalIssuances()

const shareTokensTvl = useMemo(() => {
Expand Down

0 comments on commit 539ecf8

Please sign in to comment.