Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vkulinich-cl committed Dec 11, 2024
1 parent 0ef5e75 commit 8badd5b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/api/xyk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ import { isNotNil, undefinedNoop } from "utils/helpers"
import { useAssetRegistry } from "state/store"
import { useActiveRpcUrlList, useProviderData } from "./provider"
import { PoolBase } from "@galacticcouncil/sdk"
import { millisecondsInMinute } from "date-fns"

const getAllXYKPools = (api: ApiPromise) => async () => {
const res = await api.query.xyk.poolAssets.entries()

const data = res.map(([key, data]) => {
const poolAddress = key.args[0].toString()
const assets = data.unwrap()?.map((el) => el.toString())
return { poolAddress, assets }
})

return data
}

export const useAllXykPools = () => {
const { api, isLoaded } = useRpcProvider()

return useQuery(QUERY_KEYS.allXykPools, getAllXYKPools(api), {
enabled: isLoaded,
staleTime: millisecondsInMinute,
})
}

export const useXYKPools = () => {
return useQuery<PoolBase[]>(QUERY_KEYS.xykPools, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Text } from "components/Typography/Text/Text"
import { useTranslation } from "react-i18next"
import { TExternalAsset } from "sections/wallet/addToken/AddToken.utils"
import { useMemo } from "react"
import { useXYKPools } from "api/xyk"
import { useAllXykPools } from "api/xyk"
import { DisplayValue } from "components/DisplayValue/DisplayValue"
import { BN_0 } from "utils/constants"
import { useExternalXYKVolume } from "./TokenInfo.utils"
Expand Down Expand Up @@ -45,7 +45,7 @@ export const TokenInfo = ({
const { setIsWhiteListed } = useUserExternalTokenStore()
const refetchProvider = useRefetchProviderData()
const parachains = useParachainAmount(externalAsset.id)
const { data: xykPools } = useXYKPools()
const { data: xykPools } = useAllXykPools()
const { totalSupplyInternal, totalSupplyExternal } = rugCheckData ?? {}
const externalAssetRegistry = useExternalAssetRegistry()
const refetchAssetHub = externalAssetRegistry[assethub.parachainId].refetch
Expand Down Expand Up @@ -79,13 +79,13 @@ export const TokenInfo = ({

if (chainAsset) {
const filteredXykPools = xykPools.filter((shareToken) =>
shareToken.tokens.some((token) => token.id === chainAsset.id),
shareToken.assets.includes(chainAsset.id),
)

return {
chainAsset,
isXYKPool: filteredXykPools.length,
pools: filteredXykPools.map((pool) => pool.address),
pools: filteredXykPools.map((pool) => pool.poolAddress),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export const QUERY_KEYS = {
block,
],
xykPools: ["xykPools"],
allXykPools: ["allXykPools"],
xykConsts: ["xykConsts"],
shareTokens: (rpc: string) => ["shareTokens", rpc],
totalXYKLiquidity: (address?: string) => [
Expand Down

0 comments on commit 8badd5b

Please sign in to comment.