Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core-mobile/app/consts/reactQueryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export enum ReactQueryKeys {
NETWORK_CONTRACT_TOKENS = 'networkContractTokens',
WATCHLIST_TOP_TOKENS = 'watchlistTopTokens',
WATCHLIST_TRENDING_TOKENS = 'watchlistTrendingTokens',
WATCHLIST_PRICES = 'watchlistPrices',
WATCHLIST_TOKEN_SEARCH = 'watchlistTokenSearch',
LAST_TRANSACTED_ERC20_NETWORKS = 'lastTransactedErc20Networks',

Expand Down

This file was deleted.

This file was deleted.

14 changes: 9 additions & 5 deletions packages/core-mobile/app/hooks/useSimplePrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import { Prices } from 'features/bridge/hooks/useBridge'
import { useQuery, UseQueryResult } from '@tanstack/react-query'
import { ReactQueryKeys } from 'consts/reactQueryKeys'

const REFETCH_INTERVAL = 10000 // 10 seconds

export const useSimplePrices = (
coinIds: string[],
coingeckoIds: string[],
currency: VsCurrencyType
): UseQueryResult<Prices | undefined, Error> => {
return useQuery({
enabled: coinIds.length > 0,
queryKey: [ReactQueryKeys.SIMPLE_PRICES, coinIds, currency],
enabled: coingeckoIds.length > 0,
refetchInterval: REFETCH_INTERVAL,
queryKey: [ReactQueryKeys.SIMPLE_PRICES, coingeckoIds, currency],
queryFn: async () =>
TokenService.getSimplePrice({
coinIds,
currency: currency.toLowerCase() as VsCurrencyType
coinIds: coingeckoIds,
currency: currency.toLowerCase() as VsCurrencyType,
includeMarketData: false
}),
select: data => {
if (data === undefined) {
Expand Down
30 changes: 0 additions & 30 deletions packages/core-mobile/app/hooks/watchlist/useGetPrices.ts

This file was deleted.

7 changes: 5 additions & 2 deletions packages/core-mobile/app/hooks/watchlist/useTopTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { ReactQueryKeys } from 'consts/reactQueryKeys'
import { useSelector } from 'react-redux'
import WatchlistService from 'services/watchlist/WatchlistService'
import { selectSelectedCurrency } from 'store/settings/currency'
import { TokensAndCharts } from 'store/watchlist'
import { Charts, MarketToken, Prices } from 'store/watchlist'
import { runAfterInteractions } from 'utils/runAfterInteractions'

export const useTopTokens = (): UseQueryResult<TokensAndCharts, Error> => {
export const useTopTokens = (): UseQueryResult<
{ tokens: Record<string, MarketToken>; charts: Charts; prices: Prices },
Error
> => {
const currency = useSelector(selectSelectedCurrency)
const isFocused = useIsFocused()

Expand Down
37 changes: 2 additions & 35 deletions packages/core-mobile/app/hooks/watchlist/useWatchlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import {
import { useSelector } from 'react-redux'
import { ChartData } from 'services/token/types'
import { transformTrendingTokens } from 'services/watchlist/utils/transform'
import { useIsFocused } from '@react-navigation/native'
import { LocalTokenWithBalance } from 'store/balance/types'
import { getCaip2ChainIdForToken } from 'utils/caip2ChainIds'
import { isNetworkContractToken } from 'utils/isNetworkContractToken'
import { useGetPrices } from './useGetPrices'
import { useTopTokens } from './useTopTokens'
import { useGetTrendingTokens } from './useGetTrendingTokens'

Expand Down Expand Up @@ -61,37 +59,6 @@ export const useWatchlist = (): UseWatchListReturnType => {
[trendingTokensResponse]
)

const topTokensCoingeckoIds = useMemo(() => {
return Object.values(topTokensResponse?.tokens ?? {})
.map(token => token.coingeckoId)
.filter((id): id is string => typeof id === 'string')
}, [topTokensResponse?.tokens])

const isFocused = useIsFocused()

const { data: topTokenPrices } = useGetPrices({
coingeckoIds: topTokensCoingeckoIds,
enabled: isFocused && topTokensCoingeckoIds.length > 0
})

// Map prices from coingeckoId back to internalId for consistent access
const topTokenPricesById = useMemo(() => {
if (!topTokenPrices || !topTokensResponse?.tokens) {
return {}
}

const pricesById: Prices = {}
Object.values(topTokensResponse.tokens).forEach(token => {
const price = token.coingeckoId
? topTokenPrices[token.coingeckoId]
: undefined
if (price) {
pricesById[token.id] = price
}
})
return pricesById
}, [topTokenPrices, topTokensResponse?.tokens])

const isLoadingFavorites = favoriteIds.length > 0 && isLoading

const favorites = useMemo(() => {
Expand Down Expand Up @@ -150,9 +117,9 @@ export const useWatchlist = (): UseWatchListReturnType => {
const prices = useMemo(() => {
return {
...transformedTrendingTokens?.prices,
...topTokenPricesById
...topTokensResponse?.prices
}
}, [topTokenPricesById, transformedTrendingTokens?.prices])
}, [topTokensResponse?.prices, transformedTrendingTokens?.prices])

const getWatchlistPrice = useCallback(
(id: string): PriceData | undefined => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export const useWatchlistListener = (): void => {
matcher: isAnyOf(toggleDeveloperMode, fetchWatchlist),
effect: async () => {
await queryClient.invalidateQueries({
queryKey: [
ReactQueryKeys.WATCHLIST_TOP_TOKENS,
ReactQueryKeys.WATCHLIST_PRICES
]
queryKey: [ReactQueryKeys.WATCHLIST_TOP_TOKENS]
})
}
})
Expand Down
4 changes: 2 additions & 2 deletions packages/core-mobile/app/new/common/hooks/useMarketToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export const useMarketToken = ({

const resolvedMarketToken = resolveMarketToken(token)
if (errorContext && !resolvedMarketToken) {
Logger.error(`[${errorContext}] Market token not found`, {
Logger.warn(`[${errorContext}] Market token not found`, {
symbol: token.symbol
})
}
if (
errorContext &&
resolvedMarketToken?.priceChangePercentage24h === undefined
) {
Logger.error(
Logger.warn(
`[${errorContext}] Market token priceChangePercentage24h is undefined`,
{
symbol: token.symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
showAlertWithTextInput
} from 'common/utils/alertWithTextInput'
import { GAS_LIMIT_FOR_X_CHAIN } from 'consts/fees'
import { useNativeTokenPriceForNetwork } from 'hooks/networks/useNativeTokenPriceForNetwork'
import { useNetworks } from 'hooks/networks/useNetworks'
import { useNetworkFee } from 'hooks/useNetworkFee'
import { useCallback, useEffect, useMemo, useState } from 'react'
Expand All @@ -18,6 +17,7 @@ import { isAvmNetwork } from 'utils/network/isAvalancheNetwork'
import { sanitizeDecimalInput } from 'utils/units/sanitize'
import { calculateGasAndFees, Eip1559Fees, GasAndFees } from 'utils/Utils'
import { normalizeNumericTextInput } from '@avalabs/k2-alpine/src/utils/tokenUnitInput'
import { useSimplePrices } from 'hooks/useSimplePrices'
import {
DEFAULT_NETWORK_TOKEN_DECIMALS,
DEFAULT_NETWORK_TOKEN_SYMBOL
Expand Down Expand Up @@ -70,10 +70,12 @@ export const useNetworkFeeSelector = ({
const feeDecimals = networkFee?.displayDecimals
const isBaseUnitRate = feeDecimals === undefined

const { nativeTokenPrice } = useNativeTokenPriceForNetwork(
network,
const { data } = useSimplePrices(
[network?.pricingProviders?.coingecko.nativeTokenId ?? ''],
selectedCurrency.toLowerCase() as VsCurrencyType
)
const nativeTokenPrice =
data?.[network?.pricingProviders?.coingecko.nativeTokenId ?? ''] ?? 0

const isAvalancheCChain = network
? isAvalancheCChainId(network.chainId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TokenUnit } from '@avalabs/core-utils-sdk'
import { SxProp, Text, View } from '@avalabs/k2-alpine'
import { useFormatCurrency } from 'common/hooks/useFormatCurrency'
import { UNKNOWN_AMOUNT } from 'consts/amount'
import { useAvaxTokenPriceInSelectedCurrency } from 'hooks/useAvaxTokenPriceInSelectedCurrency'
import { useAvaxPrice } from 'features/portfolio/hooks/useAvaxPrice'
import React from 'react'

export const StakeTokenUnitValue = ({
Expand All @@ -14,7 +14,7 @@ export const StakeTokenUnitValue = ({
isReward?: boolean
textSx?: SxProp
}): JSX.Element => {
const avaxPrice = useAvaxTokenPriceInSelectedCurrency()
const avaxPrice = useAvaxPrice()
const { formatCurrency } = useFormatCurrency()
const valueInCurrency = value?.mul(avaxPrice)
const valueInCurrencyDisplay = valueInCurrency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { useRouter } from 'expo-router'
import { StakeTokenUnitValue } from 'features/stake/components/StakeTokenUnitValue'
import { useClaimRewards } from 'hooks/earn/useClaimRewards'
import { usePChainBalance } from 'hooks/earn/usePChainBalance'
import { useAvaxTokenPriceInSelectedCurrency } from 'hooks/useAvaxTokenPriceInSelectedCurrency'
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useSelector } from 'react-redux'
import AnalyticsService from 'services/analytics/AnalyticsService'
import NetworkService from 'services/network/NetworkService'
import { selectIsDeveloperMode } from 'store/settings/advanced'
import { useRefreshStakingBalances } from 'hooks/earn/useRefreshStakingBalances'
import { useAvaxPrice } from 'features/portfolio/hooks/useAvaxPrice'

export const ClaimStakeRewardScreen = (): JSX.Element => {
const { navigate, back } = useRouter()
Expand All @@ -37,7 +37,7 @@ export const ClaimStakeRewardScreen = (): JSX.Element => {
useState<TokenUnit>()
const isDeveloperMode = useSelector(selectIsDeveloperMode)
const pNetwork = NetworkService.getAvalancheNetworkP(isDeveloperMode)
const avaxPrice = useAvaxTokenPriceInSelectedCurrency()
const avaxPrice = useAvaxPrice()
const refreshStakingBalances = useRefreshStakingBalances()
const onClaimSuccess = (): void => {
refreshStakingBalances({ shouldRefreshStakes: false })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import {
useTheme,
View
} from '@avalabs/k2-alpine'
import { useIsFocused } from '@react-navigation/native'
import { TokenLogo } from 'common/components/TokenLogo'
import { useFormatCurrency } from 'common/hooks/useFormatCurrency'
import { useTokenDetails } from 'common/hooks/useTokenDetails'
import { UNKNOWN_AMOUNT } from 'consts/amount'
import SparklineChart from 'features/track/components/SparklineChart'
import { useGetPrices } from 'hooks/watchlist/useGetPrices'
import React, { useMemo } from 'react'
import { MarketType } from 'store/watchlist'
import { formatLargeCurrency } from 'utils/Utils'
Expand All @@ -30,27 +28,14 @@ export const ShareChart = ({
}): JSX.Element => {
const { theme } = useTheme()
const { theme: inversedTheme } = useInversedTheme({ isDark: theme.isDark })
const { chartData, ranges, coingeckoId, tokenInfo, token } = useTokenDetails({
const { chartData, ranges, tokenInfo, token } = useTokenDetails({
tokenId,
marketType
})
const isFocused = useIsFocused()

const { data: prices } = useGetPrices({
coingeckoIds: [coingeckoId],
enabled:
isFocused &&
tokenInfo?.currentPrice === undefined &&
coingeckoId.length > 0
})

const currentPrice = useMemo(() => {
return (
tokenInfo?.currentPrice ??
prices?.[coingeckoId]?.priceInCurrency ??
token?.currentPrice
)
}, [tokenInfo?.currentPrice, prices, coingeckoId, token?.currentPrice])
return tokenInfo?.currentPrice ?? token?.currentPrice
}, [tokenInfo?.currentPrice, token?.currentPrice])

const range = useMemo(() => {
return {
Expand Down
Loading
Loading